Package org.apache.camel.support
Class DefaultTimeoutMap<K,V>
java.lang.Object
org.apache.camel.support.service.BaseService
org.apache.camel.support.service.ServiceSupport
org.apache.camel.support.DefaultTimeoutMap<K,V>
- All Implemented Interfaces:
AutoCloseable
,org.apache.camel.Service
,org.apache.camel.ShutdownableService
,org.apache.camel.StatefulService
,org.apache.camel.SuspendableService
,org.apache.camel.TimeoutMap<K,
V>
public class DefaultTimeoutMap<K,V>
extends org.apache.camel.support.service.ServiceSupport
implements org.apache.camel.TimeoutMap<K,V>
Default implementation of the
TimeoutMap
.
This implementation supports thread safe and non thread safe, in the manner you can enable locking or not. By default
locking is enabled and thus we are thread safe.
You must provide a ScheduledExecutorService
in the constructor which is used to schedule
a background task which check for old entries to purge. This implementation will shutdown the scheduler if its being
stopped. You must also invoke BaseService.start()
to startup the timeout map, before its ready to be used. And you must
invoke BaseService.stop()
to stop the map when no longer in use.-
Nested Class Summary
Nested classes/interfaces inherited from interface org.apache.camel.TimeoutMap
org.apache.camel.TimeoutMap.Listener<K,
V> -
Field Summary
FieldsFields inherited from class org.apache.camel.support.service.BaseService
BUILT, FAILED, INITIALIZED, INITIALIZING, NEW, SHUTDOWN, SHUTTING_DOWN, STARTED, STARTING, status, STOPPED, STOPPING, SUSPENDED, SUSPENDING
-
Constructor Summary
ConstructorsConstructorDescriptionDefaultTimeoutMap
(ScheduledExecutorService executor) DefaultTimeoutMap
(ScheduledExecutorService executor, long requestMapPollTimeMillis) DefaultTimeoutMap
(ScheduledExecutorService executor, long requestMapPollTimeMillis, boolean useLock) DefaultTimeoutMap
(ScheduledExecutorService executor, long requestMapPollTimeMillis, Lock lock) -
Method Summary
Modifier and TypeMethodDescriptionvoid
addListener
(org.apache.camel.TimeoutMap.Listener<K, V> listener) protected long
protected void
doStart()
protected void
doStop()
long
protected boolean
isValidForEviction
(TimeoutMapEntry<K, V> entry) A hook to allow derivations to avoid evicting the current entryprotected void
purge()
putIfAbsent
(K key, V value, long timeoutMillis) protected void
lets schedule each time to allow folks to change the time at runtimeint
size()
protected void
updateExpireTime
(TimeoutMapEntry<K, V> entry) Methods inherited from class org.apache.camel.support.service.BaseService
build, doBuild, doFail, doInit, doLifecycleChange, doResume, doShutdown, doSuspend, fail, getInternalLock, getStatus, init, isBuild, isInit, isNew, isRunAllowed, isShutdown, isStarted, isStarting, isStartingOrStarted, isStopped, isStopping, isStoppingOrStopped, isSuspended, isSuspending, isSuspendingOrSuspended, resume, shutdown, start, stop, suspend
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.apache.camel.Service
build, close, init, start, stop
Methods inherited from interface org.apache.camel.ShutdownableService
shutdown
Methods inherited from interface org.apache.camel.StatefulService
getStatus, isRunAllowed, isStarted, isStarting, isStopped, isStopping, isSuspending
Methods inherited from interface org.apache.camel.SuspendableService
isSuspended, resume, suspend
-
Field Details
-
log
protected final org.slf4j.Logger log
-
-
Constructor Details
-
DefaultTimeoutMap
-
DefaultTimeoutMap
-
DefaultTimeoutMap
public DefaultTimeoutMap(ScheduledExecutorService executor, long requestMapPollTimeMillis, boolean useLock) -
DefaultTimeoutMap
public DefaultTimeoutMap(ScheduledExecutorService executor, long requestMapPollTimeMillis, Lock lock)
-
-
Method Details
-
get
-
put
-
putIfAbsent
-
remove
-
size
public int size() -
purge
protected void purge() -
getPurgePollTime
public long getPurgePollTime() -
getExecutor
-
addListener
-
schedulePoll
protected void schedulePoll()lets schedule each time to allow folks to change the time at runtime -
isValidForEviction
A hook to allow derivations to avoid evicting the current entry -
updateExpireTime
-
currentTime
protected long currentTime() -
doStart
- Overrides:
doStart
in classorg.apache.camel.support.service.BaseService
- Throws:
Exception
-
doStop
- Overrides:
doStop
in classorg.apache.camel.support.service.BaseService
- Throws:
Exception
-