Search in sources :

Example 1 with SwiftletException

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

the class AMQPSwiftlet method createListener.

private void createListener(Entity listenerEntity) throws SwiftletException {
    Entity connectionTemplate = getConnectionTemplate((String) listenerEntity.getProperty("connection-template").getValue());
    String listenerName = listenerEntity.getName();
    int port = ((Integer) listenerEntity.getProperty("port").getValue()).intValue();
    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) connectionTemplate.getProperty("router-input-buffer-size").getValue()).intValue();
    int inputExtendSize = ((Integer) connectionTemplate.getProperty("router-input-extend-size").getValue()).intValue();
    int outputBufferSize = ((Integer) connectionTemplate.getProperty("router-output-buffer-size").getValue()).intValue();
    int outputExtendSize = ((Integer) connectionTemplate.getProperty("router-output-extend-size").getValue()).intValue();
    boolean useTCPNoDelay = ((Boolean) connectionTemplate.getProperty("use-tcp-no-delay").getValue()).booleanValue();
    AMQPInputHandler protHandler = new AMQPInputHandler();
    ListenerMetaData meta = new ListenerMetaData(bindAddress, port, this, -1, (String) connectionTemplate.getProperty("socketfactory-class").getValue(), new Acceptor(listenerName, listenerEntity.getProperty("max-connections"), listenerEntity.getProperty("sasl-enabled"), listenerEntity.getProperty("connection-template")), inputBufferSize, inputExtendSize, outputBufferSize, outputExtendSize, useTCPNoDelay, protHandler, new RawOutputHandler());
    listenerEntity.setUserObject(meta);
    createHostAccessList(meta, (EntityList) listenerEntity.getEntity("host-access-list"));
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(getName(), "starting listener '" + listenerName + "' ...");
    try {
        ctx.networkSwiftlet.createTCPListener(meta);
    } catch (Exception e) {
        throw new SwiftletException(e.getMessage());
    }
}
Also used : AMQPInputHandler(com.swiftmq.net.protocol.amqp.AMQPInputHandler) RawOutputHandler(com.swiftmq.net.protocol.raw.RawOutputHandler) SwiftletException(com.swiftmq.swiftlet.SwiftletException) ConnectionVetoException(com.swiftmq.swiftlet.net.ConnectionVetoException) SwiftletException(com.swiftmq.swiftlet.SwiftletException) ListenerMetaData(com.swiftmq.swiftlet.net.ListenerMetaData) InetAddress(java.net.InetAddress)

Example 2 with SwiftletException

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

the class TraceSwiftletImpl method shutdown.

protected void shutdown() throws SwiftletException {
    super.shutdown();
    for (Iterator iter = files.entrySet().iterator(); iter.hasNext(); ) {
        Map.Entry entry = (Map.Entry) iter.next();
        String name = (String) entry.getKey();
        PrintWriter writer = (PrintWriter) entry.getValue();
        try {
            if (!name.equals(TraceDestination.VAL_CONSOLE))
                writer.close();
        } catch (Exception ignored) {
        }
    }
    files.clear();
    spaces.clear();
}
Also used : Iterator(java.util.Iterator) Map(java.util.Map) SwiftletException(com.swiftmq.swiftlet.SwiftletException) PrintWriter(java.io.PrintWriter)

Example 3 with SwiftletException

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

the class StoreSwiftletImpl method startup.

protected void startup(Configuration config) throws SwiftletException {
    try {
        ctx = new StoreContext(this, config);
        ctx.swapFileFactory = createSwapFileFactory();
        ctx.swapPath = SwiftUtilities.addWorkingDir((String) ctx.swapEntity.getProperty("path").getValue());
        swapMaxLength = ((Long) ctx.swapEntity.getProperty("roll-over-size").getValue()).longValue();
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace("sys$store", "startup...");
        ctx.durableStore = createDurableSubscriberStore(ctx, SwiftUtilities.addWorkingDir((String) ctx.durableEntity.getProperty("path").getValue()));
        deleteSwaps();
        ctx.recoveryManager = new RecoveryManager(ctx);
        ctx.stableStore = createStableStore(ctx, SwiftUtilities.addWorkingDir((String) ctx.dbEntity.getProperty("path").getValue()), ((Integer) ctx.dbEntity.getProperty("initial-page-size").getValue()).intValue());
        Property minCacheSizeProp = ctx.cacheEntity.getProperty("min-size");
        Property maxCacheSizeProp = ctx.cacheEntity.getProperty("max-size");
        int minCacheSize = ((Integer) minCacheSizeProp.getValue()).intValue();
        int maxCacheSize = ((Integer) maxCacheSizeProp.getValue()).intValue();
        if (minCacheSize > maxCacheSize)
            throw new Exception("Cache/min-size is invalid, must be less than max-size!");
        minCacheSizeProp.setPropertyChangeListener(new PropertyChangeAdapter(null) {

            public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
                int n = ((Integer) newValue).intValue();
                if (n > ((Integer) ctx.cacheEntity.getProperty("max-size").getValue()).intValue())
                    throw new PropertyChangeException("min-size is invalid, must be less than max-size!");
            }
        });
        maxCacheSizeProp.setPropertyChangeListener(new PropertyChangeAdapter(null) {

            public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
                int n = ((Integer) newValue).intValue();
                if (n < ((Integer) ctx.cacheEntity.getProperty("min-size").getValue()).intValue())
                    throw new PropertyChangeException("max-size is invalid, must be greater than min-size!");
            }
        });
        // ctx.preparedLog = new PreparedLogFile(ctx, SwiftUtilities.addWorkingDir((String) ctx.xaEntity.getProperty("path").getValue()),
        // ((Boolean) ctx.xaEntity.getProperty("force-sync").getValue()).booleanValue());
        ctx.cacheManager = new CacheManager(ctx, ctx.stableStore, minCacheSize, maxCacheSize);
        ctx.transactionManager = new TransactionManager(ctx);
        ctx.logManager = createLogManagerFactory().createLogManager(ctx, ctx.transactionManager, SwiftUtilities.addWorkingDir((String) ctx.txEntity.getProperty("path").getValue()), ((Long) ctx.txEntity.getProperty("checkpoint-size").getValue()).longValue(), ((Boolean) ctx.txEntity.getProperty("force-sync").getValue()).booleanValue());
        ctx.recoveryManager.restart(isRecoverOnStartup());
        rootIndex = new RootIndex(ctx, 0);
        ctx.preparedLog = new PreparedLogQueue(ctx, rootIndex.getQueueIndex(PREPARED_LOG_QUEUE));
        ctx.backupProcessor = new BackupProcessor(ctx);
        checkBackupPath();
        ctx.shrinkProcessor = new ShrinkProcessor(ctx);
        CommandRegistry commandRegistry = ctx.dbEntity.getCommandRegistry();
        CommandExecutor shrinkExecutor = new CommandExecutor() {

            public String[] execute(String[] context, Entity entity, String[] cmd) {
                if (cmd.length != 1)
                    return new String[] { TreeCommands.ERROR, "Invalid command, please try 'shrink'" };
                Semaphore sem = new Semaphore();
                StartShrink po = new StartShrink(sem);
                ctx.shrinkProcessor.enqueue(po);
                sem.waitHere();
                String[] result = null;
                if (po.isSuccess())
                    result = new String[] { TreeCommands.INFO, "Shrink initiated." };
                else
                    result = new String[] { TreeCommands.ERROR, po.getException() };
                return result;
            }
        };
        Command backupCommand = new Command("shrink", "shrink", "Perform Shrink Now", true, shrinkExecutor, true, false);
        commandRegistry.addCommand(backupCommand);
        SwiftletManager.getInstance().addSwiftletManagerListener("sys$scheduler", new SwiftletManagerAdapter() {

            public void swiftletStarted(SwiftletManagerEvent event) {
                ctx.schedulerSwiftlet = (SchedulerSwiftlet) SwiftletManager.getInstance().getSwiftlet("sys$scheduler");
                jobRegistrar = new JobRegistrar(ctx);
                jobRegistrar.register();
            }

            public void swiftletStopInitiated(SwiftletManagerEvent event) {
                jobRegistrar.unregister();
            }
        });
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace("sys$store", "startup...done");
    } catch (Exception e) {
        e.printStackTrace();
        throw new SwiftletException(e.getMessage());
    }
}
Also used : Semaphore(com.swiftmq.tools.concurrent.Semaphore) BackupProcessor(com.swiftmq.impl.store.standard.backup.BackupProcessor) SwiftletManagerAdapter(com.swiftmq.swiftlet.event.SwiftletManagerAdapter) SwiftletManagerEvent(com.swiftmq.swiftlet.event.SwiftletManagerEvent) SchedulerSwiftlet(com.swiftmq.swiftlet.scheduler.SchedulerSwiftlet) CacheManager(com.swiftmq.impl.store.standard.cache.CacheManager) JobRegistrar(com.swiftmq.impl.store.standard.jobs.JobRegistrar) IOException(java.io.IOException) SwiftletException(com.swiftmq.swiftlet.SwiftletException) StartShrink(com.swiftmq.impl.store.standard.cache.po.StartShrink) RecoveryManager(com.swiftmq.impl.store.standard.recover.RecoveryManager) ShrinkProcessor(com.swiftmq.impl.store.standard.cache.ShrinkProcessor) SwiftletException(com.swiftmq.swiftlet.SwiftletException) TransactionManager(com.swiftmq.impl.store.standard.transaction.TransactionManager) RootIndex(com.swiftmq.impl.store.standard.index.RootIndex) PreparedLogQueue(com.swiftmq.impl.store.standard.xa.PreparedLogQueue)

Example 4 with SwiftletException

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

the class SchedulerSwiftletImpl 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 ...");
    myJobGroup.removeAll();
    try {
        scheduleAdapter.close();
        calendarAdapter.close();
    } catch (Exception e) {
    }
    ctx.scheduler.close();
    try {
        ctx.close();
    } catch (Exception e) {
        throw new SwiftletException(e.toString());
    }
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(getName(), "shutdown done");
    ctx = null;
}
Also used : SwiftletException(com.swiftmq.swiftlet.SwiftletException) SwiftletException(com.swiftmq.swiftlet.SwiftletException) InvalidScheduleException(com.swiftmq.swiftlet.scheduler.InvalidScheduleException)

Example 5 with SwiftletException

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

the class AuthenticationSwiftletImpl method startup.

protected void startup(Configuration config) throws SwiftletException {
    this.config = config;
    logSwiftlet = (LogSwiftlet) SwiftletManager.getInstance().getSwiftlet("sys$log");
    traceSwiftlet = (TraceSwiftlet) SwiftletManager.getInstance().getSwiftlet("sys$trace");
    traceSpace = traceSwiftlet.getTraceSpace(TraceSwiftlet.SPACE_KERNEL);
    if (traceSpace.enabled)
        traceSpace.trace(getName(), "startup ...");
    useEncryption = Boolean.valueOf(System.getProperty(PROP_ENCRYPTED_PASSWORDS, "false"));
    if (useEncryption) {
        masterPassword = System.getenv(ENV_MASTER_PASSWORD);
        if (masterPassword == null)
            throw new SwiftletException("Encrypted Passwords require to set the master password with environment var " + ENV_MASTER_PASSWORD);
    }
    createGroups((EntityList) config.getEntity("groups"));
    createRLGroups((EntityList) config.getEntity("resource-limit-groups"));
    createUsers((EntityList) config.getEntity("users"));
    Property authProp = config.getProperty("authentication-enabled");
    authenticationOff = !((Boolean) authProp.getValue()).booleanValue();
    Property pwOnlyProp = config.getProperty("password-check-only");
    passwordCheckOnly = ((Boolean) pwOnlyProp.getValue()).booleanValue();
    if (traceSpace.enabled)
        traceSpace.trace(getName(), "startup, authentication is " + (authenticationOff ? "OFF" : "ON"));
    authProp.setPropertyChangeListener(new PropertyChangeAdapter(null) {

        public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
            if (traceSpace.enabled)
                traceSpace.trace(getName(), "propertyChanged (authentication.enabled): oldValue=" + oldValue + ", newValue=" + newValue);
            authenticationOff = !((Boolean) newValue).booleanValue();
            if (traceSpace.enabled)
                traceSpace.trace(getName(), "authentication is " + (authenticationOff ? "OFF" : "ON"));
        }
    });
    if (traceSpace.enabled)
        traceSpace.trace(getName(), "startup: done.");
}
Also used : SwiftletException(com.swiftmq.swiftlet.SwiftletException)

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