Class ObjectPool<KeyT extends @NonNull java.lang.Object,​ObjectT extends @NonNull java.lang.Object>

  • Type Parameters:
    KeyT - > Key to share objects by
    ObjectT - > Shared object
    Direct Known Subclasses:
    ObjectPool.ClientPool

    @Internal
    @Experimental
    public class ObjectPool<KeyT extends @NonNull java.lang.Object,​ObjectT extends @NonNull java.lang.Object>
    extends java.lang.Object
    Reference counting object pool to easily share & destroy objects.

    Internal only, subject to incompatible changes or removal at any time!

    NOTE: This relies heavily on the implementation of Object.equals(Object) for ObjectPool. If not implemented properly, clients can't be shared between instances of DoFn.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  ObjectPool.ClientPool<ClientT extends software.amazon.awssdk.core.SdkClient>
      Client pool to easily share AWS clients per configuration.
    • Constructor Summary

      Constructors 
      Constructor Description
      ObjectPool​(java.util.function.Function<KeyT,​ObjectT> builder)  
      ObjectPool​(java.util.function.Function<KeyT,​ObjectT> builder, @Nullable org.apache.beam.sdk.function.ThrowingConsumer<java.lang.Exception,​ObjectT> finalizer)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static <ClientT extends software.amazon.awssdk.core.SdkClient,​BuilderT extends software.amazon.awssdk.awscore.client.builder.AwsClientBuilder<BuilderT,​ClientT>>
      ObjectPool.ClientPool<ClientT>
      pooledClientFactory​(BuilderT builder)  
      void release​(ObjectT object)
      Release a reference to a shared client instance.
      void releaseByKey​(KeyT key)
      Release a reference to a shared object instance using ObjectPool.
      ObjectT retain​(KeyT key)
      Retain a reference to a shared client instance.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ObjectPool

        public ObjectPool​(java.util.function.Function<KeyT,​ObjectT> builder)
      • ObjectPool

        public ObjectPool​(java.util.function.Function<KeyT,​ObjectT> builder,
                          @Nullable org.apache.beam.sdk.function.ThrowingConsumer<java.lang.Exception,​ObjectT> finalizer)
    • Method Detail

      • retain

        public ObjectT retain​(KeyT key)
        Retain a reference to a shared client instance. If not available, an instance is created.
      • releaseByKey

        public void releaseByKey​(KeyT key)
        Release a reference to a shared object instance using ObjectPool. If that instance is not used anymore, it will be removed and destroyed.
      • release

        public void release​(ObjectT object)
        Release a reference to a shared client instance. If that instance is not used anymore, it will be removed and destroyed.
      • pooledClientFactory

        public static <ClientT extends software.amazon.awssdk.core.SdkClient,​BuilderT extends software.amazon.awssdk.awscore.client.builder.AwsClientBuilder<BuilderT,​ClientT>> ObjectPool.ClientPool<ClientT> pooledClientFactory​(BuilderT builder)