Class ProducerServicePool

java.lang.Object
org.apache.camel.support.service.BaseService
org.apache.camel.support.service.ServiceSupport
org.apache.camel.support.cache.ProducerServicePool
All Implemented Interfaces:
AutoCloseable, org.apache.camel.NonManagedService, org.apache.camel.Service, org.apache.camel.ShutdownableService, org.apache.camel.StatefulService, org.apache.camel.SuspendableService

public class ProducerServicePool extends org.apache.camel.support.service.ServiceSupport
Producer pool.
  • Field Summary

    Fields inherited from class org.apache.camel.support.service.BaseService

    BUILT, FAILED, INITIALIZED, INITIALIZING, lock, NEW, SHUTDOWN, SHUTTING_DOWN, STARTED, STARTING, status, STOPPED, STOPPING, SUSPENDED, SUSPENDING
  • Constructor Summary

    Constructors
    Constructor
    Description
    ProducerServicePool(org.apache.camel.util.function.ThrowingFunction<org.apache.camel.Endpoint,org.apache.camel.AsyncProducer,Exception> creator, Function<org.apache.camel.AsyncProducer,org.apache.camel.Endpoint> getEndpoint, int capacity)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    org.apache.camel.AsyncProducer
    acquire(org.apache.camel.Endpoint endpoint)
    Tries to acquire the producer/consumer with the given key
    void
    Cleanup the pool (removing stale instances that should be evicted)
    protected void
     
    protected void
     
    protected void
     
    protected void
    onEvict(org.apache.camel.AsyncProducer s)
    This callback is invoked by LRUCache from a separate background cleanup thread.
    void
    release(org.apache.camel.Endpoint endpoint, org.apache.camel.AsyncProducer s)
    Releases the producer/consumer back to the pool
    int
    Returns the current size of the pool

    Methods inherited from class org.apache.camel.support.service.BaseService

    build, 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

    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
  • Constructor Details

    • ProducerServicePool

      public ProducerServicePool(org.apache.camel.util.function.ThrowingFunction<org.apache.camel.Endpoint,org.apache.camel.AsyncProducer,Exception> creator, Function<org.apache.camel.AsyncProducer,org.apache.camel.Endpoint> getEndpoint, int capacity)
  • Method Details

    • onEvict

      protected void onEvict(org.apache.camel.AsyncProducer s)
      This callback is invoked by LRUCache from a separate background cleanup thread. Therefore we mark the entries to be evicted from this thread only, and then let SinglePool and MultiPool handle the evictions (stop the producer/consumer safely) when they are acquiring/releases producers/consumers. If we sop the producer/consumer from the LRUCache background thread we can have a race condition with a pooled producer may have been acquired at the same time its being evicted.
    • acquire

      public org.apache.camel.AsyncProducer acquire(org.apache.camel.Endpoint endpoint) throws Exception
      Tries to acquire the producer/consumer with the given key
      Parameters:
      endpoint - the endpoint
      Returns:
      the acquired producer/consumer
      Throws:
      Exception
    • release

      public void release(org.apache.camel.Endpoint endpoint, org.apache.camel.AsyncProducer s)
      Releases the producer/consumer back to the pool
      Parameters:
      endpoint - the endpoint
      s - the producer/consumer
    • size

      public int size()
      Returns the current size of the pool
    • cleanUp

      public void cleanUp()
      Cleanup the pool (removing stale instances that should be evicted)
    • doBuild

      protected void doBuild() throws Exception
      Overrides:
      doBuild in class org.apache.camel.support.service.BaseService
      Throws:
      Exception
    • 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