Migrate to simplified implementation using improved client/server model and proper dependency injection

This commit is contained in:
2015-06-21 14:52:18 +01:00
parent 20a235781d
commit 50567a9846
19 changed files with 136 additions and 407 deletions

View File

@@ -32,8 +32,6 @@ repositories {
} }
dependencies { dependencies {
compile 'org.slf4j:slf4j-api:1.7.12'
compile 'org.slf4j:slf4j-log4j12:1.7.12'
compile 'org.picocontainer:picocontainer:2.15' compile 'org.picocontainer:picocontainer:2.15'
compile 'com.github.boukefalos:jlibusb:0.5.7' compile 'com.github.boukefalos:jlibusb:0.5.7'
} }

View File

@@ -2,76 +2,45 @@ package com.github.boukefalos.ibuddy;
import java.util.Properties; import java.util.Properties;
import org.picocontainer.Parameter; import base.exception.LoaderException;
import org.picocontainer.parameters.ConstantParameter;
import base.loader.AbstractLoader; import base.loader.AbstractLoader;
import base.work.Work;
import com.github.boukefalos.ibuddy.client.iBuddyTcpClient; import com.github.boukefalos.ibuddy.implementation.Local;
import com.github.boukefalos.ibuddy.implementation.LocalImplementation; import com.github.boukefalos.ibuddy.implementation.Remote;
import com.github.boukefalos.ibuddy.implementation.TcpImplementation;
import com.github.boukefalos.ibuddy.implementation.UdpImplementation;
import com.github.boukefalos.ibuddy.server.iBuddyServer;
import com.github.boukefalos.ibuddy.server.iBuddyTcpServer;
import com.github.boukefalos.ibuddy.server.iBuddyUdpServer;
public class Loader extends AbstractLoader { public class Loader extends AbstractLoader<Loader> {
protected static final String PROPERTIES_FILE = "ibuddy.properties"; protected static final String PROPERTIES_FILE = "ibuddy.properties";
public Loader(Properties properties) { public Loader(Properties properties) throws LoaderException {
super(); super();
/* Add implementation */ /* Add implementation */
switch (properties.getProperty("implementation")) { switch (properties.getProperty("implementation")) {
case "local": case "local":
pico.addComponent(LocalImplementation.class); pico.addComponent(Local.class);
break; break;
case "remote": case "remote":
//pico.addComponent(Remote.class); pico.addComponent(Remote.class);
break;
}
/* Add protocol */ /* Add sender implementation */
if (properties.getProperty("protocol") != null) { addSender(properties);
switch (properties.getProperty("protocol")) { break;
case "tcp":
pico.addComponent(TcpImplementation.class, TcpImplementation.class, new Parameter[]{
new ConstantParameter(properties.getProperty("remote.host")),
new ConstantParameter(Integer.valueOf(properties.getProperty("remote.port")))});
break;
case "udp":
pico.addComponent(UdpImplementation.class, UdpImplementation.class, new Parameter[] {
new ConstantParameter(properties.getProperty("remote.host")),
new ConstantParameter(Integer.valueOf(properties.getProperty("remote.port")))});
break;
}
} }
/* Add server */ /* Add server */
if (properties.getProperty("server") != null) { if (properties.getProperty("server") != null) {
switch (properties.getProperty("server.protocol")) { pico.addComponent(Server.class);
case "tcp":
pico.addComponent(iBuddyTcpServer.class, iBuddyTcpServer.class, new Parameter[]{ /* Add server forwarder implementation */
new ConstantParameter(getiBuddy()), addForwarder(properties);
new ConstantParameter(Integer.valueOf(properties.getProperty("server.port"))),
new ConstantParameter(iBuddyTcpClient.class)});
break;
case "udp":
pico.addComponent(iBuddyUdpServer.class, iBuddyUdpServer.class, new Parameter[]{
new ConstantParameter(getiBuddy()),
new ConstantParameter(Integer.valueOf(properties.getProperty("server.port")))});
}
} }
} }
public iBuddy getiBuddy() { public iBuddy getiBuddy() {
return pico.getComponent(iBuddy.class); return pico.getComponent(iBuddy.class);
} }
public Work getServer() { public Server getServer() {
return (Work) pico.getComponent(iBuddyServer.class); return pico.getComponent(Server.class);
} }
} }

View File

@@ -1,4 +1,4 @@
package com.github.boukefalos.ibuddy.helper; package com.github.boukefalos.ibuddy;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.IOException; import java.io.IOException;
@@ -14,13 +14,34 @@ import proto.Ibuddy.Flap;
import proto.Ibuddy.Head; import proto.Ibuddy.Head;
import proto.Ibuddy.Nudge; import proto.Ibuddy.Nudge;
import proto.Ibuddy.State; import proto.Ibuddy.State;
import base.Control;
import base.receiver.Forwarder;
import base.receiver.Receiver;
import com.github.boukefalos.ibuddy.iBuddy; public class Server implements Receiver, Control {
protected Logger logger = LoggerFactory.getLogger(getClass());
protected iBuddy iBuddy;
protected Forwarder forwarder;
public class ServerHelper { public Server(iBuddy iBuddy, Forwarder forwarder) {
protected static Logger logger = LoggerFactory.getLogger(ServerHelper.class); this.iBuddy = iBuddy;
this.forwarder = forwarder;
forwarder.register(this);
}
public static void receive(iBuddy iBuddy, byte[] buffer) { public void start() {
forwarder.start();
}
public void stop() {
forwarder.stop();
}
public void exit() {
forwarder.exit();
}
public void receive(byte[] buffer) {
ByteArrayInputStream input = new ByteArrayInputStream(buffer); ByteArrayInputStream input = new ByteArrayInputStream(buffer);
logger.debug("Received input"); logger.debug("Received input");
try { try {

View File

@@ -1,22 +0,0 @@
package com.github.boukefalos.ibuddy.client;
import java.net.Socket;
import java.nio.channels.SocketChannel;
import base.server.channel.TcpServer;
import base.server.channel.TcpServerClient;
public class iBuddyTcpClient extends TcpServerClient {
public iBuddyTcpClient(TcpServer server, SocketChannel socketChannel) {
super(server, socketChannel);
// TODO Auto-generated constructor stub
}
/*public iBuddyTcpClient(Socket socket) {
super(socket);
}*/
public void work() {
// Work in progress
}
}

View File

@@ -1,6 +0,0 @@
package com.github.boukefalos.ibuddy.exception;
public class LoaderException extends Exception {
private static final long serialVersionUID = 1L;
}

View File

@@ -1,6 +0,0 @@
package com.github.boukefalos.ibuddy.exception;
public class ServerException extends Exception {
private static final long serialVersionUID = 1L;
}

View File

@@ -1,6 +1,5 @@
package com.github.boukefalos.ibuddy.exception; package com.github.boukefalos.ibuddy.exception;
public class iBuddyException extends Exception { public class iBuddyException extends Exception {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;

View File

@@ -1,12 +1,12 @@
package com.github.boukefalos.ibuddy; package com.github.boukefalos.ibuddy;
import org.jraf.jlibibuddy.IBuddyException; import org.jraf.jlibibuddy.IBuddyException;
import proto.Ibuddy.Color; import proto.Ibuddy.Color;
import proto.Ibuddy.Direction; import proto.Ibuddy.Direction;
import base.Control;
public interface iBuddy { public interface iBuddy extends Control {
public void setHeart(boolean on) throws IBuddyException; public void setHeart(boolean on) throws IBuddyException;
public void setHeadRed(boolean on) throws IBuddyException; public void setHeadRed(boolean on) throws IBuddyException;
public void setHeadBlue(boolean on) throws IBuddyException; public void setHeadBlue(boolean on) throws IBuddyException;
@@ -21,7 +21,7 @@ public interface iBuddy {
public void setRotateCenter() throws IBuddyException; public void setRotateCenter() throws IBuddyException;
public void setRotate(Direction direction) throws IBuddyException; public void setRotate(Direction direction) throws IBuddyException;
public void off() throws IBuddyException; public void off() throws IBuddyException;
public void blink(Color color, long onTime, long offTime, int times) throws IBuddyException; public void blink(Color color, int onTime, int offTime, int times) throws IBuddyException;
public void nudge(long delay, int times) throws IBuddyException; public void nudge(int delay, int times) throws IBuddyException;
public void flap(long delay, int times) throws IBuddyException; public void flap(int delay, int times) throws IBuddyException;
} }

View File

@@ -9,14 +9,18 @@ import proto.Ibuddy.Direction;
import com.github.boukefalos.ibuddy.iBuddy; import com.github.boukefalos.ibuddy.iBuddy;
public class LocalImplementation implements iBuddy { public class Local implements iBuddy {
IBuddy IBuddy; IBuddy IBuddy;
@SuppressWarnings("static-access") @SuppressWarnings("static-access")
public LocalImplementation() { public Local() {
IBuddy = IBuddy.getIBuddy(); IBuddy = IBuddy.getIBuddy();
} }
public void start() {}
public void stop() {}
public void exit() {}
public void setHeadRed(boolean on) throws IBuddyException { public void setHeadRed(boolean on) throws IBuddyException {
IBuddy.sendHeadRed(on); IBuddy.sendHeadRed(on);
} }
@@ -92,15 +96,15 @@ public class LocalImplementation implements iBuddy {
IBuddy.sendAllOff(); IBuddy.sendAllOff();
} }
public void blink(Color color, long onTime, long offTime, int times) throws IBuddyException { public void blink(Color color, int onTime, int offTime, int times) throws IBuddyException {
IBuddyUtils.blink(IBuddy, mapColor(color), onTime, offTime, times); IBuddyUtils.blink(IBuddy, mapColor(color), onTime, offTime, times);
} }
public void nudge(long delay, int times) throws IBuddyException { public void nudge(int delay, int times) throws IBuddyException {
IBuddyUtils.nudge(IBuddy, delay, times); IBuddyUtils.nudge(IBuddy, delay, times);
} }
public void flap(long delay, int times) throws IBuddyException { public void flap(int delay, int times) throws IBuddyException {
IBuddyUtils.flap(IBuddy, delay, times); IBuddyUtils.flap(IBuddy, delay, times);
} }

View File

@@ -1,4 +1,4 @@
package com.github.boukefalos.ibuddy.helper; package com.github.boukefalos.ibuddy.implementation;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
@@ -19,26 +19,43 @@ import proto.Ibuddy.Rotate;
import proto.Ibuddy.State; import proto.Ibuddy.State;
import proto.Ibuddy.Type; import proto.Ibuddy.Type;
import proto.Ibuddy.Wings; import proto.Ibuddy.Wings;
import base.Control;
import base.sender.Sender; import base.sender.Sender;
import com.github.boukefalos.ibuddy.iBuddy;
public class SenderHelper { public class Remote implements iBuddy, Control {
protected final static int BUFFER_SIZE = 1024; protected final static int BUFFER_SIZE = 1024;
protected static Logger logger = LoggerFactory.getLogger(SenderHelper.class); protected Logger logger = LoggerFactory.getLogger(getClass());
protected Sender sender;
public static void setHeart(Sender sender, boolean on) throws IBuddyException { public Remote(Sender sender) {
send( this.sender = sender;
sender, }
public void start() {
sender.start();
}
public void stop() {
sender.stop();
}
public void exit() {
sender.exit();
}
public void setHeart(boolean on) throws IBuddyException {
send(
Command.newBuilder() Command.newBuilder()
.setType(Type.HEART) .setType(Type.HEART)
.setHeart(Heart.newBuilder() .setHeart(Heart.newBuilder()
.setState(mapState(on))).build()); .setState(mapState(on))).build());
} }
public static void setHeadRed(Sender sender, boolean on) throws IBuddyException { public void setHeadRed(boolean on) throws IBuddyException {
send( send(
sender,
Command.newBuilder() Command.newBuilder()
.setType(Type.HEAD) .setType(Type.HEAD)
.setHead(Head.newBuilder() .setHead(Head.newBuilder()
@@ -47,10 +64,8 @@ public class SenderHelper {
.setColor(Color.RED)).build()); .setColor(Color.RED)).build());
} }
public void setHeadBlue(boolean on) throws IBuddyException {
public static void setHeadBlue(Sender sender, boolean on) throws IBuddyException { send(
send(
sender,
Command.newBuilder() Command.newBuilder()
.setType(Type.HEAD) .setType(Type.HEAD)
.setHead(Head.newBuilder() .setHead(Head.newBuilder()
@@ -60,9 +75,8 @@ public class SenderHelper {
} }
public static void setHeadGreen(Sender sender, boolean on) throws IBuddyException { public void setHeadGreen(boolean on) throws IBuddyException {
send( send(
sender,
Command.newBuilder() Command.newBuilder()
.setType(Type.HEAD) .setType(Type.HEAD)
.setHead(Head.newBuilder() .setHead(Head.newBuilder()
@@ -71,76 +85,65 @@ public class SenderHelper {
.setColor(Color.GREEN)).build()); .setColor(Color.GREEN)).build());
} }
public void setHead(Color color) throws IBuddyException {
public static void setHead(Sender sender, Color color) throws IBuddyException {
State state = mapState(!color.equals(Color.NONE)); State state = mapState(!color.equals(Color.NONE));
send( send(
sender,
Command.newBuilder() Command.newBuilder()
.setType(Type.HEAD) .setType(Type.HEAD)
.setHead(Head.newBuilder() .setHead(Head.newBuilder()
.setState(state) .setState(state)
.setSingle(false) .setSingle(false)
.setColor(color)).build()); .setColor(color)).build());
} }
public void setWingsUp() throws IBuddyException {
public static void setWingsUp(Sender sender) throws IBuddyException { setWings(Direction.UP);
setWings(sender, Direction.UP);
} }
public static void setWingsDown(Sender sender) throws IBuddyException { public void setWingsDown() throws IBuddyException {
setWings(sender, Direction.DOWN); setWings(Direction.DOWN);
} }
public void setWingsCenter() throws IBuddyException {
public static void setWingsCenter(Sender sender) throws IBuddyException { setWings(Direction.CENTER);
setWings(sender, Direction.CENTER);
} }
public static void setWings(Sender sender, Direction direction) throws IBuddyException { public void setWings(Direction direction) throws IBuddyException {
send( send(
sender,
Command.newBuilder() Command.newBuilder()
.setType(Type.WINGS) .setType(Type.WINGS)
.setWings(Wings.newBuilder() .setWings(Wings.newBuilder()
.setDirection(direction)).build()); .setDirection(direction)).build());
} }
public static void setRotateLeft(Sender sender) throws IBuddyException { public void setRotateLeft() throws IBuddyException {
setRotate(sender, Direction.LEFT); setRotate(Direction.LEFT);
} }
public static void setRotateRight(Sender sender) throws IBuddyException { public void setRotateRight() throws IBuddyException {
setRotate(sender, Direction.RIGHT); setRotate(Direction.RIGHT);
} }
public static void setRotateCenter(Sender sender) throws IBuddyException { public void setRotateCenter() throws IBuddyException {
setRotate(sender, Direction.CENTER); setRotate(Direction.CENTER);
} }
public static void setRotate(Sender sender, Direction direction) throws IBuddyException { public void setRotate(Direction direction) throws IBuddyException {
send( send(
sender,
Command.newBuilder() Command.newBuilder()
.setType(Type.ROTATE) .setType(Type.ROTATE)
.setRotate(Rotate.newBuilder() .setRotate(Rotate.newBuilder()
.setDirection(direction)).build()); .setDirection(direction)).build());
} }
public void off() throws IBuddyException {
public static void off(Sender sender) throws IBuddyException { send(
send(
sender,
Command.newBuilder() Command.newBuilder()
.setType(Type.STATE).build()); .setType(Type.STATE).build());
} }
public static void blink(Sender sender, Color color, int onTime, int offTime, int times) throws IBuddyException { public void blink(Color color, int onTime, int offTime, int times) throws IBuddyException {
send( send(
sender,
Command.newBuilder() Command.newBuilder()
.setType(Type.BLINK) .setType(Type.BLINK)
.setBlink(Blink.newBuilder() .setBlink(Blink.newBuilder()
@@ -149,9 +152,8 @@ public class SenderHelper {
.setTimes(times)).build()); .setTimes(times)).build());
} }
public static void nudge(Sender sender, int delay, int times) throws IBuddyException { public void nudge(int delay, int times) throws IBuddyException {
send( send(
sender,
Command.newBuilder() Command.newBuilder()
.setType(Type.NUDGE) .setType(Type.NUDGE)
.setNudge(Nudge.newBuilder() .setNudge(Nudge.newBuilder()
@@ -159,10 +161,8 @@ public class SenderHelper {
.setTimes(times)).build()); .setTimes(times)).build());
} }
public void flap(int delay, int times) throws IBuddyException {
public static void flap(Sender sender, int delay, int times) throws IBuddyException { send(
send(
sender,
Command.newBuilder() Command.newBuilder()
.setType(Type.FLAP) .setType(Type.FLAP)
.setFlap(Flap.newBuilder() .setFlap(Flap.newBuilder()
@@ -174,7 +174,7 @@ public class SenderHelper {
return on ? State.ON : State.OFF; return on ? State.ON : State.OFF;
} }
protected static void send(Sender sender, Command command) { protected void send(Command command) {
ByteArrayOutputStream output = new ByteArrayOutputStream(BUFFER_SIZE); ByteArrayOutputStream output = new ByteArrayOutputStream(BUFFER_SIZE);
try { try {
command.writeDelimitedTo(output); command.writeDelimitedTo(output);

View File

@@ -1,84 +0,0 @@
package com.github.boukefalos.ibuddy.implementation;
import org.jraf.jlibibuddy.IBuddyException;
import proto.Ibuddy.Color;
import proto.Ibuddy.Direction;
import base.sender.TcpSender;
import com.github.boukefalos.ibuddy.iBuddy;
import com.github.boukefalos.ibuddy.helper.SenderHelper;
public class TcpImplementation extends TcpSender implements iBuddy {
public TcpImplementation(String host, int port) {
super(host, port);
}
public void setHeart(boolean on) throws IBuddyException {
SenderHelper.setHeart(this, on);
}
public void setHeadRed(boolean on) throws IBuddyException {
SenderHelper.setHeadRed(this, on);
}
public void setHeadBlue(boolean on) throws IBuddyException {
SenderHelper.setHeadBlue(this, on);
}
public void setHeadGreen(boolean on) throws IBuddyException {
SenderHelper.setHeadGreen(this, on);
}
public void setHead(Color color) throws IBuddyException {
SenderHelper.setHead(this, color);
}
public void setWingsUp() throws IBuddyException {
SenderHelper.setWingsUp(this);
}
public void setWingsDown() throws IBuddyException {
SenderHelper.setWingsDown(this);
}
public void setWingsCenter() throws IBuddyException {
SenderHelper.setWingsCenter(this);
}
public void setWings(Direction direction) throws IBuddyException {
SenderHelper.setWings(this, direction);
}
public void setRotateLeft() throws IBuddyException {
SenderHelper.setRotateLeft(this);
}
public void setRotateRight() throws IBuddyException {
SenderHelper.setRotateRight(this);
}
public void setRotateCenter() throws IBuddyException {
SenderHelper.setRotateCenter(this);
}
public void setRotate(Direction direction) throws IBuddyException {
SenderHelper.setRotate(this, direction);
}
public void off() throws IBuddyException {
SenderHelper.off(this);
}
public void blink(Color color, long onTime, long offTime, int times) throws IBuddyException {
SenderHelper.blink(this, color, (int) onTime, (int) offTime, times);
}
public void nudge(long delay, int times) throws IBuddyException {
SenderHelper.nudge(this, (int) delay, (int) times);
}
public void flap(long delay, int times) throws IBuddyException {
SenderHelper.flap(this, (int) delay, times);
}
}

View File

@@ -1,86 +0,0 @@
package com.github.boukefalos.ibuddy.implementation;
import java.net.UnknownHostException;
import org.jraf.jlibibuddy.IBuddyException;
import proto.Ibuddy.Color;
import proto.Ibuddy.Direction;
import base.sender.UdpSender;
import com.github.boukefalos.ibuddy.iBuddy;
import com.github.boukefalos.ibuddy.helper.SenderHelper;
public class UdpImplementation extends UdpSender implements iBuddy {
public UdpImplementation(String host, int port) throws UnknownHostException {
super(host, port);
}
public void setHeart(boolean on) throws IBuddyException {
SenderHelper.setHeart(this, on);
}
public void setHeadRed(boolean on) throws IBuddyException {
SenderHelper.setHeadRed(this, on);
}
public void setHeadBlue(boolean on) throws IBuddyException {
SenderHelper.setHeadBlue(this, on);
}
public void setHeadGreen(boolean on) throws IBuddyException {
SenderHelper.setHeadGreen(this, on);
}
public void setHead(Color color) throws IBuddyException {
SenderHelper.setHead(this, color);
}
public void setWingsUp() throws IBuddyException {
SenderHelper.setWingsUp(this);
}
public void setWingsDown() throws IBuddyException {
SenderHelper.setWingsDown(this);
}
public void setWingsCenter() throws IBuddyException {
SenderHelper.setWingsCenter(this);
}
public void setWings(Direction direction) throws IBuddyException {
SenderHelper.setWings(this, direction);
}
public void setRotateLeft() throws IBuddyException {
SenderHelper.setRotateLeft(this);
}
public void setRotateRight() throws IBuddyException {
SenderHelper.setRotateRight(this);
}
public void setRotateCenter() throws IBuddyException {
SenderHelper.setRotateCenter(this);
}
public void setRotate(Direction direction) throws IBuddyException {
SenderHelper.setRotate(this, direction);
}
public void off() throws IBuddyException {
SenderHelper.off(this);
}
public void blink(Color color, long onTime, long offTime, int times) throws IBuddyException {
SenderHelper.blink(this, color, (int) onTime, (int) offTime, times);
}
public void nudge(long delay, int times) throws IBuddyException {
SenderHelper.nudge(this, (int) delay, (int) times);
}
public void flap(long delay, int times) throws IBuddyException {
SenderHelper.flap(this, (int) delay, times);
}
}

View File

@@ -1,5 +0,0 @@
package com.github.boukefalos.ibuddy.server;
public interface iBuddyServer {
}

View File

@@ -1,19 +0,0 @@
package com.github.boukefalos.ibuddy.server;
import com.github.boukefalos.ibuddy.iBuddy;
import com.github.boukefalos.ibuddy.helper.ServerHelper;
import base.server.socket.TcpServer;
public class iBuddyTcpServer extends TcpServer implements iBuddyServer {
protected iBuddy iBuddy;
public iBuddyTcpServer(iBuddy iBuddy, int port, Class<?> clientClass) {
super(port, clientClass);
this.iBuddy = iBuddy;
}
public void receive(byte[] buffer) {
ServerHelper.receive(iBuddy, buffer);
}
}

View File

@@ -1,24 +0,0 @@
package com.github.boukefalos.ibuddy.server;
import base.server.datagram.UdpServer;
import com.github.boukefalos.ibuddy.iBuddy;
import com.github.boukefalos.ibuddy.helper.ServerHelper;
public class iBuddyUdpServer extends UdpServer implements iBuddyServer {
protected iBuddy iBuddy;
public iBuddyUdpServer(iBuddy iBuddy, int port) {
this(iBuddy, port, BUFFER_SIZE);
}
public iBuddyUdpServer(iBuddy iBuddy, int port, int bufferSize) {
super(port, bufferSize);
this.iBuddy = iBuddy;
this.bufferSize = bufferSize;
}
protected void receive(byte[] buffer) {
ServerHelper.receive(iBuddy, buffer);
}
}

View File

@@ -2,4 +2,5 @@ implementation=local
remote.host=localhost remote.host=localhost
remote.port=8883 remote.port=8883
server.port=8883 server.port=8883
server=true server=true
server.protocol=tcp

View File

@@ -1,13 +0,0 @@
package test;
import com.github.boukefalos.ibuddy.Loader;
public class TestProperties {
public static void main(String[] args) {
try {
Loader.getLoader().getServer().start();
} catch (Exception e) {
e.printStackTrace();
}
}
}

View File

@@ -3,9 +3,9 @@ package test;
import java.util.Properties; import java.util.Properties;
import proto.Ibuddy.Color; import proto.Ibuddy.Color;
import base.work.Work;
import com.github.boukefalos.ibuddy.Loader; import com.github.boukefalos.ibuddy.Loader;
import com.github.boukefalos.ibuddy.Server;
import com.github.boukefalos.ibuddy.iBuddy; import com.github.boukefalos.ibuddy.iBuddy;
public class TestTcpCommunication { public class TestTcpCommunication {
@@ -16,6 +16,7 @@ public class TestTcpCommunication {
localProperties.setProperty("server", "true"); localProperties.setProperty("server", "true");
localProperties.setProperty("server.port", "8883"); localProperties.setProperty("server.port", "8883");
localProperties.setProperty("server.protocol", "tcp"); localProperties.setProperty("server.protocol", "tcp");
localProperties.setProperty("tcp.implementation", "socket");
Properties remoteProperties = new Properties(); Properties remoteProperties = new Properties();
remoteProperties.setProperty("implementation", "remote"); remoteProperties.setProperty("implementation", "remote");
@@ -26,15 +27,16 @@ public class TestTcpCommunication {
Loader localLoader = new Loader(localProperties); Loader localLoader = new Loader(localProperties);
Loader remoteLoader = new Loader(remoteProperties); Loader remoteLoader = new Loader(remoteProperties);
iBuddy localiBuddy = localLoader.getiBuddy(); Server server = localLoader.getServer();
iBuddy remoteiBuddy = remoteLoader.getiBuddy(); iBuddy iBuddy = remoteLoader.getiBuddy();
//localiBuddy.setHead(Color.WHITE);
Work server = localLoader.getServer();
server.start(); server.start();
remoteiBuddy.setHeadRed(true); iBuddy.start();
Thread.sleep(1000);
//server.exit(); iBuddy.setHead(Color.BLUE);
server.exit();
iBuddy.exit();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }

View File

@@ -2,9 +2,10 @@ package test;
import java.util.Properties; import java.util.Properties;
import base.work.Work; import proto.Ibuddy.Color;
import com.github.boukefalos.ibuddy.Loader; import com.github.boukefalos.ibuddy.Loader;
import com.github.boukefalos.ibuddy.Server;
import com.github.boukefalos.ibuddy.iBuddy; import com.github.boukefalos.ibuddy.iBuddy;
public class TestUdpCommunication { public class TestUdpCommunication {
@@ -25,17 +26,16 @@ public class TestUdpCommunication {
Loader localLoader = new Loader(localProperties); Loader localLoader = new Loader(localProperties);
Loader remoteLoader = new Loader(remoteProperties); Loader remoteLoader = new Loader(remoteProperties);
iBuddy localiBuddy = localLoader.getiBuddy(); iBuddy iBuddy = remoteLoader.getiBuddy();
iBuddy remoteiBuddy = remoteLoader.getiBuddy(); Server server = localLoader.getServer();
localiBuddy.setHeadRed(false);
Work server = localLoader.getServer();
iBuddy.start();
server.start(); server.start();
remoteiBuddy.setHeadRed(true);
Thread.sleep(1000); iBuddy.setHead(Color.WHITE);
server.exit(); server.exit();
iBuddy.exit();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }