T - The type of the service this sync service is a sub service of.public abstract class AbstractSyncService<T extends AbstractAuthenticatedService> extends AbstractSubService<T>
| Modifier and Type | Field and Description |
|---|---|
protected LoggingScheduledThreadPoolExecutor |
executorService
This executor service will be used to schedule the synchronisation.
|
protected long |
period
The period of the default synchronisation.
|
protected java.util.concurrent.atomic.AtomicLong |
sequence
The transient sequence used if no sequence ID is provided.
|
protected java.lang.String |
sequenceId
The ID of the SQL sequence used for retrieving unique ascending IDs for
synchronisation runs.
|
protected java.util.concurrent.ScheduledFuture<?> |
synchronisation
The future for the currently scheduled synchronisation.
|
protected java.lang.String |
syncType
An arbitrary string used for logging messages and thread names.
|
protected TxManager<SessionToken> |
txManager |
logger, runtimeRequiredServices, service, startupRequiredServices| Constructor and Description |
|---|
AbstractSyncService(T omm,
TxManager<SessionToken> txManager,
java.lang.String syncType,
long syncPeriod)
Creates a new service for synchronising objects from org model extension
with the org model entities and relations.
|
AbstractSyncService(T omm,
TxManager<SessionToken> txManager,
java.lang.String syncType,
long syncPeriod,
java.lang.String sequenceId)
Creates a new service for synchronising objects from org model extension
with the org model entities and relations.
|
| Modifier and Type | Method and Description |
|---|---|
protected SessionToken |
createSession()
Creates a session token to start the synchronisation after starting.
|
protected abstract java.lang.Runnable |
createSyncRunnable()
Creates a runnable that performs the actual synchronisation.
|
long |
getRunId(SessionToken session)
Gets the unique and ascending ID for the next synchronisation run.
|
void |
init()
Initialise the sub service.
|
void |
scheduleSync(SessionToken session,
long start,
long period)
Schedules a new synchronisation running regularly with the designated
period.
|
void |
shutdown(boolean emergency)
Signals this service that it is being shut down.
|
void |
start()
Starts the sub service.
|
java.util.concurrent.ScheduledFuture<?> |
startDelayedSync(SessionToken session,
long delayMillis,
boolean logException,
boolean rethrow)
Starts the synchronisation to run asynchronously right after calling this method.
|
java.util.concurrent.Future<java.lang.Boolean> |
startSync(SessionToken session,
boolean logException)
Starts the synchronisation to run asynchronously right after calling this method.
|
getLocalUris, getRuntimeRequiredServices, getStartupRequiredServices, getURIs, ping, privilegeSession, sessionActive, sessionFinishedprotected final java.lang.String syncType
protected final java.lang.String sequenceId
null, no sequence will be
created but a transient sequence will be used.protected final java.util.concurrent.atomic.AtomicLong sequence
protected long period
protected LoggingScheduledThreadPoolExecutor executorService
protected java.util.concurrent.ScheduledFuture<?> synchronisation
protected final TxManager<SessionToken> txManager
public AbstractSyncService(T omm, TxManager<SessionToken> txManager, java.lang.String syncType, long syncPeriod)
omm - The org model manager this sub service belongs to which provides
session tokens.syncType - An identifying name for the extension this synchronisation
service belongs to.syncPeriod - The period of the synchronisation. If this is greater
than 0, the default synchronisation will be started automatically.
If it is 0, the default synchronisation will not be started,
negative values are forbidden.public AbstractSyncService(T omm, TxManager<SessionToken> txManager, java.lang.String syncType, long syncPeriod, java.lang.String sequenceId)
omm - The org model manager this sub service belongs to which provides
session tokens.syncType - An identifying name for the extension this synchronisation
service belongs to.syncPeriod - The period of the synchronisation. If this is greater
than 0, the default synchronisation will be started automatically.
If it is 0, the default synchronisation will not be started,
negative values are forbidden.sequenceId - The ID of the sequence allowing to create unique
ascending IDs for synchronisation runs.public void init()
throws AbortServiceException
AbstractSubServiceAbstractSubService.init(), the sub service must be ready for
AbstractSubService.start().
This implementation is empty which allows subclasses to omit the initialisation if they do not need one.
init in class AbstractSubService<T extends AbstractAuthenticatedService>AbortServiceException - If this sub service cannot be initialised due
to a severe problem, an AbortServiceException will
be thrown. AbstractSubService.shutdown(boolean) will not be called when aborting;
the sub service has to shut down itself/clean up before throwing
the exception.public void start()
throws AbortServiceException
AbstractSubServiceAbstractSubService.start(), the service must be ready to receive
any API call. This implicates for instance, that the thread calling this
method may not leave the method before a server thread is actually ready to
receive requests.
This implementation is empty which allows subclasses to omit the start procedure if they do not need one.
start in class AbstractSubService<T extends AbstractAuthenticatedService>AbortServiceException - If this sub service cannot be started due to
a severe problem, an AbortServiceException will be
thrown. AbstractSubService.shutdown(boolean) will not be called when aborting; the
sub service has to shut down itself/clean up before throwing the
exception.public void shutdown(boolean emergency)
AbstractSubServiceServiceThreadHandling. This implementation is empty.
shutdown in class AbstractSubService<T extends AbstractAuthenticatedService>emergency - Whether the shutdown will be an emergency shutdown.public java.util.concurrent.Future<java.lang.Boolean> startSync(SessionToken session, boolean logException)
logException is set to false, make sure to check the
returned future, especially for exceptions.session - The session which is used to check for access rights on this method.logException - Whether to additionally log an exception occurring while synchronising. If
false, make sure to check the returned future, especially for exceptions.public java.util.concurrent.ScheduledFuture<?> startDelayedSync(SessionToken session, long delayMillis, boolean logException, boolean rethrow)
logException is set to false, make sure to check the returned future after
the delay, especially for exceptions.session - The session which is used to check for access rights on this method.delayMillis - Number of milliseconds the sync will be delayed. If less than or equal zero,
the synchronisation will be started immediately.logException - Whether to additionally log an exception occurring while synchronising. If
false, make sure to check the returned future after the delay, especially for
exceptions.rethrow - Whether to rethrow the logged runtime exception/virtual machine error. This
parameter will be ignored if logException is false.public void scheduleSync(SessionToken session, long start, long period)
session - The session which is used to check for access rights on this
method.start - The absolute time (starting on 1970-01-01 00:00 UTC
in milliseconds) when to start the synchronisation. If this is in
the past, the next run is calculated based on the period starting
from this time. The first run may be delayed more in case a
currently running synchronisation does not terminate before.
System.currentTimeMillis() + initialDelay.period - The time between the start of consecutive synchronisations.
Synchronisations will have a fixed rate/frequency.public long getRunId(SessionToken session)
session - The session token identifying the synchronisation run.InternalServiceException - If there are problems retrieving the next
ID from the database sequence, an
InternalServiceException will be thrown.protected SessionToken createSession()
protected abstract java.lang.Runnable createSyncRunnable()