use of com.swiftmq.tools.concurrent.Semaphore in project swiftmq-ce by iitsoftware.
the class DispatchQueue method close.
// <-- EventVisitor methods
public void close() {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.mgmtSwiftlet.getName(), toString() + "/close ...");
Semaphore sem = new Semaphore();
pipelineQueue.enqueue(new Close(sem));
sem.waitHere();
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.mgmtSwiftlet.getName(), toString() + "/close done");
}
use of com.swiftmq.tools.concurrent.Semaphore 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.tools.concurrent.Semaphore 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.tools.concurrent.Semaphore in project swiftmq-ce by iitsoftware.
the class StoreWriteTransactionImpl method abort.
public void abort(XidImpl globalTxId) throws StoreException {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace("sys$store", toString() + "/abort, globalTxId: " + globalTxId);
txId = ctx.transactionManager.createTxId();
sem = new Semaphore();
journal = new ArrayList();
queueIndex.setJournal(journal);
try {
for (int i = 0; i < keys.size(); i++) {
addMessagePageReference(queueIndex.remove((QueueIndexEntry) keys.get(i)));
}
ctx.recoveryManager.commit(new CommitLogRecord(txId, sem, journal, this, messagePageRefs));
sem.waitHere();
ctx.transactionManager.removeTxId(txId);
} catch (Exception e) {
throw new StoreException(e.toString());
}
if (prepareLogRecord != null) {
try {
ctx.preparedLog.remove(prepareLogRecord);
} catch (IOException e) {
throw new StoreException(e.toString());
}
prepareLogRecord = null;
}
close();
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace("sys$store", toString() + "/abort, globalTxId: " + globalTxId + ", done");
}
use of com.swiftmq.tools.concurrent.Semaphore in project swiftmq-ce by iitsoftware.
the class BackupProcessor method close.
public void close() {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.storeSwiftlet.getName(), toString() + "/close ...");
Semaphore sem = new Semaphore();
pipelineQueue.enqueue(new Close(sem));
sem.waitHere();
pipelineQueue.close();
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.storeSwiftlet.getName(), toString() + "/close done");
}
Aggregations