Search in sources :

Example 1 with SchedulerSwiftlet

use of com.swiftmq.swiftlet.scheduler.SchedulerSwiftlet in project swiftmq-ce by iitsoftware.

the class StoreSwiftletImpl method startup.

protected void startup(Configuration config) throws SwiftletException {
    try {
        ctx = new StoreContext(this, config);
        ctx.swapFileFactory = createSwapFileFactory();
        ctx.swapPath = SwiftUtilities.addWorkingDir((String) ctx.swapEntity.getProperty("path").getValue());
        swapMaxLength = ((Long) ctx.swapEntity.getProperty("roll-over-size").getValue()).longValue();
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace("sys$store", "startup...");
        ctx.durableStore = createDurableSubscriberStore(ctx, SwiftUtilities.addWorkingDir((String) ctx.durableEntity.getProperty("path").getValue()));
        deleteSwaps();
        ctx.recoveryManager = new RecoveryManager(ctx);
        ctx.stableStore = createStableStore(ctx, SwiftUtilities.addWorkingDir((String) ctx.dbEntity.getProperty("path").getValue()), ((Integer) ctx.dbEntity.getProperty("initial-page-size").getValue()).intValue());
        Property minCacheSizeProp = ctx.cacheEntity.getProperty("min-size");
        Property maxCacheSizeProp = ctx.cacheEntity.getProperty("max-size");
        int minCacheSize = ((Integer) minCacheSizeProp.getValue()).intValue();
        int maxCacheSize = ((Integer) maxCacheSizeProp.getValue()).intValue();
        if (minCacheSize > maxCacheSize)
            throw new Exception("Cache/min-size is invalid, must be less than max-size!");
        minCacheSizeProp.setPropertyChangeListener(new PropertyChangeAdapter(null) {

            public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
                int n = ((Integer) newValue).intValue();
                if (n > ((Integer) ctx.cacheEntity.getProperty("max-size").getValue()).intValue())
                    throw new PropertyChangeException("min-size is invalid, must be less than max-size!");
            }
        });
        maxCacheSizeProp.setPropertyChangeListener(new PropertyChangeAdapter(null) {

            public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
                int n = ((Integer) newValue).intValue();
                if (n < ((Integer) ctx.cacheEntity.getProperty("min-size").getValue()).intValue())
                    throw new PropertyChangeException("max-size is invalid, must be greater than min-size!");
            }
        });
        // ctx.preparedLog = new PreparedLogFile(ctx, SwiftUtilities.addWorkingDir((String) ctx.xaEntity.getProperty("path").getValue()),
        // ((Boolean) ctx.xaEntity.getProperty("force-sync").getValue()).booleanValue());
        ctx.cacheManager = new CacheManager(ctx, ctx.stableStore, minCacheSize, maxCacheSize);
        ctx.transactionManager = new TransactionManager(ctx);
        ctx.logManager = createLogManagerFactory().createLogManager(ctx, ctx.transactionManager, SwiftUtilities.addWorkingDir((String) ctx.txEntity.getProperty("path").getValue()), ((Long) ctx.txEntity.getProperty("checkpoint-size").getValue()).longValue(), ((Boolean) ctx.txEntity.getProperty("force-sync").getValue()).booleanValue());
        ctx.recoveryManager.restart(isRecoverOnStartup());
        rootIndex = new RootIndex(ctx, 0);
        ctx.preparedLog = new PreparedLogQueue(ctx, rootIndex.getQueueIndex(PREPARED_LOG_QUEUE));
        ctx.backupProcessor = new BackupProcessor(ctx);
        checkBackupPath();
        ctx.shrinkProcessor = new ShrinkProcessor(ctx);
        CommandRegistry commandRegistry = ctx.dbEntity.getCommandRegistry();
        CommandExecutor shrinkExecutor = new CommandExecutor() {

            public String[] execute(String[] context, Entity entity, String[] cmd) {
                if (cmd.length != 1)
                    return new String[] { TreeCommands.ERROR, "Invalid command, please try 'shrink'" };
                Semaphore sem = new Semaphore();
                StartShrink po = new StartShrink(sem);
                ctx.shrinkProcessor.enqueue(po);
                sem.waitHere();
                String[] result = null;
                if (po.isSuccess())
                    result = new String[] { TreeCommands.INFO, "Shrink initiated." };
                else
                    result = new String[] { TreeCommands.ERROR, po.getException() };
                return result;
            }
        };
        Command backupCommand = new Command("shrink", "shrink", "Perform Shrink Now", true, shrinkExecutor, true, false);
        commandRegistry.addCommand(backupCommand);
        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("sys$store", "startup...done");
    } catch (Exception e) {
        e.printStackTrace();
        throw new SwiftletException(e.getMessage());
    }
}
Also used : Semaphore(com.swiftmq.tools.concurrent.Semaphore) BackupProcessor(com.swiftmq.impl.store.standard.backup.BackupProcessor) SwiftletManagerAdapter(com.swiftmq.swiftlet.event.SwiftletManagerAdapter) SwiftletManagerEvent(com.swiftmq.swiftlet.event.SwiftletManagerEvent) SchedulerSwiftlet(com.swiftmq.swiftlet.scheduler.SchedulerSwiftlet) CacheManager(com.swiftmq.impl.store.standard.cache.CacheManager) JobRegistrar(com.swiftmq.impl.store.standard.jobs.JobRegistrar) IOException(java.io.IOException) SwiftletException(com.swiftmq.swiftlet.SwiftletException) StartShrink(com.swiftmq.impl.store.standard.cache.po.StartShrink) RecoveryManager(com.swiftmq.impl.store.standard.recover.RecoveryManager) ShrinkProcessor(com.swiftmq.impl.store.standard.cache.ShrinkProcessor) SwiftletException(com.swiftmq.swiftlet.SwiftletException) TransactionManager(com.swiftmq.impl.store.standard.transaction.TransactionManager) RootIndex(com.swiftmq.impl.store.standard.index.RootIndex) PreparedLogQueue(com.swiftmq.impl.store.standard.xa.PreparedLogQueue)

Example 2 with SchedulerSwiftlet

use of com.swiftmq.swiftlet.scheduler.SchedulerSwiftlet 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 3 with SchedulerSwiftlet

use of com.swiftmq.swiftlet.scheduler.SchedulerSwiftlet 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)

Aggregations

SwiftletManagerAdapter (com.swiftmq.swiftlet.event.SwiftletManagerAdapter)3 SwiftletManagerEvent (com.swiftmq.swiftlet.event.SwiftletManagerEvent)3 SchedulerSwiftlet (com.swiftmq.swiftlet.scheduler.SchedulerSwiftlet)3 SwiftletException (com.swiftmq.swiftlet.SwiftletException)2 IOException (java.io.IOException)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 TransactionManager (com.swiftmq.impl.store.standard.transaction.TransactionManager)1 PreparedLogQueue (com.swiftmq.impl.store.standard.xa.PreparedLogQueue)1 AuthenticationException (com.swiftmq.swiftlet.auth.AuthenticationException)1 JNDISwiftlet (com.swiftmq.swiftlet.jndi.JNDISwiftlet)1 MgmtSwiftlet (com.swiftmq.swiftlet.mgmt.MgmtSwiftlet)1 MgmtListener (com.swiftmq.swiftlet.mgmt.event.MgmtListener)1