use of com.swiftmq.swiftlet.SwiftletException in project swiftmq-ce by iitsoftware.
the class AuthenticationSwiftletImpl method createGroup.
private Group createGroup(String groupName, Entity groupEntity) throws SwiftletException {
if (groups.get(groupName) != null)
throw new SwiftletException("Group '" + groupName + "' is already defined!");
Group group = new Group(groupName);
createQueueGrants(group, (EntityList) groupEntity.getEntity("queue-grants"));
createTopicGrants(group, (EntityList) groupEntity.getEntity("topic-grants"));
if (traceSpace.enabled)
traceSpace.trace(getName(), "createGroup: " + group);
groups.put(group.getName(), group);
if (group.getName().equals(PUBLIC_GROUP))
publicGroup = group;
return group;
}
use of com.swiftmq.swiftlet.SwiftletException in project swiftmq-ce by iitsoftware.
the class RoutingSwiftletImpl method createStaticRoutes.
private void createStaticRoutes(EntityList staticRouteList) throws SwiftletException {
String[] staticRoutes = staticRouteList.getEntityNames();
if (staticRoutes != null) {
for (int i = 0; i < staticRoutes.length; i++) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "creating static route to: " + staticRoutes[i]);
try {
Scheduler scheduler = ctx.schedulerRegistry.getScheduler(staticRoutes[i]);
addRoute(new RouteImpl(staticRoutes[i], scheduler.getQueueName(), true, scheduler));
} catch (Exception e) {
throw new SwiftletException(e.getMessage());
}
}
}
staticRouteList.setEntityAddListener(new EntityChangeAdapter(null) {
public void onEntityAdd(Entity parent, Entity newEntity) throws EntityAddException {
String dest = newEntity.getName();
try {
SwiftUtilities.verifyRouterName(dest);
Scheduler scheduler = ctx.schedulerRegistry.getScheduler(dest);
RouteImpl route = (RouteImpl) getRoute(dest);
if (route == null)
addRoute(new RouteImpl(dest, scheduler.getQueueName(), false, scheduler));
else {
route.setStaticRoute(true);
if (route.getScheduler() == null)
route.setScheduler(scheduler);
}
} catch (Exception e) {
throw new EntityAddException(e.getMessage());
}
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "onEntityAdd (staticroute.routers): new staticroute=" + dest);
}
});
staticRouteList.setEntityRemoveListener(new EntityChangeAdapter(null) {
public void onEntityRemove(Entity parent, Entity delEntity) throws EntityRemoveException {
String dest = delEntity.getName();
try {
Scheduler scheduler = ctx.schedulerRegistry.getScheduler(dest);
if (scheduler.getNumberConnections() == 0) {
scheduler.close();
removeRoute(getRoute(dest));
}
} catch (Exception e) {
throw new EntityRemoveException(e.getMessage());
}
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "onEntityRemove (staticroute.routers): del staticroute=" + dest);
}
});
}
use of com.swiftmq.swiftlet.SwiftletException in project swiftmq-ce by iitsoftware.
the class RoutingSwiftletImpl method createListener.
private ListenerMetaData createListener(Entity listenerEntity) throws SwiftletException {
String listenerName = listenerEntity.getName();
int port = ((Integer) listenerEntity.getProperty("port").getValue()).intValue();
String socketFactoryClass = (String) listenerEntity.getProperty("socketfactory-class").getValue();
long keepAliveInterval = ((Long) listenerEntity.getProperty("keepalive-interval").getValue()).longValue();
Property prop = listenerEntity.getProperty("password");
String password = (String) prop.getValue();
InetAddress bindAddress = null;
try {
String s = (String) listenerEntity.getProperty("bindaddress").getValue();
if (s != null && s.trim().length() > 0)
bindAddress = InetAddress.getByName(s);
} catch (Exception e) {
throw new SwiftletException(e.getMessage());
}
int inputBufferSize = ((Integer) listenerEntity.getProperty("router-input-buffer-size").getValue()).intValue();
int inputExtendSize = ((Integer) listenerEntity.getProperty("router-input-extend-size").getValue()).intValue();
int outputBufferSize = ((Integer) listenerEntity.getProperty("router-output-buffer-size").getValue()).intValue();
int outputExtendSize = ((Integer) listenerEntity.getProperty("router-output-extend-size").getValue()).intValue();
boolean useTCPNoDelay = ((Boolean) listenerEntity.getProperty("use-tcp-no-delay").getValue()).booleanValue();
ListenerMetaData meta = new ListenerMetaData(bindAddress, port, this, keepAliveInterval, socketFactoryClass, acceptor, inputBufferSize, inputExtendSize, outputBufferSize, outputExtendSize, useTCPNoDelay);
listenerEntity.setUserObject(meta);
createHostAccessList(meta, (EntityList) listenerEntity.getEntity("host-access-list"));
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "starting listener '" + listenerName + "' ...");
try {
passwords.put(meta, password);
connectionEntities.put(meta, listenerEntity);
ctx.networkSwiftlet.createTCPListener(meta);
} catch (Exception e) {
throw new SwiftletException(e.getMessage());
}
prop.setPropertyChangeListener(new PropertyChangeAdapter(meta) {
public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
passwords.put(configObject, newValue);
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "propertyChanged (listenerPassword): oldValue=" + oldValue + ", newValue=" + newValue);
}
});
return meta;
}
use of com.swiftmq.swiftlet.SwiftletException 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.SwiftletException 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;
}
Aggregations