Search in sources :

Example 1 with SwiftletManagerEvent

use of com.swiftmq.swiftlet.event.SwiftletManagerEvent 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 SwiftletManagerEvent

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

the class NetworkSwiftletImpl method startup.

@Override
protected void startup(Configuration config) throws SwiftletException {
    try {
        ctx = new SwiftletContext(config, this);
    } catch (Exception e) {
        throw new SwiftletException(e.getMessage());
    }
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(getName(), "startup ...");
    setConnectionManager(new ConnectionManagerImpl(ctx));
    ivmScheduler = new IntraVMScheduler(ctx);
    ioScheduler = new NettyIOScheduler(ctx);
    Property prop = config.getProperty("reuse-serversockets");
    reuseServerSocket = (Boolean) prop.getValue();
    prop = config.getProperty("dns-resolve-enabled");
    prop.setPropertyChangeListener(new PropertyChangeAdapter(null) {

        public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
            dnsResolve = (Boolean) newValue;
        }
    });
    dnsResolve = (Boolean) prop.getValue();
    prop = config.getProperty("zombi-connection-timeout");
    zombiConnectionTimeout = (Long) prop.getValue();
    prop.setPropertyChangeListener(new PropertyChangeAdapter(null) {

        public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
            zombiConnectionTimeout = (Long) newValue;
        }
    });
    prop = config.getProperty("collect-interval");
    prop.setPropertyChangeListener(new PropertyChangeAdapter(null) {

        public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
            collectInterval = (Long) newValue;
            collectChanged((Long) oldValue, collectInterval);
        }
    });
    collectInterval = (Long) prop.getValue();
    if (collectOn) {
        if (collectInterval > 0) {
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace(getName(), "startup: registering byte count collector");
            ctx.timerSwiftlet.addTimerListener(collectInterval, this);
        } else if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace(getName(), "startup: collect interval <= 0; no byte count collector");
    }
    try {
        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);
                }
            }
        });
    } catch (Exception e) {
        throw new SwiftletException(e.getMessage());
    }
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(getName(), "startup DONE");
}
Also used : MgmtListener(com.swiftmq.swiftlet.mgmt.event.MgmtListener) MgmtSwiftlet(com.swiftmq.swiftlet.mgmt.MgmtSwiftlet) PropertyChangeException(com.swiftmq.mgmt.PropertyChangeException) SwiftletException(com.swiftmq.swiftlet.SwiftletException) PropertyChangeException(com.swiftmq.mgmt.PropertyChangeException) SwiftletManagerAdapter(com.swiftmq.swiftlet.event.SwiftletManagerAdapter) SwiftletManagerEvent(com.swiftmq.swiftlet.event.SwiftletManagerEvent) SwiftletException(com.swiftmq.swiftlet.SwiftletException) PropertyChangeAdapter(com.swiftmq.mgmt.PropertyChangeAdapter) Property(com.swiftmq.mgmt.Property)

Example 3 with SwiftletManagerEvent

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

the class MgmtSwiftletImpl method startup.

protected void startup(Configuration config) throws SwiftletException {
    ctx = new SwiftletContext(this, config);
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(getName(), "startup ...");
    SwiftletManager.getInstance().addSwiftletManagerListener("sys$routing", new SwiftletManagerAdapter() {

        public void swiftletStarted(SwiftletManagerEvent evt) {
            try {
                ctx.routingSwiftlet = (RoutingSwiftlet) SwiftletManager.getInstance().getSwiftlet("sys$routing");
                ctx.routingSwiftlet.addRoutingListener(ctx.dispatchQueue);
                miController = new MessageInterfaceController(ctx);
            } catch (Exception e) {
                if (ctx.traceSpace.enabled)
                    ctx.traceSpace.trace(getName(), "swiftletStartet, exception=" + e);
            }
        }
    });
    SwiftletManager.getInstance().addSwiftletManagerListener("sys$amqp", new SwiftletManagerAdapter() {

        public void swiftletStarted(SwiftletManagerEvent evt) {
            try {
                listener = new Listener(ctx);
            } catch (Exception e) {
                if (ctx.traceSpace.enabled)
                    ctx.traceSpace.trace(getName(), "swiftletStartet, exception=" + e);
            }
        }
    });
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(getName(), "startup done");
}
Also used : RoutingSwiftlet(com.swiftmq.swiftlet.routing.RoutingSwiftlet) SwiftletManagerEvent(com.swiftmq.swiftlet.event.SwiftletManagerEvent) SwiftletException(com.swiftmq.swiftlet.SwiftletException) SwiftletManagerAdapter(com.swiftmq.swiftlet.event.SwiftletManagerAdapter)

Example 4 with SwiftletManagerEvent

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

the class StableStore method init.

private void init() throws Exception {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace("sys$store", toString() + "/init ...");
    nFree = 0;
    if (freePoolEnabled)
        freePool = new IntRingBuffer[10];
    filename = path + File.separatorChar + FILENAME;
    emptyData = new byte[Page.PAGE_SIZE];
    // emtpy
    emptyData[0] = 1;
    for (int i = 1; i < Page.PAGE_SIZE; i++) emptyData[i] = 0;
    file = new RandomAccessFile(filename, "rw");
    fileLength = file.length();
    if (fileLength > 0) {
        numberPages = (int) (fileLength / Page.PAGE_SIZE);
        if (!offline)
            shrinkFile();
    } else
        initialize(initialPages);
    sync();
    if (freePoolEnabled)
        buildFreePageList();
    if (!offline) {
        Entity entity = ctx.filesList.createEntity();
        entity.setName(FILENAME);
        entity.createCommands();
        ctx.filesList.addEntity(entity);
        freeProp = entity.getProperty("free-pages");
        usedProp = entity.getProperty("used-pages");
        fileSizeProp = entity.getProperty("file-size");
        sizeCollectProp = ctx.dbEntity.getProperty("size-collect-interval");
        collectInterval = (long) (Long) sizeCollectProp.getValue();
        startTimer();
        PropertyChangeListener propChangeListener = new PropertyChangeListener() {

            public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
                stopTimer();
                collectInterval = (Long) newValue;
                startTimer();
            }
        };
        sizeCollectProp.setPropertyChangeListener(propChangeListener);
        swiftletManagerAdapter = new SwiftletManagerAdapter() {

            public void swiftletStarted(SwiftletManagerEvent event) {
                mgmtSwiftlet = (MgmtSwiftlet) SwiftletManager.getInstance().getSwiftlet("sys$mgmt");
                mgmtSwiftlet.addMgmtListener(StableStore.this);
            }
        };
        SwiftletManager.getInstance().addSwiftletManagerListener("sys$mgmt", swiftletManagerAdapter);
    }
    ctx.logSwiftlet.logInformation("sys$store", toString() + "/init done, size=" + numberPages + ", freePages=" + getNumberFreePages());
}
Also used : IntRingBuffer(com.swiftmq.tools.collection.IntRingBuffer) Entity(com.swiftmq.mgmt.Entity) SwiftletManagerEvent(com.swiftmq.swiftlet.event.SwiftletManagerEvent) RandomAccessFile(java.io.RandomAccessFile) PropertyChangeListener(com.swiftmq.mgmt.PropertyChangeListener) MgmtSwiftlet(com.swiftmq.swiftlet.mgmt.MgmtSwiftlet) Property(com.swiftmq.mgmt.Property) SwiftletManagerAdapter(com.swiftmq.swiftlet.event.SwiftletManagerAdapter)

Example 5 with SwiftletManagerEvent

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

the class SwiftletManager method startUpSwiftlet.

private void startUpSwiftlet(Swiftlet swiftlet, Configuration config) throws SwiftletException {
    System.out.println("... startup: " + config.getMetaData().getDisplayName());
    if (swiftlet.isKernel()) {
        trace("Swiftlet " + swiftlet.getName() + "', fireSwiftletManagerEvent: swiftletStartInitiated");
        fireSwiftletManagerEvent(swiftlet.getName(), "swiftletStartInitiated", new SwiftletManagerEvent(this, swiftlet.getName()));
        trace("Swiftlet " + swiftlet.getName() + "', swiftlet.startup()");
    }
    swiftlet.startup(config);
    swiftlet.setState(Swiftlet.STATE_ACTIVE);
    if (swiftlet.isKernel()) {
        trace("Swiftlet " + swiftlet.getName() + "', fireSwiftletManagerEvent: swiftletStarted");
        fireSwiftletManagerEvent(swiftlet.getName(), "swiftletStarted", new SwiftletManagerEvent(this, swiftlet.getName()));
    }
}
Also used : SwiftletManagerEvent(com.swiftmq.swiftlet.event.SwiftletManagerEvent)

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