use of com.swiftmq.ms.MessageSelector in project swiftmq-ce by iitsoftware.
the class Viewer method createCollector.
private ViewCollector createCollector(String queueName, String selectorString, int from) throws Exception {
if (!ctx.queueManager.isQueueDefined(queueName))
throw new Exception("Unknown queue: " + queueName);
MessageSelector selector = null;
if (selectorString != null) {
selector = new MessageSelector(selectorString);
selector.compile();
}
return new ViewCollector(ctx.queueManager.getQueueForInternalUse(queueName), from, selector, MAX_RESULT);
}
use of com.swiftmq.ms.MessageSelector in project swiftmq-ce by iitsoftware.
the class QueueMoverJob method start.
public void start(Properties properties, JobTerminationListener jobTerminationListener) throws JobException {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.queueManager.getName(), toString() + "/start, properties=" + properties + " ...");
this.properties = properties;
int cnt = 0;
String queueName = properties.getProperty("Source Queue");
if (!queueName.startsWith("tpc$")) {
MessageSelector selector = null;
String s = properties.getProperty("Message Selector");
if (s != null) {
selector = new MessageSelector(s);
try {
selector.compile();
} catch (InvalidSelectorException e) {
throw new JobException(e.toString(), e, false);
}
}
try {
receiver = ctx.queueManager.createQueueReceiver(queueName, null, selector);
pullTx = receiver.createTransaction(false);
targetQueue = new QueueImpl(properties.getProperty("Target Queue"));
sender = ctx.queueManager.createQueueSender(targetQueue.getQueueName(), null);
pushTx = sender.createTransaction();
} catch (Exception e) {
throw new JobException(e.toString(), e, false);
}
if (stopCalled) {
terminate();
return;
}
try {
MessageEntry entry = null;
while ((entry = pullTx.getMessage(0, selector)) != null) {
MessageImpl msg = entry.getMessage();
msg.setJMSDestination(targetQueue);
msg.setSourceRouter(null);
msg.setDestRouter(null);
pushTx.putMessage(msg);
cnt++;
pushTx.commit();
pullTx.commit();
if (stopCalled) {
terminate();
return;
}
pullTx = receiver.createTransaction(false);
pushTx = sender.createTransaction();
}
} catch (Exception e) {
terminate();
throw new JobException(e.toString(), e, false);
}
}
terminate();
jobTerminationListener.jobTerminated(cnt + " Messages moved");
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.queueManager.getName(), toString() + "/start, properties=" + properties + " done, cnt=" + cnt);
}
use of com.swiftmq.ms.MessageSelector in project swiftmq-ce by iitsoftware.
the class QueuePurgerJob method start.
public void start(Properties properties, JobTerminationListener jobTerminationListener) throws JobException {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.queueManager.getName(), toString() + "/start, properties=" + properties + " ...");
this.properties = properties;
int cnt = 0;
String queueName = properties.getProperty("Queue Name");
if (!queueName.startsWith("tpc$")) {
MessageSelector selector = null;
String s = properties.getProperty("Message Selector");
if (s != null) {
selector = new MessageSelector(s);
try {
selector.compile();
} catch (InvalidSelectorException e) {
throw new JobException(e.toString(), e, false);
}
}
try {
receiver = ctx.queueManager.createQueueReceiver(queueName, null, selector);
transaction = receiver.createTransaction(false);
} catch (Exception e) {
throw new JobException(e.toString(), e, false);
}
if (stopCalled) {
terminate();
return;
}
try {
while (transaction.getMessage(0, selector) != null) {
cnt++;
transaction.commit();
if (stopCalled) {
terminate();
return;
}
transaction = receiver.createTransaction(false);
}
} catch (Exception e) {
terminate();
throw new JobException(e.toString(), e, false);
}
}
terminate();
jobTerminationListener.jobTerminated(cnt + " Messages purged");
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.queueManager.getName(), toString() + "/start, properties=" + properties + " done, cnt=" + cnt);
}
use of com.swiftmq.ms.MessageSelector in project swiftmq-ce by iitsoftware.
the class BrowserManager method createBrowser.
public void createBrowser(CreateBrowserRequest request) {
CreateBrowserReply reply = (CreateBrowserReply) request.createReply();
QueueImpl queue = request.getQueue();
String messageSelector = request.getMessageSelector();
MessageSelector msel = null;
String queueName = null;
try {
queueName = queue.getQueueName();
} catch (JMSException ignored) {
}
try {
if (messageSelector != null) {
msel = new MessageSelector(messageSelector);
msel.compile();
}
if (!ctx.queueManager.isQueueRunning(queueName)) {
ctx.logSwiftlet.logWarning("sys$jms", ctx.tracePrefix + "/" + toString() + ": Invalid destination: " + queueName);
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/" + toString() + ": Invalid destination: " + queue);
reply.setOk(false);
reply.setException(new InvalidDestinationException("Invalid destination: " + queueName));
} else {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/" + toString() + ": Creating browser with selector: " + msel);
com.swiftmq.swiftlet.queue.QueueBrowser queueBrowser = ctx.queueManager.createQueueBrowser(queueName, ctx.activeLogin, msel);
int idx = ArrayListTool.setFirstFreeOrExpand(queueBrowsers, queueBrowser);
reply.setOk(true);
reply.setQueueBrowserId(idx);
if (browserEntityList != null) {
Entity browserEntity = browserEntityList.createEntity();
browserEntity.setName(queueName + "-" + idx);
browserEntity.setDynamicObject(queueBrowser);
browserEntity.createCommands();
Property prop = browserEntity.getProperty("queue");
prop.setValue(queueName);
prop.setReadOnly(true);
prop = browserEntity.getProperty("selector");
if (msel != null) {
prop.setValue(msel.getConditionString());
}
prop.setReadOnly(true);
browserEntityList.addEntity(browserEntity);
}
}
} catch (InvalidSelectorException e) {
ctx.logSwiftlet.logWarning("sys$jms", ctx.tracePrefix + "/" + toString() + ": CreateBrowser has invalid Selector: " + e);
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/" + toString() + ": CreateBrowser has invalid Selector: " + e);
reply.setOk(false);
reply.setException(e);
} catch (Exception e) {
ctx.logSwiftlet.logWarning("sys$jms", ctx.tracePrefix + "/" + toString() + ": Exception during createQueueBrowser: " + e);
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/" + toString() + ": Exception during createQueueBrowser: " + e);
reply.setOk(false);
reply.setException(e);
}
reply.send();
}
use of com.swiftmq.ms.MessageSelector in project swiftmq-client by iitsoftware.
the class SessionImpl method createReceiver.
public QueueReceiver createReceiver(Queue queue, String messageSelector) throws JMSException {
verifyState();
if (queue == null)
throw new InvalidDestinationException("createReceiver, queue is null!");
if (queue instanceof TemporaryQueueImpl && !((TemporaryQueueImpl) queue).isCreatungSession(this))
throw new JMSException("A receiver on a TemporaryQueue can only be created from the session the temporary queue was created from");
QueueReceiverImpl qr = null;
CreateConsumerReply reply = null;
try {
String ms = messageSelector;
if (messageSelector != null && messageSelector.trim().length() == 0)
ms = null;
if (ms != null) {
MessageSelector msel = new MessageSelector(ms);
msel.compile();
}
reply = (CreateConsumerReply) requestRegistry.request(new CreateConsumerRequest(this, dispatchId, (QueueImpl) queue, ms));
} catch (Exception e) {
throw ExceptionConverter.convert(e);
}
if (reply.isOk()) {
int qcId = reply.getQueueConsumerId();
qr = new QueueReceiverImpl(transacted, acknowledgeMode, requestRegistry, queue, messageSelector, this);
qr.setServerQueueConsumerId(qcId);
qr.setDoAck(!transacted && acknowledgeMode != Session.CLIENT_ACKNOWLEDGE);
addMessageConsumerImpl(qr);
} else {
throw ExceptionConverter.convert(reply.getException());
}
return (qr);
}
Aggregations