Implement basic mailbox server
This commit is contained in:
parent
d39a3151fa
commit
7d75217dbe
@ -1,12 +1,22 @@
|
|||||||
package dslab.mailbox;
|
package dslab.mailbox;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
|
import java.net.ServerSocket;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import at.ac.tuwien.dsg.orvell.Shell;
|
||||||
|
import at.ac.tuwien.dsg.orvell.StopShellException;
|
||||||
|
import at.ac.tuwien.dsg.orvell.annotation.Command;
|
||||||
import dslab.ComponentFactory;
|
import dslab.ComponentFactory;
|
||||||
import dslab.util.Config;
|
import dslab.util.Config;
|
||||||
|
|
||||||
public class MailboxServer implements IMailboxServer, Runnable {
|
public class MailboxServer implements IMailboxServer, Runnable {
|
||||||
|
private static final Logger logger = Logger.getLogger(MailboxServer.class.getName());
|
||||||
|
private ServerSocket serverSocket;
|
||||||
|
private final Shell shell;
|
||||||
|
private final Integer serverPort;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new server instance.
|
* Creates a new server instance.
|
||||||
@ -17,17 +27,39 @@ public class MailboxServer implements IMailboxServer, Runnable {
|
|||||||
* @param out the output stream to write console output to
|
* @param out the output stream to write console output to
|
||||||
*/
|
*/
|
||||||
public MailboxServer(String componentId, Config config, InputStream in, PrintStream out) {
|
public MailboxServer(String componentId, Config config, InputStream in, PrintStream out) {
|
||||||
// TODO
|
// TODO initialize email and user storage (concurrent hashmap?)
|
||||||
|
this.shell = new Shell(in, out);
|
||||||
|
this.shell.register(this);
|
||||||
|
this.shell.setPrompt("Mailboxserver> ");
|
||||||
|
this.serverPort = config.getInt("tcp.port");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
// TODO
|
logger.info("Creating serverSocket for " + this.toString());
|
||||||
|
try {
|
||||||
|
this.serverSocket = new ServerSocket(serverPort);
|
||||||
|
} catch (IOException e) {
|
||||||
|
logger.severe("Error creating serverSocket " + serverSocket.toString());
|
||||||
|
e.printStackTrace();
|
||||||
|
shutdown();
|
||||||
|
}
|
||||||
|
// TODO spawn listener for transfer servers
|
||||||
|
// TODO spawn listener for user clients
|
||||||
|
this.shell.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Command
|
||||||
@Override
|
@Override
|
||||||
public void shutdown() {
|
public void shutdown() {
|
||||||
// TODO
|
try {
|
||||||
|
if (serverSocket != null)
|
||||||
|
serverSocket.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
logger.severe("Error closing serverSocket " + serverSocket.toString());
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
throw new StopShellException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user