Search in sources :

Example 26 with SwiftletException

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

the class QueueManagerImpl method createQueues.

private void createQueues(EntityList queueList) throws SwiftletException {
    Map m = queueList.getEntities();
    if (m.size() > 0) {
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace(getName(), "createQueues: begin starting queues ...");
        try {
            for (Iterator iter = m.entrySet().iterator(); iter.hasNext(); ) {
                Entity queueEntity = (Entity) ((Map.Entry) iter.next()).getValue();
                createQueue(queueEntity);
            }
        } catch (Exception e) {
            e.printStackTrace();
            throw new SwiftletException(e.getMessage());
        }
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace(getName(), "createQueues: end starting queues ...");
    } else if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(getName(), "createQueues: no queues defined");
    queueList.setEntityAddListener(new EntityChangeAdapter(null) {

        public void onEntityAdd(Entity parent, Entity newEntity) throws EntityAddException {
            try {
                createQueue(newEntity);
                if (ctx.traceSpace.enabled)
                    ctx.traceSpace.trace(getName(), "onEntityAdd (queue): new queue=" + newEntity.getName());
            } catch (Exception e) {
                throw new EntityAddException(e.getMessage());
            }
        }
    });
    queueList.setEntityRemoveListener(new EntityChangeAdapter(null) {

        public void onEntityRemove(Entity parent, Entity delEntity) throws EntityRemoveException {
            try {
                String qn = delEntity.getName() + '@' + localRouterName;
                ActiveQueue queue = getQueue(qn);
                queue.getAbstractQueue().deleteContent();
                deleteQueue(qn, false);
                if (ctx.traceSpace.enabled)
                    ctx.traceSpace.trace(getName(), "onEntityRemove (queue): del queue=" + delEntity.getName());
            } catch (Exception e) {
                throw new EntityRemoveException(e.getMessage());
            }
        }
    });
}
Also used : SwiftletException(com.swiftmq.swiftlet.SwiftletException) IOException(java.io.IOException) SwiftletException(com.swiftmq.swiftlet.SwiftletException) AuthenticationException(com.swiftmq.swiftlet.auth.AuthenticationException)

Example 27 with SwiftletException

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

the class JMSSwiftlet 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 SwiftletException
 */
protected void startup(Configuration config) throws SwiftletException {
    ctx = new SwiftletContext(config, this);
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(getName(), "startup ...");
    Property prop = ctx.root.getProperty("allow-same-clientid");
    if (prop != null) {
        allowSameClientId = ((Boolean) prop.getValue()).booleanValue();
        prop.setPropertyChangeListener(new PropertyChangeListener() {

            public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
                allowSameClientId = ((Boolean) newValue).booleanValue();
            }
        });
    }
    // set default props
    prop = ((EntityList) ctx.root.getEntity("listeners")).getTemplate().getProperty("socketfactory-class");
    prop.setDefaultProp(ctx.root.getProperty("socketfactory-class"));
    createGeneralProps(ctx.root);
    createListeners((EntityList) ctx.root.getEntity("listeners"));
    intraVMMetaData = new IntraVMListenerMetaData(this, new Acceptor("intravm", null));
    try {
        ctx.networkSwiftlet.createIntraVMListener(intraVMMetaData);
        createIVMConnectionFactories((EntityList) ctx.root.getEntity("intravm-connection-factories"));
    } catch (Exception e) {
        throw new SwiftletException(e.getMessage());
    }
    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 thread 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 (JMSConnection): " + myConnection);
        }
    });
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(getName(), "startup: done");
}
Also used : InvalidClientIDException(javax.jms.InvalidClientIDException) UnknownHostException(java.net.UnknownHostException) SwiftletException(com.swiftmq.swiftlet.SwiftletException) SwiftletException(com.swiftmq.swiftlet.SwiftletException)

Example 28 with SwiftletException

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

the class JMSSwiftlet method shutdown.

/**
 * Shutdown the swiftlet. Check if all shutdown conditions are met. Do shutdown work (i. e. stop working thread, close resources).
 * If any condition prevends from shutdown fire a SwiftletException.
 *
 * @throws SwiftletException
 */
protected void shutdown() throws SwiftletException {
    // true when shutdown while standby
    if (ctx == null)
        return;
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(getName(), "shutdown: stopping listener ...");
    ctx.jndiSwiftlet.deregisterJNDIObjects(new CFComparable(INTRAVM_LISTENER));
    ctx.networkSwiftlet.removeIntraVMListener(intraVMMetaData);
    EntityList listenerList = (EntityList) ctx.root.getEntity("listeners");
    String[] inboundNames = listenerList.getEntityNames();
    if (inboundNames != null) {
        for (int i = 0; i < inboundNames.length; i++) {
            ListenerMetaData meta = (ListenerMetaData) listenerList.getEntity(inboundNames[i]).getUserObject();
            ctx.networkSwiftlet.removeTCPListener(meta);
        }
    }
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(getName(), "shutdown: shutdown all jms 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) {
        }
    }
    clientSet.clear();
    ctx.mgmtSwiftlet.removeMgmtListener(this);
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(getName(), "shutdown: done");
    ctx = null;
}
Also used : Semaphore(com.swiftmq.tools.concurrent.Semaphore) InvalidClientIDException(javax.jms.InvalidClientIDException) UnknownHostException(java.net.UnknownHostException) SwiftletException(com.swiftmq.swiftlet.SwiftletException)

Example 29 with SwiftletException

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

the class JMSSwiftlet method createGeneralProps.

private void createGeneralProps(Entity root) throws SwiftletException {
    Property prop = root.getProperty("crfactory-class");
    String crf = (String) root.getProperty("crfactory-class").getValue();
    try {
        challengeResponseFactory = (ChallengeResponseFactory) Class.forName(crf).newInstance();
    } catch (Exception e) {
        String msg = "Error creating class instance of challenge/response factory '" + crf + "', exception=" + e;
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace(getName(), msg);
        throw new SwiftletException(msg);
    }
    prop.setPropertyChangeListener(new PropertyChangeAdapter(null) {

        public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
            try {
                ChallengeResponseFactory sf = (ChallengeResponseFactory) Class.forName((String) newValue).newInstance();
            } catch (Exception e) {
                String msg = "Error creating class instance of default challenge/response factory '" + newValue + "', exception=" + e;
                if (ctx.traceSpace.enabled)
                    ctx.traceSpace.trace(getName(), msg);
                throw new PropertyChangeException(msg);
            }
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace(getName(), "propertyChanged (crfactory.class): oldValue=" + oldValue + ", newValue=" + newValue);
        }
    });
    prop = root.getProperty("max-connections");
    maxConnections = ((Integer) prop.getValue()).intValue();
    if (maxConnections < -1 || maxConnections == 0)
        throw new SwiftletException("Invalid Value, must be -1 (unlimited) or > 0");
    prop.setPropertyChangeListener(new PropertyChangeAdapter(null) {

        public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
            int n = ((Integer) newValue).intValue();
            if (n < -1 || n == 0)
                throw new PropertyChangeException("Invalid Value, must be -1 (unlimited) or > 0");
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace(getName(), "propertyChanged (maxconnections): oldValue=" + oldValue + ", newValue=" + newValue);
            maxConnections = n;
        }
    });
}
Also used : ChallengeResponseFactory(com.swiftmq.auth.ChallengeResponseFactory) SwiftletException(com.swiftmq.swiftlet.SwiftletException) InvalidClientIDException(javax.jms.InvalidClientIDException) UnknownHostException(java.net.UnknownHostException) SwiftletException(com.swiftmq.swiftlet.SwiftletException)

Example 30 with SwiftletException

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

the class JMSSwiftlet 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();
    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());
    }
    String connectIP = (String) listenerEntity.getProperty("connectaddress").getValue();
    if (connectIP != null && connectIP.trim().length() > 0)
        connectAddresses.put(listenerName, connectIP);
    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, new Acceptor(listenerName, listenerEntity.getProperty("max-connections")), inputBufferSize, inputExtendSize, outputBufferSize, outputExtendSize, useTCPNoDelay);
    listenerEntity.setUserObject(meta);
    createHostAccessList(meta, (EntityList) listenerEntity.getEntity("host-access-list"));
    EntityList cfList = (EntityList) listenerEntity.getEntity("connection-factories");
    try {
        createConnectionFactories(listenerEntity, cfList);
    } catch (Exception e) {
        throw new SwiftletException(e.toString());
    }
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(getName(), "starting listener '" + listenerName + "' ...");
    try {
        ctx.networkSwiftlet.createTCPListener(meta);
    } catch (Exception e) {
        throw new SwiftletException(e.getMessage());
    }
    if (cfList.getEntity(listenerName + "@" + SwiftletManager.getInstance().getRouterName()) == null) {
        ctx.timerSwiftlet.addInstantTimerListener(5000, new CFTimer(listenerName, cfList));
    }
    return meta;
}
Also used : InvalidClientIDException(javax.jms.InvalidClientIDException) UnknownHostException(java.net.UnknownHostException) SwiftletException(com.swiftmq.swiftlet.SwiftletException) SwiftletException(com.swiftmq.swiftlet.SwiftletException) InetAddress(java.net.InetAddress)

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