Package org.javlo.service.syncro
Class AbstractSynchroService<SC extends AbstractSynchroContext>
- java.lang.Object
-
- org.javlo.service.syncro.AbstractSynchroService<SC>
-
- Type Parameters:
SC
- A subclass ofAbstractSynchroContext
specialized 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 void
applyAction(SC context, String path, AbstractSynchroContext.SynchroAction action)
Apply the action required for the path.protected void
applyActions(SC context)
CallapplyAction(AbstractSynchroContext, String, SynchroAction)
for each path with a required action.protected AbstractSynchroContext.SynchroAction
defineAction(SC context, String path)
Called to define the required action for the specified path.protected void
defineActions(SC context)
Called in the synchro process.abstract String
getDistantName()
Get the name of the distant side.abstract String
getLocalName()
Get the name of the local side.protected void
initializeContext(SC context, Object previousState)
Initialize the context.protected abstract SC
newSynchroContext()
Instanciate a context for ONE synchro run.protected void
onActionsApplied(SC context)
Called when all actions are applied.protected void
onActionsDefined(SC context)
Called when all paths are analysed and required actions defined.protected void
onFatalException(SC context, SynchroFatalException ex)
Called when anSynchroFatalException
is thrown during the synchro process.protected void
onNonFatalException(SC context, SynchroNonFatalException ex, String currentFilePath)
Called when anSynchroNonFatalException
is thrown during the synchro process.protected void
onShutdown(SC context)
Called every time a synchro run is finished even if aSynchroFatalException
is thrown.protected void
onUncaughtException(SC context, Throwable ex)
Called when an exception is thrown during the synchro process.boolean
synchronize()
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:
true
if 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
AbstractSynchroContext
specialized for the currentAbstractSynchroService
implementation.
-
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 currentAbstractSynchroContext
path
-- Returns:
- the required action.
- Throws:
SynchroNonFatalException
SynchroFatalException
-
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 currentAbstractSynchroContext
path
-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 anSynchroNonFatalException
is thrown during the synchro process. Only the current file will be skipped.- Parameters:
context
- the currentAbstractSynchroContext
ex
-currentFilePath
-
-
onFatalException
protected void onFatalException(SC context, SynchroFatalException ex)
Called when anSynchroFatalException
is thrown during the synchro process. This is fatal for ONE run.- Parameters:
context
- the currentAbstractSynchroContext
ex
-
-
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 benull
if 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 aSynchroFatalException
is thrown. SeeAbstractSynchroContext.isErrorOccured()
.
Not called thenewSynchroContext()
failed.- Parameters:
context
- the currentAbstractSynchroContext
-
-