Package com.sun.messaging.jmq.util.txnlog

Examples of com.sun.messaging.jmq.util.txnlog.TransactionLogRecord


        Iterator itr = msgLogWriter.iterator();
        while (itr.hasNext()) {
          count++; // Keep track the number of records processed

          // Read in the acks or msgs & acks
          TransactionLogRecord rec = (TransactionLogRecord) itr
              .next();

          byte[] data = rec.getBody();
          TransactionEvent txnEvent = readTransactionEvent(data);
          int type = txnEvent.getType();
          if (Store.getDEBUG()) {
            String msg = getPrefix()
                + " replayTransactionLogOnStartup() recordSeq= " + rec.getSequence()+ " txnEvent= "
                + txnEvent;
            logger.log(Logger.DEBUG, msg);
          }
          if (type == BaseTransaction.NON_TRANSACTED_MSG_TYPE) {
            transactionLogReplayer.replayNonTxnMsg((NonTransactedMsgEvent)txnEvent,dstLoadedSet);
View Full Code Here


      store.txnLogSharedLock.lock();

      MsgRemovalEvent txnEvent = new MsgRemovalEvent(dstID,mid);
      byte[] data = txnEvent.writeToBytes();

      TransactionLogRecord record = msgLogWriter
          .newTransactionLogRecord();
      record.setBody(data);
      msgLogWriter.write(record);

    } catch (IOException ioe) {
      throw new BrokerException("error logging transaction", ioe);
    } finally {
View Full Code Here

 
  public void writeTransactionEvent(TransactionEvent txnEvent) throws BrokerException
  {
    try {     
      byte[] data = txnEvent.writeToBytes();
      TransactionLogRecord record = msgLogWriter
          .newTransactionLogRecord();
      record.setBody(data);
      msgLogWriter.write(record);

    } catch (IOException ioe) {
      throw new BrokerException("error logging transaction", ioe);
    }
View Full Code Here

        if (!txnLoggerInited) {
            return;
        }

        if (type == TransactionLogType.PRODUCE_TRANSACTION) {
            TransactionLogRecord record = msgLogWriter.newTransactionLogRecord();
            record.setType(type);
            record.setBody(data);
            msgLogWriter.write(record);
        } else {
            TransactionLogRecord record = ackLogWriter.newTransactionLogRecord();
            record.setType(type);
            record.setBody(data);
            ackLogWriter.write(record);
        }
    }
View Full Code Here

                BrokerResources.E_CREATE_TXNLOG_FILE_FAILED, filename), ex);
        }

        // reconstruct persistence store if needed
        try {
            TransactionLogRecord rec;
            byte[] data;
            ByteArrayInputStream bis;
            DataInputStream dis;
            HashSet dstLoadedSet = new HashSet(); // Keep track of loaded dst

            // Check to see if we need to process log files
            if (msgLogWriter.playBackRequired()) {
                storeNeedsRestart = true;
                logger.log(logger.FORCE, BrokerResources.I_PROCESS_MSG_TXNLOG);

                // All destinations need to be loaded
                Destination.init();
                Subscription.initSubscriptions();

                int count = 0;

                Iterator itr = msgLogWriter.iterator();
                while (itr.hasNext()) {
                    count++; // Keep track the number of records processed

                    // Read in the messages
                    rec = (TransactionLogRecord)itr.next();

                    int recType = rec.getType();
                    if (recType != TransactionLogType.PRODUCE_TRANSACTION) {
                        // Shouldn't happens
                        logger.log(logger.ERROR,
                            BrokerResources.E_PROCESS_TXNLOG_RECORD_FAILED,
                            String.valueOf(rec.getSequence()),
                            "record type " + recType + " is invalid");
                        continue;
                    }

                    data = rec.getBody();
                    bis = new ByteArrayInputStream(data);
                    dis = new DataInputStream(bis);

                    long tid = dis.readLong(); // Transaction ID
                    String tidStr = String.valueOf(tid);

                    logger.log(logger.FORCE,
                        BrokerResources.I_PROCESS_TXNLOG_RECORD,
                        tidStr, String.valueOf(recType));

                    // Process all msgs in the txn
                    processTxnRecMsgPart(dis, dstLoadedSet);

                    // Check to see if we need to commit the txn
                    if (tid > 0) {
                        TransactionUID tuid = new TransactionUID(tid);
                        int state = tidList.getTransactionStateValue(tuid);
                        if (state != TransactionState.NULL &&
                            state != TransactionState.COMMITTED) {
                            logger.log(logger.FORCE,
                                BrokerResources.I_COMMIT_TXNLOG_RECORD, tidStr);
                            tidList.updateTransactionState(tuid,
                                TransactionState.COMMITTED, false);
                        }
                    }

                    dis.close();
                    bis.close();
                }

                logger.log(logger.FORCE, BrokerResources.I_LOAD_MSG_TXNLOG,
                    String.valueOf(count));
                logger.flush();
            }

            // Note: the ack log file contains message(s) consume but
            // it can also contains message(s) produce and consume in the
            // same txn. Instead of creating another log file for this type
            // of record, we'll just store it the same file for simplicity.
            if (ackLogWriter.playBackRequired()) {
                storeNeedsRestart = true;
                logger.log(logger.FORCE, BrokerResources.I_PROCESS_ACK_TXNLOG);

                // All destinations need to be loaded
                Destination.init();
                Subscription.initSubscriptions();

                int count = 0;

                Iterator itr = ackLogWriter.iterator();
                while (itr.hasNext()) {
                    count++; // Keep track the number of records processed

                    // Read in the acks or msgs & acks
                    rec = (TransactionLogRecord)itr.next();

                    int recType = rec.getType();
                    if (!(recType == TransactionLogType.CONSUME_TRANSACTION ||
                        recType == TransactionLogType.PRODUCE_AND_CONSUME_TRANSACTION)) {
                        // shouldn't happens
                        logger.log(logger.ERROR,
                            BrokerResources.E_PROCESS_TXNLOG_RECORD_FAILED,
                            String.valueOf(rec.getSequence()),
                            "record type " + recType + " is invalid");
                        continue;
                    }

                    data = rec.getBody();
                    bis = new ByteArrayInputStream(data);
                    dis = new DataInputStream(bis);

                    long tid = dis.readLong(); // Transaction ID
                    String tidStr = String.valueOf(tid);
View Full Code Here

    }
   
    if (records.length == 1) {
  //    log("transactionLogRecordList ==1 ");
      // only a single record so just save it normally
      TransactionLogRecord entry = records[0];

      try {
        writeRecord(entry);
      } catch (IOException e) {
        entry.setException(e);

      }

      // wake up waiting thread
  //    log("synchronized (entry) ");
      synchronized (entry) {
  //      log("notifying entry ");
        entry.setWritten(true);
        entry.notify();
      }

      return;
    }

    try {
      writeCompoundRecord(records);
    } catch (IOException ioe) {
      for (int i = 0; i < records.length; i++) {
        TransactionLogRecord e = records[i];
        e.setException(ioe);
      }
    }

    for (int i = 0; i < records.length; i++) {
      TransactionLogRecord e = records[i];
  //    log("synchronized (entry) ");
      synchronized (e) {
  //      log("notifying entry ");
        e.setWritten(true);
        e.notify();
      }
    }

  }
View Full Code Here

      }
     
      int numRecords = records.length;
      // log("writeCompoundRecord list size = "+records.length);

      TransactionLogRecord entry = new FileTransactionLogRecord();
      entry.setType(TransactionLogType.COMPOUND_TRANSACTION);

      // get bytes

      // calculate compoundBody size;
      int compoundBodySize = 4;
      for (int i = 0; i < numRecords; i++) {
        compoundBodySize += 8;
        compoundBodySize += records[i].getBody().length;
      }

      byte[] compoundBody = new byte[compoundBodySize];
      ByteBuffer subBuf = ByteBuffer.wrap(compoundBody);

      subBuf.putInt(numRecords);
      for (int i = 0; i < numRecords; i++) {
        subBuf.putInt(records[i].getType());
        subBuf.putInt(records[i].getBody().length);
        subBuf.put(records[i].getBody());
      }

      entry.setBody(compoundBody);

      // write entry, we need to sync from this point
      // First come first serve
      entry.setCheckPointSequence(checkpointSequence);

      // set timestamp
      entry.setTimestamp(System.currentTimeMillis());

      // set entry sequence. increase 1 after addition.
      entry.setSequence(entrySequence++);

      // 1. calculate record size
      int size = RECORD_HEADER_SIZE + entry.getBody().length;

      // 2. allocate byte buffer
      byte[] bytes = new byte[size];
      ByteBuffer buf = ByteBuffer.wrap(bytes);

      // 3. write record header
      writeRecordHeader(buf, entry);

      // 4. write body
      buf.put(entry.getBody());

      // write (and sync) bytes to disk
      // raf.write(bytes);
      doWrite(bytes);
View Full Code Here

TOP

Related Classes of com.sun.messaging.jmq.util.txnlog.TransactionLogRecord

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.