Class 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 extends Object,​V extends Object>
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected org.slf4j.Logger log  
      • 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
    • 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 entry
      protected 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 runtime
      int 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 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 Detail

      • log

        protected final org.slf4j.Logger log
    • Method Detail

      • 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()
      • 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