use of com.swiftmq.tools.concurrent.Semaphore in project swiftmq-ce by iitsoftware.
the class MQTTSwiftlet method shutdown.
@Override
protected void shutdown() throws SwiftletException {
// true when shutdown while standby
if (ctx == null)
return;
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "shutdown ...");
try {
collectChanged(collectInterval, -1);
listenerAdapter.close();
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "shutdown: shutdown all MQTT connections");
Semaphore sem = getShutdownSemaphore();
ConnectionManager connectionManager = ctx.networkSwiftlet.getConnectionManager();
Connection[] c = (Connection[]) connections.toArray(new Connection[connections.size()]);
connections.clear();
for (int i = 0; i < c.length; i++) {
connectionManager.removeConnection(c[i]);
}
if (sem != null) {
System.out.println("+++ waiting for connection shutdown ...");
sem.waitHere();
try {
Thread.sleep(5000);
} catch (Exception ignored) {
}
}
ctx.mgmtSwiftlet.removeMgmtListener(this);
ctx.sessionRegistry.close();
ctx.retainer.close();
} catch (Exception e) {
e.printStackTrace();
}
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "shutdown done.");
ctx = null;
}
use of com.swiftmq.tools.concurrent.Semaphore in project swiftmq-ce by iitsoftware.
the class MQTTConnection method close.
public void close() {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.mqttSwiftlet.getName(), toString() + ", close ...");
closeLock.lock();
if (closeInProgress) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.mqttSwiftlet.getName(), toString() + ", close in progress, return");
return;
}
// Todo: Remove Usage entry
ctx.timerSwiftlet.removeTimerListener(this);
closeInProgress = true;
closeLock.unlock();
Semaphore sem = new Semaphore();
connectionQueue.enqueue(new POClose(sem));
sem.waitHere();
outboundQueue.stopQueue();
closed = true;
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.mqttSwiftlet.getName(), toString() + ", close done");
}
use of com.swiftmq.tools.concurrent.Semaphore in project swiftmq-ce by iitsoftware.
the class Listener method receive.
public void receive() {
try {
Semaphore sem1 = new Semaphore();
subscriber.setMessageListener(new MyListener(new MsgNoVerifier(this, nMsgs, "no"), sem1));
Semaphore sem2 = new Semaphore();
subscriber1.setMessageListener(new MyListener(new MsgNoVerifier(this, nMsgs, "no"), sem2));
Semaphore sem3 = new Semaphore();
subscriber2.setMessageListener(new MyListener(new MsgNoVerifier(this, nMsgs, "no"), sem3));
sem1.waitHere();
sem2.waitHere();
sem3.waitHere();
if (exception != null)
throw exception;
} catch (Exception e) {
failFast("test failed: " + e);
}
}
use of com.swiftmq.tools.concurrent.Semaphore in project swiftmq-ce by iitsoftware.
the class Listener method receive.
public void receive() {
try {
sem = new Semaphore();
subscriber.setMessageListener(this);
sem.waitHere();
if (exception != null)
throw exception;
verifier.verify();
} catch (Exception e) {
failFast("test failed: " + e);
}
}
use of com.swiftmq.tools.concurrent.Semaphore in project swiftmq-ce by iitsoftware.
the class Listener method receive.
public void receive() {
try {
Semaphore sem1 = new Semaphore();
subscriber.setMessageListener(new MyListener(ts, new MsgNoVerifier(this, nMsgs, "no"), sem1));
Semaphore sem2 = new Semaphore();
subscriber1.setMessageListener(new MyListener(session1, new MsgNoVerifier(this, nMsgs, "no"), sem2));
Semaphore sem3 = new Semaphore();
subscriber2.setMessageListener(new MyListener(session2, new MsgNoVerifier(this, nMsgs, "no"), sem3));
sem1.waitHere();
sem2.waitHere();
sem3.waitHere();
if (exception != null)
throw exception;
} catch (Exception e) {
failFast("test failed: " + e);
}
}
Aggregations