/**
*
*/
package info.walnutstreet.vs.ps03.appserver;
import info.walnutstreet.vs.ps03.appserver.handler.DataStore;
import info.walnutstreet.vs.ps03.appserver.listener.ConnectionListener;
import java.io.IOException;
import java.net.SocketTimeoutException;
import org.apache.log4j.Logger;
/**
* @author Christoph Gostner
* @author Christian Bitschnau
* @version 0.1
*
*/
public class AppServer {
/**
* Logging ...
*/
private static Logger logger = Logger.getLogger(AppServer.class);
private ConnectionListener listener;
/**
* Constructor.
*
* @throws IOException
*/
public AppServer(int port) throws IOException {
this.listener = new ConnectionListener(port);
DataStore.getInstance().refreshLocalStore();
}
/**
* Start the listen process.
* The method generates a thread with the listener
* class and starts it.
* @throws InterruptedException
*/
private void startListener() throws InterruptedException {
Thread th = new Thread(this.listener);
th.start();
th.join();
}
/**
* This method starts the listen process of the process.
* The generated Listener Thread listens for incoming
* connections and tries to handle them.
* The server can be closed by typing quit into the console,
* where the server was started.
* @throws InterruptedException
*/
public void startServer() throws InterruptedException {
this.startListener();
}
/**
* Main method - start the server.
*
* @param args Ignored
*/
public static void main(String[] args) {
int port= 12345;
if (args.length==1) {
port= Integer.parseInt(args[0]);
}
try {
AppServer server = new AppServer(port);
server.startServer();
} catch (SocketTimeoutException e) {
AppServer.logger.error(e.toString());
} catch (IOException e) {
AppServer.logger.error("Ports: " + e.toString());
} catch (InterruptedException e) {
AppServer.logger.error("Interrupt: " + e.toString());
}
}
}