Search in sources :

Example 6 with SwiftletManagerEvent

use of com.swiftmq.swiftlet.event.SwiftletManagerEvent in project swiftmq-client by iitsoftware.

the class RouterMemoryMeter method start.

public synchronized void start() {
    timerSwiftlet = (TimerSwiftlet) SwiftletManager.getInstance().getSwiftlet("sys$timer");
    mgmtSwiftlet = (MgmtSwiftlet) SwiftletManager.getInstance().getSwiftlet("sys$mgmt");
    if (mgmtSwiftlet != null)
        mgmtSwiftlet.addMgmtListener(RouterMemoryMeter.this);
    else {
        SwiftletManager.getInstance().addSwiftletManagerListener("sys$mgmt", new SwiftletManagerAdapter() {

            public void swiftletStarted(SwiftletManagerEvent evt) {
                mgmtSwiftlet = (MgmtSwiftlet) SwiftletManager.getInstance().getSwiftlet("sys$mgmt");
                mgmtSwiftlet.addMgmtListener(RouterMemoryMeter.this);
            }
        });
    }
}
Also used : SwiftletManagerEvent(com.swiftmq.swiftlet.event.SwiftletManagerEvent) MgmtSwiftlet(com.swiftmq.swiftlet.mgmt.MgmtSwiftlet) SwiftletManagerAdapter(com.swiftmq.swiftlet.event.SwiftletManagerAdapter)

Example 7 with SwiftletManagerEvent

use of com.swiftmq.swiftlet.event.SwiftletManagerEvent in project swiftmq-ce by iitsoftware.

the class RoutingSwiftletImpl method startup.

protected void startup(Configuration config) throws SwiftletException {
    this.config = config;
    root = config;
    passwords = Collections.synchronizedMap(new HashMap());
    connectionEntities = Collections.synchronizedMap(new HashMap());
    connections = Collections.synchronizedSet(new HashSet());
    ctx = createSwiftletContext(this, root);
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(getName(), "startup ...");
    acceptor = new Acceptor();
    createRoutingQueues();
    createStaticRoutes((EntityList) root.getEntity("static-routes"));
    createListeners((EntityList) root.getEntity("listeners"));
    createConnectors((EntityList) root.getEntity("connectors"));
    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();
        }
    });
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(getName(), "startup done");
}
Also used : SwiftletManagerEvent(com.swiftmq.swiftlet.event.SwiftletManagerEvent) SchedulerSwiftlet(com.swiftmq.swiftlet.scheduler.SchedulerSwiftlet) JobRegistrar(com.swiftmq.impl.routing.single.jobs.JobRegistrar) SwiftletManagerAdapter(com.swiftmq.swiftlet.event.SwiftletManagerAdapter)

Example 8 with SwiftletManagerEvent

use of com.swiftmq.swiftlet.event.SwiftletManagerEvent 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.");
}
Also used : JNDISwiftlet(com.swiftmq.swiftlet.jndi.JNDISwiftlet) SwiftletManagerAdapter(com.swiftmq.swiftlet.event.SwiftletManagerAdapter) RoutingSwiftlet(com.swiftmq.swiftlet.routing.RoutingSwiftlet) SwiftletManagerEvent(com.swiftmq.swiftlet.event.SwiftletManagerEvent) SchedulerSwiftlet(com.swiftmq.swiftlet.scheduler.SchedulerSwiftlet) MgmtListener(com.swiftmq.swiftlet.mgmt.event.MgmtListener) MgmtSwiftlet(com.swiftmq.swiftlet.mgmt.MgmtSwiftlet) JobRegistrar(com.swiftmq.impl.queue.standard.jobs.JobRegistrar) IOException(java.io.IOException) SwiftletException(com.swiftmq.swiftlet.SwiftletException) AuthenticationException(com.swiftmq.swiftlet.auth.AuthenticationException) SwiftletException(com.swiftmq.swiftlet.SwiftletException)

Example 9 with SwiftletManagerEvent

use of com.swiftmq.swiftlet.event.SwiftletManagerEvent 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.");
}
Also used : JNDISwiftlet(com.swiftmq.swiftlet.jndi.JNDISwiftlet) SwiftletManagerAdapter(com.swiftmq.swiftlet.event.SwiftletManagerAdapter) RoutingSwiftlet(com.swiftmq.swiftlet.routing.RoutingSwiftlet) DurableStoreEntry(com.swiftmq.swiftlet.store.DurableStoreEntry) ActiveLogin(com.swiftmq.swiftlet.auth.ActiveLogin) SwiftletManagerEvent(com.swiftmq.swiftlet.event.SwiftletManagerEvent) MessageSelector(com.swiftmq.ms.MessageSelector) TopicImpl(com.swiftmq.jms.TopicImpl) TopicAnnounceSender(com.swiftmq.impl.topic.standard.announce.TopicAnnounceSender) JobRegistrar(com.swiftmq.impl.topic.standard.jobs.JobRegistrar) InvalidDestinationException(javax.jms.InvalidDestinationException) IOException(java.io.IOException) JMSException(javax.jms.JMSException) SwiftletException(com.swiftmq.swiftlet.SwiftletException) AuthenticationException(com.swiftmq.swiftlet.auth.AuthenticationException) TopicException(com.swiftmq.swiftlet.topic.TopicException) SwiftletException(com.swiftmq.swiftlet.SwiftletException) TopicAnnounceReceiver(com.swiftmq.impl.topic.standard.announce.TopicAnnounceReceiver)

Example 10 with SwiftletManagerEvent

use of com.swiftmq.swiftlet.event.SwiftletManagerEvent 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");
    }
}
Also used : MgmtListener(com.swiftmq.swiftlet.mgmt.event.MgmtListener) MgmtSwiftlet(com.swiftmq.swiftlet.mgmt.MgmtSwiftlet) SwiftletException(com.swiftmq.swiftlet.SwiftletException) SwiftletManagerAdapter(com.swiftmq.swiftlet.event.SwiftletManagerAdapter) SwiftletManagerEvent(com.swiftmq.swiftlet.event.SwiftletManagerEvent) SwiftletException(com.swiftmq.swiftlet.SwiftletException) Iterator(java.util.Iterator) TimerSwiftlet(com.swiftmq.swiftlet.timer.TimerSwiftlet)

Aggregations

SwiftletManagerEvent (com.swiftmq.swiftlet.event.SwiftletManagerEvent)10 SwiftletManagerAdapter (com.swiftmq.swiftlet.event.SwiftletManagerAdapter)9 SwiftletException (com.swiftmq.swiftlet.SwiftletException)6 MgmtSwiftlet (com.swiftmq.swiftlet.mgmt.MgmtSwiftlet)5 MgmtListener (com.swiftmq.swiftlet.mgmt.event.MgmtListener)3 RoutingSwiftlet (com.swiftmq.swiftlet.routing.RoutingSwiftlet)3 SchedulerSwiftlet (com.swiftmq.swiftlet.scheduler.SchedulerSwiftlet)3 IOException (java.io.IOException)3 Property (com.swiftmq.mgmt.Property)2 AuthenticationException (com.swiftmq.swiftlet.auth.AuthenticationException)2 JNDISwiftlet (com.swiftmq.swiftlet.jndi.JNDISwiftlet)2 JobRegistrar (com.swiftmq.impl.queue.standard.jobs.JobRegistrar)1 JobRegistrar (com.swiftmq.impl.routing.single.jobs.JobRegistrar)1 BackupProcessor (com.swiftmq.impl.store.standard.backup.BackupProcessor)1 CacheManager (com.swiftmq.impl.store.standard.cache.CacheManager)1 ShrinkProcessor (com.swiftmq.impl.store.standard.cache.ShrinkProcessor)1 StartShrink (com.swiftmq.impl.store.standard.cache.po.StartShrink)1 RootIndex (com.swiftmq.impl.store.standard.index.RootIndex)1 JobRegistrar (com.swiftmq.impl.store.standard.jobs.JobRegistrar)1 RecoveryManager (com.swiftmq.impl.store.standard.recover.RecoveryManager)1