use of com.swiftmq.swiftlet.SwiftletException in project swiftmq-ce by iitsoftware.
the class NetworkSwiftletImpl method startup.
@Override
protected void startup(Configuration config) throws SwiftletException {
try {
ctx = new SwiftletContext(config, this);
} catch (Exception e) {
throw new SwiftletException(e.getMessage());
}
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "startup ...");
setConnectionManager(new ConnectionManagerImpl(ctx));
ivmScheduler = new IntraVMScheduler(ctx);
ioScheduler = new NettyIOScheduler(ctx);
Property prop = config.getProperty("reuse-serversockets");
reuseServerSocket = (Boolean) prop.getValue();
prop = config.getProperty("dns-resolve-enabled");
prop.setPropertyChangeListener(new PropertyChangeAdapter(null) {
public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
dnsResolve = (Boolean) newValue;
}
});
dnsResolve = (Boolean) prop.getValue();
prop = config.getProperty("zombi-connection-timeout");
zombiConnectionTimeout = (Long) prop.getValue();
prop.setPropertyChangeListener(new PropertyChangeAdapter(null) {
public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
zombiConnectionTimeout = (Long) newValue;
}
});
prop = config.getProperty("collect-interval");
prop.setPropertyChangeListener(new PropertyChangeAdapter(null) {
public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
collectInterval = (Long) newValue;
collectChanged((Long) oldValue, collectInterval);
}
});
collectInterval = (Long) prop.getValue();
if (collectOn) {
if (collectInterval > 0) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "startup: registering byte count collector");
ctx.timerSwiftlet.addTimerListener(collectInterval, this);
} else if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "startup: collect interval <= 0; no byte count collector");
}
try {
SwiftletManager.getInstance().addSwiftletManagerListener("sys$mgmt", new SwiftletManagerAdapter() {
public void swiftletStarted(SwiftletManagerEvent evt) {
try {
ctx.mgmtSwiftlet = (MgmtSwiftlet) SwiftletManager.getInstance().getSwiftlet("sys$mgmt");
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "registering MgmtListener ...");
ctx.mgmtSwiftlet.addMgmtListener(new MgmtListener() {
public void adminToolActivated() {
collectOn = true;
collectChanged(-1, collectInterval);
}
public void adminToolDeactivated() {
collectChanged(collectInterval, -1);
collectOn = false;
}
});
} catch (Exception e) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "swiftletStartet, exception=" + e);
}
}
});
} catch (Exception e) {
throw new SwiftletException(e.getMessage());
}
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "startup DONE");
}
use of com.swiftmq.swiftlet.SwiftletException in project swiftmq-ce by iitsoftware.
the class StreamsSwiftlet method createDomainAdapter.
private void createDomainAdapter(EntityList list) throws SwiftletException {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "createDomainAdapter ...");
domainAdapter = new EntityListEventAdapter(list, true, true) {
public void onEntityAdd(Entity parent, Entity newEntity) throws EntityAddException {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "onEntityAdd: " + newEntity.getName() + " ...");
try {
final String domainName = newEntity.getName();
EntityListEventAdapter packageAdapter = new EntityListEventAdapter((EntityList) newEntity.getEntity("packages"), true, true) {
@Override
public void onEntityAdd(Entity parent, Entity newEntity) throws EntityAddException {
try {
final String packageName = newEntity.getName();
newEntity.setUserObject(createStreamAdapter((EntityList) newEntity.getEntity("streams"), domainName, packageName));
} catch (SwiftletException e) {
ctx.logSwiftlet.logError(getName(), "Error starting stream: " + e);
System.err.println("Error starting stream: " + e.getMessage());
}
}
@Override
public void onEntityRemove(Entity parent, Entity delEntity) throws EntityRemoveException {
try {
((EntityListEventAdapter) delEntity.getUserObject()).close();
} catch (Exception e) {
e.printStackTrace();
}
}
};
packageAdapter.init();
newEntity.setUserObject(packageAdapter);
} catch (Exception e) {
throw new EntityAddException(e.toString());
}
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "onEntityAdd: " + newEntity.getName() + " done");
}
public void onEntityRemove(Entity parent, Entity delEntity) throws EntityRemoveException {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "onEntityRemove: " + delEntity.getName() + " ...");
EntityListEventAdapter packageAdapter = (EntityListEventAdapter) delEntity.getUserObject();
if (packageAdapter != null) {
try {
packageAdapter.close();
} catch (Exception e) {
e.printStackTrace();
}
delEntity.setUserObject(null);
}
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "onEntityRemove: " + delEntity.getName() + " done");
}
};
try {
domainAdapter.init();
} catch (Exception e) {
throw new SwiftletException(e.toString());
}
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "createDomainAdapter done");
}
use of com.swiftmq.swiftlet.SwiftletException 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;
}
use of com.swiftmq.swiftlet.SwiftletException in project swiftmq-ce by iitsoftware.
the class JNDISwiftletImpl method startup.
/**
* Startup the swiftlet. Check if all required properties are defined and all other
* startup conditions are met. Do startup work (i. e. start working thread, get/open resources).
* If any condition prevends from startup fire a SwiftletException.
*
* @throws SwiftletException to prevend from startup
*/
protected void startup(Configuration config) throws SwiftletException {
ctx = new SwiftletContext();
ctx.config = config;
ctx.root = config;
ctx.usageList = (EntityList) ctx.root.getEntity("usage");
ctx.logSwiftlet = (LogSwiftlet) SwiftletManager.getInstance().getSwiftlet("sys$log");
ctx.traceSwiftlet = (TraceSwiftlet) SwiftletManager.getInstance().getSwiftlet("sys$trace");
ctx.traceSpace = ctx.traceSwiftlet.getTraceSpace(TraceSwiftlet.SPACE_KERNEL);
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "startup ...");
ctx.timerSwiftlet = (TimerSwiftlet) SwiftletManager.getInstance().getSwiftlet("sys$timer");
ctx.threadpoolSwiftlet = (ThreadpoolSwiftlet) SwiftletManager.getInstance().getSwiftlet("sys$threadpool");
ctx.myTP = ctx.threadpoolSwiftlet.getPool(TP_LISTENER);
ctx.queueManager = (QueueManager) SwiftletManager.getInstance().getSwiftlet("sys$queuemanager");
ctx.topicManager = (TopicManager) SwiftletManager.getInstance().getSwiftlet("sys$topicmanager");
ctx.jndiSwiftlet = this;
createStatics((EntityList) config.getEntity("remote-queues"));
createAliases((EntityList) config.getEntity("aliases"));
createReplications((EntityList) config.getEntity("jndi-replications"));
bindExternal();
try {
if (!ctx.queueManager.isQueueDefined(JNDISwiftlet.JNDI_QUEUE))
ctx.queueManager.createQueue(JNDISwiftlet.JNDI_QUEUE, (ActiveLogin) null);
if (!ctx.topicManager.isTopicDefined(JNDISwiftlet.JNDI_TOPIC))
ctx.topicManager.createTopic(JNDISwiftlet.JNDI_TOPIC);
queueJNDIProcessor = new QueueJNDIProcessor(ctx);
topicJNDIProcessor = new TopicJNDIProcessor(ctx);
} catch (Exception e) {
throw new SwiftletException(e.getMessage());
}
}
use of com.swiftmq.swiftlet.SwiftletException in project swiftmq-ce by iitsoftware.
the class MgmtSwiftletImpl method startup.
protected void startup(Configuration config) throws SwiftletException {
ctx = new SwiftletContext(this, config);
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "startup ...");
SwiftletManager.getInstance().addSwiftletManagerListener("sys$routing", new SwiftletManagerAdapter() {
public void swiftletStarted(SwiftletManagerEvent evt) {
try {
ctx.routingSwiftlet = (RoutingSwiftlet) SwiftletManager.getInstance().getSwiftlet("sys$routing");
ctx.routingSwiftlet.addRoutingListener(ctx.dispatchQueue);
miController = new MessageInterfaceController(ctx);
} catch (Exception e) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "swiftletStartet, exception=" + e);
}
}
});
SwiftletManager.getInstance().addSwiftletManagerListener("sys$amqp", new SwiftletManagerAdapter() {
public void swiftletStarted(SwiftletManagerEvent evt) {
try {
listener = new Listener(ctx);
} catch (Exception e) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "swiftletStartet, exception=" + e);
}
}
});
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "startup done");
}
Aggregations