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