use of com.swiftmq.swiftlet.net.ConnectionManager in project swiftmq-ce by iitsoftware.
the class MQTTSwiftlet method startup.
@Override
protected void startup(Configuration config) throws SwiftletException {
try {
ctx = new SwiftletContext(config, this);
} catch (Exception e) {
e.printStackTrace();
throw new SwiftletException(e.getMessage());
}
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "startup ...");
createListenerAdapter((EntityList) ctx.root.getEntity("listeners"));
Property prop = ctx.root.getProperty("collect-interval");
prop.setPropertyChangeListener(new PropertyChangeAdapter(null) {
public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
collectInterval = ((Long) newValue).longValue();
collectChanged(((Long) oldValue).longValue(), collectInterval);
}
});
collectInterval = ((Long) prop.getValue()).longValue();
if (collectOn) {
if (collectInterval > 0) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "startup: registering msg/s count collector");
ctx.timerSwiftlet.addTimerListener(collectInterval, this);
} else if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "startup: collect interval <= 0; no msg/s count collector");
}
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "registering MgmtListener ...");
ctx.mgmtSwiftlet.addMgmtListener(this);
ctx.usageListConnections.setEntityRemoveListener(new EntityChangeAdapter(null) {
public void onEntityRemove(Entity parent, Entity delEntity) throws EntityRemoveException {
Connection myConnection = (Connection) delEntity.getDynamicObject();
ConnectionManager connectionManager = ctx.networkSwiftlet.getConnectionManager();
connectionManager.removeConnection(myConnection);
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "onEntityRemove (Connection): " + myConnection);
}
});
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "startup done.");
}
use of com.swiftmq.swiftlet.net.ConnectionManager 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.swiftlet.net.ConnectionManager in project swiftmq-ce by iitsoftware.
the class AMQPSwiftlet method startup.
protected void startup(Configuration configuration) throws SwiftletException {
ctx = new SwiftletContext(configuration, this);
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "startup ...");
Security.addProvider(new SASLProvider(SASLProvider.PROVIDER_NAME, 1.0, "SwiftMQ SASL Security Provider"));
createListenerAdapter((EntityList) ctx.root.getEntity("listeners"));
Property prop = ctx.root.getProperty("collect-interval");
prop.setPropertyChangeListener(new PropertyChangeAdapter(null) {
public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
collectInterval = ((Long) newValue).longValue();
collectChanged(((Long) oldValue).longValue(), collectInterval);
}
});
collectInterval = ((Long) prop.getValue()).longValue();
if (collectOn) {
if (collectInterval > 0) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "startup: registering msg/s count collector");
ctx.timerSwiftlet.addTimerListener(collectInterval, this);
} else if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "startup: collect interval <= 0; no msg/s count collector");
}
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "registering MgmtListener ...");
ctx.mgmtSwiftlet.addMgmtListener(this);
ctx.usageList.setEntityRemoveListener(new EntityChangeAdapter(null) {
public void onEntityRemove(Entity parent, Entity delEntity) throws EntityRemoveException {
Connection myConnection = (Connection) delEntity.getDynamicObject();
ConnectionManager connectionManager = ctx.networkSwiftlet.getConnectionManager();
connectionManager.removeConnection(myConnection);
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "onEntityRemove (Connection): " + myConnection);
}
});
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "startup done.");
}
use of com.swiftmq.swiftlet.net.ConnectionManager in project swiftmq-ce by iitsoftware.
the class AMQPSwiftlet method shutdown.
protected void shutdown() throws SwiftletException {
// true when shutdown while standby
if (ctx == null)
return;
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "shutdown ...");
try {
listenerAdapter.close();
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "shutdown: shutdown all AMQP 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);
Security.removeProvider(SASLProvider.PROVIDER_NAME);
} catch (Exception e) {
e.printStackTrace();
}
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "shutdown done.");
ctx = null;
}
Aggregations