Search in sources :

Example 46 with Semaphore

use of com.swiftmq.tools.concurrent.Semaphore in project swiftmq-ce by iitsoftware.

the class Listener method receive.

public void receive() {
    try {
        Semaphore sem1 = new Semaphore();
        subscriber.setMessageListener(new MyListener(ts, new MsgNoVerifier(this, nMsgs, "no"), sem1));
        Semaphore sem2 = new Semaphore();
        subscriber1.setMessageListener(new MyListener(session1, new MsgNoVerifier(this, nMsgs, "no"), sem2));
        Semaphore sem3 = new Semaphore();
        subscriber2.setMessageListener(new MyListener(session2, new MsgNoVerifier(this, nMsgs, "no"), sem3));
        sem1.waitHere();
        sem2.waitHere();
        sem3.waitHere();
        if (exception != null)
            throw exception;
    } catch (Exception e) {
        failFast("test failed: " + e);
    }
}
Also used : MsgNoVerifier(jms.base.MsgNoVerifier) Semaphore(com.swiftmq.tools.concurrent.Semaphore)

Example 47 with Semaphore

use of com.swiftmq.tools.concurrent.Semaphore in project swiftmq-ce by iitsoftware.

the class Listener method receive.

public void receive() {
    try {
        Semaphore sem1 = new Semaphore();
        subscriber.setMessageListener(new MyListener(new MsgNoVerifier(this, nMsgs, "no"), sem1));
        Semaphore sem2 = new Semaphore();
        subscriber1.setMessageListener(new MyListener(new MsgNoVerifier(this, nMsgs, "no"), sem2));
        Semaphore sem3 = new Semaphore();
        subscriber2.setMessageListener(new MyListener(new MsgNoVerifier(this, nMsgs, "no"), sem3));
        sem1.waitHere();
        sem2.waitHere();
        sem3.waitHere();
        if (exception != null)
            throw exception;
    } catch (Exception e) {
        failFast("test failed: " + e);
    }
}
Also used : MsgNoVerifier(jms.base.MsgNoVerifier) Semaphore(com.swiftmq.tools.concurrent.Semaphore)

Example 48 with Semaphore

use of com.swiftmq.tools.concurrent.Semaphore in project swiftmq-ce by iitsoftware.

the class PreparedLogQueue method add.

public synchronized long add(PrepareLogRecordImpl logRecord) throws IOException {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace("sys$store", toString() + "/add, logRecord: " + logRecord);
    CacheEntry cacheEntry = new CacheEntry();
    cacheEntry.logRecord = logRecord;
    long address = (long) ArrayListTool.setFirstFreeOrExpand(cache, cacheEntry);
    logRecord.setAddress(address);
    outStream.rewind();
    logRecord.writeContent(outStream);
    try {
        BytesMessageImpl msg = new BytesMessageImpl();
        msg.writeBytes(outStream.getBuffer(), 0, outStream.getCount());
        StoreEntry storeEntry = new StoreEntry();
        storeEntry.message = msg;
        long txId = ctx.transactionManager.createTxId(false);
        List journal = new ArrayList();
        queueIndex.setJournal(journal);
        cacheEntry.indexEntry = queueIndex.add(storeEntry);
        Semaphore sem = new Semaphore();
        ctx.recoveryManager.commit(new CommitLogRecord(txId, sem, journal, this, null));
        sem.waitHere();
        ctx.transactionManager.removeTxId(txId);
    } catch (Exception e) {
        throw new IOException(e.toString());
    }
    return address;
}
Also used : BytesMessageImpl(com.swiftmq.jms.BytesMessageImpl) StoreEntry(com.swiftmq.swiftlet.store.StoreEntry) CommitLogRecord(com.swiftmq.impl.store.standard.log.CommitLogRecord) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Semaphore(com.swiftmq.tools.concurrent.Semaphore) IOException(java.io.IOException) IOException(java.io.IOException) EOFException(java.io.EOFException)

Example 49 with Semaphore

use of com.swiftmq.tools.concurrent.Semaphore in project swiftmq-ce by iitsoftware.

the class StreamController method stop.

private synchronized void stop() {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.streamsSwiftlet.getName(), toString() + "/stop ...");
    if (!started)
        return;
    try {
        ctx.streamsSwiftlet.stopDependencies(fqn);
    } catch (Exception e) {
        e.printStackTrace();
    }
    ctx.logSwiftlet.logInformation(ctx.streamsSwiftlet.getName(), "Stopping Stream: " + fqn);
    started = false;
    Semaphore sem = new Semaphore();
    streamContext.streamProcessor.dispatch(new POClose(sem));
    sem.waitHere(5000);
    try {
        ctx.usageList.removeEntity(streamContext.usage);
    } catch (EntityRemoveException e) {
    }
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.streamsSwiftlet.getName(), toString() + "/stop done");
}
Also used : Semaphore(com.swiftmq.tools.concurrent.Semaphore) POClose(com.swiftmq.impl.streams.processor.po.POClose) MalformedURLException(java.net.MalformedURLException)

Example 50 with Semaphore

use of com.swiftmq.tools.concurrent.Semaphore in project swiftmq-ce by iitsoftware.

the class RootIndex method deleteQueueIndex.

public synchronized void deleteQueueIndex(String queueName, QueueIndex queueIndex) throws Exception {
    List entries = queueIndex.getEntries();
    Semaphore sem = new Semaphore();
    List journal = new ArrayList();
    queueIndex.setJournal(journal);
    List refs = new ArrayList();
    for (Iterator iter = entries.iterator(); iter.hasNext(); ) {
        MessagePageReference ref = queueIndex.remove((QueueIndexEntry) iter.next());
        if (ref != null)
            refs.add(ref);
        if (journal.size() > 10000) {
            long txId = ctx.transactionManager.createTxId();
            CommitLogRecord logRecord = new CommitLogRecord(txId, sem, journal, new QueueIndexRelease(queueIndex), refs);
            ctx.recoveryManager.commit(logRecord);
            sem.waitHere();
            sem.reset();
            journal.clear();
            refs = new ArrayList();
            ctx.transactionManager.removeTxId(txId);
        }
    }
    IndexPage root = queueIndex.getIndexPage(queueIndex.getRootPageNo());
    byte[] bi = new byte[root.getFirstFreePosition()];
    System.arraycopy(root.getPage().data, 0, bi, 0, bi.length);
    journal.add(new DeleteLogAction(root.getPage().pageNo, bi));
    root.getPage().dirty = true;
    root.getPage().empty = true;
    setJournal(journal);
    remove(queueName);
    long txId = ctx.transactionManager.createTxId();
    CommitLogRecord logRecord = new CommitLogRecord(txId, sem, journal, new QueueRootIndexRelease(this, queueIndex), refs);
    ctx.recoveryManager.commit(logRecord);
    sem.waitHere();
    ctx.transactionManager.removeTxId(txId);
}
Also used : DeleteLogAction(com.swiftmq.impl.store.standard.log.DeleteLogAction) CommitLogRecord(com.swiftmq.impl.store.standard.log.CommitLogRecord) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) 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