Skip to content

Commit

Permalink
Minik bugfix.
Browse files Browse the repository at this point in the history
  • Loading branch information
antimon committed Feb 15, 2011
1 parent ed81e5a commit ab13db9
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 3 deletions.
11 changes: 8 additions & 3 deletions a-cma/src/edu/atilim/acma/Server.java
Expand Up @@ -15,6 +15,7 @@ public class Server implements Runnable, ConnectionListener {

private InstanceSet instances;
private ConcurrentTask currentTask = null;
private Listener listener = null;
private volatile boolean running = false;

public Server(int port) {
Expand All @@ -30,12 +31,13 @@ public void run() {
try {
Server server = new Server(port);
if (!first)
server.autostart = 60;
server.autostart = 30;
first = false;

server.runInternal();
server.dispose();

try { Thread.sleep(2000); } catch (InterruptedException e) { }
try { Thread.sleep(5000); } catch (InterruptedException e) { }
} catch (TaskInterruptedException e) {
}
}
Expand All @@ -44,7 +46,7 @@ public void run() {
private void runInternal() {
System.out.printf("[Server] Listening port %d for incoming connections.\n", port);

Listener listener = SocketInstance.tryListen(port, this);
listener = SocketInstance.tryListen(port, this);

if (listener == null) {
System.out.printf("[Server] Can not listen port %d\n", port);
Expand Down Expand Up @@ -98,6 +100,8 @@ private void runInternal() {
run(new TerminateTask());
}

currentTask.clearInterrupt();

System.out.printf("[Server] Running algorithm task %s, Remaining: %d.\n", currentTask, TaskQueue.size() - 1);

run(currentTask);
Expand Down Expand Up @@ -139,6 +143,7 @@ public synchronized void dispose() {
System.out.println("[Server] Disposing server.");
try { instances.dispose(); } catch (Exception e) { }
try { currentTask.interrupt(); } catch (Exception e) { }
try { listener.stop(); } catch (Exception e) { }
}
}
}
1 change: 1 addition & 0 deletions a-cma/src/edu/atilim/acma/concurrent/ConcurrentTask.java
Expand Up @@ -6,4 +6,5 @@ public interface ConcurrentTask extends Serializable {
public void runMaster(InstanceSet instances);
public void runWorker(Instance master);
public void interrupt();
public void clearInterrupt();
}
2 changes: 2 additions & 0 deletions a-cma/src/edu/atilim/acma/concurrent/SocketInstance.java
Expand Up @@ -184,6 +184,8 @@ public synchronized void dispose() {

if (connectionListener != null)
connectionListener.onDisconnect(this);

connectionListener = null;
}
}

Expand Down
4 changes: 4 additions & 0 deletions a-cma/src/edu/atilim/acma/concurrent/TerminateTask.java
Expand Up @@ -18,4 +18,8 @@ public void runWorker(Instance master) {
@Override
public void interrupt() {
}

@Override
public void clearInterrupt() {
}
}
4 changes: 4 additions & 0 deletions a-cma/src/edu/atilim/acma/search/ConcurrentAlgorithm.java
Expand Up @@ -34,6 +34,10 @@ protected boolean isInterrupted() {
return interrupted;
}

public void clearInterrupt() {
interrupted = false;
}

@Override
public void interrupt() {
interrupted = true;
Expand Down

0 comments on commit ab13db9

Please sign in to comment.