public synchronized void recover(TransactionRecoveryListener listener) throws IOException {
    for (Map.Entry<TransactionId, List<Operation>> entry :
        theStore.preparedTransactions.entrySet()) {
      XATransactionId xid = (XATransactionId) entry.getKey();
      ArrayList<Message> messageList = new ArrayList<Message>();
      ArrayList<MessageAck> ackList = new ArrayList<MessageAck>();

      for (Operation op : entry.getValue()) {
        if (op.getClass() == AddOpperation.class) {
          AddOpperation addOp = (AddOpperation) op;
          Message msg =
              (Message)
                  wireFormat()
                      .unmarshal(new DataInputStream(addOp.getCommand().getMessage().newInput()));
          messageList.add(msg);
        } else {
          RemoveOpperation rmOp = (RemoveOpperation) op;
          Buffer ackb = rmOp.getCommand().getAck();
          MessageAck ack =
              (MessageAck) wireFormat().unmarshal(new DataInputStream(ackb.newInput()));
          ackList.add(ack);
        }
      }

      Message[] addedMessages = new Message[messageList.size()];
      MessageAck[] acks = new MessageAck[ackList.size()];
      messageList.toArray(addedMessages);
      ackList.toArray(acks);
      xid.setPreparedAcks(ackList);
      theStore.trackRecoveredAcks(ackList);
      listener.recover(xid, addedMessages, acks);
    }
  }
  public KahaTransactionInfo createTransactionInfo(TransactionId txid) {
    if (txid == null) {
      return null;
    }
    KahaTransactionInfo rc = new KahaTransactionInfo();

    if (txid.isLocalTransaction()) {
      LocalTransactionId t = (LocalTransactionId) txid;
      KahaLocalTransactionId kahaTxId = new KahaLocalTransactionId();
      kahaTxId.setConnectionId(t.getConnectionId().getValue());
      kahaTxId.setTransactionId(t.getValue());
      rc.setLocalTransactionId(kahaTxId);
    } else {
      XATransactionId t = (XATransactionId) txid;
      KahaXATransactionId kahaTxId = new KahaXATransactionId();
      kahaTxId.setBranchQualifier(new Buffer(t.getBranchQualifier()));
      kahaTxId.setGlobalTransactionId(new Buffer(t.getGlobalTransactionId()));
      kahaTxId.setFormatId(t.getFormatId());
      rc.setXaTransactionId(kahaTxId);
    }
    return rc;
  }
 protected void forgetRecoveredAcks(TransactionId txid) throws IOException {
   if (txid.isXATransaction()) {
     XATransactionId xaTid = ((XATransactionId) txid);
     theStore.forgetRecoveredAcks(xaTid.getPreparedAcks());
   }
 }
Exemplo n.º 4
0
 public static XidImpl toXID(XATransactionId xaXid) {
   return new XidImpl(
       xaXid.getBranchQualifier(), xaXid.getFormatId(), xaXid.getGlobalTransactionId());
 }