Implemented `stopManager` function which also calls on the now implemented `stopWatcher` and `stopGC` functions.
This commit is contained in:
parent
3494df6fdb
commit
2960a8ec57
|
@ -19,6 +19,11 @@ public final class GarbageCollector : Thread
|
|||
*/
|
||||
private Request[]* requestQueueVariable;
|
||||
|
||||
/**
|
||||
* Whether or not the watcher is active
|
||||
*/
|
||||
private bool isActive;
|
||||
|
||||
this(Manager manager)
|
||||
{
|
||||
/* Set the worker function */
|
||||
|
@ -29,12 +34,19 @@ public final class GarbageCollector : Thread
|
|||
|
||||
/* Set the pointer */
|
||||
requestQueueVariable = cast(Request[]*)manager.getQueueVariable();
|
||||
|
||||
isActive = true;
|
||||
}
|
||||
|
||||
public void stopGC()
|
||||
{
|
||||
isActive = false;
|
||||
}
|
||||
|
||||
/* TODO: Add timeout ability */
|
||||
private void cleaner()
|
||||
{
|
||||
while(true)
|
||||
while(isActive)
|
||||
{
|
||||
/* Lock the queue */
|
||||
manager.lockQueue();
|
||||
|
|
|
@ -60,6 +60,24 @@ public final class Manager
|
|||
gc.start();
|
||||
}
|
||||
|
||||
public void stopManager()
|
||||
{
|
||||
/* Will caue watcher to not block */
|
||||
socket.close();
|
||||
|
||||
/* Stop watcher */
|
||||
watcher.stopWatcher();
|
||||
|
||||
/* Stop gc */
|
||||
gc.stopGC();
|
||||
|
||||
/* Wait for watcher thread to stop */
|
||||
watcher.join();
|
||||
|
||||
/* Wait for garbage collector thread to stop */
|
||||
gc.join();
|
||||
}
|
||||
|
||||
public void sendMessage(ulong tag, byte[] data)
|
||||
{
|
||||
/* Encode the message */
|
||||
|
|
|
@ -22,16 +22,27 @@ public final class Watcher : Thread
|
|||
*/
|
||||
private Socket endpoint;
|
||||
|
||||
/**
|
||||
* Whether or not the watcher is active
|
||||
*/
|
||||
private bool isActive;
|
||||
|
||||
this(Manager manager, Socket endpoint)
|
||||
{
|
||||
super(&watchLoop);
|
||||
this.manager = manager;
|
||||
this.endpoint = endpoint;
|
||||
isActive = true;
|
||||
}
|
||||
|
||||
public void stopWatcher()
|
||||
{
|
||||
isActive = false;
|
||||
}
|
||||
|
||||
private void watchLoop()
|
||||
{
|
||||
while(true)
|
||||
while(isActive)
|
||||
{
|
||||
/* The received message (tag+data) */
|
||||
byte[] receivedPayload;
|
||||
|
|
Loading…
Reference in New Issue