use of com.swiftmq.swiftlet.queue.QueueLimitException in project swiftmq-client by iitsoftware.
the class ReplyNE method createException.
private void createException(String className, String msg) throws Exception {
if (className.equals("com.swiftmq.swiftlet.queue.QueueException"))
exception = new QueueException(msg);
else if (className.equals("com.swiftmq.swiftlet.queue.QueueLimitException"))
exception = new QueueLimitException(msg);
else if (className.equals("com.swiftmq.swiftlet.queue.UnknownQueueException"))
exception = new InvalidDestinationException(msg);
else if (className.equals("com.swiftmq.swiftlet.auth.ResourceLimitException"))
exception = new ResourceLimitException(msg);
else if (className.equals("com.swiftmq.swiftlet.auth.AuthenticationException"))
exception = new AuthenticationException(msg);
else if (className.equals("javax.jms.InvalidDestinationException"))
exception = new InvalidDestinationException(msg);
else
exception = new Exception(className + ": " + msg);
}
use of com.swiftmq.swiftlet.queue.QueueLimitException in project swiftmq-ce by iitsoftware.
the class TopicTransaction method noParentTxCommit.
private long noParentTxCommit() throws Exception {
long delay = 0;
List durPersSubs = new ArrayList(subscriberTransactions.length);
for (int i = 0; i < subscriberTransactions.length; i++) {
TopicSubscriberTransaction sub = subscriberTransactions[i];
if (sub != null) {
TopicSubscription subscription = sub.getTopicSubscription();
if (subscription.isRemote() || !subscription.isDurable() || !sub.isPersistentMessageIncluded()) {
try {
delay = Math.max(delay, sub.commit());
} catch (QueueTransactionClosedException ignored) {
}
} else
durPersSubs.add(sub);
}
}
int size = durPersSubs.size();
if (size > 0) {
if (size == 1) {
TopicSubscriberTransaction sub = (TopicSubscriberTransaction) durPersSubs.get(0);
try {
delay = Math.max(delay, sub.commit());
} catch (QueueTransactionClosedException ignored) {
}
} else {
int lastLocked = -1;
boolean spaceLeft = true;
for (int i = 0; i < size; i++) {
TopicSubscriberTransaction sub = (TopicSubscriberTransaction) durPersSubs.get(i);
sub.getTransaction().lockQueue();
lastLocked = i;
if (!sub.getTransaction().hasSpaceLeft()) {
spaceLeft = false;
break;
}
}
if (!spaceLeft) {
for (int i = 0; i <= lastLocked; i++) {
TopicSubscriberTransaction sub = (TopicSubscriberTransaction) durPersSubs.get(i);
sub.getTransaction().unlockQueue(false);
}
throw new QueueLimitException("Maximum Messages in at least one Durable Subscriber Queue reached!");
}
CompositeStoreTransaction compositeTx = ctx.storeSwiftlet.createCompositeStoreTransaction();
try {
for (int i = 0; i < size; i++) {
TopicSubscriberTransaction sub = (TopicSubscriberTransaction) durPersSubs.get(i);
try {
sub.getTransaction().setCompositeStoreTransaction(compositeTx);
delay = Math.max(delay, sub.commit());
sub.getTransaction().setCompositeStoreTransaction(null);
} catch (QueueTransactionClosedException ignored) {
}
}
compositeTx.commitTransaction();
} finally {
for (int i = 0; i < size; i++) {
TopicSubscriberTransaction sub = (TopicSubscriberTransaction) durPersSubs.get(i);
sub.getTransaction().unlockQueue(false);
}
}
}
}
subscriberTransactions = null;
return delay;
}
use of com.swiftmq.swiftlet.queue.QueueLimitException in project swiftmq-ce by iitsoftware.
the class TopicTransaction method commit.
protected void commit(AsyncCompletionCallback callback) {
final DelayCollector delayCollector = new DelayCollector(callback);
if (subscriberTransactions != null) {
final List durPersSubs = new ArrayList(subscriberTransactions.length);
for (int i = 0; i < subscriberTransactions.length; i++) {
TopicSubscriberTransaction sub = subscriberTransactions[i];
if (sub != null) {
TopicSubscription subscription = sub.getTopicSubscription();
if (subscription.isRemote() || !subscription.isDurable() || !sub.isPersistentMessageIncluded()) {
delayCollector.incNumberCallbacks();
sub.commit(new AsyncCompletionCallback() {
public void done(boolean success) {
delayCollector.done(this, success);
}
});
} else
durPersSubs.add(sub);
}
}
final int size = durPersSubs.size();
long delay = 0;
if (size > 0) {
// Only 1 subscriber, direct commit
if (size == 1) {
TopicSubscriberTransaction sub = (TopicSubscriberTransaction) durPersSubs.get(0);
delayCollector.incNumberCallbacks();
sub.commit(new AsyncCompletionCallback() {
public void done(boolean success) {
delayCollector.done(this, success);
}
});
} else {
// Multiple subscriber, composite tx
int lastLocked = -1;
boolean spaceLeft = true;
for (int i = 0; i < size; i++) {
TopicSubscriberTransaction sub = (TopicSubscriberTransaction) durPersSubs.get(i);
sub.getTransaction().lockQueue();
lastLocked = i;
if (!sub.getTransaction().hasSpaceLeft()) {
spaceLeft = false;
break;
}
}
if (!spaceLeft) {
for (int i = 0; i <= lastLocked; i++) {
TopicSubscriberTransaction sub = (TopicSubscriberTransaction) durPersSubs.get(i);
sub.getTransaction().unlockQueue(false);
}
callback.setException(new QueueLimitException("Maximum Messages in at least one Durable Subscriber Queue reached!"));
callback.notifyCallbackStack(false);
return;
}
CompositeStoreTransaction compositeTx = ctx.storeSwiftlet.createCompositeStoreTransaction();
for (int i = 0; i < size; i++) {
TopicSubscriberTransaction sub = (TopicSubscriberTransaction) durPersSubs.get(i);
sub.getTransaction().setCompositeStoreTransaction(compositeTx);
try {
delay = Math.max(delay, sub.commit());
} catch (Exception e) {
e.printStackTrace();
}
sub.getTransaction().setCompositeStoreTransaction(null);
sub.getTransaction().unlockQueue(true);
}
delayCollector.incNumberCallbacks();
AsyncCompletionCallback cb = new AsyncCompletionCallback() {
public void done(boolean success) {
for (int i = 0; i < size; i++) {
TopicSubscriberTransaction sub = (TopicSubscriberTransaction) durPersSubs.get(i);
sub.getTransaction().unmarkAsyncActive();
}
delayCollector.done(this, success);
}
};
cb.setResult(Long.valueOf(delay));
compositeTx.commitTransaction(cb);
}
}
subscriberTransactions = null;
}
delayCollector.setBlocked(false);
}
Aggregations