use of com.swiftmq.impl.store.standard.log.CommitLogRecord 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.impl.store.standard.log.CommitLogRecord 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);
}
use of com.swiftmq.impl.store.standard.log.CommitLogRecord 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.impl.store.standard.log.CommitLogRecord in project swiftmq-ce by iitsoftware.
the class StoreWriteTransactionImpl method prepare.
public void prepare(XidImpl globalTxId) throws StoreException {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace("sys$store", toString() + "/prepare, globalTxId=" + globalTxId);
try {
prepareLogRecord = new PrepareLogRecordImpl(PrepareLogRecordImpl.WRITE_TRANSACTION, queueName, globalTxId, keys);
ctx.preparedLog.add(prepareLogRecord);
ctx.recoveryManager.commit(new CommitLogRecord(txId, sem, journal, this, null));
sem.waitHere();
ctx.transactionManager.removeTxId(txId);
} catch (Exception e) {
throw new StoreException(e.getMessage());
}
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace("sys$store", toString() + "/prepare, globalTxId=" + globalTxId + ", done");
}
use of com.swiftmq.impl.store.standard.log.CommitLogRecord in project swiftmq-ce by iitsoftware.
the class RootIndex method getQueueIndex.
public synchronized QueueIndex getQueueIndex(String queueName) throws Exception {
IndexEntry entry = find(queueName);
if (entry == null) {
Semaphore sem = new Semaphore();
List journal = new ArrayList();
setJournal(journal);
QueueIndexPage indexPage = new QueueIndexPage(ctx, -1);
journal.add(new InsertLogAction(indexPage.getPage().pageNo));
indexPage.setJournal(journal);
indexPage.setPrevPage(-1);
indexPage.setNextPage(-1);
entry = new RootIndexEntry();
entry.setKey(queueName);
entry.setRootPageNo(indexPage.getPage().pageNo);
add(entry);
long txId = ctx.transactionManager.createTxId();
CommitLogRecord logRecord = new CommitLogRecord(txId, sem, journal, new IndexPageRelease(this, indexPage), null);
ctx.recoveryManager.commit(logRecord);
sem.waitHere();
ctx.transactionManager.removeTxId(txId);
} else
unloadPages();
return new QueueIndex(ctx, entry.getRootPageNo());
}
Aggregations