use of com.swiftmq.swiftlet.SwiftletException in project swiftmq-ce by iitsoftware.
the class MQTTSwiftlet method createListener.
private void createListener(Entity listenerEntity) throws SwiftletException {
Entity connectionTemplate = getConnectionTemplate((String) listenerEntity.getProperty("connection-template").getValue());
String listenerName = listenerEntity.getName();
int port = ((Integer) listenerEntity.getProperty("port").getValue()).intValue();
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) connectionTemplate.getProperty("router-input-buffer-size").getValue()).intValue();
int inputExtendSize = ((Integer) connectionTemplate.getProperty("router-input-extend-size").getValue()).intValue();
int outputBufferSize = ((Integer) connectionTemplate.getProperty("router-output-buffer-size").getValue()).intValue();
int outputExtendSize = ((Integer) connectionTemplate.getProperty("router-output-extend-size").getValue()).intValue();
boolean useTCPNoDelay = ((Boolean) connectionTemplate.getProperty("use-tcp-no-delay").getValue()).booleanValue();
ListenerMetaData meta = new ListenerMetaData(bindAddress, port, this, -1, (String) connectionTemplate.getProperty("socketfactory-class").getValue(), new Acceptor(listenerName, listenerEntity.getProperty("max-connections"), listenerEntity.getProperty("connection-template")), inputBufferSize, inputExtendSize, outputBufferSize, outputExtendSize, useTCPNoDelay, new RawInputHandler(), new RawOutputHandler());
listenerEntity.setUserObject(meta);
createHostAccessList(meta, (EntityList) listenerEntity.getEntity("host-access-list"));
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "starting listener '" + listenerName + "' ...");
try {
ctx.networkSwiftlet.createTCPListener(meta);
} catch (Exception e) {
throw new SwiftletException(e.getMessage());
}
}
use of com.swiftmq.swiftlet.SwiftletException in project swiftmq-ce by iitsoftware.
the class XAResourceManagerSwiftletImpl method startup.
protected void startup(Configuration configuration) throws SwiftletException {
ctx = new SwiftletContext(this, configuration);
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "startup...");
try {
ctx.heuristicHandler.loadHeuristics();
} catch (Exception e) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "exception during loadHeuristics: " + e.toString());
ctx.logSwiftlet.logError(getName(), "exception during loadHeuristics: " + e.toString());
}
try {
buildPreparedTransactions();
} catch (Exception e) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "exception during buildPreparedTransactions: " + e.toString());
ctx.logSwiftlet.logError(getName(), "exception during buildPreparedTransactions: " + e.toString());
}
if (contexts.size() > 0) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), contexts.size() + " prepared transactions found");
ctx.logSwiftlet.logWarning(getName(), contexts.size() + " prepared transactions found!");
System.out.println("+++ WARNING! " + contexts.size() + " prepared transactions found!");
System.out.println("+++ HA/Routing XA transactions are automatically recovered.");
System.out.println("+++ You may also use Explorer/CLI for heuristic commit or rollback.");
}
Property prop = configuration.getProperty("scan-interval");
scanInterval = ((Long) prop.getValue()).longValue();
ctx.timerSwiftlet.addTimerListener(scanInterval, this);
prop.setPropertyChangeListener(new PropertyChangeListener() {
public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
ctx.timerSwiftlet.removeTimerListener(XAResourceManagerSwiftletImpl.this);
scanInterval = ((Long) newValue).longValue();
ctx.timerSwiftlet.addTimerListener(scanInterval, XAResourceManagerSwiftletImpl.this);
}
});
prop = configuration.getProperty("default-transaction-timeout");
defaultTxTimeout = ((Long) prop.getValue()).longValue();
long timeout = getTransactionTimeout();
if (timeout > 0)
ctx.timerSwiftlet.addTimerListener(timeout, txTimer);
prop.setPropertyChangeListener(new PropertyChangeListener() {
public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
long timeout = getTransactionTimeout();
if (timeout > 0)
ctx.timerSwiftlet.removeTimerListener(txTimer);
defaultTxTimeout = ((Long) newValue).longValue();
timeout = getTransactionTimeout();
if (timeout > 0)
ctx.timerSwiftlet.addTimerListener(timeout, txTimer);
}
});
CommandRegistry commandRegistry = ctx.preparedUsageList.getCommandRegistry();
CommandExecutor commitExecutor = new CommandExecutor() {
public String[] execute(String[] context, Entity entity, String[] cmd) {
if (cmd.length != 2)
return new String[] { TreeCommands.ERROR, "Invalid command, please try 'commit <id>'" };
Entity e = ctx.preparedUsageList.getEntity(cmd[1]);
if (e == null)
return new String[] { TreeCommands.ERROR, "Unknown Entity: " + cmd[1] };
XAContext xac = (XAContext) contexts.get(e.getDynamicObject());
XidImpl xid = xac.getXid();
try {
xac.commit(false);
if (!xid.isRouting())
ctx.heuristicHandler.addHeuristic(xid, true);
} catch (Exception e1) {
return new String[] { TreeCommands.ERROR, "Exception during commit: " + e1 };
}
removeXAContext(xid);
return null;
}
};
Command commitCommand = new Command("commit", "commit <id>", "Commit", true, commitExecutor, true, true);
commandRegistry.addCommand(commitCommand);
CommandExecutor rollbackExecutor = new CommandExecutor() {
public String[] execute(String[] context, Entity entity, String[] cmd) {
if (cmd.length != 2)
return new String[] { TreeCommands.ERROR, "Invalid command, please try 'rollback <id>'" };
Entity e = ctx.preparedUsageList.getEntity(cmd[1]);
if (e == null)
return new String[] { TreeCommands.ERROR, "Unknown Entity: " + cmd[1] };
XAContext xac = (XAContext) contexts.get(e.getDynamicObject());
XidImpl xid = xac.getXid();
try {
xac.rollback();
if (!xid.isRouting())
ctx.heuristicHandler.addHeuristic(xid, false);
} catch (Exception e1) {
return new String[] { TreeCommands.ERROR, "Exception during rollback: " + e1 };
}
removeXAContext(xid);
return null;
}
};
Command rollbackCommand = new Command("rollback", "rollback <id>", "Rollback", true, rollbackExecutor, true, true);
commandRegistry.addCommand(rollbackCommand);
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "startup...done");
}
use of com.swiftmq.swiftlet.SwiftletException in project swiftmq-ce by iitsoftware.
the class TraceSwiftletImpl method startup.
protected void startup(Configuration config) throws SwiftletException {
this.config = config;
files = new Hashtable();
spaces = new Hashtable();
Property prop = config.getProperty("max-file-size");
int mfs = ((Integer) prop.getValue()).intValue();
if (mfs <= 0)
maxFileSize = -1;
else
maxFileSize = mfs * 1024;
prop.setPropertyChangeListener(new PropertyChangeAdapter(null) {
public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
int n = ((Integer) newValue).intValue();
if (n <= 0)
maxFileSize = -1;
else
maxFileSize = n * 1024;
}
});
EntityList spaceList = (EntityList) config.getEntity("spaces");
try {
createSpaces(spaceList);
} catch (Exception e) {
throw new SwiftletException(e.getMessage());
}
}
use of com.swiftmq.swiftlet.SwiftletException in project swiftmq-ce by iitsoftware.
the class RoutingSwiftletImpl method createConnector.
private ConnectorMetaData createConnector(Entity connectorEntity) throws SwiftletException {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace("sys$routing", "starting connector: " + connectorEntity.getName());
String host = (String) connectorEntity.getProperty("hostname").getValue();
int port = ((Integer) connectorEntity.getProperty("port").getValue()).intValue();
long retry = ((Long) connectorEntity.getProperty("retry-time").getValue()).longValue();
String socketFactoryClass = (String) connectorEntity.getProperty("socketfactory-class").getValue();
Property prop = connectorEntity.getProperty("password");
String password = (String) prop.getValue();
int inputBufferSize = ((Integer) connectorEntity.getProperty("router-input-buffer-size").getValue()).intValue();
int inputExtendSize = ((Integer) connectorEntity.getProperty("router-input-extend-size").getValue()).intValue();
int outputBufferSize = ((Integer) connectorEntity.getProperty("router-output-buffer-size").getValue()).intValue();
int outputExtendSize = ((Integer) connectorEntity.getProperty("router-output-extend-size").getValue()).intValue();
boolean useTCPNoDelay = ((Boolean) connectorEntity.getProperty("use-tcp-no-delay").getValue()).booleanValue();
ConnectorMetaData meta = new ConnectorMetaData(host, port, retry, this, -1, socketFactoryClass, acceptor, inputBufferSize, inputExtendSize, outputBufferSize, outputExtendSize, useTCPNoDelay);
connectorEntity.setUserObject(meta);
passwords.put(meta, password);
connectionEntities.put(meta, connectorEntity);
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 (connectorPassword): oldValue=" + oldValue + ", newValue=" + newValue);
}
});
prop = connectorEntity.getProperty("enabled");
if (((Boolean) prop.getValue()).booleanValue()) {
try {
ctx.networkSwiftlet.createTCPConnector(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 {
try {
boolean enabled = ((Boolean) newValue).booleanValue();
if (enabled)
ctx.networkSwiftlet.createTCPConnector((ConnectorMetaData) configObject);
else
ctx.networkSwiftlet.removeTCPConnector((ConnectorMetaData) configObject);
} catch (Exception e) {
throw new PropertyChangeException(e.getMessage());
}
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "propertyChanged (enabled): oldValue=" + oldValue + ", newValue=" + newValue);
}
});
return meta;
}
use of com.swiftmq.swiftlet.SwiftletException in project swiftmq-ce by iitsoftware.
the class QueueManagerImpl 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 com.swiftmq.swiftlet.SwiftletException
*/
protected void startup(Configuration config) throws SwiftletException {
startupTime = System.currentTimeMillis();
ctx = createSwiftletContext(config);
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "startup ...");
ctx.usageList.getCommandRegistry().addCommand(new Activate(ctx).createCommand());
ctx.usageList.getCommandRegistry().addCommand(new Viewer(ctx).createCommand());
ctx.usageList.getCommandRegistry().addCommand(new Exporter(ctx).createCommand());
ctx.usageList.getCommandRegistry().addCommand(new Importer(ctx).createCommand());
ctx.usageList.getCommandRegistry().addCommand(new Remover(ctx).createCommand());
ctx.usageList.getCommandRegistry().addCommand(new Copier(ctx).createCommand());
ctx.usageList.getCommandRegistry().addCommand(new Mover(ctx).createCommand());
ctx.usageList.getCommandRegistry().addCommand(new Resetter(ctx).createCommand());
if (ctx.smartTree)
ctx.usageList.getTemplate().removeEntities();
Property prop = ctx.root.getProperty(PROP_MAX_FLOWCONTROL_DELAY);
maxFlowControlDelay = ((Long) prop.getValue()).longValue();
queueControllerList = (EntityList) ctx.root.getEntity("queue-controllers");
ctx.messageQueueFactory = createMessageQueueFactory();
ctx.messageGroupDispatchPolicyFactory = createMessaageGroupDispatchPolicyFactory();
ctx.cacheTableFactory = createCacheTableFactory();
ctx.dispatchPolicyRegistry = new DispatchPolicyRegistry(ctx);
ctx.redispatcherController = new RedispatcherController(ctx);
regularQueueFactory = createRegularQueueFactory();
tempQueueFactory = createTempQueueFactory();
systemQueueFactory = createSystemQueueFactory();
tempQueueController = getQueueController(PREFIX_TEMP_QUEUE + "000");
if (tempQueueController == null)
throw new SwiftletException("No Queue Controller for temporary Queues defined!");
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "Queue Controller for temp queues: " + tempQueueController.getName());
localRouterName = SwiftletManager.getInstance().getRouterName();
queueTable = new HashMap();
inboundRedirectors = new HashMap();
outboundRedirectors = new HashMap();
// Create DLQ
try {
createQueue(DLQ, (ActiveLogin) null);
((MessageQueue) getQueueForInternalUse(DLQ)).setAlwaysDeliverExpired(true);
} catch (Exception e) {
e.printStackTrace();
throw new SwiftletException(e.toString());
}
createQueues((EntityList) ctx.root.getEntity("queues"));
SwiftletManager.getInstance().addSwiftletManagerListener("sys$jndi", new SwiftletManagerAdapter() {
public void swiftletStarted(SwiftletManagerEvent evt) {
try {
ctx.jndiSwiftlet = (JNDISwiftlet) SwiftletManager.getInstance().getSwiftlet("sys$jndi");
ctx.jndiAliasList = (EntityList) SwiftletManager.getInstance().getConfiguration("sys$jndi").getEntity("aliases");
registerJNDIQueues();
} catch (Exception e) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "swiftletStartet, exception=" + e);
}
}
public void swiftletStopped(SwiftletManagerEvent swiftletManagerEvent) {
ctx.jndiSwiftlet = null;
ctx.jndiAliasList = null;
}
});
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);
}
}
});
prop = ctx.root.getProperty(PROP_LOG_DUPLICATES);
prop.setPropertyChangeListener(new PropertyChangeAdapter(null) {
public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
logDuplicates = ((Boolean) newValue).booleanValue();
}
});
logDuplicates = ((Boolean) prop.getValue()).booleanValue();
prop = ctx.root.getProperty(PROP_LOG_EXPIRED);
prop.setPropertyChangeListener(new PropertyChangeAdapter(null) {
public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
logExpired = ((Boolean) newValue).booleanValue();
}
});
logExpired = ((Boolean) prop.getValue()).booleanValue();
prop = ctx.root.getProperty(PROP_DELIVER_EXPIRED);
prop.setPropertyChangeListener(new PropertyChangeAdapter(null) {
public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
deliverExpired = ((Boolean) newValue).booleanValue();
}
});
deliverExpired = ((Boolean) prop.getValue()).booleanValue();
prop = ctx.root.getProperty(PROP_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 message count collector");
ctx.timerSwiftlet.addTimerListener(collectInterval, this);
} else if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "startup: collect interval <= 0; no message count collector");
}
prop = ctx.root.getProperty(PROP_MULTI_QUEUE_TX_GLOBAL_LOCK);
if (prop != null) {
prop.setPropertyChangeListener(new PropertyChangeAdapter(null) {
public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
setUseGlobalLocking(((Boolean) newValue).booleanValue());
}
});
setUseGlobalLocking(((Boolean) prop.getValue()).booleanValue());
}
SwiftletManager.getInstance().addSwiftletManagerListener("sys$scheduler", new SwiftletManagerAdapter() {
public void swiftletStarted(SwiftletManagerEvent event) {
ctx.schedulerSwiftlet = (SchedulerSwiftlet) SwiftletManager.getInstance().getSwiftlet("sys$scheduler");
jobRegistrar = new JobRegistrar(ctx);
jobRegistrar.register();
}
public void swiftletStopInitiated(SwiftletManagerEvent event) {
jobRegistrar.unregister();
}
});
SwiftletManager.getInstance().addSwiftletManagerListener("sys$routing", new SwiftletManagerAdapter() {
public void swiftletStarted(SwiftletManagerEvent event) {
try {
startCluster();
startCompositeQueues();
} catch (Exception e) {
e.printStackTrace();
}
ctx.routingSwiftlet = (RoutingSwiftlet) SwiftletManager.getInstance().getSwiftlet("sys$routing");
routingListener = new ClusterRoutingListener();
ctx.routingSwiftlet.addRoutingListener(routingListener);
}
public void swiftletStopInitiated(SwiftletManagerEvent event) {
ctx.routingSwiftlet.removeRoutingListener(routingListener);
try {
stopCluster();
stopCompositeQueues();
} catch (Exception e) {
e.printStackTrace();
}
}
});
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "startup: done.");
}
Aggregations