Interface IgniteServices
-
- All Superinterfaces:
IgniteAsyncSupport
public interface IgniteServices extends IgniteAsyncSupport
Defines functionality necessary to deploy distributed services on the grid.Instance of
IgniteServices
which spans all cluster nodes can be obtained from Ignite as follows:Ignite ignite = Ignition.ignite(); IgniteServices svcs = ignite.services();
You can also obtain an instance of the services facade over a specific cluster group:// Cluster group over remote nodes (excluding the local node). ClusterGroup remoteNodes = ignite.cluster().forRemotes(); // Services instance spanning all remote cluster nodes. IgniteServices svcs = ignite.services(remoteNodes);
With distributed services you can do the following:
- Automatically deploy any number of service instances on the grid.
- Automatically deploy singletons, including cluster-singleton, node-singleton, or key-affinity-singleton.
- Automatically deploy services on node start-up by specifying them in grid configuration.
- Undeploy any of the deployed services.
- Get information about service deployment topology within the grid.
Deployment From Configuration
In addition to deploying managed services by calling any of the provideddeploy(...)
methods, you can also automatically deploy services on startup by specifying them inIgniteConfiguration
like so:IgniteConfiguration cfg = new IgniteConfiguration(); ServiceConfiguration svcCfg1 = new ServiceConfiguration(); // Cluster-wide singleton configuration. svcCfg1.setName("myClusterSingletonService"); svcCfg1.setMaxPerNodeCount(1); svcCfg1.setTotalCount(1); svcCfg1.setService(new MyClusterSingletonService()); ServiceConfiguration svcCfg2 = new ServiceConfiguration(); // Per-node singleton configuration. svcCfg2.setName("myNodeSingletonService"); svcCfg2.setMaxPerNodeCount(1); svcCfg2.setService(new MyNodeSingletonService()); cfg.setServiceConfiguration(svcCfg1, svcCfg2); ... Ignition.start(cfg);
Load Balancing
In all cases, other than singleton service deployment, Ignite will automatically make sure that an about equal number of services are deployed on each node within the grid. Whenever cluster topology changes, Ignite will re-evaluate service deployments and may re-deploy an already deployed service on another node for better load balancing.Fault Tolerance
Ignite guarantees that services are deployed according to specified configuration regardless of any topology changes, including node crashes.Resource Injection
All distributed services can be injected with ignite resources. Both, field and method based injections are supported. The following ignite resources can be injected: Refer to corresponding resource documentation for more information.Service Example
Here is an example of how an distributed service may be implemented and deployed:// Simple service implementation. public class MyIgniteService implements Service { ... // Example of ignite resource injection. All resources are optional. // You should inject resources only as needed. @IgniteInstanceResource private Ignite ignite; ... @Override public void cancel(ServiceContext ctx) { // No-op. } @Override public void execute(ServiceContext ctx) { // Loop until service is cancelled. while (!ctx.isCancelled()) { // Do something. ... } } } ... IgniteServices svcs = ignite.services(); svcs.deployClusterSingleton("mySingleton", new MyIgniteService());
-
-
Method Summary
All Methods Instance Methods Abstract Methods Deprecated Methods Modifier and Type Method Description void
cancel(String name)
Cancels service deployment.void
cancelAll()
Cancels all deployed services.void
cancelAll(Collection<String> names)
Cancels services with specified names.IgniteFuture<Void>
cancelAllAsync()
Asynchronously cancels all deployed services.IgniteFuture<Void>
cancelAllAsync(Collection<String> names)
Asynchronously cancels services with specified names.IgniteFuture<Void>
cancelAsync(String name)
Asynchronously cancels service deployment.ClusterGroup
clusterGroup()
Gets the cluster group to which thisIgniteServices
instance belongs.void
deploy(ServiceConfiguration cfg)
Deploys multiple instances of the service on the grid according to provided configuration.void
deployAll(Collection<ServiceConfiguration> cfgs)
Deploys multiple services described by provided configurations.IgniteFuture<Void>
deployAllAsync(Collection<ServiceConfiguration> cfgs)
Asynchronously deploys multiple services described by provided configurations.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, @Nullable 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, @Nullable 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.<T> T
service(String name)
Deprecated.Use the proxies likeserviceProxy(String, Class, boolean)
.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 handle on remote or local service.<T> T
serviceProxy(String name, Class<? super T> svcItf, boolean sticky, long timeout)
Gets a handle on remote or local service with the timeout.<T> T
serviceProxy(String name, Class<? super T> svcItf, boolean sticky, ServiceCallContext callCtx)
Gets a handle on remote or local service with the specified caller context.<T> T
serviceProxy(String name, Class<? super T> svcItf, boolean sticky, ServiceCallContext callCtx, long timeout)
Gets a handle on remote or local service with the specified caller context and the timeout.<T> Collection<T>
services(String name)
Deprecated.Use the proxies likeserviceProxy(String, Class, boolean)
.IgniteServices
withAsync()
Deprecated.-
Methods inherited from interface org.apache.ignite.lang.IgniteAsyncSupport
future, isAsync
-
-
-
-
Method Detail
-
clusterGroup
ClusterGroup clusterGroup()
Gets the cluster group to which thisIgniteServices
instance belongs.- Returns:
- Cluster group to which this
IgniteServices
instance belongs.
-
deployClusterSingleton
@IgniteAsyncSupported void deployClusterSingleton(String name, Service svc) throws ServiceDeploymentException
Deploys a cluster-wide singleton service. Ignite will guarantee that there is always one instance of the service in the cluster. In case if grid node on which the service was deployed crashes or stops, Ignite will automatically redeploy it on another node. However, if the node on which the service is deployed remains in topology, then the service will always be deployed on that node only, regardless of topology changes.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.- Parameters:
name
- Service name.svc
- Service instance.- Throws:
ServiceDeploymentException
- If failed to deploy service.
-
deployClusterSingletonAsync
IgniteFuture<Void> deployClusterSingletonAsync(String name, Service svc)
Asynchronously deploys a cluster-wide singleton service. Ignite will guarantee that there is always one instance of the service in the cluster. In case if grid node on which the service was deployed crashes or stops, Ignite will automatically redeploy it on another node. However, if the node on which the service is deployed remains in topology, then the service will always be deployed on that node only, regardless of topology changes.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.- Parameters:
name
- Service name.svc
- Service instance.- Returns:
- a Future representing pending completion of the operation.
-
deployNodeSingleton
@IgniteAsyncSupported void deployNodeSingleton(String name, Service svc) throws ServiceDeploymentException
Deploys a per-node singleton service. Ignite will guarantee that there is always one instance of the service running on each node. Whenever new nodes are started within the underlying cluster group, Ignite will automatically deploy one instance of the service on every new node.This method is analogous to calling
deployMultiple(name, svc, 0, 1)
method.- Parameters:
name
- Service name.svc
- Service instance.- Throws:
ServiceDeploymentException
- If failed to deploy service.
-
deployNodeSingletonAsync
IgniteFuture<Void> deployNodeSingletonAsync(String name, Service svc)
Asynchronously deploys a per-node singleton service. Ignite will guarantee that there is always one instance of the service running on each node. Whenever new nodes are started within the underlying cluster group, Ignite will automatically deploy one instance of the service on every new node.This method is analogous to calling
deployMultipleAsync(name, svc, 0, 1)
method.- Parameters:
name
- Service name.svc
- Service instance.- Returns:
- a Future representing pending completion of the operation.
-
deployKeyAffinitySingleton
@IgniteAsyncSupported void deployKeyAffinitySingleton(String name, Service svc, @Nullable @Nullable String cacheName, Object affKey) throws ServiceDeploymentException
Deploys one instance of this service on the primary node for a given affinity key. Whenever topology changes and primary node assignment changes, Ignite will always make sure that the service is undeployed on the previous primary node and deployed on the new primary node.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
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);
- Parameters:
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.- Throws:
ServiceDeploymentException
- If failed to deploy service.
-
deployKeyAffinitySingletonAsync
IgniteFuture<Void> deployKeyAffinitySingletonAsync(String name, Service svc, @Nullable @Nullable String cacheName, Object affKey)
Asynchronously deploys one instance of this service on the primary node for a given affinity key. Whenever topology changes and primary node assignment changes, Ignite will always make sure that the service is undeployed on the previous primary node and deployed on the new primary node.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
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);
- Parameters:
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.- Returns:
- a Future representing pending completion of the operation.
-
deployMultiple
@IgniteAsyncSupported void deployMultiple(String name, Service svc, int totalCnt, int maxPerNodeCnt) throws ServiceDeploymentException
Deploys multiple instances of the service on the grid. Ignite will deploy a maximum amount of services equal to'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 than0
.This method is analogous to the invocation of
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);
- Parameters:
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.- Throws:
ServiceDeploymentException
- If failed to deploy service.
-
deployMultipleAsync
IgniteFuture<Void> deployMultipleAsync(String name, Service svc, int totalCnt, int maxPerNodeCnt)
Asynchronously deploys multiple instances of the service on the grid. Ignite will deploy a maximum amount of services equal to'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 than0
.This method is analogous to the invocation of
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);
- Parameters:
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.- Returns:
- a Future representing pending completion of the operation.
-
deploy
@IgniteAsyncSupported void deploy(ServiceConfiguration cfg) throws ServiceDeploymentException
Deploys multiple instances of the service on the grid according to provided configuration. Ignite will deploy a maximum amount of services equal tocfg.getTotalCount()
parameter making sure that there are no more thancfg.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 notnull
, then Ignite will deploy the service on the primary node for given affinity key. The affinity will be calculated on the cache withcfg.getCacheName()
name.If
cfg.getNodeFilter()
is notnull
, then Ignite will deploy service on all grid nodes for which the provided filter evaluates totrue
. 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 than0
.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);
- Parameters:
cfg
- Service configuration.- Throws:
ServiceDeploymentException
- If failed to deploy service.
-
deployAsync
IgniteFuture<Void> deployAsync(ServiceConfiguration cfg)
Asynchronously deploys multiple instances of the service on the grid according to provided configuration. Ignite will deploy a maximum amount of services equal tocfg.getTotalCount()
parameter making sure that there are no more thancfg.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 notnull
, then Ignite will deploy the service on the primary node for given affinity key. The affinity will be calculated on the cache withcfg.getCacheName()
name.If
cfg.getNodeFilter()
is notnull
, then Ignite will deploy service on all grid nodes for which the provided filter evaluates totrue
. 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 than0
.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);
- Parameters:
cfg
- Service configuration.- Returns:
- a Future representing pending completion of the operation.
-
deployAll
void deployAll(Collection<ServiceConfiguration> cfgs) throws ServiceDeploymentException
Deploys multiple services described by provided configurations. Depending on specified parameters, multiple instances of the same service may be deployed (seeServiceConfiguration
). 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 deployment of some of the provided services fails, thenServiceDeploymentException
containing a list of failed services will be thrown. It is guaranteed that all services that were provided to this method and are not present in the list of failed services are successfully deployed by the moment of the exception being thrown. Note that if exception is thrown, then partial deployment may have occurred.- Parameters:
cfgs
-Collection
of service configurations to be deployed.- Throws:
ServiceDeploymentException
- If failed to deploy services.- See Also:
deploy(ServiceConfiguration)
,deployAllAsync(Collection)
-
deployAllAsync
IgniteFuture<Void> deployAllAsync(Collection<ServiceConfiguration> cfgs)
Asynchronously deploys multiple services described by provided configurations. Depending on specified parameters, multiple instances of the same service may be deployed (seeServiceConfiguration
). 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 deployment of some of the provided services fails, thenServiceDeploymentException
containing a list of failed services will be thrown fromget()
method of the returned future. It is guaranteed that all services, that were provided to this method and are not present in the list of failed services, are successfully deployed by the moment of the exception being thrown. Note that if exception is thrown, then partial deployment may have occurred.- Parameters:
cfgs
-Collection
of service configurations to be deployed.- Returns:
- a Future representing pending completion of the operation.
- See Also:
deploy(ServiceConfiguration)
,deployAll(Collection)
-
cancel
@IgniteAsyncSupported void cancel(String name) throws IgniteException
Cancels service deployment. If a service with specified name was deployed on the grid, thenService.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 wheneverService.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
).- Parameters:
name
- Name of service to cancel.- Throws:
IgniteException
- If failed to cancel service.
-
cancelAsync
IgniteFuture<Void> cancelAsync(String name)
Asynchronously cancels service deployment. If a service with specified name was deployed on the grid, thenService.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 wheneverService.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.- Parameters:
name
- Name of service to cancel.- Returns:
- a Future representing pending completion of the operation.
-
cancelAll
@IgniteAsyncSupported void cancelAll(Collection<String> names) throws IgniteException
Cancels services with specified names.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
).- Parameters:
names
- Names of services to cancel.- Throws:
IgniteException
- If failed to cancel services.
-
cancelAllAsync
IgniteFuture<Void> cancelAllAsync(Collection<String> names)
Asynchronously cancels services with specified names.Note that depending on user logic, it may still take extra time for a service to finish execution, even after it was cancelled.
- Parameters:
names
- Names of services to cancel.- Returns:
- a Future representing pending completion of the operation.
-
cancelAll
@IgniteAsyncSupported void cancelAll() throws IgniteException
Cancels all deployed services.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
).- Throws:
IgniteException
- If failed to cancel services.
-
cancelAllAsync
IgniteFuture<Void> cancelAllAsync()
Asynchronously cancels all deployed services.Note that depending on user logic, it may still take extra time for a service to finish execution, even after it was cancelled.
- Returns:
- a Future representing pending completion of the operation.
-
serviceDescriptors
Collection<ServiceDescriptor> serviceDescriptors()
Gets metadata about all deployed services in the grid.- Returns:
- Metadata about all deployed services in the grid.
-
service
@Deprecated <T> T service(String name)
Deprecated.Use the proxies likeserviceProxy(String, Class, boolean)
. References to local services corrupt the service statistics and bring no real performance optimization.Gets locally deployed service with specified name.- Type Parameters:
T
- Service type- Parameters:
name
- Service name.- Returns:
- Deployed service with specified name.
- See Also:
ServiceConfiguration.setStatisticsEnabled(boolean)
-
services
@Deprecated <T> Collection<T> services(String name)
Deprecated.Use the proxies likeserviceProxy(String, Class, boolean)
. References to local services corrupt the service statistics and bring no real performance optimization.Gets all locally deployed services with specified name.- Type Parameters:
T
- Service type.- Parameters:
name
- Service name.- Returns:
- all deployed services with specified name.
- See Also:
ServiceConfiguration.setStatisticsEnabled(boolean)
-
serviceProxy
<T> T serviceProxy(String name, Class<? super T> svcItf, boolean sticky) throws IgniteException
Gets a handle on remote or local service. The proxy is dynamically created and provided for the specified service.- Type Parameters:
T
- Service type.- Parameters:
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.- Returns:
- Proxy over service.
- Throws:
IgniteException
- If failed to create service proxy.
-
serviceProxy
<T> T serviceProxy(String name, Class<? super T> svcItf, boolean sticky, long timeout) throws IgniteException
Gets a handle on remote or local service with the timeout. The proxy is dynamically created and provided for the specified service.- Type Parameters:
T
- Service type.- Parameters:
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.- Returns:
- Proxy over service.
- Throws:
IgniteException
- If failed to create service proxy.
-
serviceProxy
<T> T serviceProxy(String name, Class<? super T> svcItf, boolean sticky, ServiceCallContext callCtx) throws IgniteException
Gets a handle on remote or local service with the specified caller context. The proxy is dynamically created and provided for the specified service.- Type Parameters:
T
- Service type.- Parameters:
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.callCtx
- Service call context.- Returns:
- Proxy over service.
- Throws:
IgniteException
- If failed to create service proxy.- See Also:
ServiceCallContext
-
serviceProxy
<T> T serviceProxy(String name, Class<? super T> svcItf, boolean sticky, ServiceCallContext callCtx, long timeout) throws IgniteException
Gets a handle on remote or local service with the specified caller context and the timeout. The proxy is dynamically created and provided for the specified service.- Type Parameters:
T
- Service type.- Parameters:
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.callCtx
- Service call context.timeout
- If greater than 0 created proxy will wait for service availability only specified time, and will limit remote service invocation time.- Returns:
- Proxy over service.
- Throws:
IgniteException
- If failed to create service proxy.- See Also:
ServiceCallContext
-
withAsync
@Deprecated IgniteServices withAsync()
Deprecated.Gets instance of this component with asynchronous mode enabled.- Specified by:
withAsync
in interfaceIgniteAsyncSupport
- Returns:
- Instance of this component with asynchronous mode enabled.
-
-