Search in sources :

Example 86 with Semaphore

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");
}
Also used : Semaphore(com.swiftmq.tools.concurrent.Semaphore)

Example 87 with Semaphore

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;
}
Also used : SwiftletException(com.swiftmq.swiftlet.SwiftletException) Semaphore(com.swiftmq.tools.concurrent.Semaphore) IOException(java.io.IOException) SwiftletException(com.swiftmq.swiftlet.SwiftletException)

Example 88 with Semaphore

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);
}
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 89 with Semaphore

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");
}
Also used : CommitLogRecord(com.swiftmq.impl.store.standard.log.CommitLogRecord) ArrayList(java.util.ArrayList) Semaphore(com.swiftmq.tools.concurrent.Semaphore) IOException(java.io.IOException) QueueIndexEntry(com.swiftmq.impl.store.standard.index.QueueIndexEntry) StoreException(com.swiftmq.swiftlet.store.StoreException) IOException(java.io.IOException) StoreException(com.swiftmq.swiftlet.store.StoreException)

Example 90 with Semaphore

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");
}
Also used : Semaphore(com.swiftmq.tools.concurrent.Semaphore)

Aggregations

Semaphore (com.swiftmq.tools.concurrent.Semaphore)149 MsgNoVerifier (jms.base.MsgNoVerifier)18 IOException (java.io.IOException)8 SwiftletException (com.swiftmq.swiftlet.SwiftletException)6 ArrayList (java.util.ArrayList)6 CommitLogRecord (com.swiftmq.impl.store.standard.log.CommitLogRecord)5 DataStreamOutputStream (com.swiftmq.tools.util.DataStreamOutputStream)5 List (java.util.List)5 StartBackup (com.swiftmq.impl.store.standard.backup.po.StartBackup)2 StartShrink (com.swiftmq.impl.store.standard.cache.po.StartShrink)2 UnknownHostException (java.net.UnknownHostException)2 POAttachDurableConsumer (com.swiftmq.amqp.v100.client.po.POAttachDurableConsumer)1 POAuthenticate (com.swiftmq.amqp.v100.client.po.POAuthenticate)1 POCloseLink (com.swiftmq.amqp.v100.client.po.POCloseLink)1 POOpen (com.swiftmq.amqp.v100.client.po.POOpen)1 POProtocolRequest (com.swiftmq.amqp.v100.client.po.POProtocolRequest)1 POSendClose (com.swiftmq.amqp.v100.client.po.POSendClose)1 POSendMessage (com.swiftmq.amqp.v100.client.po.POSendMessage)1 AddressString (com.swiftmq.amqp.v100.generated.messaging.message_format.AddressString)1 Header (com.swiftmq.amqp.v100.generated.messaging.message_format.Header)1