public class IgniteServicesImpl extends AsyncSupportAdapter implements IgniteServices, Externalizable
IgniteServices
implementation.curFut
Constructor and Description |
---|
IgniteServicesImpl()
Required by
Externalizable . |
IgniteServicesImpl(GridKernalContext ctx,
ClusterGroupAdapter prj,
boolean async) |
Modifier and Type | Method and Description |
---|---|
void |
cancel(String name)
Cancels service deployment.
|
void |
cancelAll()
Cancels all deployed services.
|
IgniteFuture<Void> |
cancelAllAsync()
Asynchronously cancels all deployed services.
|
IgniteFuture<Void> |
cancelAsync(String name)
Asynchronously cancels service deployment.
|
ClusterGroup |
clusterGroup()
Gets the cluster group to which this
IgniteServices instance belongs. |
void |
deploy(ServiceConfiguration cfg)
Deploys multiple instances of the service on the grid according to provided
configuration.
|
IgniteFuture<Void> |
deployAsync(ServiceConfiguration cfg)
Asynchronously deploys multiple instances of the service on the grid according to provided
configuration.
|
void |
deployClusterSingleton(String name,
Service svc)
Deploys a cluster-wide singleton service.
|
IgniteFuture<Void> |
deployClusterSingletonAsync(String name,
Service svc)
Asynchronously deploys a cluster-wide singleton service.
|
void |
deployKeyAffinitySingleton(String name,
Service svc,
String cacheName,
Object affKey)
Deploys one instance of this service on the primary node for a given affinity key.
|
IgniteFuture<Void> |
deployKeyAffinitySingletonAsync(String name,
Service svc,
String cacheName,
Object affKey)
Asynchronously deploys one instance of this service on the primary node for a given affinity key.
|
void |
deployMultiple(String name,
Service svc,
int totalCnt,
int maxPerNodeCnt)
Deploys multiple instances of the service on the grid.
|
IgniteFuture<Void> |
deployMultipleAsync(String name,
Service svc,
int totalCnt,
int maxPerNodeCnt)
Asynchronously deploys multiple instances of the service on the grid.
|
void |
deployNodeSingleton(String name,
Service svc)
Deploys a per-node singleton service.
|
IgniteFuture<Void> |
deployNodeSingletonAsync(String name,
Service svc)
Asynchronously deploys a per-node singleton service.
|
void |
readExternal(ObjectInput in) |
protected Object |
readResolve()
Reconstructs object on unmarshalling.
|
<T> T |
service(String name)
Gets locally deployed service with specified name.
|
Collection<ServiceDescriptor> |
serviceDescriptors()
Gets metadata about all deployed services in the grid.
|
<T> T |
serviceProxy(String name,
Class<? super T> svcItf,
boolean sticky)
Gets a remote handle on the service.
|
<T> T |
serviceProxy(String name,
Class<? super T> svcItf,
boolean sticky,
long timeout)
Gets a remote handle on the service with timeout.
|
<T> Collection<T> |
services(String name)
Gets all locally deployed services with specified name.
|
IgniteServices |
withAsync()
Gets instance of this component with asynchronous mode enabled.
|
void |
writeExternal(ObjectOutput out) |
createAsyncInstance, createFuture, future, future, isAsync, saveOrGet
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
future, isAsync
public IgniteServicesImpl()
Externalizable
.public IgniteServicesImpl(GridKernalContext ctx, ClusterGroupAdapter prj, boolean async)
ctx
- Kernal context.prj
- Projection.async
- Async support flag.public ClusterGroup clusterGroup()
IgniteServices
instance belongs.clusterGroup
in interface IgniteServices
IgniteServices
instance belongs.public void deployNodeSingleton(String name, Service svc)
This method is analogous to calling
deployMultiple(name, svc, 0, 1)
method.
deployNodeSingleton
in interface IgniteServices
name
- Service name.svc
- Service instance.public IgniteFuture<Void> deployNodeSingletonAsync(String name, Service svc) throws IgniteException
This method is analogous to calling
deployMultipleAsync(name, svc, 0, 1)
method.
deployNodeSingletonAsync
in interface IgniteServices
name
- Service name.svc
- Service instance.IgniteException
- If failed to deploy service.public void deployClusterSingleton(String name, Service svc)
Note that in case of topology changes, due to network delays, there may be a temporary situation when a singleton service instance will be active on more than one node (e.g. crash detection delay).
This method is analogous to calling
deployMultiple(name, svc, 1, 1)
method.
deployClusterSingleton
in interface IgniteServices
name
- Service name.svc
- Service instance.public IgniteFuture<Void> deployClusterSingletonAsync(String name, Service svc) throws IgniteException
Note that in case of topology changes, due to network delays, there may be a temporary situation when a singleton service instance will be active on more than one node (e.g. crash detection delay).
This method is analogous to calling
deployMultipleAsync(name, svc, 1, 1)
method.
deployClusterSingletonAsync
in interface IgniteServices
name
- Service name.svc
- Service instance.IgniteException
- If failed to deploy service.public void deployMultiple(String name, Service svc, int totalCnt, int maxPerNodeCnt)
'totalCnt'
parameter making sure that
there are no more than 'maxPerNodeCnt'
service instances running
on each node. Whenever topology changes, Ignite will automatically rebalance
the deployed services within cluster to make sure that each node will end up with
about equal number of deployed instances whenever possible.
Note that at least one of 'totalCnt'
or 'maxPerNodeCnt'
parameters must have
value greater than 0
.
This method is analogous to the invocation of IgniteServices.deploy(org.apache.ignite.services.ServiceConfiguration)
method as follows:
ServiceConfiguration cfg = new ServiceConfiguration(); cfg.setName(name); cfg.setService(svc); cfg.setTotalCount(totalCnt); cfg.setMaxPerNodeCount(maxPerNodeCnt); ignite.services().deploy(cfg);
deployMultiple
in interface IgniteServices
name
- Service name.svc
- Service instance.totalCnt
- Maximum number of deployed services in the grid, 0
for unlimited.maxPerNodeCnt
- Maximum number of deployed services on each node, 0
for unlimited.public IgniteFuture<Void> deployMultipleAsync(String name, Service svc, int totalCnt, int maxPerNodeCnt) throws IgniteException
'totalCnt'
parameter making sure that
there are no more than 'maxPerNodeCnt'
service instances running
on each node. Whenever topology changes, Ignite will automatically rebalance
the deployed services within cluster to make sure that each node will end up with
about equal number of deployed instances whenever possible.
Note that at least one of 'totalCnt'
or 'maxPerNodeCnt'
parameters must have
value greater than 0
.
This method is analogous to the invocation of
IgniteServices.deployAsync(org.apache.ignite.services.ServiceConfiguration)
method as follows:
ServiceConfiguration cfg = new ServiceConfiguration(); cfg.setName(name); cfg.setService(svc); cfg.setTotalCount(totalCnt); cfg.setMaxPerNodeCount(maxPerNodeCnt); ignite.services().deployAsync(cfg);
deployMultipleAsync
in interface IgniteServices
name
- Service name.svc
- Service instance.totalCnt
- Maximum number of deployed services in the grid, 0
for unlimited.maxPerNodeCnt
- Maximum number of deployed services on each node, 0
for unlimited.IgniteException
- If failed to deploy service.public void deployKeyAffinitySingleton(String name, Service svc, @Nullable String cacheName, Object affKey)
Note that in case of topology changes, due to network delays, there may be a temporary situation when a service instance will be active on more than one node (e.g. crash detection delay).
This method is analogous to the invocation of IgniteServices.deploy(org.apache.ignite.services.ServiceConfiguration)
method as follows:
ServiceConfiguration cfg = new ServiceConfiguration(); cfg.setName(name); cfg.setService(svc); cfg.setCacheName(cacheName); cfg.setAffinityKey(affKey); cfg.setTotalCount(1); cfg.setMaxPerNodeCount(1); ignite.services().deploy(cfg);
deployKeyAffinitySingleton
in interface IgniteServices
name
- Service name.svc
- Service instance.cacheName
- Name of the cache on which affinity for key should be calculated, null
for
default cache.affKey
- Affinity cache key.public IgniteFuture<Void> deployKeyAffinitySingletonAsync(String name, Service svc, @Nullable String cacheName, Object affKey) throws IgniteException
Note that in case of topology changes, due to network delays, there may be a temporary situation when a service instance will be active on more than one node (e.g. crash detection delay).
This method is analogous to the invocation of
IgniteServices.deployAsync(org.apache.ignite.services.ServiceConfiguration)
method as follows:
ServiceConfiguration cfg = new ServiceConfiguration(); cfg.setName(name); cfg.setService(svc); cfg.setCacheName(cacheName); cfg.setAffinityKey(affKey); cfg.setTotalCount(1); cfg.setMaxPerNodeCount(1); ignite.services().deployAsync(cfg);
deployKeyAffinitySingletonAsync
in interface IgniteServices
name
- Service name.svc
- Service instance.cacheName
- Name of the cache on which affinity for key should be calculated, null
for
default cache.affKey
- Affinity cache key.IgniteException
- If failed to deploy service.public void deploy(ServiceConfiguration cfg)
cfg.getTotalCount()
parameter
making sure that there are no more than
cfg.getMaxPerNodeCount()
service instances running on each node. Whenever topology changes, Ignite will automatically rebalance
the deployed services within cluster to make sure that each node will end up with
about equal number of deployed instances whenever possible.
If cfg.getAffinityKey()
is not null
, then Ignite will deploy the service on the primary node for given affinity key.
The affinity will be calculated on the cache with
cfg.getCacheName()
name.
If cfg.getNodeFilter()
is not null
, then Ignite will deploy service on all grid nodes for which
the provided filter evaluates to true
.
The node filter will be checked in addition to the underlying cluster group filter, or the
whole grid, if the underlying cluster group includes all the cluster nodes.
Note that at least one of 'totalCnt'
or 'maxPerNodeCnt'
parameters must have
value greater than 0
.
Here is an example of creating service deployment configuration:
ServiceConfiguration cfg = new ServiceConfiguration(); cfg.setName(name); cfg.setService(svc); cfg.setTotalCount(0); // Unlimited. cfg.setMaxPerNodeCount(2); // Deploy 2 instances of service on each node. ignite.services().deploy(cfg);
deploy
in interface IgniteServices
cfg
- Service configuration.public IgniteFuture<Void> deployAsync(ServiceConfiguration cfg) throws IgniteException
cfg.getTotalCount()
parameter
making sure that there are no more than
cfg.getMaxPerNodeCount()
service instances running on each node. Whenever topology changes, Ignite will automatically rebalance
the deployed services within cluster to make sure that each node will end up with
about equal number of deployed instances whenever possible.
If cfg.getAffinityKey()
is not null
, then Ignite
will deploy the service on the primary node for given affinity key. The affinity will be calculated
on the cache with cfg.getCacheName()
name.
If cfg.getNodeFilter()
is not null
, then Ignite will deploy service on all grid nodes
for which the provided filter evaluates to true
.
The node filter will be checked in addition to the underlying cluster group filter, or the
whole grid, if the underlying cluster group includes all the cluster nodes.
Note that at least one of 'totalCnt'
or 'maxPerNodeCnt'
parameters must have
value greater than 0
.
Here is an example of creating service deployment configuration:
ServiceConfiguration cfg = new ServiceConfiguration(); cfg.setName(name); cfg.setService(svc); cfg.setTotalCount(0); // Unlimited. cfg.setMaxPerNodeCount(2); // Deploy 2 instances of service on each node. ignite.services().deployAsync(cfg);
deployAsync
in interface IgniteServices
cfg
- Service configuration.IgniteException
- If failed to deploy service.public void cancel(String name)
Service.cancel(org.apache.ignite.services.ServiceContext)
method will be called on it.
Note that Ignite cannot guarantee that the service exits from
Service.execute(org.apache.ignite.services.ServiceContext)
method whenever Service.cancel(org.apache.ignite.services.ServiceContext)
is called. It is up to the user to make sure that the service code properly reacts to cancellations.
Supports asynchronous execution (see IgniteAsyncSupport
).
cancel
in interface IgniteServices
name
- Name of service to cancel.public IgniteFuture<Void> cancelAsync(String name) throws IgniteException
Service.cancel(org.apache.ignite.services.ServiceContext)
method will be called on it.
Note that Ignite cannot guarantee that the service exits from
Service.execute(org.apache.ignite.services.ServiceContext)
method whenever Service.cancel(org.apache.ignite.services.ServiceContext)
is called. It is up to the user to
make sure that the service code properly reacts to cancellations.
cancelAsync
in interface IgniteServices
name
- Name of service to cancel.IgniteException
- If failed to cancel service.public void cancelAll()
Note that depending on user logic, it may still take extra time for a service to finish execution, even after it was cancelled.
Supports asynchronous execution (see IgniteAsyncSupport
).
cancelAll
in interface IgniteServices
public IgniteFuture<Void> cancelAllAsync() throws IgniteException
Note that depending on user logic, it may still take extra time for a service to finish execution, even after it was cancelled.
cancelAllAsync
in interface IgniteServices
IgniteException
- If failed to cancel services.public Collection<ServiceDescriptor> serviceDescriptors()
serviceDescriptors
in interface IgniteServices
public <T> T service(String name)
service
in interface IgniteServices
T
- Service typename
- Service name.public <T> T serviceProxy(String name, Class<? super T> svcItf, boolean sticky) throws IgniteException
serviceProxy
in interface IgniteServices
name
- Service name.svcItf
- Interface for the service.sticky
- Whether or not Ignite should always contact the same remote
service or try to load-balance between services.IgniteException
- If failed to create service proxy.public <T> T serviceProxy(String name, Class<? super T> svcItf, boolean sticky, long timeout) throws IgniteException
serviceProxy
in interface IgniteServices
name
- Service name.svcItf
- Interface for the service.sticky
- Whether or not Ignite should always contact the same remote
service or try to load-balance between services.timeout
- If greater than 0 created proxy will wait for service availability only specified time,
and will limit remote service invocation time.IgniteException
- If failed to create service proxy.public <T> Collection<T> services(String name)
services
in interface IgniteServices
T
- Service type.name
- Service name.public IgniteServices withAsync()
withAsync
in interface IgniteServices
withAsync
in interface IgniteAsyncSupport
withAsync
in class AsyncSupportAdapter
public void writeExternal(ObjectOutput out) throws IOException
writeExternal
in interface Externalizable
IOException
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
readExternal
in interface Externalizable
IOException
ClassNotFoundException
protected Object readResolve() throws ObjectStreamException
ObjectStreamException
- Thrown in case of unmarshalling error.
Follow @ApacheIgnite
Ignite Fabric : ver. 2.0.0 Release Date : April 30 2017