use of com.swiftmq.swiftlet.auth.ActiveLogin in project swiftmq-ce by iitsoftware.
the class HeuristicHandler method loadHeuristics.
public void loadHeuristics() throws Exception {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.xaSwiftlet.getName(), toString() + "/loadHeuristics");
duringLoad = true;
try {
if (!ctx.queueManager.isQueueDefined(HEURISTIC_QUEUE))
ctx.queueManager.createQueue(HEURISTIC_QUEUE, (ActiveLogin) null);
QueueReceiver receiver = ctx.queueManager.createQueueReceiver(HEURISTIC_QUEUE, null, null);
QueuePullTransaction t = receiver.createTransaction(false);
MessageEntry entry = null;
while ((entry = t.getMessage(0)) != null) {
Entity entity = ctx.heuristicUsageList.createEntity();
MessageImpl msg = entry.getMessage();
maxId = Math.max(maxId, msg.getIntProperty(PROP_IID));
messageToEntity(msg, entity);
entity.createCommands();
ctx.heuristicUsageList.addEntity(entity);
}
t.rollback();
receiver.close();
} finally {
duringLoad = false;
}
}
use of com.swiftmq.swiftlet.auth.ActiveLogin 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.auth.ActiveLogin in project swiftmq-ce by iitsoftware.
the class TopicInput method start.
@Override
public void start() throws Exception {
if (started)
return;
if (!ctx.ctx.topicManager.isTopicDefined(destinationName))
ctx.ctx.topicManager.createTopic(destinationName);
MessageSelector ms = null;
if (selector != null) {
ms = new MessageSelector(selector);
ms.compile();
}
if (durable) {
ActiveLogin dlogin = ctx.ctx.authenticationSwiftlet.createActiveLogin(clientId, "DURABLE");
dlogin.setClientId(clientId);
TopicImpl topic = ctx.ctx.topicManager.verifyTopic(new TopicImpl(destinationName));
queueName = ctx.ctx.topicManager.subscribeDurable(durableName, topic, ms, false, dlogin);
} else {
queueName = ctx.ctx.queueManager.createTemporaryQueue();
subscriberId = ctx.ctx.topicManager.subscribe(destinationName, ms, false, queueName, true);
}
QueueReceiver receiver = ctx.ctx.queueManager.createQueueReceiver(queueName, (ActiveLogin) null, null);
messageProcessor = new QueueMessageProcessor(ctx, this, receiver, null);
messageProcessor.restart();
started = true;
}
use of com.swiftmq.swiftlet.auth.ActiveLogin in project swiftmq-ce by iitsoftware.
the class SchedulerRegistry method getScheduler.
public synchronized Scheduler getScheduler(String destinationRouter) throws Exception {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString() + "/getScheduler, destinationRouter=" + destinationRouter);
Scheduler scheduler = (Scheduler) schedulers.get(destinationRouter);
if (scheduler == null) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString() + "/getScheduler, destinationRouter=" + destinationRouter + ", creating scheduler...");
String queueName = QUEUE_PREFIX + destinationRouter + "@" + ctx.routerName;
if (!ctx.queueManager.isQueueDefined(queueName))
ctx.queueManager.createQueue(queueName, (ActiveLogin) null);
ctx.queueManager.setQueueOutboundRedirector(OUTBOUND_REDIR_PRED + destinationRouter, queueName);
if (ctx.roundRobinEnabled) {
scheduler = new RoundRobinScheduler(ctx, destinationRouter, queueName);
} else {
scheduler = new DefaultScheduler(ctx, destinationRouter, queueName);
}
schedulers.put(destinationRouter, scheduler);
RouteImpl route = (RouteImpl) ctx.routingSwiftlet.getRoute(destinationRouter);
if (route == null)
ctx.routingSwiftlet.addRoute(new RouteImpl(destinationRouter, queueName, true, scheduler));
else
route.setScheduler(scheduler);
}
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString() + "/getScheduler, destinationRouter=" + destinationRouter + ", returns " + scheduler);
return scheduler;
}
use of com.swiftmq.swiftlet.auth.ActiveLogin in project swiftmq-ce by iitsoftware.
the class TopicManagerImpl method startup.
protected void startup(Configuration config) throws SwiftletException {
this.config = config;
root = config;
ctx = new TopicManagerContext();
ctx.topicManager = this;
ctx.traceSwiftlet = (TraceSwiftlet) SwiftletManager.getInstance().getSwiftlet("sys$trace");
ctx.traceSpace = ctx.traceSwiftlet.getTraceSpace(TraceSwiftlet.SPACE_KERNEL);
ctx.logSwiftlet = (LogSwiftlet) SwiftletManager.getInstance().getSwiftlet("sys$log");
ctx.storeSwiftlet = (StoreSwiftlet) SwiftletManager.getInstance().getSwiftlet("sys$store");
ctx.queueManager = (QueueManager) SwiftletManager.getInstance().getSwiftlet("sys$queuemanager");
ctx.authSwiftlet = (AuthenticationSwiftlet) SwiftletManager.getInstance().getSwiftlet("sys$authentication");
ctx.threadpoolSwiftlet = (ThreadpoolSwiftlet) SwiftletManager.getInstance().getSwiftlet("sys$threadpool");
ctx.timerSwiftlet = (TimerSwiftlet) SwiftletManager.getInstance().getSwiftlet("sys$timer");
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "startup ...");
ctx.activeDurableList = (EntityList) root.getEntity("usage").getEntity("durables");
ctx.activeSubscriberList = (EntityList) root.getEntity("usage").getEntity("subscriber");
ctx.remoteSubscriberList = (EntityList) root.getEntity("usage").getEntity("subscriber-remote");
if (ctx.remoteSubscriberList != null) {
ctx.remoteSubscriberList.setEntityRemoveListener(new EntityRemoveListener() {
public void onEntityRemove(Entity parent, Entity delEntity) throws EntityRemoveException {
removeRemoteSubscriptions(delEntity.getName());
if (ctx.announceSender != null)
ctx.announceSender.routerRemoved(delEntity.getName());
}
});
new TopicAnnounceSender(ctx);
}
SwiftletManager.getInstance().addSwiftletManagerListener("sys$routing", new SwiftletManagerAdapter() {
public void swiftletStarted(SwiftletManagerEvent evt) {
try {
ctx.routingSwiftlet = (RoutingSwiftlet) SwiftletManager.getInstance().getSwiftlet("sys$routing");
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "starting topic announcer ...");
Route[] routes = ctx.routingSwiftlet.getRoutes();
if (routes != null) {
for (int i = 0; i < routes.length; i++) {
ctx.announceSender.destinationAdded(routes[i]);
}
}
ctx.routingSwiftlet.addRoutingListener(ctx.announceSender);
} catch (Exception e) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "swiftletStartet, exception=" + e);
}
ctx.announceSender.start();
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "creating static remote subscriptions ...");
try {
createStaticRemoteRouterSubs();
} catch (SwiftletException e) {
e.printStackTrace();
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "creating static remote subscriptions ...");
ctx.logSwiftlet.logError("sys$topicmanager", e.getMessage());
}
}
});
SwiftletManager.getInstance().addSwiftletManagerListener("sys$jndi", new SwiftletManagerAdapter() {
public void swiftletStarted(SwiftletManagerEvent evt) {
try {
ctx.jndiSwiftlet = (JNDISwiftlet) SwiftletManager.getInstance().getSwiftlet("sys$jndi");
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "registering JNDI topics ...");
Iterator iter = rootBrokers.entrySet().iterator();
while (iter.hasNext()) {
TopicBroker broker = (TopicBroker) ((Map.Entry) iter.next()).getValue();
String[] names = broker.getTopicNames();
for (int i = 0; i < names.length; i++) {
registerJNDI(names[i], new TopicImpl(names[i]));
}
}
} catch (Exception e) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "swiftletStartet, exception=" + e);
}
}
});
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "startup: creating topics ...");
ctx.logSwiftlet.logInformation(getName(), "startup: creating topics ...");
try {
createTopics((EntityList) root.getEntity("topics"));
} catch (Exception e) {
throw new SwiftletException(e.getMessage());
}
if (ctx.remoteSubscriberList != null) {
topicQueue = TOPIC_QUEUE + '@' + SwiftletManager.getInstance().getRouterName();
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "starting TopicAnnounceReceiver ...");
try {
new TopicAnnounceReceiver(ctx, topicQueue);
} catch (Exception e) {
throw new SwiftletException(e.getMessage());
}
}
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "creating durable subscribers ... ");
try {
durableSubscriptions = loadDurables();
} catch (Exception e) {
throw new SwiftletException("error loading durable subscriptions: " + e);
}
Iterator iter = durableSubscriptions.keySet().iterator();
while (iter.hasNext()) {
String queueName = (String) iter.next();
DurableSubscription durable = (DurableSubscription) durableSubscriptions.get(queueName);
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "creating durable subscriber: " + durable);
durableSubscriptions.put(durable.getQueueName(), durable);
try {
ctx.queueManager.createQueue(durable.getQueueName(), (ActiveLogin) null);
TopicImpl topic = new TopicImpl(getQueueForTopic(durable.getTopicName()), durable.getTopicName());
// it could be the topic isn't defined but it MUST for dursubs!
try {
createTopic(topic.getTopicName());
} catch (Exception ignored) {
}
ActiveLogin dlogin = ctx.authSwiftlet.createActiveLogin(durable.getClientId(), DURABLE_TYPE);
dlogin.setClientId(durable.getClientId());
int id = subscribe(topic, durable.getSelector(), durable.isNoLocal(), durable.getQueueName(), dlogin);
durable.setTopicSubscription((TopicSubscription) topicSubscriptions.get(id));
Entity durEntity = ctx.activeDurableList.createEntity();
durEntity.setName(durable.getQueueName());
durEntity.setDynamicObject(durable);
durEntity.createCommands();
Property prop = durEntity.getProperty("clientid");
prop.setValue(dlogin.getClientId());
prop.setReadOnly(true);
prop = durEntity.getProperty("durablename");
prop.setValue(durable.getDurableName());
prop.setReadOnly(true);
prop = durEntity.getProperty("topic");
prop.setValue(durable.getTopicName());
prop.setReadOnly(true);
prop = durEntity.getProperty("boundto");
prop.setValue(durable.getQueueName());
prop.setReadOnly(true);
prop = durEntity.getProperty("nolocal");
prop.setValue(new Boolean(durable.isNoLocal()));
prop.setReadOnly(true);
prop = durEntity.getProperty("selector");
if (durable.getSelector() != null) {
prop.setValue(durable.getSelector().getConditionString());
}
prop.setReadOnly(true);
ctx.activeDurableList.addEntity(durEntity);
} catch (Exception e) {
e.printStackTrace();
throw new SwiftletException(e.getMessage());
}
}
ctx.activeDurableList.setEntityAddListener(new EntityChangeAdapter(null) {
public void onEntityAdd(Entity parent, Entity newEntity) throws EntityAddException {
try {
if (programmaticDurableInProgress)
// do nothing
return;
String clientId = (String) newEntity.getProperty("clientid").getValue();
SwiftUtilities.verifyClientId(clientId);
String durableName = (String) newEntity.getProperty("durablename").getValue();
SwiftUtilities.verifyDurableName(durableName);
if (!newEntity.getName().equals(clientId + "$" + durableName))
throw new Exception("The name of this entity must be: " + clientId + "$" + durableName + " (but it is " + newEntity.getName() + ")");
if (clientId.indexOf('@') == -1) {
clientId = clientId + "@" + SwiftletManager.getInstance().getRouterName();
newEntity.getProperty("clientid").setValue(clientId);
}
String sel = (String) newEntity.getProperty("selector").getValue();
MessageSelector selector = null;
if (sel != null) {
selector = new MessageSelector(sel);
selector.compile();
}
String topicName = (String) newEntity.getProperty("topic").getValue();
if (!isTopicDefined(topicName))
throw new Exception("Unknown topic: " + topicName);
TopicImpl topic = verifyTopic(new TopicImpl(topicName));
boolean noLocal = ((Boolean) newEntity.getProperty("nolocal").getValue()).booleanValue();
ActiveLogin dlogin = ctx.authSwiftlet.createActiveLogin(clientId, DURABLE_TYPE);
dlogin.setClientId(clientId);
subscribeDurable(durableName, topic, selector, noLocal, dlogin, newEntity, false);
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "onEntityAdd (durable): new durable=" + newEntity.getName());
} catch (Exception e) {
throw new EntityAddException(e.getMessage());
}
}
});
ctx.activeDurableList.setEntityRemoveListener(new EntityChangeAdapter(null) {
public void onEntityRemove(Entity parent, Entity delEntity) throws EntityRemoveException {
try {
DurableSubscription myDurable = (DurableSubscription) delEntity.getDynamicObject();
ActiveLogin myLogin = ctx.authSwiftlet.createActiveLogin(myDurable.getClientId(), "DURABLE");
myLogin.setClientId(myDurable.getClientId());
deleteDurable(myDurable.getDurableName(), myLogin);
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "onEntityRemove (durable): del durable=" + myDurable);
} catch (Exception e) {
throw new EntityRemoveException(e.getMessage());
}
}
});
createSlowSubscriberConditions();
SwiftletManager.getInstance().addSwiftletManagerListener("sys$scheduler", new SwiftletManagerAdapter() {
public void swiftletStarted(SwiftletManagerEvent event) {
jobRegistrar = new JobRegistrar(TopicManagerImpl.this, (SchedulerSwiftlet) SwiftletManager.getInstance().getSwiftlet("sys$scheduler"), ctx);
jobRegistrar.register();
}
public void swiftletStopInitiated(SwiftletManagerEvent event) {
jobRegistrar.unregister();
}
});
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "startup done.");
}
Aggregations