use of com.swiftmq.jms.MessageImpl in project swiftmq-ce by iitsoftware.
the class SourceMessageProcessor method transformMessage.
private Delivery transformMessage(MessageEntry messageEntry) throws JMSException {
try {
MessageImpl message = sourceLink.isQueue ? messageEntry.getMessage() : copyMessage(messageEntry.getMessage());
MessageIndex messageIndex = messageEntry.getMessageIndex();
OutboundTransformer transformer = sourceLink.getTransformer();
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + "/transformMessage, transformer=" + transformer);
if (transformer == null)
throw new JMSException("No outbound message transformer found!");
Delivery delivery = new Delivery(sourceLink, message, messageIndex);
transformer.transform(delivery);
return delivery;
} catch (Exception e) {
e.printStackTrace();
throw new JMSException(e.toString());
}
}
use of com.swiftmq.jms.MessageImpl in project swiftmq-ce by iitsoftware.
the class ChannelHandler method publishCurrentMessage.
private void publishCurrentMessage(Exchange exchange) {
if (exchange.getType() == Exchange.DIRECT) {
String rk = getMapping(currentMessage.getPublish().getRoutingKey());
QueueSender sender = (QueueSender) producers.get(rk);
try {
if (sender == null) {
if (producers.size() > 10) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + ", sender cache > 10, closing all");
for (Iterator iter = producers.entrySet().iterator(); iter.hasNext(); ) {
QueueSender s = (QueueSender) ((Map.Entry) iter.next()).getValue();
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + ", closing sender for queue: " + s.getQueueName());
s.close();
iter.remove();
}
}
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + ", creating new sender on queue: " + rk);
sender = ctx.queueManager.createQueueSender(rk, versionedConnection.getActiveLogin());
producers.put(rk, sender);
}
QueuePushTransaction t = sender.createTransaction();
MessageImpl msg = inboundTransformer.transform(currentMessage, this);
msg.setJMSDestination(create(rk));
msg.reset();
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + ", converted JMS message: " + msg);
t.putMessage(msg);
t.commit();
if (remoteFlowActive) {
long fcDelay = t.getFlowControlDelay();
if (fcDelay > 100) {
sendFlow(false);
ctx.timerSwiftlet.addInstantTimerListener(fcDelay, new TimerListener() {
public void performTimeAction() {
dispatch(PO_ACTIVATE_FLOW);
}
});
}
}
} catch (JMSException e) {
amqpHandler.dispatch(new POSendChannelClose(channelNo, Constants.CHANNEL_ERROR, "Exception on publishing to exchange '" + currentMessage.getPublish().getExchange() + "': " + e, currentMessage.getPublish()));
}
} else
amqpHandler.dispatch(new POSendChannelClose(channelNo, Constants.NOT_IMPLEMENTED, "Exchange is not of type direct: " + currentMessage.getPublish().getExchange(), currentMessage.getPublish()));
}
use of com.swiftmq.jms.MessageImpl in project swiftmq-ce by iitsoftware.
the class TransactedTopicSession method visit.
public void visit(CommitRequest req) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/visitCommitRequest");
CommitReply reply = (CommitReply) req.createReply();
reply.setOk(true);
try {
// first: produce all messages
List ml = req.getMessages();
ctx.incMsgsSent(ml.size());
req.setMessages(null);
long fcDelay = 0;
RingBuffer tempProducers = null;
for (int i = 0; i < ml.size(); i++) {
DataByteArrayInputStream dis = new DataByteArrayInputStream((byte[]) ml.get(i));
int producerId = dis.readInt();
int type = dis.readInt();
MessageImpl msg = MessageImpl.createInstance(type);
msg.readContent(dis);
dis.close();
long ttl = msg.getJMSExpiration();
if (ttl > 0)
msg.setJMSExpiration(System.currentTimeMillis() + ttl);
Producer producer = null;
if (producerId == -1) {
TopicImpl topic = (TopicImpl) msg.getJMSDestination();
if (topic.getType() != DestinationFactory.TYPE_TEMPTOPIC)
ctx.authSwiftlet.verifyTopicSenderSubscription(topic.getTopicName(), ctx.activeLogin.getLoginId());
producer = new TopicProducer(ctx, topic);
if (tempProducers == null)
tempProducers = new RingBuffer(8);
tempProducers.add(producer);
transactionManager.addTransactionFactory(producer);
} else {
producer = (Producer) producerList.get(producerId);
}
QueuePushTransaction transaction = producer.getTransaction();
transaction.putMessage(msg);
fcDelay = Math.max(fcDelay, transaction.getFlowControlDelay());
if (producerId == -1)
producer.markForClose();
}
// Next: do the commit
transactionManager.commit();
if (tempProducers != null) {
int size = tempProducers.getSize();
for (int i = 0; i < size; i++) {
((Producer) tempProducers.remove()).close();
}
}
reply.setDelay(fcDelay);
purgeMarkedProducers();
purgeMarkedConsumers();
} catch (Exception e) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/commit produced messages failed: " + e.getMessage());
reply.setOk(false);
reply.setException(e);
}
reply.send();
}
use of com.swiftmq.jms.MessageImpl in project swiftmq-ce by iitsoftware.
the class NontransactedTopicSession method visit.
public void visit(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();
int producerId = req.getQueueProducerId();
Producer producer = null;
try {
MessageImpl msg = SMQPUtil.getMessage(req);
long ttl = msg.getJMSExpiration();
if (ttl > 0)
msg.setJMSExpiration(System.currentTimeMillis() + ttl);
if (producerId == -1) {
TopicImpl topic = (TopicImpl) msg.getJMSDestination();
if (topic.getType() != DestinationFactory.TYPE_TEMPTOPIC)
ctx.authSwiftlet.verifyTopicSenderSubscription(topic.getTopicName(), ctx.activeLogin.getLoginId());
producer = new TopicProducer(ctx, topic);
} else {
producer = (Producer) producerList.get(producerId);
}
QueuePushTransaction transaction = (QueuePushTransaction) producer.createTransaction();
transaction.putMessage(msg);
transaction.commit(new ProduceMessageCallback(producerId == -1 ? producer : null, reply));
} 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);
reply.send();
}
}
}
use of com.swiftmq.jms.MessageImpl in project swiftmq-ce by iitsoftware.
the class TransactionRequest method readContent.
public void readContent(DataInput input) throws IOException {
super.readContent(input);
sequenceNo = input.readInt();
xid = new XidImpl();
xid.readContent(input);
int size = input.readInt();
messageList = new ArrayList();
for (int i = 0; i < size; i++) {
MessageImpl msg = MessageImpl.createInstance(input.readInt());
msg.readContent(input);
messageList.add(msg);
}
}
Aggregations