Interface ProcessorMetaSupplier
- All Superinterfaces:
Serializable
- All Known Implementing Classes:
ProcessorMetaSupplier.RandomMemberPms
,ProcessorMetaSupplier.SpecificMemberPms
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
ProcessorSupplier
instances. The starting point of the
chain leading to the eventual creation of Processor
instances on
each cluster member:
-
client or member creates
ProcessorMetaSupplier
as a part of the DAG; -
client or member sends it to the job coordinator (if the member is job coordinator
and the DAG consists of reusable
ProcessorMetaSupplier
s, the serialization may be skipped); -
the job coordinator uses it to create one
ProcessorSupplier
for each cluster member; -
serializes each
ProcessorSupplier
and sends it to its target member; -
the target member deserializes and uses it to instantiate as many instances
of
Processor
as requested by the parallelism property on the correspondingVertex
.
ProcessorSupplier
s this meta-supplier
will be given access to the Hazelcast instance and, in particular, its
cluster topology and partitioning services. It can use the information from
these services to precisely parameterize each Processor
instance
that will be created on each member.- Since:
- Jet 3.0
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic interface
Context passed to the meta-supplier at init time on the member that received a job request from the client.static class
static class
static class
A meta-supplier that will only use the givenProcessorSupplier
on a node with givenAddress
or random member if address is not given. -
Method Summary
Modifier and TypeMethodDescriptiondefault void
Called on coordinator member after execution has finished on all members, successfully or not.default boolean
Returnstrue
if theclose(Throwable)
method of this instance is cooperative.static ProcessorMetaSupplier
forceTotalParallelismOne
(ProcessorSupplier supplier) Variant offorceTotalParallelismOne(ProcessorSupplier, String, Permission)
where the node for the supplier will be chosen randomly and without any required permission.static ProcessorMetaSupplier
forceTotalParallelismOne
(ProcessorSupplier supplier, Address memberAddress) Wraps the providedProcessorSupplier
into a meta-supplier that will only use the givenProcessorSupplier
on a node with the givenAddress
.static ProcessorMetaSupplier
forceTotalParallelismOne
(ProcessorSupplier supplier, String partitionKey) Variant offorceTotalParallelismOne(ProcessorSupplier, String, Permission)
without any required permission.static ProcessorMetaSupplier
forceTotalParallelismOne
(ProcessorSupplier supplier, String partitionKey, Permission permission) Wraps the providedProcessorSupplier
into a meta-supplier that will only use the givenProcessorSupplier
on a single node.static ProcessorMetaSupplier
forceTotalParallelismOne
(ProcessorSupplier supplier, Permission permission) Variant offorceTotalParallelismOne(ProcessorSupplier, String, Permission)
where the node for the supplier will be chosen randomly.Function<? super Address,
? extends ProcessorSupplier> Called to create a mapping from memberAddress
to theProcessorSupplier
that will be sent to that member.default Permission
Returns the required permission to execute the vertex which has this ProcessorMetaSupplier.getTags()
Returns the metadata on this supplier, a string-to-string map.default void
init
(ProcessorMetaSupplier.Context context) Called on the cluster member that receives the job request.default boolean
default boolean
Returnstrue
if the same instance can be reused in different job executions or in different vertices.static ProcessorMetaSupplier
of
(int preferredLocalParallelism, FunctionEx<? super Address, ? extends ProcessorSupplier> addressToSupplier) Factory method that creates aProcessorMetaSupplier
from the supplied function that maps a cluster member address to aProcessorSupplier
.static ProcessorMetaSupplier
of
(int preferredLocalParallelism, SupplierEx<? extends Processor> procSupplier) Factory method that wraps the givenSupplier<Processor>
and uses it as the supplier of allProcessor
instances.static ProcessorMetaSupplier
of
(int preferredLocalParallelism, ProcessorSupplier procSupplier) Variant ofof(int, Permission, ProcessorSupplier)
where the processor does not require any permission to run.static ProcessorMetaSupplier
of
(int preferredLocalParallelism, Permission permission, ProcessorSupplier procSupplier) Factory method that wraps the givenProcessorSupplier
and returns the same instance for each givenAddress
.static ProcessorMetaSupplier
of
(FunctionEx<? super Address, ? extends ProcessorSupplier> addressToSupplier) Factory method that creates aProcessorMetaSupplier
from the supplied function that maps a cluster member address to aProcessorSupplier
.static ProcessorMetaSupplier
of
(SupplierEx<? extends Processor> procSupplier) Factory method that wraps the givenSupplier<Processor>
and uses it as the supplier of allProcessor
instances.static ProcessorMetaSupplier
of
(ProcessorSupplier procSupplier) Variant ofof(Permission, ProcessorSupplier)
where the processor does not require any permission to run.static ProcessorMetaSupplier
of
(Permission permission, ProcessorSupplier procSupplier) Wraps the providedProcessorSupplier
into a meta-supplier that will always return it.static ProcessorMetaSupplier
preferLocalParallelismOne
(SupplierEx<? extends Processor> procSupplier) Variant ofpreferLocalParallelismOne(ProcessorSupplier)
where the suppliedSupplierEx<Processor>
will be wrapped into aProcessorSupplier
.static ProcessorMetaSupplier
preferLocalParallelismOne
(ProcessorSupplier supplier) Wraps the providedProcessorSupplier
into a meta-supplier that will always return it.static ProcessorMetaSupplier
preferLocalParallelismOne
(Permission permission, SupplierEx<? extends Processor> procSupplier) Variant ofpreferLocalParallelismOne(SupplierEx)
where the processor requires given permission to run.static ProcessorMetaSupplier
preferLocalParallelismOne
(Permission permission, ProcessorSupplier supplier) Variant ofpreferLocalParallelismOne(ProcessorSupplier)
where the processor requires given permission to run.default int
Returns the local parallelism the vertex should be configured with.static ProcessorMetaSupplier
randomMember
(ProcessorSupplier supplier) Wraps the providedProcessorSupplier
into a meta-supplier that will only use the givenProcessorSupplier
on a random node
-
Method Details
-
getRequiredPermission
Returns the required permission to execute the vertex which has this ProcessorMetaSupplier. This is an Enterprise feature. -
getTags
Returns the metadata on this supplier, a string-to-string map. There is no predefined metadata; this facility exists to allow the DAG vertices to contribute some information to the execution planning phase.- Since:
- Jet 4.0
-
preferredLocalParallelism
default int preferredLocalParallelism()Returns the local parallelism the vertex should be configured with. The default implementation returnsVertex.LOCAL_PARALLELISM_USE_DEFAULT
. -
init
Called on the cluster member that receives the job request. Gives access to the Hazelcast instance's services and provides the parallelism parameters determined from the cluster size.- Throws:
Exception
- See Also:
-
initIsCooperative
default boolean initIsCooperative()Returnstrue
if both theinit(Context)
andget(List)
methods of this instance are cooperative. If they are not, the call to theinit()
andget()
method is off-loaded to another thread.- Since:
- 5.2
-
get
@Nonnull Function<? super Address,? extends ProcessorSupplier> get(@Nonnull List<Address> addresses) Called to create a mapping from memberAddress
to theProcessorSupplier
that will be sent to that member. Jet calls this method with a list of all cluster members' addresses and the returned function must be a mapping that returns a non-null value for each given address.The method will be called once per job execution on the job's coordinator member.
init()
will have already been called.- See Also:
-
closeIsCooperative
default boolean closeIsCooperative()Returnstrue
if theclose(Throwable)
method of this instance is cooperative. If it's not, the call to theclose()
method is off-loaded to another thread.- Since:
- 5.2
-
close
Called on coordinator member after execution has finished on all members, successfully or not. This method will be called afterProcessorSupplier.close(Throwable)
has been called on all available members. The job can be restarted later.If there is an exception during the creation of the execution plan, this method will be called regardless of whether the
init()
orget()
method have been called or not. If this method throws an exception, it will be logged and ignored; it won't be reported as a job failure.If you rely on the fact that this method is run once per cluster, it can happen that it is not called at all, if the coordinator member crashed. It can be also called multiple times, if the job restarts.
- Parameters:
error
- the exception (if any) that caused the job to fail;null
in the case of successful job completion. Note that it might not be the actual error that caused the job to fail - it can be several other exceptions. We only guarantee that it's non-null if the job didn't complete successfully.- Throws:
Exception
- See Also:
-
isReusable
default boolean isReusable()Returnstrue
if the same instance can be reused in different job executions or in different vertices. In that case,init(com.hazelcast.jet.core.ProcessorMetaSupplier.Context)
,get(java.util.List<com.hazelcast.cluster.Address>)
andclose(java.lang.Throwable)
methods must be thread-safe and obey additional conditions defined below.When a job is submitted from a client, the job definition is serialized, so the job coordinator will receive a different copy of processor meta-suppliers even if they are used multiple times within the same DAG, or across different DAGs, or submitted through different jobs. While this serialization mechanism ensures that processor meta-supplier instances do not share any internal state, it is unnecessary —and avoided— for jobs consisting of reusable meta-suppliers and submitted from the job coordinator —which is always the case for member-originated light jobs.
Non-reusable meta-suppliers (default) have a simple order of method executions:
init(com.hazelcast.jet.core.ProcessorMetaSupplier.Context)
(once),get(java.util.List<com.hazelcast.cluster.Address>)
(at most once afterinit(com.hazelcast.jet.core.ProcessorMetaSupplier.Context)
,close(java.lang.Throwable)
(last).Reusable meta-suppliers differ because the meta supplier instance may be shared and reused. That is why:
-
init(com.hazelcast.jet.core.ProcessorMetaSupplier.Context)
can be invoked multiple times (also afterclose(java.lang.Throwable)
). -
get(java.util.List<com.hazelcast.cluster.Address>)
can be invoked multiple times, but eachget(java.util.List<com.hazelcast.cluster.Address>)
invocation will be preceded byinit(com.hazelcast.jet.core.ProcessorMetaSupplier.Context)
invocation for given job execution. -
close(java.lang.Throwable)
can be invoked multiple times with or without preceding invocations of the other methods. - Meta-supplier method invocation sequences for different concurrent job executions may be interleaved.
init(com.hazelcast.jet.core.ProcessorMetaSupplier.Context)
method, for example, save some constant data fromProcessorMetaSupplier.Context
for further usage. Note, however, that cluster topology may change and should not be stored.- Since:
- 5.3
-
-
of
@Nonnull static ProcessorMetaSupplier of(int preferredLocalParallelism, @Nullable Permission permission, @Nonnull ProcessorSupplier procSupplier) Factory method that wraps the givenProcessorSupplier
and returns the same instance for each givenAddress
.- Parameters:
preferredLocalParallelism
- the value to return frompreferredLocalParallelism()
permission
- the required permission to run the processorprocSupplier
- the processor supplier
-
of
@Nonnull static ProcessorMetaSupplier of(int preferredLocalParallelism, @Nonnull ProcessorSupplier procSupplier) Variant ofof(int, Permission, ProcessorSupplier)
where the processor does not require any permission to run. -
of
@Nonnull static ProcessorMetaSupplier of(@Nullable Permission permission, @Nonnull ProcessorSupplier procSupplier) Wraps the providedProcessorSupplier
into a meta-supplier that will always return it. ThepreferredLocalParallelism()
of the meta-supplier will beVertex.LOCAL_PARALLELISM_USE_DEFAULT
. -
of
Variant ofof(Permission, ProcessorSupplier)
where the processor does not require any permission to run. -
of
@Nonnull static ProcessorMetaSupplier of(int preferredLocalParallelism, @Nonnull SupplierEx<? extends Processor> procSupplier) Factory method that wraps the givenSupplier<Processor>
and uses it as the supplier of allProcessor
instances. Specifically, returns a meta-supplier that will always return the result of callingProcessorSupplier.of(SupplierEx)
.- Parameters:
preferredLocalParallelism
- the value to return frompreferredLocalParallelism()
procSupplier
- the supplier of processors
-
of
Factory method that wraps the givenSupplier<Processor>
and uses it as the supplier of allProcessor
instances. Specifically, returns a meta-supplier that will always return the result of callingProcessorSupplier.of(SupplierEx)
. ThepreferredLocalParallelism()
of the meta-supplier will beVertex.LOCAL_PARALLELISM_USE_DEFAULT
. -
of
@Nonnull static ProcessorMetaSupplier of(int preferredLocalParallelism, @Nonnull FunctionEx<? super Address, ? extends ProcessorSupplier> addressToSupplier) Factory method that creates aProcessorMetaSupplier
from the supplied function that maps a cluster member address to aProcessorSupplier
.- Parameters:
preferredLocalParallelism
- the value to return frompreferredLocalParallelism()
addressToSupplier
- the mapping from address to ProcessorSupplier
-
of
@Nonnull static ProcessorMetaSupplier of(@Nonnull FunctionEx<? super Address, ? extends ProcessorSupplier> addressToSupplier) Factory method that creates aProcessorMetaSupplier
from the supplied function that maps a cluster member address to aProcessorSupplier
. ThepreferredLocalParallelism()
of the meta-supplier will beVertex.LOCAL_PARALLELISM_USE_DEFAULT
. -
preferLocalParallelismOne
@Nonnull static ProcessorMetaSupplier preferLocalParallelismOne(@Nonnull ProcessorSupplier supplier) Wraps the providedProcessorSupplier
into a meta-supplier that will always return it. ThepreferredLocalParallelism()
of the meta-supplier will be one, i.e., no local parallelization.The parallelism will be overridden if the
Vertex.localParallelism(int)
is set to a specific value. -
preferLocalParallelismOne
@Nonnull static ProcessorMetaSupplier preferLocalParallelismOne(@Nullable Permission permission, @Nonnull ProcessorSupplier supplier) Variant ofpreferLocalParallelismOne(ProcessorSupplier)
where the processor requires given permission to run. -
preferLocalParallelismOne
@Nonnull static ProcessorMetaSupplier preferLocalParallelismOne(@Nonnull SupplierEx<? extends Processor> procSupplier) Variant ofpreferLocalParallelismOne(ProcessorSupplier)
where the suppliedSupplierEx<Processor>
will be wrapped into aProcessorSupplier
. -
preferLocalParallelismOne
@Nonnull static ProcessorMetaSupplier preferLocalParallelismOne(@Nullable Permission permission, @Nonnull SupplierEx<? extends Processor> procSupplier) Variant ofpreferLocalParallelismOne(SupplierEx)
where the processor requires given permission to run. -
forceTotalParallelismOne
@Nonnull static ProcessorMetaSupplier forceTotalParallelismOne(@Nonnull ProcessorSupplier supplier, @Nullable Permission permission) Variant offorceTotalParallelismOne(ProcessorSupplier, String, Permission)
where the node for the supplier will be chosen randomly. -
forceTotalParallelismOne
Variant offorceTotalParallelismOne(ProcessorSupplier, String, Permission)
where the node for the supplier will be chosen randomly and without any required permission. -
forceTotalParallelismOne
@Nonnull static ProcessorMetaSupplier forceTotalParallelismOne(@Nonnull ProcessorSupplier supplier, @Nonnull String partitionKey) Variant offorceTotalParallelismOne(ProcessorSupplier, String, Permission)
without any required permission. -
forceTotalParallelismOne
@Nonnull static ProcessorMetaSupplier forceTotalParallelismOne(@Nonnull ProcessorSupplier supplier, @Nonnull String partitionKey, @Nullable Permission permission) Wraps the providedProcessorSupplier
into a meta-supplier that will only use the givenProcessorSupplier
on a single node. The node will be chosen according to thepartitionKey
supplied. This is mainly provided as a convenience for implementing non-distributed sources where data can't be read in parallel by multiple consumers. When used as a sink or intermediate vertex, the DAG should ensure that only the processor instance on the designated node receives any data, otherwise anIllegalStateException
will be thrown.The vertex containing the
ProcessorMetaSupplier
must have a local parallelism setting of 1, otherwise {code IllegalArgumentException} is thrown.- Parameters:
supplier
- the supplier that will be wrappedpartitionKey
- the supplier will only be created on the node that owns the supplied partition keypermission
- the required permission to run the processor- Returns:
- the wrapped
ProcessorMetaSupplier
- Throws:
IllegalArgumentException
- if vertex has local parallelism setting of greater than 1
-
forceTotalParallelismOne
@Nonnull static ProcessorMetaSupplier forceTotalParallelismOne(@Nonnull ProcessorSupplier supplier, @Nonnull Address memberAddress) Wraps the providedProcessorSupplier
into a meta-supplier that will only use the givenProcessorSupplier
on a node with the givenAddress
. This is mainly provided as a convenience for implementing non-distributed sources where data can't be read in parallel by multiple consumers. When used as a sink or intermediate vertex, the DAG should ensure that only the processor instance on the designated node receives any data, otherwise anIllegalStateException
will be thrown.The vertex containing the
ProcessorMetaSupplier
must have a local parallelism setting of 1, otherwise {code IllegalArgumentException} is thrown.- Parameters:
supplier
- the supplier that will be wrappedmemberAddress
- the supplier will only be created on the node with givenAddress
- Returns:
- the wrapped
ProcessorMetaSupplier
- Throws:
IllegalArgumentException
- if vertex has local parallelism setting of greater than 1
-
randomMember
Wraps the providedProcessorSupplier
into a meta-supplier that will only use the givenProcessorSupplier
on a random node- Parameters:
supplier
- the supplier that will be wrapped- Returns:
- the wrapped
ProcessorMetaSupplier
- Since:
- 5.3
-