Search in sources :

Example 1 with JMSAck

use of com.sun.messaging.jmq.jmsservice.JMSAck in project openmq by eclipse-ee4j.

the class DirectMDBSession method _deliverMessage.

/**
 * Deliver a message from this DirectSession - only one thread can do this at a time.
 */
@Override
protected synchronized JMSAck _deliverMessage(jakarta.jms.MessageListener msgListener, JMSPacket jmsPacket, long consumerId) throws ConsumerClosedNoDeliveryException {
    JMSAck jmsAck = null;
    if (this.enableThreadCheck) {
        // Relies on the *same* thread being used to deliver all messages
        // while this sesion is alive
        long tId = Thread.currentThread().getId();
        if (this.deliverThreadId == 0L) {
            // first time
            this.deliverThreadId = tId;
        } else {
            if (this.deliverThreadId != tId) {
                throw new RuntimeException("Invalid to call deliver from two different threads!");
            }
        }
    }
    jakarta.jms.Message jmsMsg = null;
    if (msgListener == null) {
        throw new RuntimeException("DirectConsumer:MessageListener not set!");
    }
    if (jmsPacket == null) {
        throw new RuntimeException("DirectConsumer:JMSPacket is null!");
    }
    try {
        jmsMsg = DirectPacket.constructMessage(jmsPacket, consumerId, this, this.jmsservice, false);
    } catch (Exception e) {
    }
    if (jmsMsg == null) {
        throw new RuntimeException("DirectConsumer:JMS Message in Packet is null!");
    }
    try {
        this.inDeliver = true;
        msgListener.onMessage(jmsMsg);
        // this.ds._deliverMessage(this.msgListener, jmsMsg);
        this.inDeliver = false;
        if (this.ackMode != SessionAckMode.CLIENT_ACKNOWLEDGE) {
            jmsAck = new DirectAck(this.connectionId, this.sessionId, consumerId, ((DirectPacket) jmsMsg).getReceivedSysMessageID(), JMSService.MessageAckType.ACKNOWLEDGE);
        }
    } catch (Exception e) {
        System.out.println("DirectConsumer:Caught Exception delivering message" + e.getMessage());
    }
    return jmsAck;
}
Also used : jakarta.jms(jakarta.jms) JMSAck(com.sun.messaging.jmq.jmsservice.JMSAck) ConsumerClosedNoDeliveryException(com.sun.messaging.jmq.jmsservice.ConsumerClosedNoDeliveryException)

Example 2 with JMSAck

use of com.sun.messaging.jmq.jmsservice.JMSAck in project openmq by eclipse-ee4j.

the class StompSubscriberSession method deliver.

@Override
public JMSAck deliver(JMSPacket msgpkt) throws ConsumerClosedNoDeliveryException {
    if (closing || closed || stompconn.isClosed()) {
        throw new ConsumerClosedNoDeliveryException("Subscriber " + this + " is closed");
    }
    try {
        final boolean needAck = (ackMode != SessionAckMode.AUTO_ACKNOWLEDGE);
        StompFrameMessage msg = toStompFrameMessage(subid, stompdest, msgpkt.getPacket(), needAck);
        if (stompconn.getProtocolHandler().getDEBUG()) {
            logger.log(logger.INFO, " SEND message " + msg + " for " + toString());
        }
        if (ackMode != SessionAckMode.CLIENT_ACKNOWLEDGE) {
            out.sendToClient(msg, stompconn.getProtocolHandler(), null);
            return new Ack(msgpkt.getPacket(), MessageAckType.ACKNOWLEDGE);
        } else {
            unackedMessages.add(msgpkt.getPacket().getSysMessageID());
            out.sendToClient(msg, stompconn.getProtocolHandler(), null);
        }
    } catch (Exception e) {
        logger.logStack(logger.WARNING, e.getMessage(), e);
    }
    return null;
}
Also used : ConsumerClosedNoDeliveryException(com.sun.messaging.jmq.jmsservice.ConsumerClosedNoDeliveryException) StompFrameMessage(com.sun.messaging.bridge.api.StompFrameMessage) JMSAck(com.sun.messaging.jmq.jmsservice.JMSAck) ConsumerClosedNoDeliveryException(com.sun.messaging.jmq.jmsservice.ConsumerClosedNoDeliveryException) StompProtocolException(com.sun.messaging.bridge.api.StompProtocolException) JMSServiceException(com.sun.messaging.jmq.jmsservice.JMSServiceException)

Example 3 with JMSAck

use of com.sun.messaging.jmq.jmsservice.JMSAck in project openmq by eclipse-ee4j.

the class DirectSession method _deliverMessage.

/**
 * Deliver a message from this DirectSession - only one thread can do this at a time.
 */
protected synchronized JMSAck _deliverMessage(jakarta.jms.MessageListener msgListener, JMSPacket jmsPacket, long consumerId) throws ConsumerClosedNoDeliveryException {
    JMSAck jmsAck = null;
    SysMessageID messageID = null;
    if (this.enableThreadCheck) {
        // Relies on the *same* thread being used to deliver all messages
        // while this sesion is alive
        long tId = Thread.currentThread().getId();
        if (this.deliverThreadId == 0L) {
            // first time
            this.deliverThreadId = tId;
        } else {
            if (this.deliverThreadId != tId) {
                throw new RuntimeException("Invalid to call deliver from two different threads!");
            }
        }
    }
    jakarta.jms.Message jmsMsg = null;
    if (msgListener == null) {
        throw new RuntimeException("DirectConsumer:MessageListener not set!");
    }
    if (jmsPacket == null) {
        throw new RuntimeException("DirectConsumer:JMSPacket is null!");
    }
    try {
        jmsMsg = DirectPacket.constructMessage(jmsPacket, consumerId, this, this.jmsservice, false);
    } catch (Exception e) {
    }
    if (jmsMsg == null) {
        throw new RuntimeException("DirectConsumer:JMS Message in Packet is null!");
    }
    try {
        this.inDeliver = true;
        msgListener.onMessage(jmsMsg);
        // this.ds._deliverMessage(this.msgListener, jmsMsg);
        this.inDeliver = false;
        messageID = ((DirectPacket) jmsMsg).getReceivedSysMessageID();
        if (this.ackMode != SessionAckMode.CLIENT_ACKNOWLEDGE) {
            /*
                 * if (this.dc.isManaged() && this.dc.isEnlisted()){ xaTxnId = this.dc._getXAResource()._getTransactionId(); } else {
                 * xaTxnId = this._getTransactionId(); }
                 */
            jmsAck = new DirectAck(this.connectionId, this.sessionId, consumerId, messageID, JMSService.MessageAckType.ACKNOWLEDGE);
        } else {
            // Do not need to recover an MDB Session
            if (!this._isMDBSession()) {
                // Insert message's SysMessageID and consumerId for recover
                // for non-MDB Session
                unackedMessageIDs.add(messageID);
                unackedConsumerIDs.add(consumerId);
            }
        }
    } catch (ConsumerClosedNoDeliveryException e) {
        throw e;
    } catch (Exception e) {
        System.out.println("DirectConsumer:Caught Exception delivering message" + e.getMessage());
    // Re-attempt redelivery semantics here
    // Ack UNDELIVERABLE or DEAD
    }
    return jmsAck;
}
Also used : Message(jakarta.jms.Message) ConsumerClosedNoDeliveryException(com.sun.messaging.jmq.jmsservice.ConsumerClosedNoDeliveryException) JMSAck(com.sun.messaging.jmq.jmsservice.JMSAck) SysMessageID(com.sun.messaging.jmq.io.SysMessageID) JMSException(jakarta.jms.JMSException) JMSServiceException(com.sun.messaging.jmq.jmsservice.JMSServiceException) InvalidDestinationException(jakarta.jms.InvalidDestinationException) MessageFormatException(jakarta.jms.MessageFormatException) InvalidSelectorException(jakarta.jms.InvalidSelectorException) ConsumerClosedNoDeliveryException(com.sun.messaging.jmq.jmsservice.ConsumerClosedNoDeliveryException) IllegalStateException(com.sun.messaging.jms.IllegalStateException) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) JMSSecurityException(jakarta.jms.JMSSecurityException)

Aggregations

ConsumerClosedNoDeliveryException (com.sun.messaging.jmq.jmsservice.ConsumerClosedNoDeliveryException)3 JMSAck (com.sun.messaging.jmq.jmsservice.JMSAck)3 JMSServiceException (com.sun.messaging.jmq.jmsservice.JMSServiceException)2 StompFrameMessage (com.sun.messaging.bridge.api.StompFrameMessage)1 StompProtocolException (com.sun.messaging.bridge.api.StompProtocolException)1 SysMessageID (com.sun.messaging.jmq.io.SysMessageID)1 BrokerException (com.sun.messaging.jmq.jmsserver.util.BrokerException)1 IllegalStateException (com.sun.messaging.jms.IllegalStateException)1 jakarta.jms (jakarta.jms)1 InvalidDestinationException (jakarta.jms.InvalidDestinationException)1 InvalidSelectorException (jakarta.jms.InvalidSelectorException)1 JMSException (jakarta.jms.JMSException)1 JMSSecurityException (jakarta.jms.JMSSecurityException)1 Message (jakarta.jms.Message)1 MessageFormatException (jakarta.jms.MessageFormatException)1