Search in sources :

Example 16 with SwiftletException

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

the class StoreSwiftletImpl 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 com.swiftmq.swiftlet.SwiftletException
 */
protected void shutdown() throws SwiftletException {
    // true if shutdown while standby
    if (ctx == null)
        return;
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace("sys$store", "shutdown...");
    try {
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace("sys$store", "shutdown, stopping backup processor...");
        ctx.backupProcessor.close();
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace("sys$store", "shutdown, stopping log manager...");
        Semaphore sem = new Semaphore();
        ctx.logManager.enqueue(new CloseLogOperation(sem));
        sem.waitHere();
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace("sys$store", "shutdown, stopping log manager...done");
        ctx.logManager.stopQueue();
        ctx.cacheManager.close();
    } catch (Exception e) {
        throw new SwiftletException(e.getMessage());
    }
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace("sys$store", "shutdown...done");
    ctx = null;
}
Also used : SwiftletException(com.swiftmq.swiftlet.SwiftletException) Semaphore(com.swiftmq.tools.concurrent.Semaphore) IOException(java.io.IOException) SwiftletException(com.swiftmq.swiftlet.SwiftletException)

Example 17 with SwiftletException

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

the class StoreSwiftletImpl method checkBackupPath.

private void checkBackupPath() throws SwiftletException {
    Property prop = ctx.backupEntity.getProperty("path");
    String path = SwiftUtilities.addWorkingDir((String) prop.getValue());
    File f = new File(path);
    if (f.exists()) {
        if (!f.isDirectory())
            throw new SwiftletException("Invalid Backup Path (not a Directory): " + path + "(absolute paths must be prefixed with \"absolute:\")");
    } else {
        if (!f.mkdirs())
            throw new SwiftletException("Invalid Backup Path (unable to create Directory): " + path + "(absolute paths must be prefixed with \"absolute:\")");
    }
    ctx.backupProcessor.enqueue(new ScanSaveSets());
    prop.setPropertyChangeListener(new PropertyChangeListener() {

        public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
            String s = SwiftUtilities.addWorkingDir((String) newValue);
            File file = new File(s);
            if (file.exists()) {
                if (!file.isDirectory())
                    throw new PropertyChangeException("Invalid Backup Path (not a Directory): " + s + "(absolute paths must be prefixed with \"absolute:\")");
            } else {
                if (!file.mkdirs())
                    throw new PropertyChangeException("Invalid Backup Path (unable to create Directory): " + s + "(absolute paths must be prefixed with \"absolute:\")");
            }
            Semaphore sem = new Semaphore();
            ChangePath po = new ChangePath(sem, (String) newValue);
            ctx.backupProcessor.enqueue(po);
            sem.waitHere();
            if (!po.isSuccess())
                throw new PropertyChangeException(po.getException());
            ctx.backupProcessor.enqueue(new ScanSaveSets());
        }
    });
    prop = ctx.backupEntity.getProperty("keep-generations");
    prop.setPropertyChangeListener(new PropertyChangeListener() {

        public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
            int i = ((Integer) newValue).intValue();
            Semaphore sem = new Semaphore();
            ChangeGenerations po = new ChangeGenerations(sem, i);
            ctx.backupProcessor.enqueue(po);
            sem.waitHere();
            if (!po.isSuccess())
                throw new PropertyChangeException(po.getException());
            ctx.backupProcessor.enqueue(new ScanSaveSets());
        }
    });
    CommandRegistry commandRegistry = ctx.backupEntity.getCommandRegistry();
    CommandExecutor backupExecutor = new CommandExecutor() {

        public String[] execute(String[] context, Entity entity, String[] cmd) {
            if (cmd.length != 1)
                return new String[] { TreeCommands.ERROR, "Invalid command, please try 'backup'" };
            Semaphore sem = new Semaphore();
            StartBackup po = new StartBackup(sem, null);
            ctx.backupProcessor.enqueue(po);
            sem.waitHere();
            String[] result = null;
            if (po.isSuccess())
                result = new String[] { TreeCommands.INFO, "Backup initiated. Please watch Folder 'Generated Backup Save Sets'." };
            else
                result = new String[] { TreeCommands.ERROR, po.getException() };
            return result;
        }
    };
    Command backupCommand = new Command("backup", "backup", "Perform Backup Now", true, backupExecutor, true, false);
    commandRegistry.addCommand(backupCommand);
}
Also used : ChangePath(com.swiftmq.impl.store.standard.backup.po.ChangePath) Semaphore(com.swiftmq.tools.concurrent.Semaphore) ChangeGenerations(com.swiftmq.impl.store.standard.backup.po.ChangeGenerations) SwiftletException(com.swiftmq.swiftlet.SwiftletException) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) StartBackup(com.swiftmq.impl.store.standard.backup.po.StartBackup) ScanSaveSets(com.swiftmq.impl.store.standard.backup.po.ScanSaveSets)

Example 18 with SwiftletException

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

the class SchedulerSwiftletImpl method startup.

protected void startup(Configuration config) throws SwiftletException {
    try {
        ctx = new SwiftletContext(this, config);
    } catch (Exception e) {
        throw new SwiftletException(e.toString());
    }
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(getName(), "startup ...");
    ctx.scheduler = new Scheduler(ctx);
    createCalendarAdapter((EntityList) ctx.root.getEntity("calendars"));
    createScheduleAdapter((EntityList) ctx.root.getEntity("schedules"));
    myJobGroup = getJobGroup(SwiftletContext.JOBGROUP);
    JobFactory jf = new MessageSenderJobFactory(ctx);
    myJobGroup.addJobFactory(jf.getName(), jf);
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(getName(), "startup done");
}
Also used : JobFactory(com.swiftmq.swiftlet.scheduler.JobFactory) MessageSenderJobFactory(com.swiftmq.impl.scheduler.standard.job.MessageSenderJobFactory) SwiftletException(com.swiftmq.swiftlet.SwiftletException) MessageSenderJobFactory(com.swiftmq.impl.scheduler.standard.job.MessageSenderJobFactory) SwiftletException(com.swiftmq.swiftlet.SwiftletException) InvalidScheduleException(com.swiftmq.swiftlet.scheduler.InvalidScheduleException)

Example 19 with SwiftletException

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

the class StreamsSwiftlet method createStreamAdapter.

private EntityListEventAdapter createStreamAdapter(EntityList list, final String domainName, final String packageName) throws SwiftletException {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(getName(), "createStreamAdapter ...");
    EntityListEventAdapter streamAdapter = 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 {
                StreamController streamController = new StreamController(ctx, repositorySupport, newEntity, domainName, packageName);
                if (!isStartup)
                    streamController.init();
                newEntity.setUserObject(streamController);
            } 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() + " ...");
            StreamController streamController = (StreamController) delEntity.getUserObject();
            if (streamController != null) {
                streamController.close();
                delEntity.setUserObject(null);
                if (!isShutdown)
                    streamLibDeployer.removeStreamLibs(streamController.fqn());
            }
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace(getName(), "onEntityRemove: " + delEntity.getName() + " done");
        }
    };
    try {
        streamAdapter.init();
    } catch (Exception e) {
        throw new SwiftletException(e.toString());
    }
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(getName(), "createStreamAdapter done");
    return streamAdapter;
}
Also used : SwiftletException(com.swiftmq.swiftlet.SwiftletException) SwiftletException(com.swiftmq.swiftlet.SwiftletException)

Example 20 with SwiftletException

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

the class StreamsSwiftlet method startup.

protected void startup(Configuration config) throws SwiftletException {
    ctx = new SwiftletContext(config, this);
    if (!ctx.HASENGINE) {
        ctx.logSwiftlet.logInformation(ctx.streamsSwiftlet.getName(), "You are using Java " + ctx.JAVAVERSION + " but not GraalVM. Cannot start Streams Swiftlet. Please use GraalVM: https://graalvm.org");
        ctx.logSwiftlet.logWarning(ctx.streamsSwiftlet.getName(), "You are using Java " + ctx.JAVAVERSION + " but not GraalVM. Cannot start Streams Swiftlet. Please use GraalVM: https://graalvm.org");
        return;
    }
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(getName(), "startup ...");
    isStartup = true;
    ctx.logSwiftlet.logInformation(ctx.streamsSwiftlet.getName(), "starting, available Scripting Engines:");
    ScriptEngineManager manager = new ScriptEngineManager();
    List<ScriptEngineFactory> factories = manager.getEngineFactories();
    for (int i = 0; i < factories.size(); i++) {
        ctx.logSwiftlet.logInformation(ctx.streamsSwiftlet.getName(), "name=" + factories.get(i).getEngineName() + ", version=" + factories.get(i).getEngineVersion() + ", language name=" + factories.get(i).getLanguageName() + ", language version=" + factories.get(i).getLanguageVersion() + ", names=" + factories.get(i).getNames());
    }
    ctx.authenticationSwiftlet.addTopicAuthenticationDelegate(this);
    createDomainAdapter((EntityList) config.getEntity("domains"));
    try {
        startStreams((EntityList) config.getEntity("domains"));
    } catch (Exception e) {
        throw new SwiftletException(e.getMessage());
    }
    /*${evalstartupmark}*/
    jobRegistrar = new JobRegistrar(ctx);
    jobRegistrar.register();
    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();
    ctx.mgmtSwiftlet.addMgmtListener(new MgmtListener() {

        public void adminToolActivated() {
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace(getName(), "adminToolActivated");
            collectOn = true;
            collectChanged(-1, collectInterval);
        }

        public void adminToolDeactivated() {
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace(getName(), "adminToolDeactivated");
            collectChanged(collectInterval, -1);
            collectOn = false;
        }
    });
    try {
        streamLibDeployer = new StreamLibDeployer(ctx);
    } catch (Exception e) {
        throw new SwiftletException(e.toString());
    }
    isStartup = false;
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(getName(), "startup done.");
}
Also used : MgmtListener(com.swiftmq.swiftlet.mgmt.event.MgmtListener) ScriptEngineManager(javax.script.ScriptEngineManager) JobRegistrar(com.swiftmq.impl.streams.jobs.JobRegistrar) SwiftletException(com.swiftmq.swiftlet.SwiftletException) SwiftletException(com.swiftmq.swiftlet.SwiftletException) ScriptEngineFactory(javax.script.ScriptEngineFactory)

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