Package org.javlo.service.syncro
Class AbstractSynchroService<SC extends AbstractSynchroContext>
- java.lang.Object
-
- org.javlo.service.syncro.AbstractSynchroService<SC>
-
- Type Parameters:
SC- A subclass ofAbstractSynchroContextspecialized for subclasses.
- Direct Known Subclasses:
BaseSynchroService
public abstract class AbstractSynchroService<SC extends AbstractSynchroContext> extends Object
Abstract service defining required elements for synchronisation.- Author:
- bdumont
-
-
Constructor Summary
Constructors Constructor Description AbstractSynchroService()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract voidapplyAction(SC context, String path, AbstractSynchroContext.SynchroAction action)Apply the action required for the path.protected voidapplyActions(SC context)CallapplyAction(AbstractSynchroContext, String, SynchroAction)for each path with a required action.protected AbstractSynchroContext.SynchroActiondefineAction(SC context, String path)Called to define the required action for the specified path.protected voiddefineActions(SC context)Called in the synchro process.abstract StringgetDistantName()Get the name of the distant side.abstract StringgetLocalName()Get the name of the local side.protected voidinitializeContext(SC context, Object previousState)Initialize the context.protected abstract SCnewSynchroContext()Instanciate a context for ONE synchro run.protected voidonActionsApplied(SC context)Called when all actions are applied.protected voidonActionsDefined(SC context)Called when all paths are analysed and required actions defined.protected voidonFatalException(SC context, SynchroFatalException ex)Called when anSynchroFatalExceptionis thrown during the synchro process.protected voidonNonFatalException(SC context, SynchroNonFatalException ex, String currentFilePath)Called when anSynchroNonFatalExceptionis thrown during the synchro process.protected voidonShutdown(SC context)Called every time a synchro run is finished even if aSynchroFatalExceptionis thrown.protected voidonUncaughtException(SC context, Throwable ex)Called when an exception is thrown during the synchro process.booleansynchronize()The synchronisation process main method.
-
-
-
Field Detail
-
logger
public static Logger logger
-
-
Method Detail
-
getLocalName
public abstract String getLocalName()
Get the name of the local side. Can be used in conflict file name.- Returns:
- the local name
-
getDistantName
public abstract String getDistantName()
Get the name of the distant side.- Returns:
- the ditant name
-
synchronize
public boolean synchronize()
The synchronisation process main method.- Returns:
trueif the synchronisation ended without error.
-
initializeContext
protected void initializeContext(SC context, Object previousState) throws SynchroFatalException
Initialize the context. It's the first method that can thrown synchro exception.- Parameters:
context-previousState-- Throws:
SynchroFatalException
-
newSynchroContext
protected abstract SC newSynchroContext()
Instanciate a context for ONE synchro run.- Returns:
- an instance of
AbstractSynchroContextspecialized for the currentAbstractSynchroServiceimplementation.
-
defineActions
protected void defineActions(SC context) throws SynchroFatalException
Called in the synchro process. CalldefineAction(AbstractSynchroContext, String)for each path andAbstractSynchroContext.setAction(String, SynchroAction)with the result.- Parameters:
context- the currentAbstractSynchroContext- Throws:
SynchroFatalException
-
defineAction
protected AbstractSynchroContext.SynchroAction defineAction(SC context, String path) throws SynchroNonFatalException, SynchroFatalException
Called to define the required action for the specified path.- Parameters:
context- the currentAbstractSynchroContextpath-- Returns:
- the required action.
- Throws:
SynchroNonFatalExceptionSynchroFatalException
-
onActionsDefined
protected void onActionsDefined(SC context)
Called when all paths are analysed and required actions defined.- Parameters:
context- the currentAbstractSynchroContext
-
applyActions
protected void applyActions(SC context)
CallapplyAction(AbstractSynchroContext, String, SynchroAction)for each path with a required action.- Parameters:
context- the currentAbstractSynchroContext
-
applyAction
protected abstract void applyAction(SC context, String path, AbstractSynchroContext.SynchroAction action) throws SynchroNonFatalException
Apply the action required for the path.- Parameters:
context- the currentAbstractSynchroContextpath-action-- Throws:
SynchroNonFatalException
-
onActionsApplied
protected void onActionsApplied(SC context)
Called when all actions are applied.- Parameters:
context- the currentAbstractSynchroContext
-
onNonFatalException
protected void onNonFatalException(SC context, SynchroNonFatalException ex, String currentFilePath)
Called when anSynchroNonFatalExceptionis thrown during the synchro process. Only the current file will be skipped.- Parameters:
context- the currentAbstractSynchroContextex-currentFilePath-
-
onFatalException
protected void onFatalException(SC context, SynchroFatalException ex)
Called when anSynchroFatalExceptionis thrown during the synchro process. This is fatal for ONE run.- Parameters:
context- the currentAbstractSynchroContextex-
-
onUncaughtException
protected void onUncaughtException(SC context, Throwable ex)
Called when an exception is thrown during the synchro process. This is fatal for ONE run.- Parameters:
context- the currentAbstractSynchroContext. Can benullif the exception is thrown during the call ofnewSynchroContext().ex-
-
onShutdown
protected void onShutdown(SC context)
Called every time a synchro run is finished even if aSynchroFatalExceptionis thrown. SeeAbstractSynchroContext.isErrorOccured().
Not called thenewSynchroContext()failed.- Parameters:
context- the currentAbstractSynchroContext
-
-