Package com.sun.messaging.jmq.jmsserver.data.handlers

Examples of com.sun.messaging.jmq.jmsserver.data.handlers.TransactionHandler


                         realstate != TransactionState.PREPARED &&
                         realstate != TransactionState.COMMITTED) ||
                         msgs == 0 && acks == 0) {
                        logger.log((DEBUG ? Logger.INFO:Logger.DEBUG),
                                    "Removing finished transaction " + tid);
                        TransactionHandler thandler = (TransactionHandler)
                            Globals.getPacketRouter(0).getHandler(PacketType.ROLLBACK_TRANSACTION);
                        thandler.doRollback(tid, null, null, state, null, null,
                                            RollbackReason.TAKEOVER_CLEANUP);
                        itr.remove();
                    } else if (realstate == TransactionState.ROLLEDBACK) {
                    }
                }
View Full Code Here


            ((Integer)cmd_props.get(MessageType.JMQ_MESSAGE_TYPE)).intValue();
        int status = Status.OK;
  String errMsg = null;
        TransactionUID tid = null;
        TransactionState ts = null;
        TransactionHandler thandler = null;

        // Get the packet handler that handles transaction packets
        if (parent.adminPktRtr != null) {
            thandler = (TransactionHandler)
            parent.adminPktRtr.getHandler(PacketType.ROLLBACK_TRANSACTION);
        }

  Long id = (Long)cmd_props.get(MessageType.JMQ_TRANSACTION_ID);

        HAMonitorService hamonitor = Globals.getHAMonitorService();
        if (hamonitor != null && hamonitor.inTakeover()) {
            status = Status.ERROR;
            errMsg =  rb.getString(rb.E_CANNOT_PROCEED_TAKEOVER_IN_PROCESS);

            logger.log(Logger.ERROR, this.getClass().getName() + ": " + errMsg);
  }

        if (id != null) {
            tid = new TransactionUID(id.longValue());
        } else {
            status = Status.BAD_REQUEST;
        }

        if (status == Status.OK) {
            ts = tl.retrieveState(tid);
            if (ts == null) {
                // Specified transaction did not exist
                status = Status.NOT_FOUND;
          errMsg = rb.getString(rb.E_NO_SUCH_TRANSACTION, tid);
            } else if (requestType == MessageType.COMMIT_TRANSACTION &&
                        ts.getState() != TransactionState.PREPARED) {
                status = Status.PRECONDITION_FAILED;
          errMsg = rb.getString(rb.E_TRANSACTION_NOT_PREPARED, tid);
            } else if (requestType == MessageType.ROLLBACK_TRANSACTION &&
                        (ts.getState() < TransactionState.STARTED ||
                         ts.getState() > TransactionState.PREPARED)) {
                status = Status.PRECONDITION_FAILED;
          errMsg = rb.getString(rb.E_INVALID_TXN_STATE_FOR_ROLLBACK, tid);
            } else {
                JMQXid xid = tl.UIDToXid(tid);

                if (xid == null &&
                    (!(Globals.getHAEnabled() &&
                       ts.getState() == TransactionState.PREPARED))) {
        /*
         * Need to pick the right error message:
         * If (action is ROLLBACK and state is one of {STARTED, FAILED,
         *      INCOMPLETE, COMPLETE})
         *  "Rollback of non-XA transaction 123456789 in non-PREPARED state
         *   is not supported."
         * else
                     *  "Could not find Xid for 123456789"
         */
                    if (requestType == MessageType.ROLLBACK_TRANSACTION &&
                        (ts.getState() >= TransactionState.STARTED &&
                         ts.getState() < TransactionState.PREPARED)) {
                        errMsg = rb.getString(rb.E_INTERNAL_BROKER_ERROR,
                            "Rollback of non-XA transaction "
        + tid
        + " in non-PREPARED state is not supported.") ;
                } else {
                        errMsg = rb.getString(rb.E_INTERNAL_BROKER_ERROR,
                            "Could not find Xid for " + tid) ;
                }

                    status = Status.ERROR;
                } else if (thandler == null) {
                    errMsg = rb.getString(rb.E_INTERNAL_BROKER_ERROR,
                        "Could not locate TransactionHandler") ;
                    status = Status.ERROR;
                } else {
                    if (requestType == MessageType.ROLLBACK_TRANSACTION) {
                  if ( DEBUG ) {
                            logger.log(Logger.DEBUG,
                                "Rolling back " + tid + " in state " + ts);
                        }
                        try {
                            thandler.doRollback(tid, xid, null, ts, null,
                                                con, RollbackReason.ADMIN);
                        } catch (BrokerException e) {
                            status = Status.ERROR;
                            errMsg = e.getMessage();
                        }
                    } else if (requestType == MessageType.COMMIT_TRANSACTION) {
                  if ( DEBUG ) {
                            logger.log(Logger.DEBUG,
                                "Committing " + tid + " in state " + ts);
                        }
                        try {
                            thandler.doCommit(tid, xid,
                                new Integer(XAResource.TMNOFLAGS), ts, null,
                            false, con, null);
                        } catch (BrokerException e) {
                            status = Status.ERROR;
                            errMsg = e.getMessage();
View Full Code Here

                    TransactionList.XA_TXN_DETACHED_RETAINALL_PROP, false);
            ArrayList timeoutTIDs = new ArrayList();
            TransactionList tl = Globals.getTransactionList();
            TransactionUID tid = null;
            boolean xaretainallLogged = false;
            TransactionHandler rollbackHandler = (TransactionHandler)
                                   Globals.getPacketRouter(0).getHandler(
                                          PacketType.ROLLBACK_TRANSACTION);
            TransactionUID[] tuids = (TransactionUID[])conlist.toArray(new TransactionUID[0]);
            for (int i = 0; i < tuids.length; i ++) {
                tid = (TransactionUID) tuids[i];
                TransactionState ts = Globals.getTransactionList().retrieveState(tid);
                if (ts == null) {
                    // nothing to do if no transaction state
                    continue;
                }
                int tstate = ts.getState();
                if (ts.getXid() != null) {
                    if (xaretainall) {
                        if (!xaretainallLogged) {
                        logger.log(Logger.INFO, Globals.getBrokerResources().getKString(
                                   BrokerResources.I_CONN_CLEANUP_RETAIN_XA));
                        xaretainallLogged = true;
                        }
                        continue;
                    }
                    if(tstate > TransactionState.COMPLETE) {
                       String[] args = { ""+tid+"(XID="+ts.getXid()+")",
                                         TransactionState.toString(tstate),
                                         getConnectionUID().toString() };
                        logger.log(Logger.INFO, Globals.getBrokerResources().getKString(
                                          BrokerResources.I_CONN_CLEANUP_KEEP_TXN, args));
                        continue;
                    }
                    if (tstate == TransactionState.INCOMPLETE ||
                        tstate == TransactionState.COMPLETE ) {
                        ts.detachedFromConnection();
                        timeoutTIDs.add(tid);
                        String[] args = { ""+tid+"(XID="+ts.getXid()+")",
                                          TransactionState.toString(tstate),
                                          getConnectionUID().toString() };
                        logger.log(Logger.INFO, Globals.getBrokerResources().getKString(
                                          BrokerResources.I_CONN_CLEANUP_KEEP_TXN, args));
                        continue;
                    }
                }
                if (tstate == TransactionState.PREPARED ||
                    tstate == TransactionState.COMMITTED ||
                    tstate == TransactionState.ROLLEDBACK) {
                    String[] args = { ""+tid,
                                      TransactionState.toString(tstate),
                                      getConnectionUID().toString() };
                    logger.log(Logger.INFO, Globals.getBrokerResources().getKString(
                               BrokerResources.I_CONN_CLEANUP_KEEP_TXN, args));
                    continue;
                }
                if (DEBUG || DEBUG_TXN) {
                    logger.log(Logger.INFO, "Cleanup connection ["+getConnectionUID()+
                    "]: cleaning up transaction "+tid+"["+TransactionState.toString(tstate)+"]");
                }
                try {
                     rollbackHandler.doRollback(tid, ts.getXid(), null, ts, conlist,
                                   null, RollbackReason.CONNECTION_CLEANUP);
                } catch (Exception e) {
                     String[] args = { ""+tid+"["+TransactionState.toString(tstate)+"]",
                                       getConnectionUID().toString(), e.getMessage() };
                     logger.logStack(logger.WARNING,
View Full Code Here

        public DetachedTransactionTimerTask(long timeout) {
            super();
            this.timeout = timeout*1000;
        }
        public void run() {
            TransactionHandler rbh = (TransactionHandler)
                                       Globals.getPacketRouter(0).getHandler(
                                               PacketType.ROLLBACK_TRANSACTION);
            long currentTime = System.currentTimeMillis();
            TransactionUID[] tids = getDetachedTIDs();
            for (int i = 0; (i < tids.length && !destroyed); i++) {
                TransactionState ts = translist.retrieveState(tids[i]);
                if (ts == null || !ts.isDetachedFromConnection() ||
                    (ts.getState() != TransactionState.INCOMPLETE &&
                     ts.getState() != TransactionState.COMPLETE)) {
                    removeDetachedTID(tids[i]);
                    continue;
                }
                if (timeout == 0) continue;
                long timeoutTime = ts.getDetachedTime()+timeout;
                if (currentTime > timeoutTime) {
                    try {
                        String[] args = { tids[i]+"["+TransactionState.toString(ts.getState())+"]",
                                          String.valueOf(ts.getCreationTime()),
                                          String.valueOf(ts.getDetachedTime()) };
                        Globals.getLogger().log(Logger.WARNING,
                        Globals.getBrokerResources().getKString(
                                BrokerResources.W_ROLLBACK_TIMEDOUT_DETACHED_TXN, args));
                        rbh.doRollback(tids[i], ts.getXid(), null, ts, null,
                                                null, RollbackReason.TIMEOUT);
                        removeDetachedTID(tids[i]);
                    } catch (Exception ex) {
                        Globals.getLogger().logStack(Logger.WARNING,
                               Globals.getBrokerResources().getKString(
View Full Code Here

      if (pr == null)  {
          throw new Exception(rb.getString(rb.E_INTERNAL_BROKER_ERROR,
          "Could not locate Packet Router"));
      }

      TransactionHandler thandler = (TransactionHandler)
            pr.getHandler(PacketType.ROLLBACK_TRANSACTION);

      if (thandler == null)  {
          throw new Exception(rb.getString(rb.E_INTERNAL_BROKER_ERROR,
          "Could not locate Transaction Handler"));
      }

      if (rollback)  {
          thandler.doRollback(tid, xid, null, ts, null, null, RollbackReason.ADMIN);
      } else  {
    thandler.doCommit(tid, xid, new Integer(XAResource.TMNOFLAGS), ts, null,
        false, null, null);
      }
  } catch(Exception e)  {
      String opName;
      if (rollback)  {
View Full Code Here

          if (DEBUG) {
          Globals.getLogger().log(Logger.INFO,
          "ProtocolImpl.END TRANSACTION:TID="+id+", XID="+xid+", xaFlags="+xaFlags);
          }
         
          TransactionHandler handler = (TransactionHandler)
                      pr.getHandler(PacketType.START_TRANSACTION);
          TransactionState ts = handler.getTransactionList().retrieveState(id);

          handler.doEnd(PacketType.END_TRANSACTION, xid,
                  xaFlags, ts, id);

     }
View Full Code Here

          "ProtocolImpl.START TRANSACTION:XID="+xid+", type="+type+", conn="+con);
          }
         
          List conlist = con.getTransactionListThreadSafe();

          TransactionHandler handler = (TransactionHandler)
                      pr.getHandler(PacketType.START_TRANSACTION);

          // allocated a TID
          TransactionUID id = null;
          if (xaFlags == null ||
              TransactionState.isFlagSet(XAResource.TMNOFLAGS, xaFlags)) {
              id = new TransactionUID();
          } else if (xid != null) {
              TransactionList translist = handler.getTransactionList();

              id = translist.xidToUID(xid);
         
          } else { // XID is null, something is wrong
              throw new BrokerException("Invalid xid");
          }
         

          Object o = new Object();
          handler.doStart(id, conlist, con,
                  type, xid, xid!= null, lifetime, 0,
                        xaFlags, PacketType.START_TRANSACTION,
                        false, o.toString());
          if (DEBUG) {
          Globals.getLogger().log(Logger.INFO,
View Full Code Here

          "ProtocolImpl.COMMIT TRANSACTION:TID="+id+", XID="+xid+", xaFlags="+xaFlags);
          }
         
          List conlist = con.getTransactionListThreadSafe();

          TransactionHandler handler = (TransactionHandler)
                      pr.getHandler(PacketType.START_TRANSACTION);

          if (0L == id.longValue()) {
              if (xid == null) {
                  throw new BrokerException("Unexpected TransactionUID  " + id);
              }
              id = handler.getTransactionList().xidToUID(xid);
              if (id == null) {
                  throw new BrokerException("Unknown XID " + xid, Status.NOT_FOUND);
              }
          }

          TransactionState ts = handler.getTransactionList().retrieveState(id);

          if (ts == null) {
              throw new BrokerException(
              "Unknown transaction "+id+(xid == null ? "":" XID="+xid), Status.NOT_FOUND);
          }
          if (xid != null) {
              if (ts.getXid() == null || !xid.equals(ts.getXid())) {
                  throw new BrokerException(
                  "Transaction XID mismatch "+xid+", expected "+ts.getXid()+" for transaction "+id);
              }
          }

          handler.doCommit(id, xid, xaFlags, ts, conlist, false,con, null);
     }
View Full Code Here

          if (DEBUG) {
          Globals.getLogger().log(Logger.INFO,
          "ProtocolImpl.PREPARE TRANSACTION:TID="+id+", xaFlags="+xaFlags);
          }

          TransactionHandler handler = (TransactionHandler)
                      pr.getHandler(PacketType.START_TRANSACTION);

          TransactionState ts = handler.getTransactionList().retrieveState(id);
          handler.doPrepare(id, xaFlags, ts, PacketType.PREPARE_TRANSACTION);
     }
View Full Code Here

          ", xaFlags="+xaFlags+", redeliver="+redeliver+", setRedeliver="+setRedeliver);
          }

          List conlist = con.getTransactionListThreadSafe();

          TransactionHandler handler = (TransactionHandler)
                      pr.getHandler(PacketType.START_TRANSACTION);


          if (0L == id.longValue()) {
              if (xid == null) {
                  throw new BrokerException("Unexpected TransactionUID  " + id);
              }
              id = handler.getTransactionList().xidToUID(xid);
              if (id == null) {
                  throw new BrokerException("Unknown XID " + xid, Status.NOT_FOUND);
              }
          }

          TransactionState ts = handler.getTransactionList().retrieveState(id);

          if (ts == null) {
              throw new BrokerException(
              "Unknown transaction "+id+(xid == null ? "":" XID="+xid), Status.NOT_FOUND);
          }
          if (xid != null) {
              if (ts.getXid() == null || !xid.equals(ts.getXid())) {
                  throw new BrokerException(
                  "Transaction XID mismatch "+xid+", expected "+ts.getXid()+" for transaction "+id);
              }
          }

          handler.preRollback(id, xid, xaFlags, ts);

          if (redeliver) {
              handler.redeliverUnacked(id, true, setRedeliver);
          }

          handler.doRollback(id, xid, xaFlags, ts, conlist, con,  RollbackReason.APPLICATION);
     }
View Full Code Here

TOP

Related Classes of com.sun.messaging.jmq.jmsserver.data.handlers.TransactionHandler

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.