Commit 982fd545 authored by ducanh-le's avatar ducanh-le
Browse files

Implement methods for start or stop the GTDServerWithReactor. Close #43

parent 7bed6690
......@@ -9,7 +9,6 @@ import java.util.List;
* - the modules gtd-server-rmi and gtd-server-third should both use it
*/
public interface GTDServer {
// TODO: Add all missing methods.
void createAccount(final String username, final String password, final String pseudo, final CallBack<String> callback);
......
......@@ -2,6 +2,7 @@ package fr.alma.gtd.server.main;
import fr.alma.gtd.server.core.*;
import fr.alma.gtd.server.main.commande.Command;
import fr.alma.gtd.server.main.commande.CommandBlockingQueue;
import fr.alma.gtd.server.main.commande.CommandFactory;
import fr.alma.gtd.server.main.reactor.Acceptor;
import fr.alma.gtd.server.main.reactor.CommandThread;
......@@ -21,14 +22,14 @@ import java.util.concurrent.LinkedBlockingQueue;
public class GTDServerWithReactor implements GTDServer {
private static GTDServer instance = new GTDServerWithReactor();
private BlockingQueue<Command> arrivingCalls;
private static BlockingQueue<Command> arrivingCalls = new LinkedBlockingQueue<Command>();
private static Boolean commandIsQueueing = false;
private CommandFactory commandFactory;
private Acceptor acceptor;
private final String invalidIdentification = "Invalid identification";
private GTDServerWithReactor() {
super();
arrivingCalls = new LinkedBlockingQueue<Command>();
commandFactory = CommandFactory.getInstance();
acceptor = Acceptor.getInstance();
}
......@@ -37,6 +38,14 @@ public class GTDServerWithReactor implements GTDServer {
return instance;
}
public static BlockingQueue<Command> getQueue() {
return arrivingCalls;
}
public static Boolean isQueueing() {
return commandIsQueueing;
}
@Override
public void createAccount(String username, String password, String pseudo, CallBack<String> callback) {
final Command cmd = commandFactory.getCommandCreateAccount(username, password, pseudo, callback);
......@@ -530,11 +539,12 @@ public class GTDServerWithReactor implements GTDServer {
@Override
public void start() {
// TODO Start the thread that reads and processes the arriving calls
commandIsQueueing = true;
new Thread(new CommandBlockingQueue()).start();
}
@Override
public void stop() {
// TODO Stop the thread that processes the arriving calls
commandIsQueueing = false;
}
}
package fr.alma.gtd.server.main.commande;
import fr.alma.gtd.server.main.GTDServerWithReactor;
public class CommandBlockingQueue implements Runnable {
public CommandBlockingQueue() {
super();
}
@Override
public void run() {
try {
while (GTDServerWithReactor.isQueueing()) {
GTDServerWithReactor.getQueue().take().execute();
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment