Search in sources :

Example 6 with SwiftletException

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

the class AuthenticationSwiftletImpl method createGroup.

private Group createGroup(String groupName, Entity groupEntity) throws SwiftletException {
    if (groups.get(groupName) != null)
        throw new SwiftletException("Group '" + groupName + "' is already defined!");
    Group group = new Group(groupName);
    createQueueGrants(group, (EntityList) groupEntity.getEntity("queue-grants"));
    createTopicGrants(group, (EntityList) groupEntity.getEntity("topic-grants"));
    if (traceSpace.enabled)
        traceSpace.trace(getName(), "createGroup: " + group);
    groups.put(group.getName(), group);
    if (group.getName().equals(PUBLIC_GROUP))
        publicGroup = group;
    return group;
}
Also used : SwiftletException(com.swiftmq.swiftlet.SwiftletException)

Example 7 with SwiftletException

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

the class RoutingSwiftletImpl method createStaticRoutes.

private void createStaticRoutes(EntityList staticRouteList) throws SwiftletException {
    String[] staticRoutes = staticRouteList.getEntityNames();
    if (staticRoutes != null) {
        for (int i = 0; i < staticRoutes.length; i++) {
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace(getName(), "creating static route to: " + staticRoutes[i]);
            try {
                Scheduler scheduler = ctx.schedulerRegistry.getScheduler(staticRoutes[i]);
                addRoute(new RouteImpl(staticRoutes[i], scheduler.getQueueName(), true, scheduler));
            } catch (Exception e) {
                throw new SwiftletException(e.getMessage());
            }
        }
    }
    staticRouteList.setEntityAddListener(new EntityChangeAdapter(null) {

        public void onEntityAdd(Entity parent, Entity newEntity) throws EntityAddException {
            String dest = newEntity.getName();
            try {
                SwiftUtilities.verifyRouterName(dest);
                Scheduler scheduler = ctx.schedulerRegistry.getScheduler(dest);
                RouteImpl route = (RouteImpl) getRoute(dest);
                if (route == null)
                    addRoute(new RouteImpl(dest, scheduler.getQueueName(), false, scheduler));
                else {
                    route.setStaticRoute(true);
                    if (route.getScheduler() == null)
                        route.setScheduler(scheduler);
                }
            } catch (Exception e) {
                throw new EntityAddException(e.getMessage());
            }
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace(getName(), "onEntityAdd (staticroute.routers): new staticroute=" + dest);
        }
    });
    staticRouteList.setEntityRemoveListener(new EntityChangeAdapter(null) {

        public void onEntityRemove(Entity parent, Entity delEntity) throws EntityRemoveException {
            String dest = delEntity.getName();
            try {
                Scheduler scheduler = ctx.schedulerRegistry.getScheduler(dest);
                if (scheduler.getNumberConnections() == 0) {
                    scheduler.close();
                    removeRoute(getRoute(dest));
                }
            } catch (Exception e) {
                throw new EntityRemoveException(e.getMessage());
            }
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace(getName(), "onEntityRemove (staticroute.routers): del staticroute=" + dest);
        }
    });
}
Also used : SwiftletException(com.swiftmq.swiftlet.SwiftletException) Scheduler(com.swiftmq.impl.routing.single.schedule.Scheduler) SwiftletException(com.swiftmq.swiftlet.SwiftletException)

Example 8 with SwiftletException

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

the class RoutingSwiftletImpl method createListener.

private ListenerMetaData createListener(Entity listenerEntity) throws SwiftletException {
    String listenerName = listenerEntity.getName();
    int port = ((Integer) listenerEntity.getProperty("port").getValue()).intValue();
    String socketFactoryClass = (String) listenerEntity.getProperty("socketfactory-class").getValue();
    long keepAliveInterval = ((Long) listenerEntity.getProperty("keepalive-interval").getValue()).longValue();
    Property prop = listenerEntity.getProperty("password");
    String password = (String) prop.getValue();
    InetAddress bindAddress = null;
    try {
        String s = (String) listenerEntity.getProperty("bindaddress").getValue();
        if (s != null && s.trim().length() > 0)
            bindAddress = InetAddress.getByName(s);
    } catch (Exception e) {
        throw new SwiftletException(e.getMessage());
    }
    int inputBufferSize = ((Integer) listenerEntity.getProperty("router-input-buffer-size").getValue()).intValue();
    int inputExtendSize = ((Integer) listenerEntity.getProperty("router-input-extend-size").getValue()).intValue();
    int outputBufferSize = ((Integer) listenerEntity.getProperty("router-output-buffer-size").getValue()).intValue();
    int outputExtendSize = ((Integer) listenerEntity.getProperty("router-output-extend-size").getValue()).intValue();
    boolean useTCPNoDelay = ((Boolean) listenerEntity.getProperty("use-tcp-no-delay").getValue()).booleanValue();
    ListenerMetaData meta = new ListenerMetaData(bindAddress, port, this, keepAliveInterval, socketFactoryClass, acceptor, inputBufferSize, inputExtendSize, outputBufferSize, outputExtendSize, useTCPNoDelay);
    listenerEntity.setUserObject(meta);
    createHostAccessList(meta, (EntityList) listenerEntity.getEntity("host-access-list"));
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(getName(), "starting listener '" + listenerName + "' ...");
    try {
        passwords.put(meta, password);
        connectionEntities.put(meta, listenerEntity);
        ctx.networkSwiftlet.createTCPListener(meta);
    } catch (Exception e) {
        throw new SwiftletException(e.getMessage());
    }
    prop.setPropertyChangeListener(new PropertyChangeAdapter(meta) {

        public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
            passwords.put(configObject, newValue);
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace(getName(), "propertyChanged (listenerPassword): oldValue=" + oldValue + ", newValue=" + newValue);
        }
    });
    return meta;
}
Also used : SwiftletException(com.swiftmq.swiftlet.SwiftletException) SwiftletException(com.swiftmq.swiftlet.SwiftletException) PORemoveAllObject(com.swiftmq.impl.routing.single.manager.po.PORemoveAllObject) PORemoveObject(com.swiftmq.impl.routing.single.manager.po.PORemoveObject) InetAddress(java.net.InetAddress)

Example 9 with SwiftletException

use of com.swiftmq.swiftlet.SwiftletException 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 10 with SwiftletException

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

Aggregations

SwiftletException (com.swiftmq.swiftlet.SwiftletException)38 IOException (java.io.IOException)7 SwiftletManagerAdapter (com.swiftmq.swiftlet.event.SwiftletManagerAdapter)6 SwiftletManagerEvent (com.swiftmq.swiftlet.event.SwiftletManagerEvent)6 Semaphore (com.swiftmq.tools.concurrent.Semaphore)6 AuthenticationException (com.swiftmq.swiftlet.auth.AuthenticationException)5 ConnectionVetoException (com.swiftmq.swiftlet.net.ConnectionVetoException)5 MgmtListener (com.swiftmq.swiftlet.mgmt.event.MgmtListener)4 InetAddress (java.net.InetAddress)4 UnknownHostException (java.net.UnknownHostException)4 InvalidClientIDException (javax.jms.InvalidClientIDException)4 MgmtSwiftlet (com.swiftmq.swiftlet.mgmt.MgmtSwiftlet)3 Connection (com.swiftmq.swiftlet.net.Connection)3 ConnectionManager (com.swiftmq.swiftlet.net.ConnectionManager)3 RoutingSwiftlet (com.swiftmq.swiftlet.routing.RoutingSwiftlet)3 TopicException (com.swiftmq.swiftlet.topic.TopicException)3 InvalidDestinationException (javax.jms.InvalidDestinationException)3 JMSException (javax.jms.JMSException)3 MQTTConnection (com.swiftmq.impl.mqtt.connection.MQTTConnection)2 PORemoveAllObject (com.swiftmq.impl.routing.single.manager.po.PORemoveAllObject)2