Search in sources :

Example 6 with XidImpl

use of com.swiftmq.jms.XidImpl in project swiftmq-client by iitsoftware.

the class XAResourceImpl method rollback.

public synchronized void rollback(Xid xid) throws XAException {
    if (logWriter != null)
        log(toString() + "/rollback, xid=" + xid);
    XidImpl sxid = toSwiftMQXid(xid);
    xidMapping.remove(xid);
    XAResRollbackReply reply = null;
    try {
        int connectionId = session.getSessionImpl().getMyConnection().getConnectionId();
        session.getSessionImpl().startRecoverConsumers();
        session.getAndClearCurrentTransaction();
        List recoveryList = null;
        if (endRequestInDoubt())
            recoveryList = XARecoverRegistry.getInstance().getRequestList(sxid);
        Request request = new XAResRollbackRequest(this, session.getDispatchId(), sxid, false, recoveryList, session.getSessionImpl().getRecoveryEpoche());
        request.setConnectionId(connectionId);
        reply = (XAResRollbackReply) session.request(request);
    } catch (Exception e) {
        if (completionListener != null)
            completionListener.transactionAborted(sxid);
        XAException ex = new XAException(e.toString());
        ex.errorCode = XAException.XAER_RMFAIL;
        throw ex;
    }
    if (reply.isOk()) {
        session.getSessionImpl().endRecoverConsumersXA();
        try {
            session.getSessionImpl().closeDelayedProducers();
        } catch (JMSException e) {
            e.printStackTrace();
        }
        if (completionListener != null)
            completionListener.transactionAborted(sxid);
        XARecoverRegistry.getInstance().clear(sxid);
    } else {
        if (completionListener != null)
            completionListener.transactionAborted(sxid);
        XAException ex = new XAException(reply.getException().getMessage());
        if (reply.getErrorCode() != 0)
            ex.errorCode = reply.getErrorCode();
        else
            ex.errorCode = XAException.XAER_RMFAIL;
        throw ex;
    }
}
Also used : XAException(javax.transaction.xa.XAException) XidImpl(com.swiftmq.jms.XidImpl) Request(com.swiftmq.tools.requestreply.Request) List(java.util.List) JMSException(javax.jms.JMSException) ValidationException(com.swiftmq.tools.requestreply.ValidationException) JMSException(javax.jms.JMSException) XAException(javax.transaction.xa.XAException)

Example 7 with XidImpl

use of com.swiftmq.jms.XidImpl in project swiftmq-ce by iitsoftware.

the class HeuristicHandler method messageToEntity.

private void messageToEntity(MessageImpl message, Entity entity) throws Exception {
    entity.setName(message.getStringProperty(PROP_SID));
    BytesMessageImpl msg = (BytesMessageImpl) message;
    byte[] b = new byte[(int) msg.getBodyLength()];
    msg.readBytes(b);
    DataByteArrayInputStream dis = new DataByteArrayInputStream(b);
    XidImpl xid = new XidImpl();
    xid.readContent(dis);
    entity.setUserObject(xid);
    entity.getProperty("xid").setValue(xid.toString());
    entity.getProperty("operation").setValue(msg.getStringProperty(PROP_OPER));
}
Also used : BytesMessageImpl(com.swiftmq.jms.BytesMessageImpl) XidImpl(com.swiftmq.jms.XidImpl) DataByteArrayInputStream(com.swiftmq.tools.util.DataByteArrayInputStream)

Example 8 with XidImpl

use of com.swiftmq.jms.XidImpl in project swiftmq-ce by iitsoftware.

the class HeuristicHandler method entityToMessage.

private MessageImpl entityToMessage(Entity entity) throws Exception {
    XidImpl xid = (XidImpl) entity.getUserObject();
    DataByteArrayOutputStream dos = new DataByteArrayOutputStream();
    xid.writeContent(dos);
    BytesMessageImpl message = new BytesMessageImpl();
    message.setJMSDestination(new QueueImpl(HEURISTIC_QUEUE));
    message.setJMSDeliveryMode(DeliveryMode.PERSISTENT);
    message.setJMSPriority(Message.DEFAULT_PRIORITY);
    message.setJMSExpiration(Message.DEFAULT_TIME_TO_LIVE);
    message.setJMSMessageID(MSGID + IdGenerator.getInstance().nextId('/'));
    message.setStringProperty(PROP_OPER, (String) entity.getProperty(PROP_OPER).getValue());
    message.setStringProperty(PROP_SID, entity.getName());
    message.setIntProperty(PROP_IID, Integer.parseInt(entity.getName()));
    message.writeBytes(dos.getBuffer(), 0, dos.getCount());
    return message;
}
Also used : DataByteArrayOutputStream(com.swiftmq.tools.util.DataByteArrayOutputStream) BytesMessageImpl(com.swiftmq.jms.BytesMessageImpl) XidImpl(com.swiftmq.jms.XidImpl) QueueImpl(com.swiftmq.jms.QueueImpl)

Example 9 with XidImpl

use of com.swiftmq.jms.XidImpl in project swiftmq-ce by iitsoftware.

the class HeuristicHandler method findHeuristic.

private Entity findHeuristic(XidImpl xid) {
    Map map = ctx.heuristicUsageList.getEntities();
    if (map != null && map.size() > 0) {
        for (Iterator iter = map.entrySet().iterator(); iter.hasNext(); ) {
            Entity entity = (Entity) ((Map.Entry) iter.next()).getValue();
            XidImpl thatXid = (XidImpl) entity.getUserObject();
            if (thatXid.equals(xid))
                return entity;
        }
    }
    return null;
}
Also used : Entity(com.swiftmq.mgmt.Entity) XidImpl(com.swiftmq.jms.XidImpl) Iterator(java.util.Iterator) Map(java.util.Map)

Example 10 with XidImpl

use of com.swiftmq.jms.XidImpl in project swiftmq-client by iitsoftware.

the class XAResCommitRequest method readContent.

public void readContent(DataInput in) throws IOException {
    super.readContent(in);
    xid = new XidImpl();
    xid.readContent(in);
    onePhase = in.readBoolean();
    byte set = in.readByte();
    if (set == 0) {
        messages = null;
    } else {
        int len = in.readInt();
        messages = new Object[len];
        for (int i = 0; i < len; i++) {
            int msglen = in.readInt();
            byte[] arr = new byte[msglen];
            in.readFully(arr);
            messages[i] = arr;
        }
    }
}
Also used : XidImpl(com.swiftmq.jms.XidImpl)

Aggregations

XidImpl (com.swiftmq.jms.XidImpl)85 XAException (javax.transaction.xa.XAException)37 JMSException (javax.jms.JMSException)28 ValidationException (com.swiftmq.tools.requestreply.ValidationException)22 Request (com.swiftmq.tools.requestreply.Request)16 List (java.util.List)12 ArrayList (java.util.ArrayList)10 XAContextException (com.swiftmq.swiftlet.xa.XAContextException)9 MessageImpl (com.swiftmq.jms.MessageImpl)6 XAContext (com.swiftmq.swiftlet.xa.XAContext)5 QueuePullTransaction (com.swiftmq.swiftlet.queue.QueuePullTransaction)4 QueueReceiver (com.swiftmq.swiftlet.queue.QueueReceiver)4 QueueSender (com.swiftmq.swiftlet.queue.QueueSender)4 BytesMessageImpl (com.swiftmq.jms.BytesMessageImpl)2 QueuePushTransaction (com.swiftmq.swiftlet.queue.QueuePushTransaction)2 Comparator (java.util.Comparator)2 CommitRequest (com.swiftmq.impl.routing.single.smqpr.v400.CommitRequest)1 CommitRequest (com.swiftmq.impl.routing.single.smqpr.v942.CommitRequest)1 QueueImpl (com.swiftmq.jms.QueueImpl)1 Entity (com.swiftmq.mgmt.Entity)1