Search in sources :

Example 1 with PropertyChangeAdapter

use of com.swiftmq.mgmt.PropertyChangeAdapter 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 2 with PropertyChangeAdapter

use of com.swiftmq.mgmt.PropertyChangeAdapter in project swiftmq-ce by iitsoftware.

the class RegularQueueFactory method createQueue.

public AbstractQueue createQueue(String queueName, Entity queueEntity) throws QueueException {
    PersistentStore pStore = null;
    NonPersistentStore nStore = null;
    try {
        pStore = ctx.storeSwiftlet.getPersistentStore(queueName);
        nStore = ctx.storeSwiftlet.getNonPersistentStore(queueName);
    } catch (Exception e) {
        e.printStackTrace();
        throw new QueueException(e.toString());
    }
    Property prop = queueEntity.getProperty(QueueManagerImpl.PROP_CACHE_SIZE);
    int cacheSize = ((Integer) prop.getValue()).intValue();
    prop = queueEntity.getProperty(QueueManagerImpl.PROP_CACHE_SIZE_BYTES_KB);
    int cacheSizeBytesKB = ((Integer) prop.getValue()).intValue();
    Cache cache = new CacheImpl(cacheSize, cacheSizeBytesKB, pStore, nStore);
    cache.setCacheTable(ctx.cacheTableFactory.createCacheTable(queueName, cacheSize));
    prop = queueEntity.getProperty(QueueManagerImpl.PROP_CACHE_SIZE);
    prop.setPropertyChangeListener(new PropertyChangeAdapter(cache) {

        public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
            Cache myCache = (Cache) configObject;
            myCache.setMaxMessages(((Integer) newValue).intValue());
        }
    });
    prop = queueEntity.getProperty(QueueManagerImpl.PROP_CACHE_SIZE_BYTES_KB);
    prop.setPropertyChangeListener(new PropertyChangeAdapter(cache) {

        public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
            Cache myCache = (Cache) configObject;
            myCache.setMaxBytesKB(((Integer) newValue).intValue());
        }
    });
    prop = queueEntity.getProperty(QueueManagerImpl.PROP_CLEANUP_INTERVAL);
    long cleanUp = ((Long) prop.getValue()).longValue();
    MessageQueue mq = ctx.messageQueueFactory.createMessageQueue(ctx, queueName, cache, pStore, nStore, cleanUp, myTP);
    prop = queueEntity.getProperty(QueueManagerImpl.PROP_MESSAGES_MAXIMUM);
    int maxMessages = ((Integer) prop.getValue()).intValue();
    mq.setMaxMessages(maxMessages);
    prop.setPropertyChangeListener(new PropertyChangeAdapter(mq) {

        public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
            MessageQueue myMq = (MessageQueue) configObject;
            myMq.setMaxMessages(((Integer) newValue).intValue());
        }
    });
    prop = queueEntity.getProperty(QueueManagerImpl.PROP_PERSISTENCE);
    int pm = SwiftUtilities.persistenceModeToInt((String) prop.getValue());
    mq.setPersistenceMode(pm);
    prop.setPropertyChangeListener(new PropertyChangeAdapter(mq) {

        public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
            MessageQueue myMq = (MessageQueue) configObject;
            myMq.setPersistenceMode(SwiftUtilities.persistenceModeToInt((String) newValue));
        }
    });
    prop = queueEntity.getProperty(QueueManagerImpl.PROP_FLOWCONTROL_QUEUE_SIZE);
    int fcQueueSize = ((Integer) prop.getValue()).intValue();
    if (fcQueueSize >= 0)
        mq.setFlowController(new FlowControllerImpl(fcQueueSize, ctx.queueManager.getMaxFlowControlDelay()));
    prop.setPropertyChangeListener(new PropertyChangeAdapter(mq) {

        public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
            MessageQueue myMq = (MessageQueue) configObject;
            int newFcQueueSize = ((Integer) newValue).intValue();
            if (newFcQueueSize >= 0)
                myMq.setFlowController(new FlowControllerImpl(newFcQueueSize, ctx.queueManager.getMaxFlowControlDelay()));
            else
                myMq.setFlowController(null);
        }
    });
    prop = queueEntity.getProperty(QueueManagerImpl.PROP_DUPLICATE_DETECTION_ENABLED);
    mq.setDuplicateDetectionEnabled(((Boolean) prop.getValue()).booleanValue());
    prop.setPropertyChangeListener(new PropertyChangeAdapter(mq) {

        public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
            MessageQueue myMq = (MessageQueue) configObject;
            myMq.setDuplicateDetectionEnabled(((Boolean) newValue).booleanValue());
        }
    });
    prop = queueEntity.getProperty(QueueManagerImpl.PROP_DUPLICATE_DETECTION_BACKLOG_SIZE);
    mq.setDuplicateDetectionBacklogSize(((Integer) prop.getValue()).intValue());
    prop.setPropertyChangeListener(new PropertyChangeAdapter(mq) {

        public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
            MessageQueue myMq = (MessageQueue) configObject;
            myMq.setDuplicateDetectionBacklogSize(((Integer) newValue).intValue());
        }
    });
    prop = queueEntity.getProperty(QueueManagerImpl.PROP_CONSUMER);
    if (prop != null) {
        mq.setConsumerMode(ctx.consumerModeInt((String) prop.getValue()));
        prop.setPropertyChangeListener(new PropertyChangeAdapter(mq) {

            public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
                MessageQueue myMq = (MessageQueue) configObject;
                int cm = ctx.consumerModeInt((String) newValue);
                if (cm == AbstractQueue.EXCLUSIVE && myMq.getReceiverCount() > 1)
                    throw new PropertyChangeException("Can't set EXCLUSIVE consumer mode - queue has already '" + myMq.getReceiverCount() + "' receivers");
                myMq.setConsumerMode(cm);
            }
        });
    }
    prop = queueEntity.getProperty(QueueManagerImpl.PROP_MONITOR_ALERT_THRESHOLD);
    if (prop != null) {
        mq.setMonitorAlertThreshold(((Integer) prop.getValue()).intValue());
        prop.setPropertyChangeListener(new PropertyChangeAdapter(mq) {

            public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
                MessageQueue myMq = (MessageQueue) configObject;
                myMq.setMonitorAlertThreshold(((Integer) newValue).intValue());
            }
        });
    }
    return mq;
}
Also used : NonPersistentStore(com.swiftmq.swiftlet.store.NonPersistentStore) PersistentStore(com.swiftmq.swiftlet.store.PersistentStore) PropertyChangeException(com.swiftmq.mgmt.PropertyChangeException) QueueException(com.swiftmq.swiftlet.queue.QueueException) PropertyChangeException(com.swiftmq.mgmt.PropertyChangeException) NonPersistentStore(com.swiftmq.swiftlet.store.NonPersistentStore) PropertyChangeAdapter(com.swiftmq.mgmt.PropertyChangeAdapter) QueueException(com.swiftmq.swiftlet.queue.QueueException) Property(com.swiftmq.mgmt.Property)

Example 3 with PropertyChangeAdapter

use of com.swiftmq.mgmt.PropertyChangeAdapter in project swiftmq-ce by iitsoftware.

the class TimerSwiftletImpl method startup.

protected void startup(Configuration config) throws SwiftletException {
    logSwiftlet = (LogSwiftlet) SwiftletManager.getInstance().getSwiftlet("sys$log");
    traceSwiftlet = (TraceSwiftlet) SwiftletManager.getInstance().getSwiftlet("sys$trace");
    traceSpace = traceSwiftlet.getTraceSpace(TraceSwiftlet.SPACE_KERNEL);
    threadpoolSwiftlet = (ThreadpoolSwiftlet) SwiftletManager.getInstance().getSwiftlet("sys$threadpool");
    if (traceSpace.enabled)
        traceSpace.trace(getName(), "startup, ...");
    Property prop = config.getProperty("min-delay");
    minDelay = ((Long) prop.getValue()).longValue();
    prop.setPropertyChangeListener(new PropertyChangeAdapter(null) {

        public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
            minDelay = ((Long) newValue).longValue();
        }
    });
    prop = config.getProperty("max-delay");
    maxDelay = ((Long) prop.getValue()).longValue();
    timeChangeThreshold = maxDelay + MAX_DELAY_TIME_CHANGE_ADDITION;
    prop.setPropertyChangeListener(new PropertyChangeAdapter(null) {

        public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
            maxDelay = ((Long) newValue).longValue();
            timeChangeThreshold = maxDelay + MAX_DELAY_TIME_CHANGE_ADDITION;
        }
    });
    taskPool = threadpoolSwiftlet.getPool(TP_TASK);
    taskQueue = new GapList();
    timerListeners = new HashMap();
    sysTimeChangeListeners = new GapList();
    dispatcher = new Dispatcher();
    threadpoolSwiftlet.dispatchTask(dispatcher);
    if (traceSpace.enabled)
        traceSpace.trace(getName(), "startup, DONE");
}
Also used : PropertyChangeAdapter(com.swiftmq.mgmt.PropertyChangeAdapter) GapList(org.magicwerk.brownies.collections.GapList) Property(com.swiftmq.mgmt.Property) PropertyChangeException(com.swiftmq.mgmt.PropertyChangeException)

Aggregations

Property (com.swiftmq.mgmt.Property)3 PropertyChangeAdapter (com.swiftmq.mgmt.PropertyChangeAdapter)3 PropertyChangeException (com.swiftmq.mgmt.PropertyChangeException)3 SwiftletException (com.swiftmq.swiftlet.SwiftletException)1 SwiftletManagerAdapter (com.swiftmq.swiftlet.event.SwiftletManagerAdapter)1 SwiftletManagerEvent (com.swiftmq.swiftlet.event.SwiftletManagerEvent)1 MgmtSwiftlet (com.swiftmq.swiftlet.mgmt.MgmtSwiftlet)1 MgmtListener (com.swiftmq.swiftlet.mgmt.event.MgmtListener)1 QueueException (com.swiftmq.swiftlet.queue.QueueException)1 NonPersistentStore (com.swiftmq.swiftlet.store.NonPersistentStore)1 PersistentStore (com.swiftmq.swiftlet.store.PersistentStore)1 GapList (org.magicwerk.brownies.collections.GapList)1