Move general server code to base project, adjust loader and tests

This commit is contained in:
2015-06-21 17:38:51 +01:00
parent 50567a9846
commit 62796af99b
4 changed files with 23 additions and 25 deletions

View File

@@ -23,7 +23,15 @@ public class Loader extends AbstractLoader<Loader> {
pico.addComponent(Remote.class);
/* Add sender implementation */
addSender(properties);
try {
String protocol = properties.getOrDefault("protocol", "tcp").toString();
String implementation = properties.getOrDefault("tcp.implementation", "socket").toString();
String host = properties.getProperty("remote.host");
int port = Integer.valueOf(properties.getProperty("remote.port"));
addSender(protocol, implementation, host, port);
} catch (NumberFormatException e) {
throw new LoaderException("Failed to parse remote.port");
}
break;
}
@@ -31,8 +39,15 @@ public class Loader extends AbstractLoader<Loader> {
if (properties.getProperty("server") != null) {
pico.addComponent(Server.class);
/* Add server forwarder implementation */
addForwarder(properties);
/* Add server forwarder implementation */
try {
String protocol = properties.getOrDefault("server.protocol", "tcp").toString();
String implementation = properties.getOrDefault("tcp.implementation", "socket").toString();
int port = Integer.valueOf(properties.getProperty("server.port"));
addForwarder(protocol, implementation, port);
} catch (NumberFormatException e) {
throw new LoaderException("Failed to parse server.port");
}
}
}

View File

@@ -4,8 +4,6 @@ import java.io.ByteArrayInputStream;
import java.io.IOException;
import org.jraf.jlibibuddy.IBuddyException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import proto.Ibuddy.Blink;
import proto.Ibuddy.Color;
@@ -14,31 +12,15 @@ import proto.Ibuddy.Flap;
import proto.Ibuddy.Head;
import proto.Ibuddy.Nudge;
import proto.Ibuddy.State;
import base.Control;
import base.receiver.Forwarder;
import base.receiver.Receiver;
import base.server.forwarder.AbstractReceiver;
public class Server implements Receiver, Control {
protected Logger logger = LoggerFactory.getLogger(getClass());
public class Server extends AbstractReceiver {
protected iBuddy iBuddy;
protected Forwarder forwarder;
public Server(iBuddy iBuddy, Forwarder forwarder) {
super(forwarder);
this.iBuddy = iBuddy;
this.forwarder = forwarder;
forwarder.register(this);
}
public void start() {
forwarder.start();
}
public void stop() {
forwarder.stop();
}
public void exit() {
forwarder.exit();
}
public void receive(byte[] buffer) {

View File

@@ -33,7 +33,7 @@ public class TestTcpCommunication {
server.start();
iBuddy.start();
iBuddy.setHead(Color.BLUE);
iBuddy.setHead(Color.GREEN);
server.exit();
iBuddy.exit();

View File

@@ -13,6 +13,7 @@ public class TestUdpCommunication {
try {
Properties localProperties = new Properties();
localProperties.setProperty("implementation", "local");
localProperties.setProperty("protocol", "udp");
localProperties.setProperty("server", "true");
localProperties.setProperty("server.port", "8883");
localProperties.setProperty("server.protocol", "udp");