use of com.swiftmq.jms.MessageImpl in project swiftmq-ce by iitsoftware.
the class NontransactedQueueSession method visitProduceMessageRequest.
public void visitProduceMessageRequest(ProduceMessageRequest req) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/visitProduceMessageRequest");
ctx.incMsgsSent(1);
ProduceMessageReply reply = null;
if (req.isReplyRequired())
reply = (ProduceMessageReply) req.createReply();
MessageImpl msg = req.getMessage();
int producerId = req.getQueueProducerId();
Producer producer = null;
try {
if (producerId == -1) {
String queueName = ((QueueImpl) msg.getJMSDestination()).getQueueName();
if (!ctx.queueManager.isQueueRunning(queueName))
throw new InvalidDestinationException("Invalid destination: " + queueName);
producer = new QueueProducer(ctx, queueName);
} else {
producer = (Producer) producerList.get(producerId);
}
QueuePushTransaction transaction = (QueuePushTransaction) producer.createTransaction();
transaction.putMessage(msg);
transaction.commit();
if (req.isReplyRequired()) {
reply.setDelay(transaction.getFlowControlDelay());
reply.setOk(true);
}
if (producerId == -1)
producer.close();
} catch (Exception e) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/produce messages failed: " + e.getMessage());
if (req.isReplyRequired()) {
reply.setOk(false);
reply.setException((e instanceof JMSException) ? e : new javax.jms.JMSException(e.toString()));
}
}
if (req.isReplyRequired())
reply.send();
}
use of com.swiftmq.jms.MessageImpl in project swiftmq-ce by iitsoftware.
the class Copier method execute.
public String[] execute(String[] context, Entity entity, String[] cmd) {
if (cmd.length < 3 || !cmd[2].equals("-queue") && !cmd[2].equals("-topic"))
return new String[] { TreeCommands.ERROR, "Invalid command, please try '" + _getPattern() + "'" };
String[] result = null;
try {
if (cmd.length >= 6 && cmd[4].equals("-selector"))
result = copyWithSelector(cmd);
else {
if (!ctx.queueManager.isQueueDefined(cmd[1]))
throw new Exception("Unknown queue: " + cmd[1]);
AbstractQueue aq = ctx.queueManager.getQueueForInternalUse(cmd[1]);
if (!(aq instanceof MessageQueue))
throw new Exception("Operation not supported on this type of queue!");
MessageQueue sourceQueue = (MessageQueue) aq;
QueueSender sender = null;
QueueImpl targetQueueAddr = null;
if (cmd[2].equals("-queue")) {
sender = ctx.queueManager.createQueueSender(cmd[3], null);
targetQueueAddr = new QueueImpl(cmd[3]);
} else {
String qft = ctx.topicManager.getQueueForTopic(cmd[3]);
sender = ctx.queueManager.createQueueSender(qft, null);
targetQueueAddr = new TopicImpl(cmd[3]);
}
SortedSet content = sourceQueue.getQueueIndex();
int max = getMaxLimit(cmd);
int start = 0;
int stop = Integer.MAX_VALUE;
if (cmd.length >= 7 && cmd[4].equals("-index")) {
start = Integer.parseInt(cmd[5]);
stop = Integer.parseInt(cmd[6]);
if (stop < start)
throw new Exception("Stop index is less than start index.");
} else {
if (cmd.length != 4 && max == Integer.MAX_VALUE)
return new String[] { TreeCommands.ERROR, "Invalid command, please try '" + _getCommand() + " <source> -queue|-topic <target> -index <start> <stop>'" };
}
int i = 0, cnt = 0;
for (Iterator iter = content.iterator(); iter.hasNext(); ) {
MessageIndex mi = (MessageIndex) iter.next();
if (i >= start && i <= stop) {
try {
MessageImpl msg = copyMessage(sourceQueue.getMessageByIndex(mi).getMessage());
msg.setJMSDestination(targetQueueAddr);
msg.setSourceRouter(null);
msg.setDestRouter(null);
QueuePushTransaction t = sender.createTransaction();
t.putMessage(msg);
t.commit();
cnt++;
if (remove)
sourceQueue.removeMessageByIndex(mi);
if (cnt == max)
break;
} catch (MessageLockedException ignored) {
}
}
if (i > stop)
break;
i++;
}
return new String[] { TreeCommands.INFO, cnt + " messages processed." };
}
} catch (Exception e) {
result = new String[] { TreeCommands.ERROR, e.getMessage() };
}
return result;
}
use of com.swiftmq.jms.MessageImpl in project swiftmq-ce by iitsoftware.
the class Copier method copyWithSelector.
private String[] copyWithSelector(String[] cmd) throws Exception {
int max = getMaxLimit(cmd);
int decr = max == Integer.MAX_VALUE ? 0 : 2;
StringBuffer b = new StringBuffer();
for (int i = 5; i < cmd.length - decr; i++) {
if (i > 5)
b.append(' ');
b.append(cmd[i]);
}
MessageSelector selector = new MessageSelector(b.toString());
selector.compile();
QueueReceiver receiver = ctx.queueManager.createQueueReceiver(cmd[1], null, selector);
QueuePullTransaction pullTx = receiver.createTransaction(false);
QueueSender sender = null;
QueueImpl targetQueueAddr = null;
if (cmd[2].equals("-queue")) {
sender = ctx.queueManager.createQueueSender(cmd[3], null);
targetQueueAddr = new QueueImpl(cmd[3]);
} else {
String qft = ctx.topicManager.getQueueForTopic(cmd[3]);
sender = ctx.queueManager.createQueueSender(qft, null);
targetQueueAddr = new TopicImpl(cmd[3]);
}
QueuePushTransaction pushTx = sender.createTransaction();
int cnt = 0;
try {
MessageEntry entry = null;
while ((entry = pullTx.getMessage(0, selector)) != null && cnt < max) {
MessageImpl msg = copyMessage(entry.getMessage());
msg.setJMSDestination(targetQueueAddr);
msg.setSourceRouter(null);
msg.setDestRouter(null);
pushTx.putMessage(msg);
cnt++;
pushTx.commit();
if (remove) {
pullTx.commit();
pullTx = receiver.createTransaction(false);
}
pushTx = sender.createTransaction();
}
} finally {
try {
pullTx.rollback();
} catch (Exception e) {
}
try {
receiver.close();
} catch (Exception e) {
}
try {
pushTx.rollback();
} catch (Exception e) {
}
try {
sender.close();
} catch (Exception e) {
}
}
return new String[] { TreeCommands.INFO, cnt + " messages processed." };
}
use of com.swiftmq.jms.MessageImpl in project swiftmq-ce by iitsoftware.
the class Copier method copyMessage.
private MessageImpl copyMessage(MessageImpl msg) throws Exception {
DataByteArrayOutputStream dbos = new DataByteArrayOutputStream();
DataByteArrayInputStream dbis = new DataByteArrayInputStream();
msg.writeContent(dbos);
dbis.reset();
dbis.setBuffer(dbos.getBuffer(), 0, dbos.getCount());
MessageImpl msgCopy = MessageImpl.createInstance(dbis.readInt());
msgCopy.readContent(dbis);
return msgCopy;
}
use of com.swiftmq.jms.MessageImpl in project swiftmq-ce by iitsoftware.
the class Exporter method copyMessage.
private MessageImpl copyMessage(MessageImpl msg) throws Exception {
DataByteArrayOutputStream dbos = new DataByteArrayOutputStream();
DataByteArrayInputStream dbis = new DataByteArrayInputStream();
msg.writeContent(dbos);
dbis.reset();
dbis.setBuffer(dbos.getBuffer(), 0, dbos.getCount());
MessageImpl msgCopy = MessageImpl.createInstance(dbis.readInt());
msgCopy.readContent(dbis);
return msgCopy;
}
Aggregations