Search in sources :

Example 11 with SwiftletException

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

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

the class StreamsSwiftlet method createDomainAdapter.

private void createDomainAdapter(EntityList list) throws SwiftletException {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(getName(), "createDomainAdapter ...");
    domainAdapter = new EntityListEventAdapter(list, true, true) {

        public void onEntityAdd(Entity parent, Entity newEntity) throws EntityAddException {
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace(getName(), "onEntityAdd: " + newEntity.getName() + " ...");
            try {
                final String domainName = newEntity.getName();
                EntityListEventAdapter packageAdapter = new EntityListEventAdapter((EntityList) newEntity.getEntity("packages"), true, true) {

                    @Override
                    public void onEntityAdd(Entity parent, Entity newEntity) throws EntityAddException {
                        try {
                            final String packageName = newEntity.getName();
                            newEntity.setUserObject(createStreamAdapter((EntityList) newEntity.getEntity("streams"), domainName, packageName));
                        } catch (SwiftletException e) {
                            ctx.logSwiftlet.logError(getName(), "Error starting stream: " + e);
                            System.err.println("Error starting stream: " + e.getMessage());
                        }
                    }

                    @Override
                    public void onEntityRemove(Entity parent, Entity delEntity) throws EntityRemoveException {
                        try {
                            ((EntityListEventAdapter) delEntity.getUserObject()).close();
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                };
                packageAdapter.init();
                newEntity.setUserObject(packageAdapter);
            } catch (Exception e) {
                throw new EntityAddException(e.toString());
            }
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace(getName(), "onEntityAdd: " + newEntity.getName() + " done");
        }

        public void onEntityRemove(Entity parent, Entity delEntity) throws EntityRemoveException {
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace(getName(), "onEntityRemove: " + delEntity.getName() + " ...");
            EntityListEventAdapter packageAdapter = (EntityListEventAdapter) delEntity.getUserObject();
            if (packageAdapter != null) {
                try {
                    packageAdapter.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
                delEntity.setUserObject(null);
            }
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace(getName(), "onEntityRemove: " + delEntity.getName() + " done");
        }
    };
    try {
        domainAdapter.init();
    } catch (Exception e) {
        throw new SwiftletException(e.toString());
    }
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(getName(), "createDomainAdapter done");
}
Also used : SwiftletException(com.swiftmq.swiftlet.SwiftletException) SwiftletException(com.swiftmq.swiftlet.SwiftletException)

Example 13 with SwiftletException

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

Example 14 with SwiftletException

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

the class JNDISwiftletImpl 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 to prevend from startup
 */
protected void startup(Configuration config) throws SwiftletException {
    ctx = new SwiftletContext();
    ctx.config = config;
    ctx.root = config;
    ctx.usageList = (EntityList) ctx.root.getEntity("usage");
    ctx.logSwiftlet = (LogSwiftlet) SwiftletManager.getInstance().getSwiftlet("sys$log");
    ctx.traceSwiftlet = (TraceSwiftlet) SwiftletManager.getInstance().getSwiftlet("sys$trace");
    ctx.traceSpace = ctx.traceSwiftlet.getTraceSpace(TraceSwiftlet.SPACE_KERNEL);
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(getName(), "startup ...");
    ctx.timerSwiftlet = (TimerSwiftlet) SwiftletManager.getInstance().getSwiftlet("sys$timer");
    ctx.threadpoolSwiftlet = (ThreadpoolSwiftlet) SwiftletManager.getInstance().getSwiftlet("sys$threadpool");
    ctx.myTP = ctx.threadpoolSwiftlet.getPool(TP_LISTENER);
    ctx.queueManager = (QueueManager) SwiftletManager.getInstance().getSwiftlet("sys$queuemanager");
    ctx.topicManager = (TopicManager) SwiftletManager.getInstance().getSwiftlet("sys$topicmanager");
    ctx.jndiSwiftlet = this;
    createStatics((EntityList) config.getEntity("remote-queues"));
    createAliases((EntityList) config.getEntity("aliases"));
    createReplications((EntityList) config.getEntity("jndi-replications"));
    bindExternal();
    try {
        if (!ctx.queueManager.isQueueDefined(JNDISwiftlet.JNDI_QUEUE))
            ctx.queueManager.createQueue(JNDISwiftlet.JNDI_QUEUE, (ActiveLogin) null);
        if (!ctx.topicManager.isTopicDefined(JNDISwiftlet.JNDI_TOPIC))
            ctx.topicManager.createTopic(JNDISwiftlet.JNDI_TOPIC);
        queueJNDIProcessor = new QueueJNDIProcessor(ctx);
        topicJNDIProcessor = new TopicJNDIProcessor(ctx);
    } catch (Exception e) {
        throw new SwiftletException(e.getMessage());
    }
}
Also used : ActiveLogin(com.swiftmq.swiftlet.auth.ActiveLogin) SwiftletException(com.swiftmq.swiftlet.SwiftletException) SwiftletException(com.swiftmq.swiftlet.SwiftletException)

Example 15 with SwiftletException

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

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