Search in sources :

Example 6 with JMSServiceReply

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

the class DirectXAResource method prepare.

/**
 * Ask the resource manager to prepare for a transaction commit of the transaction specified in xid.
 *
 * @param foreignXid A global transaction identifier.
 *
 * @return A value indicating the resource manager's vote on the outcome of the transaction. The possible values are:
 * XA_RDONLY or XA_OK. If the resource manager wants to roll back the transaction, it should do so by raising an
 * appropriate XAException in the prepare method.
 *
 * @throws XAException If an error has occurred. Possible exception values are: XA_RB*, XAER_RMERR, XAER_RMFAIL,
 * XAER_NOTA, XAER_INVAL, or XAER_PROTO.
 */
@Override
public synchronized int prepare(Xid foreignXid) throws XAException {
    if (_logger.isLoggable(Level.FINE)) {
        _logger.fine(_lgrMID_INF + "DirectXAResource (" + this.hashCode() + ") Prepare     " + printXid(foreignXid) + ", connectionId=" + connectionId);
    }
    // convert to XidImpl
    // XidImpl mqxid = new XidImpl(foreignXid);
    String methodName = "prepare()";
    if (_logFINE) {
        // +
        _loggerJX.fine(// +
        _lgrMID_INF + methodName + ":transactionId=" + this.mTransactionId);
    }
    // JMS does not do RDONLY transactions
    int result = XA_OK;
    // JMSServiceReply reply = null;
    JMSServiceReply.Status status;
    try {
        // reply = jmsservice.prepareTransaction(this.connectionId,
        jmsservice.prepareTransaction(this.connectionId, this.mTransactionId, foreignXid);
        if (_logFINE) {
            _loggerJX.fine(_lgrMID_INF + methodName + ":connectionId=" + this.connectionId + ":prepared transactionId=" + this.mTransactionId);
        }
    } catch (JMSServiceException jse) {
        status = jse.getJMSServiceReply().getStatus();
        String failure_cause = getFailureCauseAsString(status, jse);
        // XXX:tharakan:This message should be in the JMSServiceException
        String exerrmsg = "prepareTransaction (XA) on JMSService:" + jmsservice.getJMSServiceID() + " failed for connectionId:" + connectionId + // "and Xid:" + mqxid.toString() +
        " due to " + failure_cause;
        _loggerOC.severe(exerrmsg);
        XAException xae = new XAException(XAException.XAER_RMERR);
        xae.initCause(jse);
        throw xae;
    }
    // update the resource state
    resourceState = PREPARED;
    return result;
}
Also used : XAException(javax.transaction.xa.XAException) JMSServiceReply(com.sun.messaging.jmq.jmsservice.JMSServiceReply) JMSServiceException(com.sun.messaging.jmq.jmsservice.JMSServiceException) Status(com.sun.messaging.jmq.jmsservice.JMSServiceReply.Status)

Example 7 with JMSServiceReply

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

the class StompTransactedSession method createSubscriber.

public StompSubscriber createSubscriber(String subid, StompDestination d, String selector, String duraname, boolean nolocal, StompOutputHandler out) throws Exception {
    checkSession();
    synchronized (this) {
        if (subscribers.get(subid) != null) {
            throw new StompProtocolException("Subscriber " + subid + " already exist in transacted session " + this);
        }
        String stompdest = stompconn.getProtocolHandler().toStompFrameDestination(d, false);
        Destination dest = ((StompDestinationImpl) d).getDestination();
        JMSServiceReply reply = null;
        try {
            reply = jmsservice.createDestination(connectionId, dest);
        } catch (JMSServiceException jmsse) {
            JMSServiceReply.Status status = jmsse.getJMSServiceReply().getStatus();
            if (status == JMSServiceReply.Status.CONFLICT) {
                if (getDEBUG()) {
                    logger.log(logger.INFO, "Destination " + stompdest + " already exist");
                }
            } else {
                throw jmsse;
            }
        }
        reply = jmsservice.startConnection(connectionId);
        reply = jmsservice.addConsumer(connectionId, sessionId, dest, selector, duraname, (duraname != null), false, false, stompconn.getClientID(), nolocal);
        long consumerId = reply.getJMQConsumerID();
        TransactedSubscriber sub = new TransactedSubscriber(subid, consumerId, duraname, stompdest, out);
        subscribers.put(subid, sub);
        return sub;
    }
}
Also used : Destination(com.sun.messaging.jmq.jmsservice.Destination) StompDestination(com.sun.messaging.bridge.api.StompDestination) JMSServiceReply(com.sun.messaging.jmq.jmsservice.JMSServiceReply) JMSServiceException(com.sun.messaging.jmq.jmsservice.JMSServiceException) StompProtocolException(com.sun.messaging.bridge.api.StompProtocolException)

Example 8 with JMSServiceReply

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

the class StompConnectionImpl method connect.

/**
 * @return the connection id
 */
@Override
public synchronized String connect(String login, String passcode, String clientid) throws Exception {
    this.clientID = clientid;
    if (connectionID != null) {
        throw new jakarta.jms.IllegalStateException("Unexpected " + StompFrameMessage.Command.CONNECT + ", already connected");
    }
    JMSServiceReply reply = jmsservice.createConnection(login, passcode);
    long connid = reply.getJMQConnectionID();
    connectionID = Long.valueOf(connid);
    closed = false;
    Connection conn = Globals.getConnectionManager().getConnection(new ConnectionUID(connid));
    if (conn != null) {
        conn.addConnectionClosedListener(this);
    } else {
        throw new StompProtocolException("No connection");
    }
    jmsservice.setClientId(connid, clientid, false, /* share */
    null);
    jmsservice.startConnection(connid);
    return connectionID.toString();
}
Also used : JMSServiceReply(com.sun.messaging.jmq.jmsservice.JMSServiceReply) StompConnection(com.sun.messaging.bridge.api.StompConnection) Connection(com.sun.messaging.jmq.jmsserver.service.Connection) ConnectionUID(com.sun.messaging.jmq.jmsserver.service.ConnectionUID) StompProtocolException(com.sun.messaging.bridge.api.StompProtocolException)

Example 9 with JMSServiceReply

use of com.sun.messaging.jmq.jmsservice.JMSServiceReply 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());
    }
}
Also used : JMSPacket(com.sun.messaging.jmq.io.JMSPacket) Packet(com.sun.messaging.jmq.io.Packet) JMSServiceReply(com.sun.messaging.jmq.jmsservice.JMSServiceReply) JMSServiceException(com.sun.messaging.jmq.jmsservice.JMSServiceException) JMSPacket(com.sun.messaging.jmq.io.JMSPacket)

Example 10 with JMSServiceReply

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

the class StompSubscriberSession method createSubscriber.

public StompSubscriber createSubscriber(StompDestination d, String selector, String duraname, boolean nolocal, StompOutputHandler out) throws Exception {
    if (consumerId != 0L) {
        throw new IllegalStateException("Subscriber already exists on this Session");
    }
    this.out = out;
    this.stompdest = stompconn.getProtocolHandler().toStompFrameDestination(d, false);
    this.duraname = duraname;
    Destination dest = ((StompDestinationImpl) d).getDestination();
    JMSServiceReply reply = null;
    try {
        reply = jmsservice.createDestination(connectionId, dest);
    } 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;
        }
    }
    reply = jmsservice.startConnection(connectionId);
    reply = jmsservice.addConsumer(connectionId, sessionId, dest, selector, duraname, (duraname != null), false, false, stompconn.getClientID(), nolocal);
    consumerId = reply.getJMQConsumerID();
    if (getDEBUG()) {
        logger.log(logger.INFO, "Created " + this);
    }
    return this;
}
Also used : Destination(com.sun.messaging.jmq.jmsservice.Destination) StompDestination(com.sun.messaging.bridge.api.StompDestination) JMSServiceReply(com.sun.messaging.jmq.jmsservice.JMSServiceReply) JMSServiceException(com.sun.messaging.jmq.jmsservice.JMSServiceException)

Aggregations

JMSServiceReply (com.sun.messaging.jmq.jmsservice.JMSServiceReply)15 JMSServiceException (com.sun.messaging.jmq.jmsservice.JMSServiceException)13 JMSException (jakarta.jms.JMSException)8 Status (com.sun.messaging.jmq.jmsservice.JMSServiceReply.Status)4 JMSSecurityException (jakarta.jms.JMSSecurityException)4 XAException (javax.transaction.xa.XAException)4 StompProtocolException (com.sun.messaging.bridge.api.StompProtocolException)3 StompDestination (com.sun.messaging.bridge.api.StompDestination)2 Destination (com.sun.messaging.jmq.jmsservice.Destination)2 XidImpl (com.sun.messaging.jmq.util.XidImpl)2 InvalidSelectorException (jakarta.jms.InvalidSelectorException)2 StompConnection (com.sun.messaging.bridge.api.StompConnection)1 JMSPacket (com.sun.messaging.jmq.io.JMSPacket)1 Packet (com.sun.messaging.jmq.io.Packet)1 Connection (com.sun.messaging.jmq.jmsserver.service.Connection)1 ConnectionUID (com.sun.messaging.jmq.jmsserver.service.ConnectionUID)1 BrokerException (com.sun.messaging.jmq.jmsserver.util.BrokerException)1 SessionAckMode (com.sun.messaging.jmq.jmsservice.JMSService.SessionAckMode)1 IllegalStateException (com.sun.messaging.jms.IllegalStateException)1