use of com.swiftmq.swiftlet.SwiftletException in project swiftmq-ce by iitsoftware.
the class QueueManagerImpl method createQueues.
private void createQueues(EntityList queueList) throws SwiftletException {
Map m = queueList.getEntities();
if (m.size() > 0) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "createQueues: begin starting queues ...");
try {
for (Iterator iter = m.entrySet().iterator(); iter.hasNext(); ) {
Entity queueEntity = (Entity) ((Map.Entry) iter.next()).getValue();
createQueue(queueEntity);
}
} catch (Exception e) {
e.printStackTrace();
throw new SwiftletException(e.getMessage());
}
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "createQueues: end starting queues ...");
} else if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "createQueues: no queues defined");
queueList.setEntityAddListener(new EntityChangeAdapter(null) {
public void onEntityAdd(Entity parent, Entity newEntity) throws EntityAddException {
try {
createQueue(newEntity);
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "onEntityAdd (queue): new queue=" + newEntity.getName());
} catch (Exception e) {
throw new EntityAddException(e.getMessage());
}
}
});
queueList.setEntityRemoveListener(new EntityChangeAdapter(null) {
public void onEntityRemove(Entity parent, Entity delEntity) throws EntityRemoveException {
try {
String qn = delEntity.getName() + '@' + localRouterName;
ActiveQueue queue = getQueue(qn);
queue.getAbstractQueue().deleteContent();
deleteQueue(qn, false);
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "onEntityRemove (queue): del queue=" + delEntity.getName());
} catch (Exception e) {
throw new EntityRemoveException(e.getMessage());
}
}
});
}
use of com.swiftmq.swiftlet.SwiftletException in project swiftmq-ce by iitsoftware.
the class JMSSwiftlet 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
*/
protected void startup(Configuration config) throws SwiftletException {
ctx = new SwiftletContext(config, this);
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "startup ...");
Property prop = ctx.root.getProperty("allow-same-clientid");
if (prop != null) {
allowSameClientId = ((Boolean) prop.getValue()).booleanValue();
prop.setPropertyChangeListener(new PropertyChangeListener() {
public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
allowSameClientId = ((Boolean) newValue).booleanValue();
}
});
}
// set default props
prop = ((EntityList) ctx.root.getEntity("listeners")).getTemplate().getProperty("socketfactory-class");
prop.setDefaultProp(ctx.root.getProperty("socketfactory-class"));
createGeneralProps(ctx.root);
createListeners((EntityList) ctx.root.getEntity("listeners"));
intraVMMetaData = new IntraVMListenerMetaData(this, new Acceptor("intravm", null));
try {
ctx.networkSwiftlet.createIntraVMListener(intraVMMetaData);
createIVMConnectionFactories((EntityList) ctx.root.getEntity("intravm-connection-factories"));
} catch (Exception e) {
throw new SwiftletException(e.getMessage());
}
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 thread 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 (JMSConnection): " + 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 JMSSwiftlet method shutdown.
/**
* Shutdown the swiftlet. Check if all shutdown conditions are met. Do shutdown work (i. e. stop working thread, close resources).
* If any condition prevends from shutdown fire a SwiftletException.
*
* @throws SwiftletException
*/
protected void shutdown() throws SwiftletException {
// true when shutdown while standby
if (ctx == null)
return;
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "shutdown: stopping listener ...");
ctx.jndiSwiftlet.deregisterJNDIObjects(new CFComparable(INTRAVM_LISTENER));
ctx.networkSwiftlet.removeIntraVMListener(intraVMMetaData);
EntityList listenerList = (EntityList) ctx.root.getEntity("listeners");
String[] inboundNames = listenerList.getEntityNames();
if (inboundNames != null) {
for (int i = 0; i < inboundNames.length; i++) {
ListenerMetaData meta = (ListenerMetaData) listenerList.getEntity(inboundNames[i]).getUserObject();
ctx.networkSwiftlet.removeTCPListener(meta);
}
}
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "shutdown: shutdown all jms 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) {
}
}
clientSet.clear();
ctx.mgmtSwiftlet.removeMgmtListener(this);
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 JMSSwiftlet method createGeneralProps.
private void createGeneralProps(Entity root) throws SwiftletException {
Property prop = root.getProperty("crfactory-class");
String crf = (String) root.getProperty("crfactory-class").getValue();
try {
challengeResponseFactory = (ChallengeResponseFactory) Class.forName(crf).newInstance();
} catch (Exception e) {
String msg = "Error creating class instance of challenge/response factory '" + crf + "', exception=" + e;
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), msg);
throw new SwiftletException(msg);
}
prop.setPropertyChangeListener(new PropertyChangeAdapter(null) {
public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
try {
ChallengeResponseFactory sf = (ChallengeResponseFactory) Class.forName((String) newValue).newInstance();
} catch (Exception e) {
String msg = "Error creating class instance of default challenge/response factory '" + newValue + "', exception=" + e;
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), msg);
throw new PropertyChangeException(msg);
}
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "propertyChanged (crfactory.class): oldValue=" + oldValue + ", newValue=" + newValue);
}
});
prop = root.getProperty("max-connections");
maxConnections = ((Integer) prop.getValue()).intValue();
if (maxConnections < -1 || maxConnections == 0)
throw new SwiftletException("Invalid Value, must be -1 (unlimited) or > 0");
prop.setPropertyChangeListener(new PropertyChangeAdapter(null) {
public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
int n = ((Integer) newValue).intValue();
if (n < -1 || n == 0)
throw new PropertyChangeException("Invalid Value, must be -1 (unlimited) or > 0");
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "propertyChanged (maxconnections): oldValue=" + oldValue + ", newValue=" + newValue);
maxConnections = n;
}
});
}
use of com.swiftmq.swiftlet.SwiftletException in project swiftmq-ce by iitsoftware.
the class JMSSwiftlet 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();
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());
}
String connectIP = (String) listenerEntity.getProperty("connectaddress").getValue();
if (connectIP != null && connectIP.trim().length() > 0)
connectAddresses.put(listenerName, connectIP);
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, new Acceptor(listenerName, listenerEntity.getProperty("max-connections")), inputBufferSize, inputExtendSize, outputBufferSize, outputExtendSize, useTCPNoDelay);
listenerEntity.setUserObject(meta);
createHostAccessList(meta, (EntityList) listenerEntity.getEntity("host-access-list"));
EntityList cfList = (EntityList) listenerEntity.getEntity("connection-factories");
try {
createConnectionFactories(listenerEntity, cfList);
} catch (Exception e) {
throw new SwiftletException(e.toString());
}
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "starting listener '" + listenerName + "' ...");
try {
ctx.networkSwiftlet.createTCPListener(meta);
} catch (Exception e) {
throw new SwiftletException(e.getMessage());
}
if (cfList.getEntity(listenerName + "@" + SwiftletManager.getInstance().getRouterName()) == null) {
ctx.timerSwiftlet.addInstantTimerListener(5000, new CFTimer(listenerName, cfList));
}
return meta;
}
Aggregations