Class ServiceFactory<C,​S>

    • Method Detail

      • withDestroyContextFn

        @Nonnull
        public ServiceFactory<C,​S> withDestroyContextFn​(@Nonnull
                                                              ConsumerEx<? super C> destroyContextFn)
        Returns a copy of this ServiceFactory with the destroyContext function replaced with the given function.

        Jet calls this function at the end of the job for each shared context object it created (one on each cluster member).

        Parameters:
        destroyContextFn - the function to destroy the shared service context. It must be stateless.
        Returns:
        a copy of this factory with the supplied destroy-function
      • withCreateServiceFn

        @Nonnull
        public <S_NEW> ServiceFactory<C,​S_NEW> withCreateServiceFn​(@Nonnull
                                                                         BiFunctionEx<? super Processor.Context,​? super C,​? extends S_NEW> createServiceFn)
        Returns a copy of this ServiceFactory with the given createService function.

        Jet calls this function to create each parallel instance of the service object (their number on each cluster member is determined by stage.localParallelism). Each invocation gets the shared context instance as the parameter, as well as the lower-level Processor.Context.

        Since the call of this method establishes the <S> type parameter of the service factory, you must call it before setting the destroyService function. Calling this method resets any pre-existing destroyService function to a no-op.

        Parameters:
        createServiceFn - the function that creates the service instance. It must be stateless.
        Returns:
        a copy of this factory with the supplied create-service-function
      • withDestroyServiceFn

        @Nonnull
        public ServiceFactory<C,​S> withDestroyServiceFn​(@Nonnull
                                                              ConsumerEx<? super S> destroyServiceFn)
        Returns a copy of this ServiceFactory with the destroyService function replaced with the given function.

        The destroy function is called at the end of the job to destroy all created services objects.

        Parameters:
        destroyServiceFn - the function to destroy the service instance. This function is called once per processor instance. It must be stateless.
        Returns:
        a copy of this factory with the supplied destroy-function
      • toNonCooperative

        @Nonnull
        public ServiceFactory<C,​S> toNonCooperative()
        Returns a copy of this ServiceFactory with the isCooperative flag set to false. Call this method if your service doesn't follow the cooperative processor contract, that is if it waits for IO, blocks for synchronization, takes too long to complete etc. If the service will perform async operations, you can typically use a cooperative processor. Cooperative processors offer higher performance.
        Returns:
        a copy of this factory with the isCooperative flag set to false.
      • setCooperative

        @Nonnull
        public ServiceFactory<C,​S> setCooperative​(boolean cooperative)
        Returns a copy of this ServiceFactory with the isCooperative flag set to cooperative argument value.

        Note: if the service will perform async operations, you can typically use a cooperative processor. Cooperative processors offer higher performance.

        Returns:
        a copy of this factory with the isCooperative flag changed.
      • withAttachedFile

        @Nonnull
        public ServiceFactory<C,​S> withAttachedFile​(@Nonnull
                                                          java.lang.String id,
                                                          @Nonnull
                                                          java.io.File file)
        Attaches a file to this service factory under the given ID. It will become a part of the Jet job and available to createContextFn() as procSupplierContext.attachedFile(id).
        Returns:
        a copy of this factory with the file attached
        Since:
        Jet 4.0
      • withAttachedDirectory

        @Nonnull
        public ServiceFactory<C,​S> withAttachedDirectory​(@Nonnull
                                                               java.lang.String id,
                                                               @Nonnull
                                                               java.io.File directory)
        Attaches a directory to this service factory under the given ID. It will become a part of the Jet job and available to createContextFn() as procSupplierContext.attachedDirectory(id).
        Returns:
        a copy of this factory with the directory attached
        Since:
        Jet 4.0
      • withoutAttachedFiles

        @Nonnull
        public ServiceFactory<C,​S> withoutAttachedFiles()
        Returns a copy of this ServiceFactory with any attached files removed.
        Since:
        Jet 4.0
      • withPermission

        @Nonnull
        public ServiceFactory<C,​S> withPermission​(@Nonnull
                                                        java.security.Permission permission)
        Returns a copy of this ServiceFactory with setting the required permission. This is en Enterprise feature.
      • isCooperative

        public boolean isCooperative()
        Returns the isCooperative flag, see toNonCooperative().
      • permission

        @Nullable
        public java.security.Permission permission()
        Returns the required permission to use this factory. This is an Enterprise feature.
      • clone

        protected ServiceFactory<C,​S> clone()
        Overrides:
        clone in class java.lang.Object