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 theTimeoutMap
. 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 aScheduledExecutorService
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 invokeBaseService.start()
to startup the timeout map, before its ready to be used. And you must invokeBaseService.stop()
to stop the map when no longer in use.
-
-
Field Summary
Fields Modifier and Type Field Description protected org.slf4j.Logger
log
-
Constructor Summary
Constructors Constructor Description DefaultTimeoutMap(ScheduledExecutorService executor)
DefaultTimeoutMap(ScheduledExecutorService executor, long requestMapPollTimeMillis)
DefaultTimeoutMap(ScheduledExecutorService executor, long requestMapPollTimeMillis, boolean useLock)
DefaultTimeoutMap(ScheduledExecutorService executor, long requestMapPollTimeMillis, Lock lock)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addListener(org.apache.camel.TimeoutMap.Listener<K,V> listener)
protected long
currentTime()
protected void
doStart()
protected void
doStop()
V
get(K key)
ScheduledExecutorService
getExecutor()
long
getPurgePollTime()
protected boolean
isValidForEviction(TimeoutMapEntry<K,V> entry)
A hook to allow derivations to avoid evicting the current entryprotected void
purge()
V
put(K key, V value, long timeoutMillis)
V
putIfAbsent(K key, V value, long timeoutMillis)
V
remove(K key)
protected void
schedulePoll()
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, 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
-
-
-
-
Constructor Detail
-
DefaultTimeoutMap
public DefaultTimeoutMap(ScheduledExecutorService executor)
-
DefaultTimeoutMap
public DefaultTimeoutMap(ScheduledExecutorService executor, long requestMapPollTimeMillis)
-
DefaultTimeoutMap
public DefaultTimeoutMap(ScheduledExecutorService executor, long requestMapPollTimeMillis, boolean useLock)
-
DefaultTimeoutMap
public DefaultTimeoutMap(ScheduledExecutorService executor, long requestMapPollTimeMillis, Lock lock)
-
-
Method Detail
-
purge
protected void purge()
-
getPurgePollTime
public long getPurgePollTime()
-
getExecutor
public ScheduledExecutorService getExecutor()
-
schedulePoll
protected void schedulePoll()
lets schedule each time to allow folks to change the time at runtime
-
isValidForEviction
protected boolean isValidForEviction(TimeoutMapEntry<K,V> entry)
A hook to allow derivations to avoid evicting the current entry
-
updateExpireTime
protected void updateExpireTime(TimeoutMapEntry<K,V> entry)
-
currentTime
protected long currentTime()
-
doStart
protected void doStart() throws Exception
- Overrides:
doStart
in classorg.apache.camel.support.service.BaseService
- Throws:
Exception
-
-