Package org.codehaus.activemq.journal

Examples of org.codehaus.activemq.journal.RecordLocation


                        return;
                    }

                    log.info("Checkpoint started.");
                    Iterator iterator = messageStores.values().iterator();
                    RecordLocation newMark = null;
                    while (iterator.hasNext()) {
                        try {
                            JournalMessageStore ms = (JournalMessageStore) iterator.next();
                            RecordLocation mark = ms.checkpoint();
                            if (mark != null && (newMark == null || newMark.compareTo(mark) < 0)) {
                                newMark = mark;
                            }
                        }
                        catch (Exception e) {
View Full Code Here


     * @throws InvalidRecordLocationException
     * @throws IllegalStateException
     */
    private void recover() throws IllegalStateException, InvalidRecordLocationException, IOException, JMSException {

        RecordLocation pos = null;
        int transactionCounter = 0;

        log.info("Journal Recovery Started.");

        // While we have records in the journal.
        while ((pos = journal.getNextRecordLocation(pos)) != null) {
            byte[] data = journal.read(pos);

            // Read the destination and packate from the record.
            String destination = null;
            Packet packet = null;
            DataInputStream is = new DataInputStream(new ByteArrayInputStream(data));
            try {
                byte type = is.readByte();
                switch (type) {
                    case PACKET_RECORD_TYPE:

                        // Is the current packet part of the destination?
                        destination = is.readUTF();
                        packet = wireFormat.readPacket(is);

                        // Try to replay the packet.
                        JournalMessageStore store = (JournalMessageStore) createQueueMessageStore(destination);
                        if (packet instanceof ActiveMQMessage) {
                            ActiveMQMessage msg = (ActiveMQMessage) packet;
                            try {
                                store.getLongTermStore().addMessage(msg);
                                transactionCounter++;
                            }
                            catch (Throwable e) {
                                log.error("Recovery Failure: Could not add message: " + msg.getJMSMessageIdentity().getMessageID() + ", reason: " + e, e);
                            }
                        }
                        else if (packet instanceof MessageAck) {
                            MessageAck ack = (MessageAck) packet;
                            try {
                                store.getLongTermStore().removeMessage(ack.getMessageIdentity(), ack);
                                transactionCounter++;
                            }
                            catch (Throwable e) {
                                log.error("Recovery Failure: Could not remove message: " + ack.getMessageIdentity().getMessageID() + ", reason: " + e, e);
                            }
                        }
                        else {
                            log.error("Unknown type of packet in transaction log which will be discarded: " + packet);
                        }

                        break;
                    case COMMAND_RECORD_TYPE:

                        break;
                    default:
                        log.error("Unknown type of record in transaction log which will be discarded: " + type);
                        break;
                }
            }
            finally {
                is.close();
            }
        }

        RecordLocation location = writeCommand("RECOVERED", true);
        journal.setMark(location, true);

        log.info("Journal Recovered: " + transactionCounter + " message(s) in transactions recovered.");
    }
View Full Code Here

   * Not synchronized since the Journal has better throughput if you increase
   * the number of conncurrent writes that it is doing.
   */
  public MessageIdentity addMessage(ActiveMQMessage message) throws JMSException {
    boolean sync = message.isReceiptRequired();
    RecordLocation location = peristenceAdapter.writePacket(destinationName, message, sync);
    synchronized(this) {
      addedMessageLocations.put(message.getJMSMessageIdentity(), location);
    }

    // Update the messageIdentity sequence number so that we can reteive the message
View Full Code Here

  /**
   */
  public void removeMessage(MessageIdentity identity, MessageAck ack)
      throws JMSException {

    RecordLocation ackLocation = peristenceAdapter.writePacket(destinationName, ack, sync);

    synchronized(this) {
      RecordLocation addLocation = (RecordLocation) addedMessageLocations.remove(identity);     
      if( addLocation==null ) {
        removedMessageLocations.add(new AckData(ack, ackLocation));
      }
    }   
  }
View Full Code Here

  /**
   * @return
   * @throws JMSException
   */
  public RecordLocation checkpoint() throws JMSException {
    final RecordLocation rc[] = new RecordLocation[]{null};
   
    // swap out the message hashmaps..
    final ArrayList addedMessageIdentitys;
    final ArrayList removedMessageLocations;
    synchronized(this) {
      addedMessageIdentitys = new ArrayList(this.addedMessageLocations.keySet());
      removedMessageLocations = this.removedMessageLocations;
      this.removedMessageLocations = new ArrayList();
    }
   
    transactionTemplate.run(new Callback() {
      public void execute() throws Throwable {
       
        // Checkpoint the added messages.
        Iterator iterator = addedMessageIdentitys.iterator();
        while (iterator.hasNext()) {         
          MessageIdentity identity = (MessageIdentity) iterator.next();
         
          ActiveMQMessage msg = getCacheMessage(identity);
          longTermStore.addMessage(msg);
          synchronized(this) {
            RecordLocation location = (RecordLocation)addedMessageLocations.remove(identity);
            if( rc[0]==null || rc[0].compareTo(location)<0 ) {
              rc[0] = location;
            }
          }
         
View Full Code Here

                        return;
                    }

                    log.info("Checkpoint started.");
                    Iterator iterator = messageStores.values().iterator();
                    RecordLocation newMark = null;
                    while (iterator.hasNext()) {
                        try {
                            JournalMessageStore ms = (JournalMessageStore) iterator.next();
                            RecordLocation mark = ms.checkpoint();
                            if (mark != null && (newMark == null || newMark.compareTo(mark) < 0)) {
                                newMark = mark;
                            }
                        }
                        catch (Exception e) {
View Full Code Here

     * @throws InvalidRecordLocationException
     * @throws IllegalStateException
     */
    private void recover() throws IllegalStateException, InvalidRecordLocationException, IOException, JMSException {

        RecordLocation pos = null;
        int transactionCounter = 0;

        log.info("Journal Recovery Started.");

        // While we have records in the journal.
        while ((pos = journal.getNextRecordLocation(pos)) != null) {
            byte[] data = journal.read(pos);

            // Read the destination and packate from the record.
            String destination = null;
            Packet packet = null;
            DataInputStream is = new DataInputStream(new ByteArrayInputStream(data));
            try {
                byte type = is.readByte();
                switch (type) {
                    case PACKET_RECORD_TYPE:

                        // Is the current packet part of the destination?
                        destination = is.readUTF();
                        packet = wireFormat.readPacket(is);

                        // Try to replay the packet.
                        JournalMessageStore store = (JournalMessageStore) createQueueMessageStore(destination);
                        if (packet instanceof ActiveMQMessage) {
                            ActiveMQMessage msg = (ActiveMQMessage) packet;
                            try {
                                store.getLongTermStore().addMessage(msg);
                                transactionCounter++;
                            }
                            catch (Throwable e) {
                                log.error("Recovery Failure: Could not add message: " + msg.getJMSMessageIdentity().getMessageID() + ", reason: " + e, e);
                            }
                        }
                        else if (packet instanceof MessageAck) {
                            MessageAck ack = (MessageAck) packet;
                            try {
                                store.getLongTermStore().removeMessage(ack.getMessageIdentity(), ack);
                                transactionCounter++;
                            }
                            catch (Throwable e) {
                                log.error("Recovery Failure: Could not remove message: " + ack.getMessageIdentity().getMessageID() + ", reason: " + e, e);
                            }
                        }
                        else {
                            log.error("Unknown type of packet in transaction log which will be discarded: " + packet);
                        }

                        break;
                    case COMMAND_RECORD_TYPE:

                        break;
                    default:
                        log.error("Unknown type of record in transaction log which will be discarded: " + type);
                        break;
                }
            }
            finally {
                is.close();
            }
        }

        RecordLocation location = writeCommand("RECOVERED", true);
        journal.setMark(location, true);

        log.info("Journal Recovered: " + transactionCounter + " message(s) in transactions recovered.");
    }
View Full Code Here

   * Not synchronized since the Journal has better throughput if you increase
   * the number of conncurrent writes that it is doing.
   */
  public MessageIdentity addMessage(ActiveMQMessage message) throws JMSException {
    boolean sync = message.isReceiptRequired();
    RecordLocation location = peristenceAdapter.writePacket(destinationName, message, sync);
    synchronized(this) {
      addedMessageLocations.put(message.getJMSMessageIdentity(), location);
    }

    // Update the messageIdentity sequence number so that we can reteive the message
View Full Code Here

  /**
   */
  public void removeMessage(MessageIdentity identity, MessageAck ack)
      throws JMSException {

    RecordLocation ackLocation = peristenceAdapter.writePacket(destinationName, ack, sync);

    synchronized(this) {
      RecordLocation addLocation = (RecordLocation) addedMessageLocations.remove(identity);     
      if( addLocation==null ) {
        removedMessageLocations.add(new AckData(ack, ackLocation));
      }
    }   
  }
View Full Code Here

  /**
   * @return
   * @throws JMSException
   */
  public RecordLocation checkpoint() throws JMSException {
    final RecordLocation rc[] = new RecordLocation[]{null};
   
    // swap out the message hashmaps..
    final ArrayList addedMessageIdentitys;
    final ArrayList removedMessageLocations;
    synchronized(this) {
      addedMessageIdentitys = new ArrayList(this.addedMessageLocations.keySet());
      removedMessageLocations = this.removedMessageLocations;
      this.removedMessageLocations = new ArrayList();
    }
   
    transactionTemplate.run(new Callback() {
      public void execute() throws Throwable {
       
        // Checkpoint the added messages.
        Iterator iterator = addedMessageIdentitys.iterator();
        while (iterator.hasNext()) {         
          MessageIdentity identity = (MessageIdentity) iterator.next();
         
          ActiveMQMessage msg = getCacheMessage(identity);
          longTermStore.addMessage(msg);
          synchronized(this) {
            RecordLocation location = (RecordLocation)addedMessageLocations.remove(identity);
            if( rc[0]==null || rc[0].compareTo(location)<0 ) {
              rc[0] = location;
            }
          }
         
View Full Code Here

TOP

Related Classes of org.codehaus.activemq.journal.RecordLocation

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.