From 1edd5bc9a87e59e532d8fe32048114f20ae52018 Mon Sep 17 00:00:00 2001 From: "liquidsnake@sapo.pt" Date: Wed, 16 Dec 2009 19:58:26 +0000 Subject: [PATCH] Within this commit, the code that implements the checkpoints is completed. However, it still needs to be tested. --- .../smart/statemanagment/StateLog.java | 21 +++++++++++++++++-- src/navigators/smart/tom/core/TOMLayer.java | 11 ++++++++-- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/navigators/smart/statemanagment/StateLog.java b/src/navigators/smart/statemanagment/StateLog.java index 858b6e8c..acbed0fd 100644 --- a/src/navigators/smart/statemanagment/StateLog.java +++ b/src/navigators/smart/statemanagment/StateLog.java @@ -24,7 +24,7 @@ package navigators.smart.statemanagment; * checkpoint together with all the batches of messages received so far, comprises this replica * current state * - * @author João Sousa + * @author Jo�o Sousa */ public class StateLog { @@ -60,6 +60,7 @@ public class StateLog { position = 0; nextEid += k; + execCounter++; this.state = state; } @@ -125,7 +126,7 @@ public class StateLog { /** * Constructs a TransferableState using this log information * @param eid Execution ID correspondent to desired state - * @return + * @return TransferableState Object containing this log information */ public TransferableState getTransferableState(int eid) { @@ -142,4 +143,20 @@ public class StateLog { else return null; } + /** + * Updates this log, according to the information contained in the TransferableState object + * @param transState TransferableState object containing the information which is used to updated this log + */ + public void update(TransferableState transState) { + + for (int i = 0; i < transState.getMessageBatches().length; i++, position = i) { + this.messageBatches[i] = transState.getMessageBatches()[i]; + } + + this.nextEid = transState.getCurrentCheckpointEid() + 1; + + this.state = transState.getState(); + + this.execCounter = this.nextEid + position; + } } diff --git a/src/navigators/smart/tom/core/TOMLayer.java b/src/navigators/smart/tom/core/TOMLayer.java index 94550468..314d4dd2 100644 --- a/src/navigators/smart/tom/core/TOMLayer.java +++ b/src/navigators/smart/tom/core/TOMLayer.java @@ -44,6 +44,7 @@ import navigators.smart.paxosatwar.executionmanager.ExecutionManager; import navigators.smart.paxosatwar.executionmanager.LeaderModule; import navigators.smart.paxosatwar.executionmanager.Round; import navigators.smart.paxosatwar.roles.Acceptor; +import navigators.smart.statemanagment.StateLog; import navigators.smart.tom.TOMRequestReceiver; import navigators.smart.tom.core.messages.TOMMessage; import navigators.smart.tom.core.timer.RTInfo; @@ -157,6 +158,10 @@ public final class TOMLayer extends Thread implements RequestReceiver { this.dt = new DeliveryThread(this, receiver, conf); // Create delivery thread this.dt.start(); + + /** ISTO E CODIGO DO JOAO, PARA TRATAR DOS CHECKPOINTS */ + stateLog = new StateLog(this.conf.getCheckpoint_period()); + /*******************************************************/ } /** @@ -888,11 +893,13 @@ public final class TOMLayer extends Thread implements RequestReceiver { } /** ISTO E CODIGO DO JOAO, PARA TRATAR DOS CHECKPOINTS */ + private StateLog stateLog = null; + public void saveState(byte[] state) { - //TODO: Concretizar o metodo. Possivelmente acrescentar mais parametros + stateLog.newCheckpoint(state); } public void saveBatch(byte[] batch) { - //TODO: Concretizar o metodo. Possivelmente acrescentar mais parametros + stateLog.addMessageBatch(batch); } /********************************************************/ } -- GitLab