package dslab.transfer; import at.ac.tuwien.dsg.orvell.StopShellException; import at.ac.tuwien.dsg.orvell.annotation.Command; import dslab.ComponentFactory; import dslab.protocol.dmtp.Dmtp; import dslab.rmi.stub.dmtp.DmtpServerStub; import dslab.threading.Dispatcher; import java.io.InputStream; import java.io.PrintStream; import java.util.logging.Logger; public class TransferServer implements ITransferServer, Runnable { private static final Logger LOG = Logger.getLogger(TransferServer.class.getSimpleName()); private final Dispatcher dmtpDispatcher; private final InputStream in; private final PrintStream out; private final ComponentFactory componentFactory; /** * Creates a new server instance. */ public TransferServer(InputStream in, PrintStream out, ComponentFactory componentFactory) { this.in = in; this.out = out; this.componentFactory = componentFactory; dmtpDispatcher = new Dispatcher<>( componentFactory.getConfig().getInt("tcp.port"), channel -> new DmtpServerStub(channel, componentFactory.getDeliveryService()), Dmtp.class.getSimpleName(), componentFactory); } @Override public void run() { dmtpDispatcher.start(); componentFactory.createShell(this, in, out).run(); } @Override @Command public void shutdown() { LOG.info(componentFactory.getComponentId() + " received shutdown command."); dmtpDispatcher.interrupt(); componentFactory.shutdown(); throw new StopShellException(); } public static void main(String[] args) throws Exception { ITransferServer server = ComponentFactory.createTransferServer(args[0], System.in, System.out); server.run(); } public ComponentFactory getComponentFactory() { return componentFactory; } }