use of com.swiftmq.swiftlet.net.Connection 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.Connection 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.Connection in project swiftmq-ce by iitsoftware.
the class ConnectionManagerImpl method collectByteCounts.
public synchronized void collectByteCounts() {
long actTime = System.currentTimeMillis();
double deltas = (actTime - lastCollectTime) / 1000.0;
for (Object o : ctx.usageList.getEntities().entrySet()) {
Entity entity = (Entity) ((Map.Entry) o).getValue();
Property input = entity.getProperty("throughput-input");
Property output = entity.getProperty("throughput-output");
Connection connection = (Connection) entity.getDynamicObject();
if (connection != null) {
Countable in = (Countable) connection.getInputStream();
Countable out = (Countable) connection.getOutputStream();
if (lastCollectTime != -1) {
try {
input.setValue(formatter.format(new Double(((double) in.getByteCount() / 1024.0) / deltas)));
output.setValue(formatter.format(new Double(((double) out.getByteCount() / 1024.0) / deltas)));
} catch (Exception ignored) {
}
} else {
try {
input.setValue(0.0);
output.setValue(0.0);
} catch (Exception ignored) {
}
}
in.resetByteCount();
out.resetByteCount();
}
}
lastCollectTime = actTime;
}
use of com.swiftmq.swiftlet.net.Connection 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.Connection 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