Search in sources :

Example 1 with ConnectionManager

use of com.swiftmq.swiftlet.net.ConnectionManager in project swiftmq-ce by iitsoftware.

the class MQTTSwiftlet method startup.

@Override
protected void startup(Configuration config) throws SwiftletException {
    try {
        ctx = new SwiftletContext(config, this);
    } catch (Exception e) {
        e.printStackTrace();
        throw new SwiftletException(e.getMessage());
    }
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(getName(), "startup ...");
    createListenerAdapter((EntityList) ctx.root.getEntity("listeners"));
    Property prop = ctx.root.getProperty("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 msg/s count collector");
            ctx.timerSwiftlet.addTimerListener(collectInterval, this);
        } else if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace(getName(), "startup: collect interval <= 0; no msg/s count collector");
    }
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(getName(), "registering MgmtListener ...");
    ctx.mgmtSwiftlet.addMgmtListener(this);
    ctx.usageListConnections.setEntityRemoveListener(new EntityChangeAdapter(null) {

        public void onEntityRemove(Entity parent, Entity delEntity) throws EntityRemoveException {
            Connection myConnection = (Connection) delEntity.getDynamicObject();
            ConnectionManager connectionManager = ctx.networkSwiftlet.getConnectionManager();
            connectionManager.removeConnection(myConnection);
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace(getName(), "onEntityRemove (Connection): " + myConnection);
        }
    });
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(getName(), "startup done.");
}
Also used : MQTTConnection(com.swiftmq.impl.mqtt.connection.MQTTConnection) Connection(com.swiftmq.swiftlet.net.Connection) SwiftletException(com.swiftmq.swiftlet.SwiftletException) ConnectionVetoException(com.swiftmq.swiftlet.net.ConnectionVetoException) ConnectionManager(com.swiftmq.swiftlet.net.ConnectionManager) SwiftletException(com.swiftmq.swiftlet.SwiftletException)

Example 2 with ConnectionManager

use of com.swiftmq.swiftlet.net.ConnectionManager in project swiftmq-ce by iitsoftware.

the class MQTTSwiftlet method shutdown.

@Override
protected void shutdown() throws SwiftletException {
    // true when shutdown while standby
    if (ctx == null)
        return;
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(getName(), "shutdown ...");
    try {
        collectChanged(collectInterval, -1);
        listenerAdapter.close();
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace(getName(), "shutdown: shutdown all MQTT connections");
        Semaphore sem = getShutdownSemaphore();
        ConnectionManager connectionManager = ctx.networkSwiftlet.getConnectionManager();
        Connection[] c = (Connection[]) connections.toArray(new Connection[connections.size()]);
        connections.clear();
        for (int i = 0; i < c.length; i++) {
            connectionManager.removeConnection(c[i]);
        }
        if (sem != null) {
            System.out.println("+++ waiting for connection shutdown ...");
            sem.waitHere();
            try {
                Thread.sleep(5000);
            } catch (Exception ignored) {
            }
        }
        ctx.mgmtSwiftlet.removeMgmtListener(this);
        ctx.sessionRegistry.close();
        ctx.retainer.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(getName(), "shutdown done.");
    ctx = null;
}
Also used : ConnectionManager(com.swiftmq.swiftlet.net.ConnectionManager) MQTTConnection(com.swiftmq.impl.mqtt.connection.MQTTConnection) Connection(com.swiftmq.swiftlet.net.Connection) Semaphore(com.swiftmq.tools.concurrent.Semaphore) SwiftletException(com.swiftmq.swiftlet.SwiftletException) ConnectionVetoException(com.swiftmq.swiftlet.net.ConnectionVetoException)

Example 3 with ConnectionManager

use of com.swiftmq.swiftlet.net.ConnectionManager in project swiftmq-ce by iitsoftware.

the class AMQPSwiftlet method startup.

protected void startup(Configuration configuration) throws SwiftletException {
    ctx = new SwiftletContext(configuration, this);
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(getName(), "startup ...");
    Security.addProvider(new SASLProvider(SASLProvider.PROVIDER_NAME, 1.0, "SwiftMQ SASL Security Provider"));
    createListenerAdapter((EntityList) ctx.root.getEntity("listeners"));
    Property prop = ctx.root.getProperty("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 msg/s count collector");
            ctx.timerSwiftlet.addTimerListener(collectInterval, this);
        } else if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace(getName(), "startup: collect interval <= 0; no msg/s count collector");
    }
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(getName(), "registering MgmtListener ...");
    ctx.mgmtSwiftlet.addMgmtListener(this);
    ctx.usageList.setEntityRemoveListener(new EntityChangeAdapter(null) {

        public void onEntityRemove(Entity parent, Entity delEntity) throws EntityRemoveException {
            Connection myConnection = (Connection) delEntity.getDynamicObject();
            ConnectionManager connectionManager = ctx.networkSwiftlet.getConnectionManager();
            connectionManager.removeConnection(myConnection);
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace(getName(), "onEntityRemove (Connection): " + myConnection);
        }
    });
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(getName(), "startup done.");
}
Also used : SASLProvider(com.swiftmq.impl.amqp.sasl.provider.SASLProvider) ConnectionManager(com.swiftmq.swiftlet.net.ConnectionManager) Connection(com.swiftmq.swiftlet.net.Connection)

Example 4 with ConnectionManager

use of com.swiftmq.swiftlet.net.ConnectionManager in project swiftmq-ce by iitsoftware.

the class AMQPSwiftlet method shutdown.

protected void shutdown() throws SwiftletException {
    // true when shutdown while standby
    if (ctx == null)
        return;
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(getName(), "shutdown ...");
    try {
        listenerAdapter.close();
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace(getName(), "shutdown: shutdown all AMQP connections");
        Semaphore sem = getShutdownSemaphore();
        ConnectionManager connectionManager = ctx.networkSwiftlet.getConnectionManager();
        Connection[] c = (Connection[]) connections.toArray(new Connection[connections.size()]);
        connections.clear();
        for (int i = 0; i < c.length; i++) {
            connectionManager.removeConnection(c[i]);
        }
        if (sem != null) {
            System.out.println("+++ waiting for connection shutdown ...");
            sem.waitHere();
            try {
                Thread.sleep(5000);
            } catch (Exception ignored) {
            }
        }
        ctx.mgmtSwiftlet.removeMgmtListener(this);
        Security.removeProvider(SASLProvider.PROVIDER_NAME);
    } catch (Exception e) {
        e.printStackTrace();
    }
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(getName(), "shutdown done.");
    ctx = null;
}
Also used : ConnectionManager(com.swiftmq.swiftlet.net.ConnectionManager) Connection(com.swiftmq.swiftlet.net.Connection) Semaphore(com.swiftmq.tools.concurrent.Semaphore) SwiftletException(com.swiftmq.swiftlet.SwiftletException) ConnectionVetoException(com.swiftmq.swiftlet.net.ConnectionVetoException)

Aggregations

Connection (com.swiftmq.swiftlet.net.Connection)4 ConnectionManager (com.swiftmq.swiftlet.net.ConnectionManager)4 SwiftletException (com.swiftmq.swiftlet.SwiftletException)3 ConnectionVetoException (com.swiftmq.swiftlet.net.ConnectionVetoException)3 MQTTConnection (com.swiftmq.impl.mqtt.connection.MQTTConnection)2 Semaphore (com.swiftmq.tools.concurrent.Semaphore)2 SASLProvider (com.swiftmq.impl.amqp.sasl.provider.SASLProvider)1