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;
}
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);
}
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");
}
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;
}
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.");
}
Aggregations