use of com.swiftmq.tools.concurrent.AsyncCompletionCallback in project swiftmq-ce by iitsoftware.
the class ClusteredQueue method commit.
public void commit(final Object txId, AsyncCompletionCallback callback) {
if (ctx.queueSpace.enabled)
ctx.queueSpace.trace(getQueueName(), toString() + "/commit (callback), txId=" + txId);
final ClusteredTransactionId cTxId = (ClusteredTransactionId) txId;
cTxId.commit(new AsyncCompletionCallback(callback) {
public synchronized void done(boolean success) {
Long fcDelay = (Long) getResult();
if (fcDelay != null) {
if (ctx.queueSpace.enabled)
ctx.queueSpace.trace(getQueueName(), toString() + "/commit (callback), txId=" + txId + ", newDelay=" + fcDelay);
((ClusteredQueueFlowController) getFlowController()).setLastDelay(fcDelay.longValue());
}
}
});
}
use of com.swiftmq.tools.concurrent.AsyncCompletionCallback in project swiftmq-ce by iitsoftware.
the class MessageQueue method acknowledgeMessages.
public void acknowledgeMessages(Object tId, List messageIndexList, AsyncCompletionCallback callback) {
lockAndWaitAsyncFinished();
try {
if (!running) {
callback.setException(new QueueException("queue " + getQueueName() + " is not running"));
callback.notifyCallbackStack(false);
return;
}
TransactionId transactionId = (TransactionId) tId;
if (ctx.queueSpace.enabled)
ctx.queueSpace.trace(getQueueName(), "acknowledgeMessage txId=" + transactionId + " messageIndexList=" + messageIndexList);
final List txList = transactionId.getTxList();
try {
if (txList != null) {
long size = 0;
int n = 0;
StoreReadTransaction srt = null;
for (int i = 0; i < messageIndexList.size(); i++) {
MessageIndex messageIndex = (MessageIndex) messageIndexList.get(i);
for (Iterator iter = txList.iterator(); iter.hasNext(); ) {
StoreId storeId = (StoreId) iter.next();
if (storeId.equals(messageIndex)) {
if (pStore != null && srt == null && storeId.isPersistent())
srt = pStore.createReadTransaction(false);
size += storeId.getMsgSize();
n++;
removeMessage(srt, storeId);
iter.remove();
}
}
}
callback.setResult(Long.valueOf(size));
if (flowController != null)
flowController.setReceiveMessageCount(n);
if (srt != null) {
asyncActive = true;
srt.commit(new AsyncCompletionCallback(callback) {
public void done(boolean b) {
queueLock.lock();
asyncActive = false;
asyncFinished.signalAll();
queueLock.unlock();
}
});
} else {
callback.notifyCallbackStack(true);
}
}
} catch (Exception e) {
callback.setException(new QueueException(e.toString()));
callback.notifyCallbackStack(false);
asyncActive = false;
asyncFinished.signalAll();
return;
}
} finally {
queueLock.unlock();
}
}
use of com.swiftmq.tools.concurrent.AsyncCompletionCallback in project swiftmq-ce by iitsoftware.
the class MessageQueue method acknowledgeMessage.
public void acknowledgeMessage(Object tId, MessageIndex messageIndex, AsyncCompletionCallback callback) {
lockAndWaitAsyncFinished();
try {
if (!running) {
callback.setException(new QueueException("queue " + getQueueName() + " is not running"));
callback.notifyCallbackStack(false);
return;
}
TransactionId transactionId = (TransactionId) tId;
if (ctx.queueSpace.enabled)
ctx.queueSpace.trace(getQueueName(), "acknowledgeMessage txId=" + transactionId + " messageIndex=" + messageIndex);
final List txList = transactionId.getTxList();
try {
if (txList != null) {
StoreId storeId = null;
for (int i = 0; i < txList.size(); i++) {
storeId = (StoreId) txList.get(i);
if (storeId.equals(messageIndex))
break;
else
storeId = null;
}
if (storeId != null) {
final StoreId sid = storeId;
callback.setResult(Long.valueOf(storeId.getMsgSize()));
txList.remove(sid);
if (flowController != null)
flowController.setReceiveMessageCount(1);
StoreReadTransaction srt = null;
if (pStore != null && storeId.isPersistent())
srt = pStore.createReadTransaction(false);
removeMessage(srt, storeId);
if (srt != null) {
asyncActive = true;
srt.commit(new AsyncCompletionCallback(callback) {
public void done(boolean b) {
queueLock.lock();
asyncActive = false;
asyncFinished.signalAll();
queueLock.unlock();
}
});
} else
callback.notifyCallbackStack(true);
} else
// May happen that an auto-ack storeId wasn't found after a transparent reconnect
// but the client is waiting for a reply...
callback.notifyCallbackStack(true);
}
} catch (Exception e) {
callback.setException(new QueueException(e.toString()));
callback.notifyCallbackStack(false);
asyncActive = false;
asyncFinished.signalAll();
return;
}
} finally {
queueLock.unlock();
}
}
use of com.swiftmq.tools.concurrent.AsyncCompletionCallback in project swiftmq-ce by iitsoftware.
the class TopicSubscriberTransaction method commit.
protected void commit(AsyncCompletionCallback callback) {
if (!valid) {
callback.setException(new QueueTransactionClosedException("TopicSubscriberTransaction is invalid"));
callback.done(false);
return;
}
transaction.commit(new AsyncCompletionCallback(callback) {
public void done(boolean success) {
topicSubscription.removeTransaction(TopicSubscriberTransaction.this);
valid = false;
fcDelay = transaction.getFlowControlDelay();
if (success)
next.setResult(Long.valueOf(fcDelay));
else
next.setException(getException());
}
});
}
use of com.swiftmq.tools.concurrent.AsyncCompletionCallback in project swiftmq-ce by iitsoftware.
the class TopicSubscriberTransaction method rollback.
protected void rollback(AsyncCompletionCallback callback) {
if (!valid) {
callback.setException(new QueueTransactionClosedException("TopicSubscriberTransaction is invalid"));
callback.done(false);
return;
}
transaction.rollback(new AsyncCompletionCallback(callback) {
public void done(boolean success) {
topicSubscription.removeTransaction(TopicSubscriberTransaction.this);
valid = false;
if (!success)
next.setException(getException());
}
});
}
Aggregations