Package org.apache.activeio.journal

Examples of org.apache.activeio.journal.RecordLocation


     * @throws IOException
     */
    public RecordLocation checkpoint(final Callback postCheckpointTest) throws IOException {

       
        RecordLocation rc;
        final ArrayList cpRemovedMessageLocations;
        final ArrayList cpActiveJournalLocations;
        final int maxCheckpointMessageAddSize = peristenceAdapter.getMaxCheckpointMessageAddSize();

        // swap out the message hash maps..
View Full Code Here


    /**
     *
     */
    public Message getMessage(MessageId identity) throws IOException {
        RecordLocation loc=null;
       
        synchronized (this) {
            QuickJournalMessageData answer = null;
            // Do we have a still have it in the journal?
            answer = (QuickJournalMessageData) messages.get(identity);
View Full Code Here

        longTermStore.recover(new MessageRecoveryListener() {
            public void recoverMessage(Message message) throws Exception {
                throw new IOException("Should not get called.");
            }
            public void recoverMessageReference(String messageReference) throws Exception {
                RecordLocation loc = toRecordLocation(messageReference);
                Message message = (Message) peristenceAdapter.readCommand(loc);
                listener.recoverMessage(message);
            }
           
            public void finished(){
View Full Code Here

            this.fullCheckPoint=false;           
        }       
        try {

            log.debug("Checkpoint started.");
            RecordLocation newMark = null;

            ArrayList futureTasks = new ArrayList(queues.size()+topics.size());
           
            //
            // We do many partial checkpoints (fullCheckpoint==false) to move topic messages
            // to long term store as soon as possible. 
            //
            // We want to avoid doing that for queue messages since removes the come in the same
            // checkpoint cycle will nullify the previous message add.  Therefore, we only
            // checkpoint queues on the fullCheckpoint cycles.
            //
            if( fullCheckpoint ) {               
                Iterator iterator = queues.values().iterator();
                while (iterator.hasNext()) {
                    try {
                        final JournalMessageStore ms = (JournalMessageStore) iterator.next();
                        FutureTask task = new FutureTask(new Callable() {
                            public Object call() throws Exception {
                                return ms.checkpoint();
                            }});
                        futureTasks.add(task);
                        checkpointExecutor.execute(task);                       
                    }
                    catch (Exception e) {
                        log.error("Failed to checkpoint a message store: " + e, e);
                    }
                }
            }

            Iterator iterator = topics.values().iterator();
            while (iterator.hasNext()) {
                try {
                    final JournalTopicMessageStore ms = (JournalTopicMessageStore) iterator.next();
                    FutureTask task = new FutureTask(new Callable() {
                        public Object call() throws Exception {
                            return ms.checkpoint();
                        }});
                    futureTasks.add(task);
                    checkpointExecutor.execute(task);                       
                }
                catch (Exception e) {
                    log.error("Failed to checkpoint a message store: " + e, e);
                }
            }

            try {
                for (Iterator iter = futureTasks.iterator(); iter.hasNext();) {
                    FutureTask ft = (FutureTask) iter.next();
                    RecordLocation mark = (RecordLocation) ft.get();
                    // We only set a newMark on full checkpoints.
                    if( fullCheckpoint ) {
                        if (mark != null && (newMark == null || newMark.compareTo(mark) < 0)) {
                            newMark = mark;
                        }
View Full Code Here

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

        RecordLocation pos = null;
        int transactionCounter = 0;

        log.info("Journal Recovery Started from: " + journal);
        ConnectionContext context = new ConnectionContext();

        // While we have records in the journal.
        while ((pos = journal.getNextRecordLocation(pos)) != null) {
            Packet data = journal.read(pos);
            DataStructure c = (DataStructure) wireFormat.unmarshal(toByteSequence(data));

            if (c instanceof Message ) {
                Message message = (Message) c;
                JournalMessageStore store = (JournalMessageStore) createMessageStore(message.getDestination());
                if ( message.isInTransaction()) {
                    transactionStore.addMessage(store, message, pos);
                }
                else {
                    store.replayAddMessage(context, message);
                    transactionCounter++;
                }
            } else {
                switch (c.getDataStructureType()) {
                case JournalQueueAck.DATA_STRUCTURE_TYPE:
                {
                    JournalQueueAck command = (JournalQueueAck) c;
                    JournalMessageStore store = (JournalMessageStore) createMessageStore(command.getDestination());
                    if (command.getMessageAck().isInTransaction()) {
                        transactionStore.removeMessage(store, command.getMessageAck(), pos);
                    }
                    else {
                        store.replayRemoveMessage(context, command.getMessageAck());
                        transactionCounter++;
                    }
                }
                break;
                case JournalTopicAck.DATA_STRUCTURE_TYPE:
                {
                    JournalTopicAck command = (JournalTopicAck) c;
                    JournalTopicMessageStore store = (JournalTopicMessageStore) createMessageStore(command.getDestination());
                    if (command.getTransactionId() != null) {
                        transactionStore.acknowledge(store, command, pos);
                    }
                    else {
                        store.replayAcknowledge(context, command.getClientId(), command.getSubscritionName(), command.getMessageId());
                        transactionCounter++;
                    }
                }
                break;
                case JournalTransaction.DATA_STRUCTURE_TYPE:
                {
                    JournalTransaction command = (JournalTransaction) c;
                    try {
                        // Try to replay the packet.
                        switch (command.getType()) {
                        case JournalTransaction.XA_PREPARE:
                            transactionStore.replayPrepare(command.getTransactionId());
                            break;
                        case JournalTransaction.XA_COMMIT:
                        case JournalTransaction.LOCAL_COMMIT:
                            Tx tx = transactionStore.replayCommit(command.getTransactionId(), command.getWasPrepared());
                            if (tx == null)
                                break; // We may be trying to replay a commit that
                                        // was already committed.

                            // Replay the committed operations.
                            tx.getOperations();
                            for (Iterator iter = tx.getOperations().iterator(); iter.hasNext();) {
                                TxOperation op = (TxOperation) iter.next();
                                if (op.operationType == TxOperation.ADD_OPERATION_TYPE) {
                                    op.store.replayAddMessage(context, (Message) op.data);
                                }
                                if (op.operationType == TxOperation.REMOVE_OPERATION_TYPE) {
                                    op.store.replayRemoveMessage(context, (MessageAck) op.data);
                                }
                                if (op.operationType == TxOperation.ACK_OPERATION_TYPE) {
                                    JournalTopicAck ack = (JournalTopicAck) op.data;
                                    ((JournalTopicMessageStore) op.store).replayAcknowledge(context, ack.getClientId(), ack.getSubscritionName(), ack
                                            .getMessageId());
                                }
                            }
                            transactionCounter++;
                            break;
                        case JournalTransaction.LOCAL_ROLLBACK:
                        case JournalTransaction.XA_ROLLBACK:
                            transactionStore.replayRollback(command.getTransactionId());
                            break;
                        }
                    }
                    catch (IOException e) {
                        log.error("Recovery Failure: Could not replay: " + c + ", reason: " + e, e);
                    }
                }
                break;
                case JournalTrace.DATA_STRUCTURE_TYPE:
                    JournalTrace trace = (JournalTrace) c;
                    log.debug("TRACE Entry: " + trace.getMessage());
                    break;
                default:
                    log.error("Unknown type of record in transaction log which will be discarded: " + c);
                }
            }
        }

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

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

    public void deleteAllMessages() throws IOException {       
        try {
            JournalTrace trace = new JournalTrace();
            trace.setMessage("DELETED");
            RecordLocation location = journal.write(toPacket(wireFormat.marshal(trace)), false);
            journal.setMark(location, true);
            log.info("Journal deleted: ");
        } catch (IOException e) {
            throw e;
        } catch (Throwable e) {
View Full Code Here

            this.fullCheckPoint=false;           
        }       
        try {

            log.debug("Checkpoint started.");
            RecordLocation newMark = null;

            ArrayList futureTasks = new ArrayList(queues.size()+topics.size());
           
            //
            // We do many partial checkpoints (fullCheckpoint==false) to move topic messages
            // to long term store as soon as possible. 
            //
            // We want to avoid doing that for queue messages since removes the come in the same
            // checkpoint cycle will nullify the previous message add.  Therefore, we only
            // checkpoint queues on the fullCheckpoint cycles.
            //
            if( fullCheckpoint ) {               
                Iterator iterator = queues.values().iterator();
                while (iterator.hasNext()) {
                    try {
                        final RapidMessageStore ms = (RapidMessageStore) iterator.next();
                        FutureTask task = new FutureTask(new Callable() {
                            public Object call() throws Exception {
                                return ms.checkpoint();
                            }});
                        futureTasks.add(task);
                        checkpointExecutor.execute(task);                       
                    }
                    catch (Exception e) {
                        log.error("Failed to checkpoint a message store: " + e, e);
                    }
                }
            }

            Iterator iterator = topics.values().iterator();
            while (iterator.hasNext()) {
                try {
                    final RapidTopicMessageStore ms = (RapidTopicMessageStore) iterator.next();
                    FutureTask task = new FutureTask(new Callable() {
                        public Object call() throws Exception {
                            return ms.checkpoint();
                        }});
                    futureTasks.add(task);
                    checkpointExecutor.execute(task);                       
                }
                catch (Exception e) {
                    log.error("Failed to checkpoint a message store: " + e, e);
                }
            }

            try {
                for (Iterator iter = futureTasks.iterator(); iter.hasNext();) {
                    FutureTask ft = (FutureTask) iter.next();
                    RecordLocation mark = (RecordLocation) ft.get();
                    // We only set a newMark on full checkpoints.
                    if( fullCheckpoint ) {
                        if (mark != null && (newMark == null || newMark.compareTo(mark) < 0)) {
                            newMark = mark;
                        }
View Full Code Here

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

        RecordLocation pos = null;
        int transactionCounter = 0;

        log.info("Journal Recovery Started.");
        ConnectionContext context = new ConnectionContext();

        // While we have records in the journal.
        while ((pos = journal.getNextRecordLocation(pos)) != null) {
            Packet data = journal.read(pos);
            DataStructure c = (DataStructure) wireFormat.unmarshal(toByteSequence(data));

            if (c instanceof Message ) {
                Message message = (Message) c;
                RapidMessageStore store = (RapidMessageStore) createMessageStore(message.getDestination());
                if ( message.isInTransaction()) {
                    transactionStore.addMessage(store, message, pos);
                }
                else {
                    store.replayAddMessage(context, message, pos);
                    transactionCounter++;
                }
            } else {
                switch (c.getDataStructureType()) {
                case JournalQueueAck.DATA_STRUCTURE_TYPE:
                {
                    JournalQueueAck command = (JournalQueueAck) c;
                    RapidMessageStore store = (RapidMessageStore) createMessageStore(command.getDestination());
                    if (command.getMessageAck().isInTransaction()) {
                        transactionStore.removeMessage(store, command.getMessageAck(), pos);
                    }
                    else {
                        store.replayRemoveMessage(context, command.getMessageAck());
                        transactionCounter++;
                    }
                }
                break;
                case JournalTopicAck.DATA_STRUCTURE_TYPE:
                {
                    JournalTopicAck command = (JournalTopicAck) c;
                    RapidTopicMessageStore store = (RapidTopicMessageStore) createMessageStore(command.getDestination());
                    if (command.getTransactionId() != null) {
                        transactionStore.acknowledge(store, command, pos);
                    }
                    else {
                        store.replayAcknowledge(context, command.getClientId(), command.getSubscritionName(), command.getMessageId());
                        transactionCounter++;
                    }
                }
                break;
                case JournalTransaction.DATA_STRUCTURE_TYPE:
                {
                    JournalTransaction command = (JournalTransaction) c;
                    try {
                        // Try to replay the packet.
                        switch (command.getType()) {
                        case JournalTransaction.XA_PREPARE:
                            transactionStore.replayPrepare(command.getTransactionId());
                            break;
                        case JournalTransaction.XA_COMMIT:
                        case JournalTransaction.LOCAL_COMMIT:
                            Tx tx = transactionStore.replayCommit(command.getTransactionId(), command.getWasPrepared());
                            if (tx == null)
                                break; // We may be trying to replay a commit that
                                        // was already committed.

                            // Replay the committed operations.
                            for (Iterator iter = tx.getOperations().iterator(); iter.hasNext();) {
                                TxOperation op = (TxOperation) iter.next();
                                if (op.operationType == TxOperation.ADD_OPERATION_TYPE) {
                                    op.store.replayAddMessage(context, (Message) op.data, op.location);
                                }
                                if (op.operationType == TxOperation.REMOVE_OPERATION_TYPE) {
                                    op.store.replayRemoveMessage(context, (MessageAck) op.data);
                                }
                                if (op.operationType == TxOperation.ACK_OPERATION_TYPE) {
                                    JournalTopicAck ack = (JournalTopicAck) op.data;
                                    ((RapidTopicMessageStore) op.store).replayAcknowledge(context, ack.getClientId(), ack.getSubscritionName(), ack
                                            .getMessageId());
                                }
                            }
                            transactionCounter++;
                            break;
                        case JournalTransaction.LOCAL_ROLLBACK:
                        case JournalTransaction.XA_ROLLBACK:
                            transactionStore.replayRollback(command.getTransactionId());
                            break;
                        }
                    }
                    catch (IOException e) {
                        log.error("Recovery Failure: Could not replay: " + c + ", reason: " + e, e);
                    }
                }
                break;
                case JournalTrace.DATA_STRUCTURE_TYPE:
                    JournalTrace trace = (JournalTrace) c;
                    log.debug("TRACE Entry: " + trace.getMessage());
                    break;
                default:
                    log.error("Unknown type of record in transaction log which will be discarded: " + c);
                }
            }
        }

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

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

    public void deleteAllMessages() throws IOException {       
        try {
            JournalTrace trace = new JournalTrace();
            trace.setMessage("DELETED");
            RecordLocation location = journal.write(toPacket(wireFormat.marshal(trace)), false);
            journal.setMark(location, true);
            log.info("Journal deleted: ");
        } catch (IOException e) {
            throw e;
        } catch (Throwable e) {
View Full Code Here

        final MessageId id = message.getMessageId();
       
        final boolean debug = log.isDebugEnabled();
        message.incrementReferenceCount();
       
        final RecordLocation location = peristenceAdapter.writeCommand(message, message.isResponseRequired());
        if( !context.isInTransaction() ) {
            if( debug )
                log.debug("Journalled message add for: "+id+", at: "+location);
            addMessage(message, location);
        } else {
View Full Code Here

TOP

Related Classes of org.apache.activeio.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.