use of com.swiftmq.swiftlet.SwiftletException in project swiftmq-ce by iitsoftware.
the class TopicManagerImpl method createSlowSubscriberConditions.
private void createSlowSubscriberConditions() throws SwiftletException {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "createSlowSubscriberConditions...");
EntityList sspList = (EntityList) root.getEntity("slow-subscriber-conditions");
Map entities = sspList.getEntities();
if (entities != null && entities.size() > 0) {
for (Iterator iter = entities.entrySet().iterator(); iter.hasNext(); ) {
Entity entity = (Entity) ((Map.Entry) iter.next()).getValue();
String[] tt = tokenizeTopicName(entity.getName());
if (tt.length != 1)
throw new SwiftletException(entity.getName() + ": Invalid topic name. Please specify only the root node of the topic hierarchy!");
try {
SwiftUtilities.verifyClientId(entity.getName());
addSlowSubscriberCondition(new SlowSubscriberCondition(entity));
} catch (Exception e) {
throw new SwiftletException("Error creating slow subscriber condition: " + e.getMessage());
}
}
}
sspList.setEntityAddListener(new EntityChangeAdapter(null) {
public void onEntityAdd(Entity parent, Entity newEntity) throws EntityAddException {
try {
String[] tt = tokenizeTopicName(newEntity.getName());
if (tt.length != 1)
throw new SwiftletException(newEntity.getName() + ": Invalid topic name. Please specify only the root node of the topic hierarchy!");
SwiftUtilities.verifyClientId(newEntity.getName());
addSlowSubscriberCondition(new SlowSubscriberCondition(newEntity));
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "onEntityAdd (slow-subscriber-conditions): new condition=" + newEntity.getName());
} catch (Exception e) {
throw new EntityAddException(e.getMessage());
}
}
});
sspList.setEntityRemoveListener(new EntityChangeAdapter(null) {
public void onEntityRemove(Entity parent, Entity delEntity) throws EntityRemoveException {
try {
removeSlowSubscriberCondition(delEntity.getName());
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "onEntityRemove (slow-subscriber-conditions): del conditions=" + delEntity.getName());
} catch (Exception e) {
throw new EntityRemoveException(e.getMessage());
}
}
});
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "createSlowSubscriberPolicies done.");
}
use of com.swiftmq.swiftlet.SwiftletException in project swiftmq-ce by iitsoftware.
the class TopicManagerImpl method createStaticRemoteRouterSubs.
private void createStaticRemoteRouterSubs() throws SwiftletException {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "createStaticRemoteRouterSubs...");
EntityList srrList = (EntityList) root.getEntity("static-remote-router-subscriptions");
if (srrList == null)
return;
Map entities = srrList.getEntities();
if (entities != null && entities.size() > 0) {
for (Iterator iter = entities.entrySet().iterator(); iter.hasNext(); ) {
Entity entity = (Entity) ((Map.Entry) iter.next()).getValue();
Route route = ctx.routingSwiftlet.getRoute(entity.getName());
if (route == null)
throw new SwiftletException("Unable to create static remote router subscriptions for router '" + entity.getName() + "', missing route. Please create a static route to '" + entity.getName() + "'");
try {
createStaticTopicSub(entity);
} catch (Exception e) {
throw new SwiftletException(e.getMessage());
}
}
}
srrList.setEntityAddListener(new EntityChangeAdapter(null) {
public void onEntityAdd(Entity parent, Entity newEntity) throws EntityAddException {
try {
Route route = ctx.routingSwiftlet.getRoute(newEntity.getName());
if (route == null)
throw new SwiftletException("Unable to create static remote router subscriptions for router '" + newEntity.getName() + "', missing route. Please create a static route to '" + newEntity.getName() + "'");
createStaticTopicSub(newEntity);
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "onEntityAdd (static-remote-router-subscriptions): new router=" + newEntity.getName());
} catch (Exception e) {
throw new EntityAddException(e.getMessage());
}
}
});
srrList.setEntityRemoveListener(new EntityChangeAdapter(null) {
public void onEntityRemove(Entity parent, Entity delEntity) throws EntityRemoveException {
try {
EntityList stsList = (EntityList) delEntity.getEntity("static-topic-subscriptions");
Map entities = stsList.getEntities();
if (entities != null && entities.size() > 0) {
for (Iterator iter = entities.entrySet().iterator(); iter.hasNext(); ) {
Entity entity = (Entity) ((Map.Entry) iter.next()).getValue();
removeStaticSubscription(delEntity.getName(), entity.getName());
}
}
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "onEntityRemove (static-remote-router-subscriptions): del router=" + delEntity.getName());
} catch (Exception e) {
throw new EntityRemoveException(e.getMessage());
}
}
});
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "createStaticRemoteRouterSubs done.");
}
use of com.swiftmq.swiftlet.SwiftletException in project swiftmq-ce by iitsoftware.
the class ThreadpoolSwiftletImpl method startup.
protected void startup(Configuration config) throws SwiftletException {
this.config = config;
root = config;
usageList = (EntityList) root.getEntity("usage");
traceSwiftlet = (TraceSwiftlet) SwiftletManager.getInstance().getSwiftlet("sys$trace");
traceSpace = traceSwiftlet.getTraceSpace(TraceSwiftlet.SPACE_KERNEL);
if (traceSpace.enabled)
traceSpace.trace(getName(), "startup ...");
EntityList poolList = (EntityList) root.getEntity("pools");
createPool(DEFAULT_POOL, null, poolList.getTemplate());
PoolDispatcher dp = (PoolDispatcher) pools.get(DEFAULT_POOL);
dp.setKernelPool(true);
String[] poolNames = getDefinedPoolnames(poolList);
if (poolNames != null && poolNames.length > 0) {
if (traceSpace.enabled)
traceSpace.trace(getName(), "startup: starting defined thread pools");
for (int i = 0; i < poolNames.length; i++) {
createPool(poolNames[i], poolList.getEntity(poolNames[i]), poolList.getTemplate());
storeThreadNamesForPool(poolNames[i], poolList.getEntity(poolNames[i]));
}
}
poolList.setEntityAddListener(new EntityChangeAdapter(null) {
public void onEntityAdd(Entity parent, Entity newEntity) throws EntityAddException {
boolean kp = ((Boolean) newEntity.getProperty(PROP_KERNEL_POOL).getValue()).booleanValue();
if (kp)
throw new EntityAddException("You cannot create a kernel pool dynamically.");
createPool(newEntity.getName(), newEntity, newEntity);
if (traceSpace.enabled)
traceSpace.trace(getName(), "onEntityAdd (pool), poolName=" + newEntity.getName());
}
});
poolList.setEntityRemoveListener(new EntityChangeAdapter(null) {
public void onEntityRemove(Entity parent, Entity delEntity) throws EntityRemoveException {
PoolDispatcher pd = null;
synchronized (pools) {
pd = (PoolDispatcher) pools.get(delEntity.getName());
if (pd.isKernelPool())
throw new EntityRemoveException("You cannot remove a kernel pool dynamically.");
pd.close();
pools.remove(delEntity.getName());
usageList.removeDynamicEntity(pd);
}
synchronized (threadNameMaps) {
for (Iterator iter = threadNameMaps.entrySet().iterator(); iter.hasNext(); ) {
String entry = (String) ((Map.Entry) iter.next()).getValue();
if (entry.equals(pd.getPoolName()))
iter.remove();
}
}
if (traceSpace.enabled)
traceSpace.trace(getName(), "onEntityRemove (pool): poolName=" + delEntity.getName());
}
});
try {
SwiftletManager.getInstance().addSwiftletManagerListener("sys$mgmt", new SwiftletManagerAdapter() {
public void swiftletStarted(SwiftletManagerEvent evt) {
try {
timerSwiftlet = (TimerSwiftlet) SwiftletManager.getInstance().getSwiftlet("sys$timer");
mgmtSwiftlet = (MgmtSwiftlet) SwiftletManager.getInstance().getSwiftlet("sys$mgmt");
if (traceSpace.enabled)
traceSpace.trace(getName(), "registering MgmtListener ...");
mgmtSwiftlet.addMgmtListener(new MgmtListener() {
public void adminToolActivated() {
collectOn = true;
collectChanged(-1, collectInterval);
}
public void adminToolDeactivated() {
collectChanged(collectInterval, -1);
collectOn = false;
}
});
} catch (Exception e) {
if (traceSpace.enabled)
traceSpace.trace(getName(), "swiftletStartet, exception=" + e);
}
}
});
} catch (Exception e) {
throw new SwiftletException(e.getMessage());
}
Property prop = 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 (traceSpace.enabled)
traceSpace.trace(getName(), "startup: registering thread count collector");
timerSwiftlet.addTimerListener(collectInterval, this);
} else if (traceSpace.enabled)
traceSpace.trace(getName(), "startup: collect interval <= 0; no thread count collector");
}
}
Aggregations