use of com.sun.messaging.jmq.io.JMSPacket in project openmq by eclipse-ee4j.
the class JMSServiceImpl method sendMessage.
/**
* Send a message to the broker.
*
* @param connectionId The Id of the connection
* @param message The Message to be sent
*
* @throws JMSServiceException if the Status returned for the sendMessage method is not
* {@link JMSServiceReply.Status#OK}
*/
@Override
public JMSServiceReply sendMessage(long connectionId, JMSPacket message) throws JMSServiceException {
JMSServiceReply reply;
HashMap props = new HashMap();
IMQConnection cxn;
cxn = checkConnectionId(connectionId, "sendMessage");
/*
* TBD: The packets used here are not compatible. Should sendMessage() have individual params (eg msg body) to pass to
* processMessage() instead of Packet ?
*
* Trying Packet.fill()...
*/
try {
Packet p = new Packet();
p.fill(message.getPacket());
protocol.processMessage(cxn, p);
} catch (Exception e) {
String errStr = "sendMessage: Sending message failed. Connection ID: " + connectionId;
logger.logStack(Logger.ERROR, errStr, e);
props.put("JMQStatus", JMSServiceReply.Status.ERROR);
throw new JMSServiceException(errStr, e, props);
}
props.put("JMQStatus", JMSServiceReply.Status.OK);
reply = new JMSServiceReply(props);
return (reply);
}
use of com.sun.messaging.jmq.io.JMSPacket in project openmq by eclipse-ee4j.
the class StompSenderSession method sendStompMessage.
public void sendStompMessage(StompFrameMessage message) throws Exception {
checkSession();
Packet pkt = new Packet();
pkt.setPersistent(jmsservice.DEFAULT_MessageDeliveryMode == MessageDeliveryMode.PERSISTENT);
pkt.setPriority(jmsservice.DEFAULT_MessagePriority.priority());
pkt.setExpiration(jmsservice.DEFAULT_TIME_TO_LIVE);
pkt.setDeliveryTime(jmsservice.DEFAULT_DELIVERY_DELAY);
stompconn.fillRemoteIPAndPort(pkt);
StompDestinationImpl d = fromStompFrameMessage(message, pkt);
String stompdest = d.getStompDestinationString();
try {
jmsservice.createDestination(connectionId, d.getDestination());
} catch (JMSServiceException jmsse) {
JMSServiceReply.Status status = jmsse.getJMSServiceReply().getStatus();
if (status == JMSServiceReply.Status.CONFLICT) {
if (logger.isFineLoggable() || stompconn.getProtocolHandler().getDEBUG()) {
logger.log(logger.INFO, "Destination " + stompdest + " already exist");
}
} else {
throw jmsse;
}
}
synchronized (this) {
Long prodid = producers.get(stompdest);
if (prodid == null) {
JMSServiceReply reply = jmsservice.addProducer(connectionId, sessionId, d.getDestination());
prodid = Long.valueOf(reply.getJMQProducerID());
producers.put(stompdest, prodid);
}
pkt.setProducerID(prodid.longValue());
}
pkt.prepareToSend();
synchronized (this) {
if (isTransacted()) {
pkt.setTransactionID(getTransactionId());
} else {
pkt.setTransactionID(0L);
}
final Packet p = pkt;
jmsservice.sendMessage(connectionId, new JMSPacket() {
@Override
public Packet getPacket() {
return p;
}
});
}
if (logger.isFineLoggable() || stompconn.getProtocolHandler().getDEBUG()) {
logger.log(logger.INFO, "Sent message " + pkt.getSysMessageID());
}
}
Aggregations