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

    Fields
    Modifier and Type
    Field
    Description
    protected final org.slf4j.Logger
     

    Fields 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

    Constructors
    Constructor
    Description
     
    DefaultTimeoutMap(ScheduledExecutorService executor, long requestMapPollTimeMillis)
     
    DefaultTimeoutMap(ScheduledExecutorService executor, long requestMapPollTimeMillis, boolean useLock)
     
    DefaultTimeoutMap(ScheduledExecutorService executor, long requestMapPollTimeMillis, Lock lock)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addListener(org.apache.camel.TimeoutMap.Listener<K,V> listener)
     
    protected long
     
    protected void
     
    protected void
     
    get(K key)
     
     
    long
     
    protected boolean
    A hook to allow derivations to avoid evicting the current entry
    protected void
     
    put(K key, V value, long timeoutMillis)
     
    putIfAbsent(K key, V value, long timeoutMillis)
     
    remove(K key)
     
    protected void
    lets schedule each time to allow folks to change the time at runtime
    int
     
    protected void
     

    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

  • Method Details

    • get

      public V get(K key)
      Specified by:
      get in interface org.apache.camel.TimeoutMap<K,V>
    • put

      public V put(K key, V value, long timeoutMillis)
      Specified by:
      put in interface org.apache.camel.TimeoutMap<K,V>
    • putIfAbsent

      public V putIfAbsent(K key, V value, long timeoutMillis)
      Specified by:
      putIfAbsent in interface org.apache.camel.TimeoutMap<K,V>
    • remove

      public V remove(K key)
      Specified by:
      remove in interface org.apache.camel.TimeoutMap<K,V>
    • size

      public int size()
      Specified by:
      size in interface org.apache.camel.TimeoutMap<K,V>
    • purge

      protected void purge()
    • getPurgePollTime

      public long getPurgePollTime()
    • getExecutor

      public ScheduledExecutorService getExecutor()
    • addListener

      public void addListener(org.apache.camel.TimeoutMap.Listener<K,V> listener)
      Specified by:
      addListener in interface org.apache.camel.TimeoutMap<K,V>
    • 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 class org.apache.camel.support.service.BaseService
      Throws:
      Exception
    • doStop

      protected void doStop() throws Exception
      Overrides:
      doStop in class org.apache.camel.support.service.BaseService
      Throws:
      Exception