Search in sources :

Example 1 with ThreadPooledServer

use of ClientServerCommunication.ThreadPooledServer in project SmartCity-Market by TechnionYP5777.

the class Main method main.

public static void main(String[] args) {
    if (!parseArguments(args))
        return;
    /* Setting log properties */
    PropertyConfigurator.configure("../log4j.properties");
    log.setLevel(verbosity);
    CommandProcess commandProcess = new CommandProcess();
    ThreadPooledServer server = null;
    try {
        server = new ThreadPooledServer(port, numOfThreads, commandProcess, serverIP);
    } catch (UnknownHostException e1) {
        log.fatal("Server IP address leads to unknown host, server won't start.");
        return;
    }
    SQLDatabaseConnection connection = new SQLDatabaseConnection();
    log.info("Disconnect from all clients");
    try {
        connection.logoutAllUsers();
        connection.close();
    } catch (CriticalError e1) {
        log.fatal("Disconnect failed");
        return;
    }
    log.info("Starting Server.");
    new Thread(server).start();
    try {
        Thread.sleep(1000 * timeout);
    } catch (InterruptedException e) {
        /* Get interrupt to stop server */
        log.info("Server Got interrupted.");
    }
    log.info("Stopping server.");
    server.stop();
}
Also used : CommandProcess(CommandHandler.CommandProcess) SQLDatabaseConnection(SQLDatabase.SQLDatabaseConnection) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) UnknownHostException(java.net.UnknownHostException) ThreadPooledServer(ClientServerCommunication.ThreadPooledServer)

Example 2 with ThreadPooledServer

use of ClientServerCommunication.ThreadPooledServer in project SmartCity-Market by TechnionYP5777.

the class ThreadPooledServerTest method ServerWorkerRunnableHelloWorldIPTest.

@Test
public void ServerWorkerRunnableHelloWorldIPTest() {
    ProcessRequestTester processRequestTester = new ProcessRequestTester();
    ThreadPooledServer server = null;
    try {
        server = new ThreadPooledServer(SERVER_PORT, 1, processRequestTester, SERVER_HOST_IP);
    } catch (UnknownHostException e1) {
        fail();
    }
    Thread client;
    new Thread(server).start();
    while (server.isStopped()) {
    }
    client = new Thread(new ClientRunner(SERVER_HOST_IP));
    client.start();
    try {
        client.join();
    } catch (InterruptedException e) {
        fail();
    }
    server.stop();
}
Also used : UnknownHostException(java.net.UnknownHostException) ThreadPooledServer(ClientServerCommunication.ThreadPooledServer) Test(org.junit.Test)

Example 3 with ThreadPooledServer

use of ClientServerCommunication.ThreadPooledServer in project SmartCity-Market by TechnionYP5777.

the class ThreadPooledServerTest method ServerWorkerRunnableHelloWorldLocalTest.

@Test
public void ServerWorkerRunnableHelloWorldLocalTest() {
    ProcessRequestTester processRequestTester = new ProcessRequestTester();
    ThreadPooledServer server = null;
    try {
        server = new ThreadPooledServer(SERVER_PORT, 1, processRequestTester);
    } catch (UnknownHostException e1) {
        fail();
    }
    Thread client;
    new Thread(server).start();
    /* waiting for server to run */
    while (server.isStopped()) {
    }
    client = new Thread(new ClientRunner(SERVER_HOST_NAME_LOCAL));
    client.start();
    try {
        client.join();
    } catch (InterruptedException e) {
        fail();
    }
    server.stop();
}
Also used : UnknownHostException(java.net.UnknownHostException) ThreadPooledServer(ClientServerCommunication.ThreadPooledServer) Test(org.junit.Test)

Aggregations

ThreadPooledServer (ClientServerCommunication.ThreadPooledServer)3 UnknownHostException (java.net.UnknownHostException)3 Test (org.junit.Test)2 CommandProcess (CommandHandler.CommandProcess)1 SQLDatabaseConnection (SQLDatabase.SQLDatabaseConnection)1 CriticalError (SQLDatabase.SQLDatabaseException.CriticalError)1