use of com.swiftmq.swiftlet.queue.QueueException in project swiftmq-ce by iitsoftware.
the class TransactionRegistry method addToTransaction.
public void addToTransaction(TxnIdIF btxnId, String linkName, MessageImpl message, TargetLink targetLink) throws EndWithErrorException {
String txnId = new String(((TransactionId) btxnId).getValue());
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + "/addToTransaction, txnId=" + txnId + ", linkName=" + linkName + ", message=" + message);
lock.lock();
try {
ActiveTxEntry activeTxEntry = (ActiveTxEntry) activeTx.get(txnId);
if (activeTxEntry == null) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + "/addToTransaction, txnId=" + txnId + ", not found!");
throw new SessionEndException(TransactionError.UNKNOWN_ID, new AMQPString("Transaction id not found: " + txnId));
}
if (activeTxEntry.inboundTxEntryMap == null)
activeTxEntry.inboundTxEntryMap = new HashMap();
InboundTxEntry inboundTxEntry = (InboundTxEntry) activeTxEntry.inboundTxEntryMap.get(linkName);
try {
if (inboundTxEntry == null) {
QueuePushTransaction tx = targetLink.getQueueSender().createTransaction();
targetLink.increaseActiveTransactions();
inboundTxEntry = new InboundTxEntry(tx, targetLink);
activeTxEntry.inboundTxEntryMap.put(linkName, inboundTxEntry);
}
((QueuePushTransaction) inboundTxEntry.tx).putMessage(message);
} catch (QueueException e) {
throw new ConnectionEndException(AmqpError.INTERNAL_ERROR, new AMQPString(e.toString()));
}
} finally {
lock.unlock();
}
}
use of com.swiftmq.swiftlet.queue.QueueException in project swiftmq-ce by iitsoftware.
the class Output method send.
/**
* Sends a Message.
*
* @param message Message
* @return Output
* @throws Exception
*/
public Output send(Message message) throws Exception {
try {
if (sender == null) {
sender = createSender();
dest = getDestination();
}
txSent++;
MessageImpl impl = message.getImpl();
impl.setJMSDestination(dest);
impl.setJMSTimestamp(System.currentTimeMillis());
impl.setJMSMessageID(ctx.nextId());
QueuePushTransaction transaction = sender.createTransaction();
transaction.putMessage(impl);
ctx.addTransaction(transaction, new TransactionFinishListener() {
@Override
public void transactionFinished() {
txSent--;
if (closed) {
try {
if (sender != null) {
if (txSent == 0) {
sender.close();
}
}
} catch (QueueException e) {
ctx.logStackTrace(e);
}
}
}
});
if (sent + 1 == Integer.MAX_VALUE)
sent = 1;
else
sent++;
} catch (Exception e) {
if (!getDestination().toString().startsWith("tmp$"))
throw e;
}
dirty = true;
return this;
}
use of com.swiftmq.swiftlet.queue.QueueException in project swiftmq-ce by iitsoftware.
the class RegularQueueFactory method createQueue.
public AbstractQueue createQueue(String queueName, Entity queueEntity) throws QueueException {
PersistentStore pStore = null;
NonPersistentStore nStore = null;
try {
pStore = ctx.storeSwiftlet.getPersistentStore(queueName);
nStore = ctx.storeSwiftlet.getNonPersistentStore(queueName);
} catch (Exception e) {
e.printStackTrace();
throw new QueueException(e.toString());
}
Property prop = queueEntity.getProperty(QueueManagerImpl.PROP_CACHE_SIZE);
int cacheSize = ((Integer) prop.getValue()).intValue();
prop = queueEntity.getProperty(QueueManagerImpl.PROP_CACHE_SIZE_BYTES_KB);
int cacheSizeBytesKB = ((Integer) prop.getValue()).intValue();
Cache cache = new CacheImpl(cacheSize, cacheSizeBytesKB, pStore, nStore);
cache.setCacheTable(ctx.cacheTableFactory.createCacheTable(queueName, cacheSize));
prop = queueEntity.getProperty(QueueManagerImpl.PROP_CACHE_SIZE);
prop.setPropertyChangeListener(new PropertyChangeAdapter(cache) {
public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
Cache myCache = (Cache) configObject;
myCache.setMaxMessages(((Integer) newValue).intValue());
}
});
prop = queueEntity.getProperty(QueueManagerImpl.PROP_CACHE_SIZE_BYTES_KB);
prop.setPropertyChangeListener(new PropertyChangeAdapter(cache) {
public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
Cache myCache = (Cache) configObject;
myCache.setMaxBytesKB(((Integer) newValue).intValue());
}
});
prop = queueEntity.getProperty(QueueManagerImpl.PROP_CLEANUP_INTERVAL);
long cleanUp = ((Long) prop.getValue()).longValue();
MessageQueue mq = ctx.messageQueueFactory.createMessageQueue(ctx, queueName, cache, pStore, nStore, cleanUp, myTP);
prop = queueEntity.getProperty(QueueManagerImpl.PROP_MESSAGES_MAXIMUM);
int maxMessages = ((Integer) prop.getValue()).intValue();
mq.setMaxMessages(maxMessages);
prop.setPropertyChangeListener(new PropertyChangeAdapter(mq) {
public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
MessageQueue myMq = (MessageQueue) configObject;
myMq.setMaxMessages(((Integer) newValue).intValue());
}
});
prop = queueEntity.getProperty(QueueManagerImpl.PROP_PERSISTENCE);
int pm = SwiftUtilities.persistenceModeToInt((String) prop.getValue());
mq.setPersistenceMode(pm);
prop.setPropertyChangeListener(new PropertyChangeAdapter(mq) {
public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
MessageQueue myMq = (MessageQueue) configObject;
myMq.setPersistenceMode(SwiftUtilities.persistenceModeToInt((String) newValue));
}
});
prop = queueEntity.getProperty(QueueManagerImpl.PROP_FLOWCONTROL_QUEUE_SIZE);
int fcQueueSize = ((Integer) prop.getValue()).intValue();
if (fcQueueSize >= 0)
mq.setFlowController(new FlowControllerImpl(fcQueueSize, ctx.queueManager.getMaxFlowControlDelay()));
prop.setPropertyChangeListener(new PropertyChangeAdapter(mq) {
public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
MessageQueue myMq = (MessageQueue) configObject;
int newFcQueueSize = ((Integer) newValue).intValue();
if (newFcQueueSize >= 0)
myMq.setFlowController(new FlowControllerImpl(newFcQueueSize, ctx.queueManager.getMaxFlowControlDelay()));
else
myMq.setFlowController(null);
}
});
prop = queueEntity.getProperty(QueueManagerImpl.PROP_DUPLICATE_DETECTION_ENABLED);
mq.setDuplicateDetectionEnabled(((Boolean) prop.getValue()).booleanValue());
prop.setPropertyChangeListener(new PropertyChangeAdapter(mq) {
public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
MessageQueue myMq = (MessageQueue) configObject;
myMq.setDuplicateDetectionEnabled(((Boolean) newValue).booleanValue());
}
});
prop = queueEntity.getProperty(QueueManagerImpl.PROP_DUPLICATE_DETECTION_BACKLOG_SIZE);
mq.setDuplicateDetectionBacklogSize(((Integer) prop.getValue()).intValue());
prop.setPropertyChangeListener(new PropertyChangeAdapter(mq) {
public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
MessageQueue myMq = (MessageQueue) configObject;
myMq.setDuplicateDetectionBacklogSize(((Integer) newValue).intValue());
}
});
prop = queueEntity.getProperty(QueueManagerImpl.PROP_CONSUMER);
if (prop != null) {
mq.setConsumerMode(ctx.consumerModeInt((String) prop.getValue()));
prop.setPropertyChangeListener(new PropertyChangeAdapter(mq) {
public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
MessageQueue myMq = (MessageQueue) configObject;
int cm = ctx.consumerModeInt((String) newValue);
if (cm == AbstractQueue.EXCLUSIVE && myMq.getReceiverCount() > 1)
throw new PropertyChangeException("Can't set EXCLUSIVE consumer mode - queue has already '" + myMq.getReceiverCount() + "' receivers");
myMq.setConsumerMode(cm);
}
});
}
prop = queueEntity.getProperty(QueueManagerImpl.PROP_MONITOR_ALERT_THRESHOLD);
if (prop != null) {
mq.setMonitorAlertThreshold(((Integer) prop.getValue()).intValue());
prop.setPropertyChangeListener(new PropertyChangeAdapter(mq) {
public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
MessageQueue myMq = (MessageQueue) configObject;
myMq.setMonitorAlertThreshold(((Integer) newValue).intValue());
}
});
}
return mq;
}
use of com.swiftmq.swiftlet.queue.QueueException in project swiftmq-ce by iitsoftware.
the class SystemQueueFactory method createQueue.
public AbstractQueue createQueue(String queueName, Entity queueController) throws QueueException {
PersistentStore pStore = null;
NonPersistentStore nStore = null;
try {
pStore = ctx.storeSwiftlet.getPersistentStore(queueName);
nStore = ctx.storeSwiftlet.getNonPersistentStore(queueName);
} catch (Exception e) {
throw new QueueException(e.toString());
}
Property prop = queueController.getProperty(QueueManagerImpl.PROP_CACHE_SIZE);
int cacheSize = ((Integer) prop.getValue()).intValue();
prop = queueController.getProperty(QueueManagerImpl.PROP_CACHE_SIZE_BYTES_KB);
int cacheSizeBytesKB = ((Integer) prop.getValue()).intValue();
Cache cache = new CacheImpl(cacheSize, cacheSizeBytesKB, pStore, nStore);
cache.setCacheTable(ctx.cacheTableFactory.createCacheTable(queueName, cacheSize));
prop = queueController.getProperty(QueueManagerImpl.PROP_CLEANUP_INTERVAL);
long cleanUp = ((Long) prop.getValue()).longValue();
MessageQueue mq = ctx.messageQueueFactory.createMessageQueue(ctx, queueName, cache, pStore, nStore, cleanUp, myTP);
prop = queueController.getProperty(QueueManagerImpl.PROP_MESSAGES_MAXIMUM);
int maxMessages = ((Integer) prop.getValue()).intValue();
mq.setMaxMessages(maxMessages);
prop = queueController.getProperty(QueueManagerImpl.PROP_PERSISTENCE);
int pm = SwiftUtilities.persistenceModeToInt((String) prop.getValue());
mq.setPersistenceMode(pm);
prop = queueController.getProperty(QueueManagerImpl.PROP_FLOWCONTROL_QUEUE_SIZE);
int fcQueueSize = ((Integer) prop.getValue()).intValue();
if (fcQueueSize >= 0)
mq.setFlowController(new FlowControllerImpl(fcQueueSize, ctx.queueManager.getMaxFlowControlDelay()));
prop = queueController.getProperty(QueueManagerImpl.PROP_DUPLICATE_DETECTION_ENABLED);
mq.setDuplicateDetectionEnabled(((Boolean) prop.getValue()).booleanValue());
prop = queueController.getProperty(QueueManagerImpl.PROP_DUPLICATE_DETECTION_BACKLOG_SIZE);
mq.setDuplicateDetectionBacklogSize(((Integer) prop.getValue()).intValue());
prop = queueController.getProperty(QueueManagerImpl.PROP_CONSUMER);
mq.setConsumerMode(ctx.consumerModeInt((String) prop.getValue()));
mq.setQueueController(queueController);
return mq;
}
use of com.swiftmq.swiftlet.queue.QueueException in project swiftmq-ce by iitsoftware.
the class TempQueueFactory method createQueue.
public AbstractQueue createQueue(String queueName, Entity queueController) throws QueueException {
NonPersistentStore nStore = null;
try {
nStore = ctx.storeSwiftlet.getNonPersistentStore(queueName);
} catch (Exception e) {
throw new QueueException(e.toString());
}
Property prop = queueController.getProperty(QueueManagerImpl.PROP_CACHE_SIZE);
int cacheSize = ((Integer) prop.getValue()).intValue();
prop = queueController.getProperty(QueueManagerImpl.PROP_CACHE_SIZE_BYTES_KB);
int cacheSizeBytesKB = ((Integer) prop.getValue()).intValue();
Cache cache = new CacheImpl(cacheSize, cacheSizeBytesKB, null, nStore);
cache.setCacheTable(ctx.cacheTableFactory.createCacheTable(queueName, cacheSize));
prop = queueController.getProperty(QueueManagerImpl.PROP_CLEANUP_INTERVAL);
long cleanUp = ((Long) prop.getValue()).longValue();
MessageQueue mq = ctx.messageQueueFactory.createMessageQueue(ctx, queueName, cache, null, nStore, cleanUp, myTP);
prop = queueController.getProperty(QueueManagerImpl.PROP_MESSAGES_MAXIMUM);
int maxMessages = ((Integer) prop.getValue()).intValue();
mq.setMaxMessages(maxMessages);
prop = queueController.getProperty(QueueManagerImpl.PROP_PERSISTENCE);
int pm = SwiftUtilities.persistenceModeToInt((String) prop.getValue());
mq.setPersistenceMode(pm);
prop = queueController.getProperty(QueueManagerImpl.PROP_FLOWCONTROL_QUEUE_SIZE);
int fcQueueSize = ((Integer) prop.getValue()).intValue();
if (fcQueueSize >= 0)
mq.setFlowController(new FlowControllerImpl(fcQueueSize, ctx.queueManager.getMaxFlowControlDelay()));
prop = queueController.getProperty(QueueManagerImpl.PROP_DUPLICATE_DETECTION_ENABLED);
mq.setDuplicateDetectionEnabled(((Boolean) prop.getValue()).booleanValue());
prop = queueController.getProperty(QueueManagerImpl.PROP_DUPLICATE_DETECTION_BACKLOG_SIZE);
mq.setDuplicateDetectionBacklogSize(((Integer) prop.getValue()).intValue());
prop = queueController.getProperty(QueueManagerImpl.PROP_CONSUMER);
mq.setConsumerMode(ctx.consumerModeInt((String) prop.getValue()));
mq.setQueueController(queueController);
return mq;
}
Aggregations