org.apache.ignite.internal

## Class IgniteServicesImpl

- java.lang.Object
- - org.apache.ignite.internal.AsyncSupportAdapter
  - - org.apache.ignite.internal.IgniteServicesImpl

All Implemented Interfaces:
  Externalizable, Serializable, IgniteServices, IgniteAsyncSupport

    public class IgniteServicesImpl
    extends AsyncSupportAdapter
    implements IgniteServices, Externalizable

`IgniteCompute` implementation.

See Also:
  Serialized Form

### Field Summary

### Fields inherited from class org.apache.ignite.internal.AsyncSupportAdapter

`curFut`

### Constructor Summary

Constructors
Constructor and Description
`IgniteServicesImpl()` Required by `Externalizable`.
`IgniteServicesImpl(GridKernalContext ctx, ClusterGroupAdapter prj, boolean async)`

### Method Summary

Methods
`void` `cancel(String name)` Cancels service deployment.
`void` `cancelAll()` Cancels all deployed services.
`ClusterGroup` `clusterGroup()` Gets the cluster group to which this `GridServices` instance belongs.
`void` `deploy(ServiceConfiguration cfg)` 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.
`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.
`void` `deployMultiple(String name, Service svc, int totalCnt, int maxPerNodeCnt)` Deploys multiple instances of the service on the grid.
`void` `deployNodeSingleton(String name, Service svc)` Deploys a per-node singleton service.
`void` `readExternal(ObjectInput in)`
`protected Object` `readResolve()` Reconstructs object on unmarshalling.
`<T> T` `service(String name)` Gets deployed service with specified name.
`Collection<ServiceDescriptor>` `serviceDescriptors()` Gets metadata about all deployed services.
`<T> T` `serviceProxy(String name, Class<? super T> svcItf, boolean sticky)` Gets a remote handle on the service.
`<T> Collection<T>` `services(String name)` Gets all deployed services with specified name.
`IgniteServices` `withAsync()` Gets instance of this component with asynchronous mode enabled.
`void` `writeExternal(ObjectOutput out)`

### Methods inherited from class org.apache.ignite.internal.AsyncSupportAdapter

`createAsyncInstance, createFuture, future, future, isAsync, saveOrGet`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Methods inherited from interface org.apache.ignite.lang.IgniteAsyncSupport

`future, isAsync`

### Constructor Detail

#### IgniteServicesImpl

    public IgniteServicesImpl()

Required by `Externalizable`.

#### IgniteServicesImpl

    public IgniteServicesImpl(GridKernalContext ctx,
                      ClusterGroupAdapter prj,
                      boolean async)

Parameters:
  `ctx` - Kernal context.
  `prj` - Projection.
  `async` - Async support flag.

### Method Detail

#### clusterGroup

    public ClusterGroup clusterGroup()

Gets the cluster group to which this `GridServices` instance belongs.

Specified by:
  `clusterGroup` in interface `IgniteServices`
Returns:
  Cluster group to which this `GridServices` instance belongs.

#### deployNodeSingleton

    public void deployNodeSingleton(String name,
                           Service svc)

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.

Specified by:
  `deployNodeSingleton` in interface `IgniteServices`
Parameters:
  `name` - Service name.
  `svc` - Service instance.

#### deployClusterSingleton

    public void deployClusterSingleton(String name,
                              Service svc)

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.

Specified by:
  `deployClusterSingleton` in interface `IgniteServices`
Parameters:
  `name` - Service name.
  `svc` - Service instance.

#### deployMultiple

    public void deployMultiple(String name,
                      Service svc,
                      int totalCnt,
                      int maxPerNodeCnt)

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 than `0`.

This method is analogous to the invocation of `IgniteServices.deploy(org.apache.ignite.services.ServiceConfiguration)` method as follows:

         GridServiceConfiguration cfg = new GridServiceConfiguration();

         cfg.setName(name);
         cfg.setService(svc);
         cfg.setTotalCount(totalCnt);
         cfg.setMaxPerNodeCount(maxPerNodeCnt);

         grid.services().deploy(cfg);

Specified by:
  `deployMultiple` in interface `IgniteServices`
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.

#### deployKeyAffinitySingleton

    public 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. 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 `IgniteServices.deploy(org.apache.ignite.services.ServiceConfiguration)` method as follows:

         GridServiceConfiguration cfg = new GridServiceConfiguration();

         cfg.setName(name);
         cfg.setService(svc);
         cfg.setCacheName(cacheName);
         cfg.setAffinityKey(affKey);
         cfg.setTotalCount(1);
         cfg.setMaxPerNodeCount(1);

         grid.services().deploy(cfg);

Specified by:
  `deployKeyAffinitySingleton` in interface `IgniteServices`
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.

#### deploy

    public void deploy(ServiceConfiguration cfg)

Deploys multiple instances of the service on the grid according to provided configuration. Ignite will deploy a maximum amount of services equal to `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:

         GridServiceConfiguration cfg = new GridServiceConfiguration();

         cfg.setName(name);
         cfg.setService(svc);
         cfg.setTotalCount(0); // Unlimited.
         cfg.setMaxPerNodeCount(2); // Deploy 2 instances of service on each node.

         grid.services().deploy(cfg);

Specified by:
  `deploy` in interface `IgniteServices`
Parameters:
  `cfg` - Service configuration.

#### cancel

    public void cancel(String name)

Cancels service deployment. If a service with specified name was deployed on the grid, then `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`).

Specified by:
  `cancel` in interface `IgniteServices`
Parameters:
  `name` - Name of service to cancel.

#### cancelAll

    public void cancelAll()

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`).

Specified by:
  `cancelAll` in interface `IgniteServices`

#### serviceDescriptors

    public Collection<ServiceDescriptor> serviceDescriptors()

Gets metadata about all deployed services.

Specified by:
  `serviceDescriptors` in interface `IgniteServices`
Returns:
  Metadata about all deployed services.

#### service

    public <T> T service(String name)

Gets deployed service with specified name.

Specified by:
  `service` in interface `IgniteServices`
Type Parameters:
  `T` - Service type
Parameters:
  `name` - Service name.
Returns:
  Deployed service with specified name.

#### serviceProxy

    public <T> T serviceProxy(String name,
                     Class<? super T> svcItf,
                     boolean sticky)
                   throws IgniteException

Gets a remote handle on the service. If service is available locally, then local instance is returned, otherwise, a remote proxy is dynamically created and provided for the specified service.

Specified by:
  `serviceProxy` in interface `IgniteServices`
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:
  Either proxy over remote service or local service if it is deployed locally.
Throws:
  `IgniteException` - If failed to create service proxy.

#### services

    public <T> Collection<T> services(String name)

Gets all deployed services with specified name.

Specified by:
  `services` in interface `IgniteServices`
Type Parameters:
  `T` - Service type.
Parameters:
  `name` - Service name.
Returns:
  all deployed services with specified name.

#### withAsync

    public IgniteServices withAsync()

Gets instance of this component with asynchronous mode enabled.

Specified by:
  `withAsync` in interface `IgniteServices`
Specified by:
  `withAsync` in interface `IgniteAsyncSupport`
Overrides:
  `withAsync` in class `AsyncSupportAdapter`
Returns:
  Instance of this component with asynchronous mode enabled.

#### writeExternal

    public void writeExternal(ObjectOutput out)
                       throws IOException

Specified by:
  `writeExternal` in interface `Externalizable`
Throws:
  `IOException`

#### readExternal

    public void readExternal(ObjectInput in)
                      throws IOException,
                             ClassNotFoundException

Specified by:
  `readExternal` in interface `Externalizable`
Throws:
  `IOException`
  `ClassNotFoundException`

#### readResolve

    protected Object readResolve()
                          throws ObjectStreamException

Reconstructs object on unmarshalling.

Returns:
  Reconstructed object.
Throws:
  `ObjectStreamException` - Thrown in case of unmarshalling error.

2015 Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Fabric | : ver. 1.7.0
Release Date | : August 1 2016