# Renaming
Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/2f809796 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/2f809796 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/2f809796 Branch: refs/heads/master Commit: 2f80979624600eda943cc72d6c423cf1177f9f29 Parents: 27c89de Author: sboikov <sboi...@gridgain.com> Authored: Fri Dec 5 10:48:13 2014 +0300 Committer: sboikov <sboi...@gridgain.com> Committed: Fri Dec 5 10:48:13 2014 +0300 ---------------------------------------------------------------------- .../examples/services/SimpleMapServiceImpl.java | 9 +- .../java/org/apache/ignite/IgniteManaged.java | 36 +-- .../configuration/IgniteConfiguration.java | 6 +- .../org/apache/ignite/managed/GridService.java | 115 ------- .../managed/GridServiceConfiguration.java | 297 ------------------- .../ignite/managed/GridServiceContext.java | 60 ---- .../ignite/managed/GridServiceDescriptor.java | 82 ----- .../apache/ignite/managed/ManagedService.java | 115 +++++++ .../managed/ManagedServiceConfiguration.java | 297 +++++++++++++++++++ .../ignite/managed/ManagedServiceContext.java | 60 ++++ .../managed/ManagedServiceDescriptor.java | 82 +++++ .../gridgain/grid/kernal/IgniteManagedImpl.java | 12 +- .../resource/GridResourceCustomInjector.java | 4 +- .../resource/GridResourceProcessor.java | 6 +- .../resource/GridResourceServiceInjector.java | 2 +- .../service/GridServiceAssignments.java | 8 +- .../service/GridServiceContextImpl.java | 148 --------- .../service/GridServiceDeployment.java | 6 +- .../service/GridServiceDeploymentFuture.java | 6 +- .../service/GridServiceDescriptorImpl.java | 93 ------ .../service/GridServiceProcessor.java | 72 ++--- .../processors/service/GridServiceProxy.java | 8 +- .../service/ManagedServiceContextImpl.java | 148 +++++++++ .../service/ManagedServiceDescriptorImpl.java | 93 ++++++ .../kernal/processors/service/DummyService.java | 8 +- .../GridServiceProcessorAbstractSelfTest.java | 26 +- ...ServiceProcessorMultiNodeConfigSelfTest.java | 10 +- .../GridServiceProcessorProxySelfTest.java | 20 +- .../resource/GridServiceInjectionSelfTest.java | 20 +- 29 files changed, 925 insertions(+), 924 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/2f809796/examples/src/main/java/org/gridgain/examples/services/SimpleMapServiceImpl.java ---------------------------------------------------------------------- diff --git a/examples/src/main/java/org/gridgain/examples/services/SimpleMapServiceImpl.java b/examples/src/main/java/org/gridgain/examples/services/SimpleMapServiceImpl.java index dee7512..6427079 100644 --- a/examples/src/main/java/org/gridgain/examples/services/SimpleMapServiceImpl.java +++ b/examples/src/main/java/org/gridgain/examples/services/SimpleMapServiceImpl.java @@ -17,7 +17,7 @@ import java.util.concurrent.*; /** * Simple service which loops infinitely and prints out a counter. */ -public class SimpleMapServiceImpl<K, V> implements GridService, SimpleMapService<K, V> { +public class SimpleMapServiceImpl<K, V> implements ManagedService, SimpleMapService<K, V> { /** Serial version UID. */ private static final long serialVersionUID = 0L; @@ -39,24 +39,25 @@ public class SimpleMapServiceImpl<K, V> implements GridService, SimpleMapService map.clear(); } + /** {@inheritDoc} */ @Override public int size() { return map.size(); } /** {@inheritDoc} */ - @Override public void cancel(GridServiceContext ctx) { + @Override public void cancel(ManagedServiceContext ctx) { System.out.println("Service was cancelled: " + ctx.name()); } /** {@inheritDoc} */ - @Override public void init(GridServiceContext ctx) throws Exception { + @Override public void init(ManagedServiceContext ctx) throws Exception { System.out.println("Service was initialized: " + ctx.name()); map = new ConcurrentHashMap<>(); } /** {@inheritDoc} */ - @Override public void execute(GridServiceContext ctx) throws Exception { + @Override public void execute(ManagedServiceContext ctx) throws Exception { System.out.println("Executing distributed service: " + ctx.name()); } } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/2f809796/modules/core/src/main/java/org/apache/ignite/IgniteManaged.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/IgniteManaged.java b/modules/core/src/main/java/org/apache/ignite/IgniteManaged.java index 61dc6e9..44fe314 100644 --- a/modules/core/src/main/java/org/apache/ignite/IgniteManaged.java +++ b/modules/core/src/main/java/org/apache/ignite/IgniteManaged.java @@ -135,7 +135,7 @@ public interface IgniteManaged extends IgniteAsyncSupport { * when a singleton service instance will be active on more than one node (e.g. crash detection delay). * <p> * This method is analogous to calling - * {@link #deployMultiple(String, org.apache.ignite.managed.GridService, int, int) deployMultiple(name, svc, 1, 1)} method. + * {@link #deployMultiple(String, org.apache.ignite.managed.ManagedService, int, int) deployMultiple(name, svc, 1, 1)} method. * <p> * Supports asynchronous execution (see {@link IgniteAsyncSupport}). * @@ -143,7 +143,7 @@ public interface IgniteManaged extends IgniteAsyncSupport { * @param svc Service instance. * @throws GridException If failed to deploy service. */ - public void deployClusterSingleton(String name, GridService svc) throws GridException; + public void deployClusterSingleton(String name, ManagedService svc) throws GridException; /** * Deploys a per-node singleton service. GridGain will guarantee that there is always @@ -152,7 +152,7 @@ public interface IgniteManaged extends IgniteAsyncSupport { * the service on every new node. * <p> * This method is analogous to calling - * {@link #deployMultiple(String, GridService, int, int) deployMultiple(name, svc, 0, 1)} method. + * {@link #deployMultiple(String, org.apache.ignite.managed.ManagedService, int, int) deployMultiple(name, svc, 0, 1)} method. * <p> * Supports asynchronous execution (see {@link IgniteAsyncSupport}). * @@ -160,7 +160,7 @@ public interface IgniteManaged extends IgniteAsyncSupport { * @param svc Service instance. * @throws GridException If failed to deploy service. */ - public void deployNodeSingleton(String name, GridService svc) throws GridException; + public void deployNodeSingleton(String name, ManagedService svc) throws GridException; /** * Deploys one instance of this service on the primary node for a given affinity key. @@ -171,7 +171,7 @@ public interface IgniteManaged extends IgniteAsyncSupport { * 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). * <p> - * This method is analogous to the invocation of {@link #deploy(GridServiceConfiguration)} method + * This method is analogous to the invocation of {@link #deploy(org.apache.ignite.managed.ManagedServiceConfiguration)} method * as follows: * <pre name="code" class="java"> * GridServiceConfiguration cfg = new GridServiceConfiguration(); @@ -195,7 +195,7 @@ public interface IgniteManaged extends IgniteAsyncSupport { * @param affKey Affinity cache key. * @throws GridException If failed to deploy service. */ - public void deployKeyAffinitySingleton(String name, GridService svc, @Nullable String cacheName, Object affKey) + public void deployKeyAffinitySingleton(String name, ManagedService svc, @Nullable String cacheName, Object affKey) throws GridException; /** @@ -209,7 +209,7 @@ public interface IgniteManaged extends IgniteAsyncSupport { * Note that at least one of {@code 'totalCnt'} or {@code 'maxPerNodeCnt'} parameters must have * value greater than {@code 0}. * <p> - * This method is analogous to the invocation of {@link #deploy(GridServiceConfiguration)} method + * This method is analogous to the invocation of {@link #deploy(org.apache.ignite.managed.ManagedServiceConfiguration)} method * as follows: * <pre name="code" class="java"> * GridServiceConfiguration cfg = new GridServiceConfiguration(); @@ -230,22 +230,22 @@ public interface IgniteManaged extends IgniteAsyncSupport { * @param maxPerNodeCnt Maximum number of deployed services on each node, {@code 0} for unlimited. * @throws GridException If failed to deploy service. */ - public void deployMultiple(String name, GridService svc, int totalCnt, int maxPerNodeCnt) throws GridException; + public void deployMultiple(String name, ManagedService svc, int totalCnt, int maxPerNodeCnt) throws GridException; /** * Deploys multiple instances of the service on the grid according to provided * configuration. GridGain will deploy a maximum amount of services equal to - * {@link GridServiceConfiguration#getTotalCount() cfg.getTotalCount()} parameter - * making sure that there are no more than {@link GridServiceConfiguration#getMaxPerNodeCount() cfg.getMaxPerNodeCount()} + * {@link org.apache.ignite.managed.ManagedServiceConfiguration#getTotalCount() cfg.getTotalCount()} parameter + * making sure that there are no more than {@link org.apache.ignite.managed.ManagedServiceConfiguration#getMaxPerNodeCount() cfg.getMaxPerNodeCount()} * service instances running on each node. Whenever topology changes, GridGain 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. * <p> - * If {@link GridServiceConfiguration#getAffinityKey() cfg.getAffinityKey()} is not {@code null}, then GridGain + * If {@link org.apache.ignite.managed.ManagedServiceConfiguration#getAffinityKey() cfg.getAffinityKey()} is not {@code null}, then GridGain * will deploy the service on the primary node for given affinity key. The affinity will be calculated - * on the cache with {@link GridServiceConfiguration#getCacheName() cfg.getCacheName()} name. + * on the cache with {@link org.apache.ignite.managed.ManagedServiceConfiguration#getCacheName() cfg.getCacheName()} name. * <p> - * If {@link GridServiceConfiguration#getNodeFilter() cfg.getNodeFilter()} is not {@code null}, then + * If {@link org.apache.ignite.managed.ManagedServiceConfiguration#getNodeFilter() cfg.getNodeFilter()} is not {@code null}, then * GridGain will deploy service on all grid nodes for which the provided filter evaluates to {@code true}. * The node filter will be checked in addition to the underlying grid projection filter, or the * whole grid, if the underlying grid projection includes all grid nodes. @@ -270,14 +270,14 @@ public interface IgniteManaged extends IgniteAsyncSupport { * @param cfg Service configuration. * @throws GridException If failed to deploy service. */ - public void deploy(GridServiceConfiguration cfg) throws GridException; + public void deploy(ManagedServiceConfiguration cfg) throws GridException; /** * Cancels service deployment. If a service with specified name was deployed on the grid, - * then {@link GridService#cancel(GridServiceContext)} method will be called on it. + * then {@link org.apache.ignite.managed.ManagedService#cancel(org.apache.ignite.managed.ManagedServiceContext)} method will be called on it. * <p> - * Note that GridGain cannot guarantee that the service exits from {@link GridService#execute(GridServiceContext)} - * method whenever {@link GridService#cancel(GridServiceContext)} is called. It is up to the user to + * Note that GridGain cannot guarantee that the service exits from {@link org.apache.ignite.managed.ManagedService#execute(org.apache.ignite.managed.ManagedServiceContext)} + * method whenever {@link org.apache.ignite.managed.ManagedService#cancel(org.apache.ignite.managed.ManagedServiceContext)} is called. It is up to the user to * make sure that the service code properly reacts to cancellations. * <p> * Supports asynchronous execution (see {@link IgniteAsyncSupport}). @@ -304,7 +304,7 @@ public interface IgniteManaged extends IgniteAsyncSupport { * * @return Metadata about all deployed services. */ - public Collection<GridServiceDescriptor> deployedServices(); + public Collection<ManagedServiceDescriptor> deployedServices(); /** * Gets deployed service with specified name. http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/2f809796/modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java b/modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java index c8a7a52..1d40d13 100644 --- a/modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java +++ b/modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java @@ -526,7 +526,7 @@ public class IgniteConfiguration { private GridSecurityCredentialsProvider securityCred; /** Service configuration. */ - private GridServiceConfiguration[] svcCfgs; + private ManagedServiceConfiguration[] svcCfgs; /** Hadoop configuration. */ private GridHadoopConfiguration hadoopCfg; @@ -3143,7 +3143,7 @@ public class IgniteConfiguration { * * @return Configurations for services to be deployed on the grid. */ - public GridServiceConfiguration[] getServiceConfiguration() { + public ManagedServiceConfiguration[] getServiceConfiguration() { return svcCfgs; } @@ -3152,7 +3152,7 @@ public class IgniteConfiguration { * * @param svcCfgs Configurations for services to be deployed on the grid. */ - public void setServiceConfiguration(GridServiceConfiguration... svcCfgs) { + public void setServiceConfiguration(ManagedServiceConfiguration... svcCfgs) { this.svcCfgs = svcCfgs; } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/2f809796/modules/core/src/main/java/org/apache/ignite/managed/GridService.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/managed/GridService.java b/modules/core/src/main/java/org/apache/ignite/managed/GridService.java deleted file mode 100644 index fe15233..0000000 --- a/modules/core/src/main/java/org/apache/ignite/managed/GridService.java +++ /dev/null @@ -1,115 +0,0 @@ -/* @java.file.header */ - -/* _________ _____ __________________ _____ - * __ ____/___________(_)______ /__ ____/______ ____(_)_______ - * _ / __ __ ___/__ / _ __ / _ / __ _ __ `/__ / __ __ \ - * / /_/ / _ / _ / / /_/ / / /_/ / / /_/ / _ / _ / / / - * \____/ /_/ /_/ \_,__/ \____/ \__,_/ /_/ /_/ /_/ - */ - -package org.apache.ignite.managed; - -import java.io.*; - -/** - * An instance of grid-managed service. Grid-managed services may be deployed from - * {@link org.apache.ignite.IgniteManaged} facade or directly from grid configuration at startup. - * <h1 class="header">Deployment</h1> - * Whenever service is deployed, GridGain will automatically calculate how many - * instances of this service should be deployed on each node within the cluster. - * Whenever service is deployed on a cluster node, GridGain will call - * {@link #execute(GridServiceContext)} method on that service. It is up to the user - * to control whenever the service should exit from the {@code execute} method. - * For example, user may choose to implement service as follows: - * <pre name="code" class="java"> - * public class MyGridService implements GridService { - * ... - * // Example of grid resource injection. All resources are optional. - * // You should inject resources only as needed. - * @GridInstanceResource - * private Grid grid; - * ... - * @Override public void cancel(GridServiceContext ctx) { - * // No-op. - * } - * - * @Override public void execute(GridServiceContext ctx) { - * // Loop until service is cancelled. - * while (!ctx.isCancelled()) { - * // Do something. - * ... - * } - * } - * } - * </pre> - * Consecutively, this service can be deployed as follows: - * <pre name="code" class="java"> - * ... - * GridServices svcs = grid.services(); - * - * GridFuture<?> fut = svcs.deployClusterSingleton("mySingleton", new MyGridService()); - * - * // Wait for deployment to complete. - * fut.get(); - * </pre> - * Or from grid configuration on startup: - * <pre name="code" class="java"> - * GridConfiguration gridCfg = new GridConfiguration(); - * - * GridServiceConfiguration svcCfg = new GridServiceConfiguration(); - * - * // Configuration for cluster-singleton service. - * svcCfg.setName("mySingleton"); - * svcCfg.setMaxPerNodeCount(1); - * svcCfg.setTotalCount(1); - * svcCfg.setService(new MyGridService()); - * - * gridCfg.setServiceConfiguration(svcCfg); - * ... - * GridGain.start(gridCfg); - * </pre> - * <h1 class="header">Cancellation</h1> - * Services can be cancelled by calling any of the {@code cancel} methods on {@link org.apache.ignite.IgniteManaged} API. - * Whenever a deployed service is cancelled, GridGain will automatically call - * {@link GridService#cancel(GridServiceContext)} method on that service. - * <p> - * Note that GridGain cannot guarantee that the service exits from {@link GridService#execute(GridServiceContext)} - * method whenever {@link #cancel(GridServiceContext)} is called. It is up to the user to - * make sure that the service code properly reacts to cancellations. - */ -public interface GridService extends Serializable { - /** - * Cancels this service. GridGain will automatically call this method whenever any of the - * {@code cancel} methods on {@link org.apache.ignite.IgniteManaged} API are called. - * <p> - * Note that GridGain cannot guarantee that the service exits from {@link #execute(GridServiceContext)} - * method whenever {@code cancel(GridServiceContext)} method is called. It is up to the user to - * make sure that the service code properly reacts to cancellations. - * - * @param ctx Service execution context. - */ - public void cancel(GridServiceContext ctx); - - /** - * Pre-initializes service before execution. This method is guaranteed to be called before - * service deployment is complete (this guarantees that this method will be called - * before method {@link #execute(GridServiceContext)} is called). - * - * @param ctx Service execution context. - * @throws Exception If service initialization failed. - */ - public void init(GridServiceContext ctx) throws Exception; - - /** - * Starts execution of this service. This method is automatically invoked whenever an instance of the service - * is deployed on a grid node. Note that service is considered deployed even after it exits the {@code execute} - * method and can be cancelled (or undeployed) only by calling any of the {@code cancel} methods on - * {@link org.apache.ignite.IgniteManaged} API. Also note that service is not required to exit from {@code execute} method until - * {@link #cancel(GridServiceContext)} method was called. - * - * @param ctx Service execution context. - * @throws Exception If service execution failed. Not that service will still remain deployed, until - * {@link org.apache.ignite.IgniteManaged#cancel(String)} method will be called. - */ - public void execute(GridServiceContext ctx) throws Exception; -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/2f809796/modules/core/src/main/java/org/apache/ignite/managed/GridServiceConfiguration.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/managed/GridServiceConfiguration.java b/modules/core/src/main/java/org/apache/ignite/managed/GridServiceConfiguration.java deleted file mode 100644 index 90f1049..0000000 --- a/modules/core/src/main/java/org/apache/ignite/managed/GridServiceConfiguration.java +++ /dev/null @@ -1,297 +0,0 @@ -/* @java.file.header */ - -/* _________ _____ __________________ _____ - * __ ____/___________(_)______ /__ ____/______ ____(_)_______ - * _ / __ __ ___/__ / _ __ / _ / __ _ __ `/__ / __ __ \ - * / /_/ / _ / _ / / /_/ / / /_/ / / /_/ / _ / _ / / / - * \____/ /_/ /_/ \_,__/ \____/ \__,_/ /_/ /_/ /_/ - */ - -package org.apache.ignite.managed; - -import org.apache.ignite.cluster.*; -import org.apache.ignite.lang.*; -import org.gridgain.grid.util.tostring.*; -import org.gridgain.grid.util.typedef.internal.*; - -import java.io.*; - -/** - * Managed service configuration. In addition to deploying managed services by - * calling any of the provided {@code deploy(...)} methods, managed services - * can also be automatically deployed on startup by specifying them in {@link org.apache.ignite.configuration.IgniteConfiguration} - * like so: - * <pre name="code" class="java"> - * GridConfiguration gridCfg = new GridConfiguration(); - * - * GridServiceConfiguration svcCfg1 = new GridServiceConfiguration(); - * - * svcCfg1.setName("myClusterSingletonService"); - * svcCfg1.setMaxPerNodeCount(1); - * svcCfg1.setTotalCount(1); - * svcCfg1.setService(new MyClusterSingletonService()); - * - * GridServiceConfiguration svcCfg2 = new GridServiceConfiguration(); - * - * svcCfg2.setName("myNodeSingletonService"); - * svcCfg2.setMaxPerNodeCount(1); - * svcCfg2.setService(new MyNodeSingletonService()); - * - * gridCfg.setServiceConfiguration(svcCfg1, svcCfg2); - * ... - * GridGain.start(gridCfg); - * </pre> - * The above configuration can also be specified in a Spring configuration file. - */ -public class GridServiceConfiguration implements Serializable { - /** */ - private static final long serialVersionUID = 0L; - - /** Service name. */ - private String name; - - /** Service instance. */ - @GridToStringExclude - private GridService svc; - - /** Total count. */ - private int totalCnt; - - /** Max per-node count. */ - private int maxPerNodeCnt; - - /** Cache name. */ - private String cacheName; - - /** Affinity key. */ - private Object affKey; - - /** Node filter. */ - @GridToStringExclude - private IgnitePredicate<ClusterNode> nodeFilter; - - /** - * Gets service name. - * <p> - * This parameter is mandatory when deploying a service. - * - * @return Service name. - */ - public String getName() { - return name; - } - - /** - * Sets service name. - * <p> - * This parameter is mandatory when deploying a service. - * - * @param name Service name. - */ - public void setName(String name) { - this.name = name; - } - - /** - * Gets service instance. - * <p> - * This parameter is mandatory when deploying a service. - * - * @return Service instance. - */ - public GridService getService() { - return svc; - } - - /** - * Sets service instance. - * <p> - * This parameter is mandatory when deploying a service. - * - * @param svc Service instance. - */ - public void setService(GridService svc) { - this.svc = svc; - } - - /** - * Gets total number of deployed service instances in the cluster, {@code 0} for unlimited. - * <p> - * At least one of {@code getTotalCount()} or {@link #getMaxPerNodeCount()} values must be positive. - * - * @return Total number of deployed service instances in the cluster, {@code 0} for unlimited. - */ - public int getTotalCount() { - return totalCnt; - } - - /** - * Sets total number of deployed service instances in the cluster, {@code 0} for unlimited. - * <p> - * At least one of {@code getTotalCount()} or {@link #getMaxPerNodeCount()} values must be positive. - * - * @param totalCnt Total number of deployed service instances in the cluster, {@code 0} for unlimited. - */ - public void setTotalCount(int totalCnt) { - this.totalCnt = totalCnt; - } - - /** - * Gets maximum number of deployed service instances on each node, {@code 0} for unlimited. - * <p> - * At least one of {@code getMaxPerNodeCount()} or {@link #getTotalCount()} values must be positive. - * - * @return Maximum number of deployed service instances on each node, {@code 0} for unlimited. - */ - public int getMaxPerNodeCount() { - return maxPerNodeCnt; - } - - /** - * Sets maximum number of deployed service instances on each node, {@code 0} for unlimited. - * <p> - * At least one of {@code getMaxPerNodeCount()} or {@link #getTotalCount()} values must be positive. - * - * @param maxPerNodeCnt Maximum number of deployed service instances on each node, {@code 0} for unlimited. - */ - public void setMaxPerNodeCount(int maxPerNodeCnt) { - this.maxPerNodeCnt = maxPerNodeCnt; - } - - /** - * Gets cache name used for key-to-node affinity calculation. - * <p> - * This parameter is optional and is set only when deploying service based on key-affinity. - * - * @return Cache name, possibly {@code null}. - */ - public String getCacheName() { - return cacheName; - } - - /** - * Sets cache name used for key-to-node affinity calculation. - * <p> - * This parameter is optional and is set only when deploying service based on key-affinity. - * - * @param cacheName Cache name, possibly {@code null}. - */ - public void setCacheName(String cacheName) { - this.cacheName = cacheName; - } - - /** - * Gets affinity key used for key-to-node affinity calculation. - * <p> - * This parameter is optional and is set only when deploying service based on key-affinity. - * - * @return Affinity key, possibly {@code null}. - */ - public Object getAffinityKey() { - return affKey; - } - - /** - * Sets affinity key used for key-to-node affinity calculation. - * <p> - * This parameter is optional and is set only when deploying service based on key-affinity. - * - * @param affKey Affinity key, possibly {@code null}. - */ - public void setAffinityKey(Object affKey) { - this.affKey = affKey; - } - - /** - * Gets node filter used to filter nodes on which the service will be deployed. - * <p> - * This parameter is optional. If not provided service may be deployed on any or all - * nodes in the grid, based on configuration. - * - * @return Node filter used to filter nodes on which the service will be deployed, possibly {@code null}. - */ - public IgnitePredicate<ClusterNode> getNodeFilter() { - return nodeFilter; - } - - /** - * Sets node filter used to filter nodes on which the service will be deployed. - * <p> - * This parameter is optional. If not provided service may be deployed on any or all - * nodes in the grid, based on configuration. - * - * @param nodeFilter Node filter used to filter nodes on which the service will be deployed, possibly {@code null}. - */ - public void setNodeFilter(IgnitePredicate<ClusterNode> nodeFilter) { - this.nodeFilter = nodeFilter; - } - - /** {@inheritDoc} */ - @SuppressWarnings({"RedundantIfStatement", "EqualsWhichDoesntCheckParameterClass"}) - @Override public boolean equals(Object o) { - if (!equalsIgnoreNodeFilter(o)) - return false; - - GridServiceConfiguration that = (GridServiceConfiguration)o; - - if (nodeFilter != null && that.nodeFilter != null) { - if (!nodeFilter.getClass().equals(that.nodeFilter.getClass())) - return false; - } - else if (nodeFilter != null || that.nodeFilter != null) - return false; - - return true; - } - - /** - * Checks if configurations are equal ignoring the node filter. Node filters control on which - * nodes the services are deployed and often can be ignored for equality checks. - * - * @param o Other configuration. - * @return {@code True} if configurations are equal, {@code false} otherwise. - */ - @SuppressWarnings("RedundantIfStatement") - public boolean equalsIgnoreNodeFilter(Object o) { - if (this == o) - return true; - - if (o == null || getClass() != o.getClass()) - return false; - - GridServiceConfiguration that = (GridServiceConfiguration)o; - - if (maxPerNodeCnt != that.maxPerNodeCnt) - return false; - - if (totalCnt != that.totalCnt) - return false; - - if (affKey != null ? !affKey.equals(that.affKey) : that.affKey != null) - return false; - - if (cacheName != null ? !cacheName.equals(that.cacheName) : that.cacheName != null) - return false; - - if (name != null ? !name.equals(that.name) : that.name != null) - return false; - - if (svc != null ? !svc.getClass().equals(that.svc.getClass()) : that.svc != null) - return false; - - return true; - } - - /** {@inheritDoc} */ - @Override public int hashCode() { - return name == null ? 0 : name.hashCode(); - } - - /** {@inheritDoc} */ - @Override public String toString() { - String svcCls = svc == null ? "" : svc.getClass().getSimpleName(); - String nodeFilterCls = nodeFilter == null ? "" : nodeFilter.getClass().getSimpleName(); - - return S.toString(GridServiceConfiguration.class, this, "svcCls", svcCls, "nodeFilterCls", nodeFilterCls); - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/2f809796/modules/core/src/main/java/org/apache/ignite/managed/GridServiceContext.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/managed/GridServiceContext.java b/modules/core/src/main/java/org/apache/ignite/managed/GridServiceContext.java deleted file mode 100644 index 946599d..0000000 --- a/modules/core/src/main/java/org/apache/ignite/managed/GridServiceContext.java +++ /dev/null @@ -1,60 +0,0 @@ -/* @java.file.header */ - -/* _________ _____ __________________ _____ - * __ ____/___________(_)______ /__ ____/______ ____(_)_______ - * _ / __ __ ___/__ / _ __ / _ / __ _ __ `/__ / __ __ \ - * / /_/ / _ / _ / / /_/ / / /_/ / / /_/ / _ / _ / / / - * \____/ /_/ /_/ \_,__/ \____/ \__,_/ /_/ /_/ /_/ - */ - -package org.apache.ignite.managed; - -import org.jetbrains.annotations.*; - -import java.io.*; -import java.util.*; - -/** - * Service execution context. Execution context is provided into {@link GridService#execute(GridServiceContext)} - * and {@link GridService#cancel(GridServiceContext)} methods and contains information about specific service - * execution. - */ -public interface GridServiceContext extends Serializable { - /** - * Gets service name. - * - * @return Service name. - */ - public String name(); - - /** - * Gets service execution ID. Execution ID is guaranteed to be unique across - * all service deployments. - * - * @return Service execution ID. - */ - public UUID executionId(); - - /** - * Get flag indicating whether service has been cancelled or not. - * - * @return Flag indicating whether service has been cancelled or not. - */ - public boolean isCancelled(); - - /** - * Gets cache name used for key-to-node affinity calculation. This parameter is optional - * and is set only when key-affinity service was deployed. - * - * @return Cache name, possibly {@code null}. - */ - @Nullable public String cacheName(); - - /** - * Gets affinity key used for key-to-node affinity calculation. This parameter is optional - * and is set only when key-affinity service was deployed. - * - * @return Affinity key, possibly {@code null}. - */ - @Nullable public <K> K affinityKey(); -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/2f809796/modules/core/src/main/java/org/apache/ignite/managed/GridServiceDescriptor.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/managed/GridServiceDescriptor.java b/modules/core/src/main/java/org/apache/ignite/managed/GridServiceDescriptor.java deleted file mode 100644 index eecf4dc..0000000 --- a/modules/core/src/main/java/org/apache/ignite/managed/GridServiceDescriptor.java +++ /dev/null @@ -1,82 +0,0 @@ -/* @java.file.header */ - -/* _________ _____ __________________ _____ - * __ ____/___________(_)______ /__ ____/______ ____(_)_______ - * _ / __ __ ___/__ / _ __ / _ / __ _ __ `/__ / __ __ \ - * / /_/ / _ / _ / / /_/ / / /_/ / / /_/ / _ / _ / / / - * \____/ /_/ /_/ \_,__/ \____/ \__,_/ /_/ /_/ /_/ - */ - -package org.apache.ignite.managed; - -import org.jetbrains.annotations.*; - -import java.io.*; -import java.util.*; - -/** - * Service deployment descriptor. Contains all service deployment configuration, and also - * deployment topology snapshot as well as origin node ID. - * <p> - * Service descriptors can be retrieved by calling {@link org.apache.ignite.IgniteManaged#deployedServices()} method. - */ -public interface GridServiceDescriptor extends Serializable { - /** - * Gets service name. - * - * @return Service name. - */ - public String name(); - - /** - * Gets service class. - * - * @return Service class. - */ - public Class<? extends GridService> serviceClass(); - - /** - * Gets maximum allowed total number of deployed services in the grid, {@code 0} for unlimited. - * - * @return Maximum allowed total number of deployed services in the grid, {@code 0} for unlimited. - */ - public int totalCount(); - - /** - * Gets maximum allowed number of deployed services on each node, {@code 0} for unlimited. - * - * @return Maximum allowed total number of deployed services on each node, {@code 0} for unlimited. - */ - public int maxPerNodeCount(); - - /** - * Gets cache name used for key-to-node affinity calculation. This parameter is optional - * and is set only when key-affinity service was deployed. - * - * @return Cache name, possibly {@code null}. - */ - @Nullable public String cacheName(); - - /** - * Gets affinity key used for key-to-node affinity calculation. This parameter is optional - * and is set only when key-affinity service was deployed. - * - * @return Affinity key, possibly {@code null}. - */ - @Nullable public <K> K affinityKey(); - - /** - * Gets ID of grid node that initiated the service deployment. - * - * @return ID of grid node that initiated the service deployment. - */ - public UUID originNodeId(); - - /** - * Gets service deployment topology snapshot. Service topology snapshot is represented - * by number of service instances deployed on a node mapped to node ID. - * - * @return Map of number of service instances per node ID. - */ - public Map<UUID, Integer> topologySnapshot(); -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/2f809796/modules/core/src/main/java/org/apache/ignite/managed/ManagedService.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/managed/ManagedService.java b/modules/core/src/main/java/org/apache/ignite/managed/ManagedService.java new file mode 100644 index 0000000..110d5f1 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/managed/ManagedService.java @@ -0,0 +1,115 @@ +/* @java.file.header */ + +/* _________ _____ __________________ _____ + * __ ____/___________(_)______ /__ ____/______ ____(_)_______ + * _ / __ __ ___/__ / _ __ / _ / __ _ __ `/__ / __ __ \ + * / /_/ / _ / _ / / /_/ / / /_/ / / /_/ / _ / _ / / / + * \____/ /_/ /_/ \_,__/ \____/ \__,_/ /_/ /_/ /_/ + */ + +package org.apache.ignite.managed; + +import java.io.*; + +/** + * An instance of grid-managed service. Grid-managed services may be deployed from + * {@link org.apache.ignite.IgniteManaged} facade or directly from grid configuration at startup. + * <h1 class="header">Deployment</h1> + * Whenever service is deployed, GridGain will automatically calculate how many + * instances of this service should be deployed on each node within the cluster. + * Whenever service is deployed on a cluster node, GridGain will call + * {@link #execute(ManagedServiceContext)} method on that service. It is up to the user + * to control whenever the service should exit from the {@code execute} method. + * For example, user may choose to implement service as follows: + * <pre name="code" class="java"> + * public class MyGridService implements GridService { + * ... + * // Example of grid resource injection. All resources are optional. + * // You should inject resources only as needed. + * @GridInstanceResource + * private Grid grid; + * ... + * @Override public void cancel(GridServiceContext ctx) { + * // No-op. + * } + * + * @Override public void execute(GridServiceContext ctx) { + * // Loop until service is cancelled. + * while (!ctx.isCancelled()) { + * // Do something. + * ... + * } + * } + * } + * </pre> + * Consecutively, this service can be deployed as follows: + * <pre name="code" class="java"> + * ... + * GridServices svcs = grid.services(); + * + * GridFuture<?> fut = svcs.deployClusterSingleton("mySingleton", new MyGridService()); + * + * // Wait for deployment to complete. + * fut.get(); + * </pre> + * Or from grid configuration on startup: + * <pre name="code" class="java"> + * GridConfiguration gridCfg = new GridConfiguration(); + * + * GridServiceConfiguration svcCfg = new GridServiceConfiguration(); + * + * // Configuration for cluster-singleton service. + * svcCfg.setName("mySingleton"); + * svcCfg.setMaxPerNodeCount(1); + * svcCfg.setTotalCount(1); + * svcCfg.setService(new MyGridService()); + * + * gridCfg.setServiceConfiguration(svcCfg); + * ... + * GridGain.start(gridCfg); + * </pre> + * <h1 class="header">Cancellation</h1> + * Services can be cancelled by calling any of the {@code cancel} methods on {@link org.apache.ignite.IgniteManaged} API. + * Whenever a deployed service is cancelled, GridGain will automatically call + * {@link ManagedService#cancel(ManagedServiceContext)} method on that service. + * <p> + * Note that GridGain cannot guarantee that the service exits from {@link ManagedService#execute(ManagedServiceContext)} + * method whenever {@link #cancel(ManagedServiceContext)} is called. It is up to the user to + * make sure that the service code properly reacts to cancellations. + */ +public interface ManagedService extends Serializable { + /** + * Cancels this service. GridGain will automatically call this method whenever any of the + * {@code cancel} methods on {@link org.apache.ignite.IgniteManaged} API are called. + * <p> + * Note that GridGain cannot guarantee that the service exits from {@link #execute(ManagedServiceContext)} + * method whenever {@code cancel(GridServiceContext)} method is called. It is up to the user to + * make sure that the service code properly reacts to cancellations. + * + * @param ctx Service execution context. + */ + public void cancel(ManagedServiceContext ctx); + + /** + * Pre-initializes service before execution. This method is guaranteed to be called before + * service deployment is complete (this guarantees that this method will be called + * before method {@link #execute(ManagedServiceContext)} is called). + * + * @param ctx Service execution context. + * @throws Exception If service initialization failed. + */ + public void init(ManagedServiceContext ctx) throws Exception; + + /** + * Starts execution of this service. This method is automatically invoked whenever an instance of the service + * is deployed on a grid node. Note that service is considered deployed even after it exits the {@code execute} + * method and can be cancelled (or undeployed) only by calling any of the {@code cancel} methods on + * {@link org.apache.ignite.IgniteManaged} API. Also note that service is not required to exit from {@code execute} method until + * {@link #cancel(ManagedServiceContext)} method was called. + * + * @param ctx Service execution context. + * @throws Exception If service execution failed. Not that service will still remain deployed, until + * {@link org.apache.ignite.IgniteManaged#cancel(String)} method will be called. + */ + public void execute(ManagedServiceContext ctx) throws Exception; +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/2f809796/modules/core/src/main/java/org/apache/ignite/managed/ManagedServiceConfiguration.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/managed/ManagedServiceConfiguration.java b/modules/core/src/main/java/org/apache/ignite/managed/ManagedServiceConfiguration.java new file mode 100644 index 0000000..985bdc5 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/managed/ManagedServiceConfiguration.java @@ -0,0 +1,297 @@ +/* @java.file.header */ + +/* _________ _____ __________________ _____ + * __ ____/___________(_)______ /__ ____/______ ____(_)_______ + * _ / __ __ ___/__ / _ __ / _ / __ _ __ `/__ / __ __ \ + * / /_/ / _ / _ / / /_/ / / /_/ / / /_/ / _ / _ / / / + * \____/ /_/ /_/ \_,__/ \____/ \__,_/ /_/ /_/ /_/ + */ + +package org.apache.ignite.managed; + +import org.apache.ignite.cluster.*; +import org.apache.ignite.lang.*; +import org.gridgain.grid.util.tostring.*; +import org.gridgain.grid.util.typedef.internal.*; + +import java.io.*; + +/** + * Managed service configuration. In addition to deploying managed services by + * calling any of the provided {@code deploy(...)} methods, managed services + * can also be automatically deployed on startup by specifying them in {@link org.apache.ignite.configuration.IgniteConfiguration} + * like so: + * <pre name="code" class="java"> + * GridConfiguration gridCfg = new GridConfiguration(); + * + * GridServiceConfiguration svcCfg1 = new GridServiceConfiguration(); + * + * svcCfg1.setName("myClusterSingletonService"); + * svcCfg1.setMaxPerNodeCount(1); + * svcCfg1.setTotalCount(1); + * svcCfg1.setService(new MyClusterSingletonService()); + * + * GridServiceConfiguration svcCfg2 = new GridServiceConfiguration(); + * + * svcCfg2.setName("myNodeSingletonService"); + * svcCfg2.setMaxPerNodeCount(1); + * svcCfg2.setService(new MyNodeSingletonService()); + * + * gridCfg.setServiceConfiguration(svcCfg1, svcCfg2); + * ... + * GridGain.start(gridCfg); + * </pre> + * The above configuration can also be specified in a Spring configuration file. + */ +public class ManagedServiceConfiguration implements Serializable { + /** */ + private static final long serialVersionUID = 0L; + + /** Service name. */ + private String name; + + /** Service instance. */ + @GridToStringExclude + private ManagedService svc; + + /** Total count. */ + private int totalCnt; + + /** Max per-node count. */ + private int maxPerNodeCnt; + + /** Cache name. */ + private String cacheName; + + /** Affinity key. */ + private Object affKey; + + /** Node filter. */ + @GridToStringExclude + private IgnitePredicate<ClusterNode> nodeFilter; + + /** + * Gets service name. + * <p> + * This parameter is mandatory when deploying a service. + * + * @return Service name. + */ + public String getName() { + return name; + } + + /** + * Sets service name. + * <p> + * This parameter is mandatory when deploying a service. + * + * @param name Service name. + */ + public void setName(String name) { + this.name = name; + } + + /** + * Gets service instance. + * <p> + * This parameter is mandatory when deploying a service. + * + * @return Service instance. + */ + public ManagedService getService() { + return svc; + } + + /** + * Sets service instance. + * <p> + * This parameter is mandatory when deploying a service. + * + * @param svc Service instance. + */ + public void setService(ManagedService svc) { + this.svc = svc; + } + + /** + * Gets total number of deployed service instances in the cluster, {@code 0} for unlimited. + * <p> + * At least one of {@code getTotalCount()} or {@link #getMaxPerNodeCount()} values must be positive. + * + * @return Total number of deployed service instances in the cluster, {@code 0} for unlimited. + */ + public int getTotalCount() { + return totalCnt; + } + + /** + * Sets total number of deployed service instances in the cluster, {@code 0} for unlimited. + * <p> + * At least one of {@code getTotalCount()} or {@link #getMaxPerNodeCount()} values must be positive. + * + * @param totalCnt Total number of deployed service instances in the cluster, {@code 0} for unlimited. + */ + public void setTotalCount(int totalCnt) { + this.totalCnt = totalCnt; + } + + /** + * Gets maximum number of deployed service instances on each node, {@code 0} for unlimited. + * <p> + * At least one of {@code getMaxPerNodeCount()} or {@link #getTotalCount()} values must be positive. + * + * @return Maximum number of deployed service instances on each node, {@code 0} for unlimited. + */ + public int getMaxPerNodeCount() { + return maxPerNodeCnt; + } + + /** + * Sets maximum number of deployed service instances on each node, {@code 0} for unlimited. + * <p> + * At least one of {@code getMaxPerNodeCount()} or {@link #getTotalCount()} values must be positive. + * + * @param maxPerNodeCnt Maximum number of deployed service instances on each node, {@code 0} for unlimited. + */ + public void setMaxPerNodeCount(int maxPerNodeCnt) { + this.maxPerNodeCnt = maxPerNodeCnt; + } + + /** + * Gets cache name used for key-to-node affinity calculation. + * <p> + * This parameter is optional and is set only when deploying service based on key-affinity. + * + * @return Cache name, possibly {@code null}. + */ + public String getCacheName() { + return cacheName; + } + + /** + * Sets cache name used for key-to-node affinity calculation. + * <p> + * This parameter is optional and is set only when deploying service based on key-affinity. + * + * @param cacheName Cache name, possibly {@code null}. + */ + public void setCacheName(String cacheName) { + this.cacheName = cacheName; + } + + /** + * Gets affinity key used for key-to-node affinity calculation. + * <p> + * This parameter is optional and is set only when deploying service based on key-affinity. + * + * @return Affinity key, possibly {@code null}. + */ + public Object getAffinityKey() { + return affKey; + } + + /** + * Sets affinity key used for key-to-node affinity calculation. + * <p> + * This parameter is optional and is set only when deploying service based on key-affinity. + * + * @param affKey Affinity key, possibly {@code null}. + */ + public void setAffinityKey(Object affKey) { + this.affKey = affKey; + } + + /** + * Gets node filter used to filter nodes on which the service will be deployed. + * <p> + * This parameter is optional. If not provided service may be deployed on any or all + * nodes in the grid, based on configuration. + * + * @return Node filter used to filter nodes on which the service will be deployed, possibly {@code null}. + */ + public IgnitePredicate<ClusterNode> getNodeFilter() { + return nodeFilter; + } + + /** + * Sets node filter used to filter nodes on which the service will be deployed. + * <p> + * This parameter is optional. If not provided service may be deployed on any or all + * nodes in the grid, based on configuration. + * + * @param nodeFilter Node filter used to filter nodes on which the service will be deployed, possibly {@code null}. + */ + public void setNodeFilter(IgnitePredicate<ClusterNode> nodeFilter) { + this.nodeFilter = nodeFilter; + } + + /** {@inheritDoc} */ + @SuppressWarnings({"RedundantIfStatement", "EqualsWhichDoesntCheckParameterClass"}) + @Override public boolean equals(Object o) { + if (!equalsIgnoreNodeFilter(o)) + return false; + + ManagedServiceConfiguration that = (ManagedServiceConfiguration)o; + + if (nodeFilter != null && that.nodeFilter != null) { + if (!nodeFilter.getClass().equals(that.nodeFilter.getClass())) + return false; + } + else if (nodeFilter != null || that.nodeFilter != null) + return false; + + return true; + } + + /** + * Checks if configurations are equal ignoring the node filter. Node filters control on which + * nodes the services are deployed and often can be ignored for equality checks. + * + * @param o Other configuration. + * @return {@code True} if configurations are equal, {@code false} otherwise. + */ + @SuppressWarnings("RedundantIfStatement") + public boolean equalsIgnoreNodeFilter(Object o) { + if (this == o) + return true; + + if (o == null || getClass() != o.getClass()) + return false; + + ManagedServiceConfiguration that = (ManagedServiceConfiguration)o; + + if (maxPerNodeCnt != that.maxPerNodeCnt) + return false; + + if (totalCnt != that.totalCnt) + return false; + + if (affKey != null ? !affKey.equals(that.affKey) : that.affKey != null) + return false; + + if (cacheName != null ? !cacheName.equals(that.cacheName) : that.cacheName != null) + return false; + + if (name != null ? !name.equals(that.name) : that.name != null) + return false; + + if (svc != null ? !svc.getClass().equals(that.svc.getClass()) : that.svc != null) + return false; + + return true; + } + + /** {@inheritDoc} */ + @Override public int hashCode() { + return name == null ? 0 : name.hashCode(); + } + + /** {@inheritDoc} */ + @Override public String toString() { + String svcCls = svc == null ? "" : svc.getClass().getSimpleName(); + String nodeFilterCls = nodeFilter == null ? "" : nodeFilter.getClass().getSimpleName(); + + return S.toString(ManagedServiceConfiguration.class, this, "svcCls", svcCls, "nodeFilterCls", nodeFilterCls); + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/2f809796/modules/core/src/main/java/org/apache/ignite/managed/ManagedServiceContext.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/managed/ManagedServiceContext.java b/modules/core/src/main/java/org/apache/ignite/managed/ManagedServiceContext.java new file mode 100644 index 0000000..61b585e --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/managed/ManagedServiceContext.java @@ -0,0 +1,60 @@ +/* @java.file.header */ + +/* _________ _____ __________________ _____ + * __ ____/___________(_)______ /__ ____/______ ____(_)_______ + * _ / __ __ ___/__ / _ __ / _ / __ _ __ `/__ / __ __ \ + * / /_/ / _ / _ / / /_/ / / /_/ / / /_/ / _ / _ / / / + * \____/ /_/ /_/ \_,__/ \____/ \__,_/ /_/ /_/ /_/ + */ + +package org.apache.ignite.managed; + +import org.jetbrains.annotations.*; + +import java.io.*; +import java.util.*; + +/** + * Service execution context. Execution context is provided into {@link ManagedService#execute(ManagedServiceContext)} + * and {@link ManagedService#cancel(ManagedServiceContext)} methods and contains information about specific service + * execution. + */ +public interface ManagedServiceContext extends Serializable { + /** + * Gets service name. + * + * @return Service name. + */ + public String name(); + + /** + * Gets service execution ID. Execution ID is guaranteed to be unique across + * all service deployments. + * + * @return Service execution ID. + */ + public UUID executionId(); + + /** + * Get flag indicating whether service has been cancelled or not. + * + * @return Flag indicating whether service has been cancelled or not. + */ + public boolean isCancelled(); + + /** + * Gets cache name used for key-to-node affinity calculation. This parameter is optional + * and is set only when key-affinity service was deployed. + * + * @return Cache name, possibly {@code null}. + */ + @Nullable public String cacheName(); + + /** + * Gets affinity key used for key-to-node affinity calculation. This parameter is optional + * and is set only when key-affinity service was deployed. + * + * @return Affinity key, possibly {@code null}. + */ + @Nullable public <K> K affinityKey(); +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/2f809796/modules/core/src/main/java/org/apache/ignite/managed/ManagedServiceDescriptor.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/managed/ManagedServiceDescriptor.java b/modules/core/src/main/java/org/apache/ignite/managed/ManagedServiceDescriptor.java new file mode 100644 index 0000000..39d3ca5 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/managed/ManagedServiceDescriptor.java @@ -0,0 +1,82 @@ +/* @java.file.header */ + +/* _________ _____ __________________ _____ + * __ ____/___________(_)______ /__ ____/______ ____(_)_______ + * _ / __ __ ___/__ / _ __ / _ / __ _ __ `/__ / __ __ \ + * / /_/ / _ / _ / / /_/ / / /_/ / / /_/ / _ / _ / / / + * \____/ /_/ /_/ \_,__/ \____/ \__,_/ /_/ /_/ /_/ + */ + +package org.apache.ignite.managed; + +import org.jetbrains.annotations.*; + +import java.io.*; +import java.util.*; + +/** + * Service deployment descriptor. Contains all service deployment configuration, and also + * deployment topology snapshot as well as origin node ID. + * <p> + * Service descriptors can be retrieved by calling {@link org.apache.ignite.IgniteManaged#deployedServices()} method. + */ +public interface ManagedServiceDescriptor extends Serializable { + /** + * Gets service name. + * + * @return Service name. + */ + public String name(); + + /** + * Gets service class. + * + * @return Service class. + */ + public Class<? extends ManagedService> serviceClass(); + + /** + * Gets maximum allowed total number of deployed services in the grid, {@code 0} for unlimited. + * + * @return Maximum allowed total number of deployed services in the grid, {@code 0} for unlimited. + */ + public int totalCount(); + + /** + * Gets maximum allowed number of deployed services on each node, {@code 0} for unlimited. + * + * @return Maximum allowed total number of deployed services on each node, {@code 0} for unlimited. + */ + public int maxPerNodeCount(); + + /** + * Gets cache name used for key-to-node affinity calculation. This parameter is optional + * and is set only when key-affinity service was deployed. + * + * @return Cache name, possibly {@code null}. + */ + @Nullable public String cacheName(); + + /** + * Gets affinity key used for key-to-node affinity calculation. This parameter is optional + * and is set only when key-affinity service was deployed. + * + * @return Affinity key, possibly {@code null}. + */ + @Nullable public <K> K affinityKey(); + + /** + * Gets ID of grid node that initiated the service deployment. + * + * @return ID of grid node that initiated the service deployment. + */ + public UUID originNodeId(); + + /** + * Gets service deployment topology snapshot. Service topology snapshot is represented + * by number of service instances deployed on a node mapped to node ID. + * + * @return Map of number of service instances per node ID. + */ + public Map<UUID, Integer> topologySnapshot(); +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/2f809796/modules/core/src/main/java/org/gridgain/grid/kernal/IgniteManagedImpl.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/gridgain/grid/kernal/IgniteManagedImpl.java b/modules/core/src/main/java/org/gridgain/grid/kernal/IgniteManagedImpl.java index 49bb06e..1ebd44e 100644 --- a/modules/core/src/main/java/org/gridgain/grid/kernal/IgniteManagedImpl.java +++ b/modules/core/src/main/java/org/gridgain/grid/kernal/IgniteManagedImpl.java @@ -58,7 +58,7 @@ public class IgniteManagedImpl extends IgniteAsyncSupportAdapter implements Igni } /** {@inheritDoc} */ - @Override public void deployNodeSingleton(String name, GridService svc) throws GridException { + @Override public void deployNodeSingleton(String name, ManagedService svc) throws GridException { A.notNull(name, "name"); A.notNull(svc, "svc"); @@ -73,7 +73,7 @@ public class IgniteManagedImpl extends IgniteAsyncSupportAdapter implements Igni } /** {@inheritDoc} */ - @Override public void deployClusterSingleton(String name, GridService svc) throws GridException { + @Override public void deployClusterSingleton(String name, ManagedService svc) throws GridException { A.notNull(name, "name"); A.notNull(svc, "svc"); @@ -88,7 +88,7 @@ public class IgniteManagedImpl extends IgniteAsyncSupportAdapter implements Igni } /** {@inheritDoc} */ - @Override public void deployMultiple(String name, GridService svc, int totalCnt, int maxPerNodeCnt) + @Override public void deployMultiple(String name, ManagedService svc, int totalCnt, int maxPerNodeCnt) throws GridException { A.notNull(name, "name"); A.notNull(svc, "svc"); @@ -104,7 +104,7 @@ public class IgniteManagedImpl extends IgniteAsyncSupportAdapter implements Igni } /** {@inheritDoc} */ - @Override public void deployKeyAffinitySingleton(String name, GridService svc, @Nullable String cacheName, + @Override public void deployKeyAffinitySingleton(String name, ManagedService svc, @Nullable String cacheName, Object affKey) throws GridException { A.notNull(name, "name"); A.notNull(svc, "svc"); @@ -121,7 +121,7 @@ public class IgniteManagedImpl extends IgniteAsyncSupportAdapter implements Igni } /** {@inheritDoc} */ - @Override public void deploy(GridServiceConfiguration cfg) throws GridException { + @Override public void deploy(ManagedServiceConfiguration cfg) throws GridException { A.notNull(cfg, "cfg"); guard(); @@ -161,7 +161,7 @@ public class IgniteManagedImpl extends IgniteAsyncSupportAdapter implements Igni } /** {@inheritDoc} */ - @Override public Collection<GridServiceDescriptor> deployedServices() { + @Override public Collection<ManagedServiceDescriptor> deployedServices() { guard(); try { http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/2f809796/modules/core/src/main/java/org/gridgain/grid/kernal/processors/resource/GridResourceCustomInjector.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/gridgain/grid/kernal/processors/resource/GridResourceCustomInjector.java b/modules/core/src/main/java/org/gridgain/grid/kernal/processors/resource/GridResourceCustomInjector.java index 5805a48..3e3b40a 100644 --- a/modules/core/src/main/java/org/gridgain/grid/kernal/processors/resource/GridResourceCustomInjector.java +++ b/modules/core/src/main/java/org/gridgain/grid/kernal/processors/resource/GridResourceCustomInjector.java @@ -71,7 +71,7 @@ class GridResourceCustomInjector implements GridResourceInjector { private GridResourceBasicInjector<IgniteLogger> logInjector; /** Service injector. */ - private GridResourceBasicInjector<Collection<GridService>> srvcInjector; + private GridResourceBasicInjector<Collection<ManagedService>> srvcInjector; /** Spring bean resources injector. */ private GridResourceInjector springBeanInjector; @@ -194,7 +194,7 @@ class GridResourceCustomInjector implements GridResourceInjector { * * @param srvcInjector Service injector. */ - public void setSrvcInjector(GridResourceBasicInjector<Collection<GridService>> srvcInjector) { + public void setSrvcInjector(GridResourceBasicInjector<Collection<ManagedService>> srvcInjector) { this.srvcInjector = srvcInjector; } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/2f809796/modules/core/src/main/java/org/gridgain/grid/kernal/processors/resource/GridResourceProcessor.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/gridgain/grid/kernal/processors/resource/GridResourceProcessor.java b/modules/core/src/main/java/org/gridgain/grid/kernal/processors/resource/GridResourceProcessor.java index f2dbbde..26a744d 100644 --- a/modules/core/src/main/java/org/gridgain/grid/kernal/processors/resource/GridResourceProcessor.java +++ b/modules/core/src/main/java/org/gridgain/grid/kernal/processors/resource/GridResourceProcessor.java @@ -102,7 +102,7 @@ public class GridResourceProcessor extends GridProcessorAdapter { private GridResourceBasicInjector<IgniteLogger> logInjector; /** Services injector. */ - private GridResourceBasicInjector<Collection<GridService>> srvcInjector; + private GridResourceBasicInjector<Collection<ManagedService>> srvcInjector; /** Address resolver injector. */ private GridResourceBasicInjector<GridAddressResolver> addrsRslvrInjector; @@ -618,7 +618,7 @@ public class GridResourceProcessor extends GridProcessorAdapter { * @param svc Service to inject. * @throws GridException If failed. */ - public void inject(GridService svc) throws GridException { + public void inject(ManagedService svc) throws GridException { if (log.isDebugEnabled()) log.debug("Injecting resources: " + svc); @@ -647,7 +647,7 @@ public class GridResourceProcessor extends GridProcessorAdapter { * @param svc Service. * @throws GridException Thrown in case of any errors. */ - public void cleanup(GridService svc) throws GridException { + public void cleanup(ManagedService svc) throws GridException { if (log.isDebugEnabled()) log.debug("Cleaning up resources: " + svc); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/2f809796/modules/core/src/main/java/org/gridgain/grid/kernal/processors/resource/GridResourceServiceInjector.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/gridgain/grid/kernal/processors/resource/GridResourceServiceInjector.java b/modules/core/src/main/java/org/gridgain/grid/kernal/processors/resource/GridResourceServiceInjector.java index 51290c9..dd4daa0 100644 --- a/modules/core/src/main/java/org/gridgain/grid/kernal/processors/resource/GridResourceServiceInjector.java +++ b/modules/core/src/main/java/org/gridgain/grid/kernal/processors/resource/GridResourceServiceInjector.java @@ -20,7 +20,7 @@ import java.util.*; /** * Grid service injector. */ -public class GridResourceServiceInjector extends GridResourceBasicInjector<Collection<GridService>> { +public class GridResourceServiceInjector extends GridResourceBasicInjector<Collection<ManagedService>> { /** */ private Ignite ignite; http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/2f809796/modules/core/src/main/java/org/gridgain/grid/kernal/processors/service/GridServiceAssignments.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/gridgain/grid/kernal/processors/service/GridServiceAssignments.java b/modules/core/src/main/java/org/gridgain/grid/kernal/processors/service/GridServiceAssignments.java index b9d89a6..34a942c 100644 --- a/modules/core/src/main/java/org/gridgain/grid/kernal/processors/service/GridServiceAssignments.java +++ b/modules/core/src/main/java/org/gridgain/grid/kernal/processors/service/GridServiceAssignments.java @@ -33,7 +33,7 @@ public class GridServiceAssignments implements Serializable, GridCacheInternal { private final long topVer; /** Service configuration. */ - private final GridServiceConfiguration cfg; + private final ManagedServiceConfiguration cfg; /** Assignments. */ @GridToStringInclude @@ -44,7 +44,7 @@ public class GridServiceAssignments implements Serializable, GridCacheInternal { * @param nodeId Node ID. * @param topVer Topology version. */ - public GridServiceAssignments(GridServiceConfiguration cfg, UUID nodeId, long topVer) { + public GridServiceAssignments(ManagedServiceConfiguration cfg, UUID nodeId, long topVer) { this.cfg = cfg; this.nodeId = nodeId; this.topVer = topVer; @@ -53,7 +53,7 @@ public class GridServiceAssignments implements Serializable, GridCacheInternal { /** * @return Configuration. */ - public GridServiceConfiguration configuration() { + public ManagedServiceConfiguration configuration() { return cfg; } @@ -67,7 +67,7 @@ public class GridServiceAssignments implements Serializable, GridCacheInternal { /** * @return Service. */ - public GridService service() { + public ManagedService service() { return cfg.getService(); } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/2f809796/modules/core/src/main/java/org/gridgain/grid/kernal/processors/service/GridServiceContextImpl.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/gridgain/grid/kernal/processors/service/GridServiceContextImpl.java b/modules/core/src/main/java/org/gridgain/grid/kernal/processors/service/GridServiceContextImpl.java deleted file mode 100644 index 91fb26b..0000000 --- a/modules/core/src/main/java/org/gridgain/grid/kernal/processors/service/GridServiceContextImpl.java +++ /dev/null @@ -1,148 +0,0 @@ -/* @java.file.header */ - -/* _________ _____ __________________ _____ - * __ ____/___________(_)______ /__ ____/______ ____(_)_______ - * _ / __ __ ___/__ / _ __ / _ / __ _ __ `/__ / __ __ \ - * / /_/ / _ / _ / / /_/ / / /_/ / / /_/ / _ / _ / / / - * \____/ /_/ /_/ \_,__/ \____/ \__,_/ /_/ /_/ /_/ - */ - -package org.gridgain.grid.kernal.processors.service; - -import org.apache.ignite.managed.*; -import org.gridgain.grid.util.tostring.*; -import org.gridgain.grid.util.typedef.internal.*; -import org.jetbrains.annotations.*; - -import java.lang.reflect.*; -import java.util.*; -import java.util.concurrent.*; - -/** - * Service context implementation. - */ -public class GridServiceContextImpl implements GridServiceContext { - /** */ - private static final long serialVersionUID = 0L; - - /** Null method. */ - private static final Method NULL_METHOD = GridServiceContextImpl.class.getMethods()[0]; - - /** Service name. */ - private final String name; - - /** Execution ID. */ - private final UUID execId; - - /** Cache name. */ - private final String cacheName; - - /** Affinity key. */ - private final Object affKey; - - /** Service. */ - @GridToStringExclude - private final GridService svc; - - /** Executor service. */ - @GridToStringExclude - private final ExecutorService exe; - - /** Methods reflection cache. */ - private final ConcurrentMap<GridServiceMethodReflectKey, Method> mtds = new ConcurrentHashMap<>(); - - /** Cancelled flag. */ - private volatile boolean isCancelled; - - - /** - * @param name Service name. - * @param execId Execution ID. - * @param cacheName Cache name. - * @param affKey Affinity key. - * @param svc Service. - * @param exe Executor service. - */ - GridServiceContextImpl(String name, UUID execId, String cacheName, Object affKey, GridService svc, - ExecutorService exe) { - this.name = name; - this.execId = execId; - this.cacheName = cacheName; - this.affKey = affKey; - this.svc = svc; - this.exe = exe; - } - - /** {@inheritDoc} */ - @Override public String name() { - return name; - } - - /** {@inheritDoc} */ - @Override public UUID executionId() { - return execId; - } - - /** {@inheritDoc} */ - @Override public boolean isCancelled() { - return isCancelled; - } - - /** {@inheritDoc} */ - @Nullable @Override public String cacheName() { - return cacheName; - } - - /** {@inheritDoc} */ - @SuppressWarnings("unchecked") - @Nullable @Override public <K> K affinityKey() { - return (K)affKey; - } - - /** - * @return Service instance. - */ - GridService service() { - return svc; - } - - /** - * @return Executor service. - */ - ExecutorService executor() { - return exe; - } - - /** - * @param key Method key. - * @return Method. - */ - @Nullable Method method(GridServiceMethodReflectKey key) { - Method mtd = mtds.get(key); - - if (mtd == null) { - try { - mtd = svc.getClass().getMethod(key.methodName(), key.argTypes()); - } - catch (NoSuchMethodException e) { - mtd = NULL_METHOD; - } - - mtds.put(key, mtd); - } - - return mtd == NULL_METHOD ? null : mtd; - } - - /** - * @param isCancelled Cancelled flag. - */ - public void setCancelled(boolean isCancelled) { - this.isCancelled = isCancelled; - } - - /** {@inheritDoc} */ - @Override public String toString() { - return S.toString(GridServiceContextImpl.class, this); - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/2f809796/modules/core/src/main/java/org/gridgain/grid/kernal/processors/service/GridServiceDeployment.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/gridgain/grid/kernal/processors/service/GridServiceDeployment.java b/modules/core/src/main/java/org/gridgain/grid/kernal/processors/service/GridServiceDeployment.java index 2ff84e7..62c3fa2 100644 --- a/modules/core/src/main/java/org/gridgain/grid/kernal/processors/service/GridServiceDeployment.java +++ b/modules/core/src/main/java/org/gridgain/grid/kernal/processors/service/GridServiceDeployment.java @@ -27,13 +27,13 @@ public class GridServiceDeployment implements GridCacheInternal, Serializable { private UUID nodeId; /** Service configuration. */ - private GridServiceConfiguration cfg; + private ManagedServiceConfiguration cfg; /** * @param nodeId Node ID. * @param cfg Service configuration. */ - public GridServiceDeployment(UUID nodeId, GridServiceConfiguration cfg) { + public GridServiceDeployment(UUID nodeId, ManagedServiceConfiguration cfg) { this.nodeId = nodeId; this.cfg = cfg; } @@ -48,7 +48,7 @@ public class GridServiceDeployment implements GridCacheInternal, Serializable { /** * @return Service configuration. */ - public GridServiceConfiguration configuration() { + public ManagedServiceConfiguration configuration() { return cfg; } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/2f809796/modules/core/src/main/java/org/gridgain/grid/kernal/processors/service/GridServiceDeploymentFuture.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/gridgain/grid/kernal/processors/service/GridServiceDeploymentFuture.java b/modules/core/src/main/java/org/gridgain/grid/kernal/processors/service/GridServiceDeploymentFuture.java index 02e9343..e495909 100644 --- a/modules/core/src/main/java/org/gridgain/grid/kernal/processors/service/GridServiceDeploymentFuture.java +++ b/modules/core/src/main/java/org/gridgain/grid/kernal/processors/service/GridServiceDeploymentFuture.java @@ -22,13 +22,13 @@ public class GridServiceDeploymentFuture extends GridFutureAdapter<Object> { private static final long serialVersionUID = 0L; /** */ - private final GridServiceConfiguration cfg; + private final ManagedServiceConfiguration cfg; /** * @param ctx Context. * @param cfg Configuration. */ - public GridServiceDeploymentFuture(GridKernalContext ctx, GridServiceConfiguration cfg) { + public GridServiceDeploymentFuture(GridKernalContext ctx, ManagedServiceConfiguration cfg) { super(ctx); this.cfg = cfg; @@ -37,7 +37,7 @@ public class GridServiceDeploymentFuture extends GridFutureAdapter<Object> { /** * @return Service configuration. */ - GridServiceConfiguration configuration() { + ManagedServiceConfiguration configuration() { return cfg; } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/2f809796/modules/core/src/main/java/org/gridgain/grid/kernal/processors/service/GridServiceDescriptorImpl.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/gridgain/grid/kernal/processors/service/GridServiceDescriptorImpl.java b/modules/core/src/main/java/org/gridgain/grid/kernal/processors/service/GridServiceDescriptorImpl.java deleted file mode 100644 index 1a904ce..0000000 --- a/modules/core/src/main/java/org/gridgain/grid/kernal/processors/service/GridServiceDescriptorImpl.java +++ /dev/null @@ -1,93 +0,0 @@ -/* @java.file.header */ - -/* _________ _____ __________________ _____ - * __ ____/___________(_)______ /__ ____/______ ____(_)_______ - * _ / __ __ ___/__ / _ __ / _ / __ _ __ `/__ / __ __ \ - * / /_/ / _ / _ / / /_/ / / /_/ / / /_/ / _ / _ / / / - * \____/ /_/ /_/ \_,__/ \____/ \__,_/ /_/ /_/ /_/ - */ - -package org.gridgain.grid.kernal.processors.service; - -import org.apache.ignite.managed.*; -import org.gridgain.grid.util.tostring.*; -import org.gridgain.grid.util.typedef.internal.*; -import org.jetbrains.annotations.*; - -import java.util.*; - -/** - * Service descriptor. - */ -public class GridServiceDescriptorImpl implements GridServiceDescriptor { - /** */ - private static final long serialVersionUID = 0L; - - /** Configuration. */ - @GridToStringInclude - private final GridServiceDeployment dep; - - /** Topology snapshot. */ - @GridToStringInclude - private Map<UUID, Integer> top; - - /** - * @param dep Deployment. - */ - public GridServiceDescriptorImpl(GridServiceDeployment dep) { - this.dep = dep; - } - - /** {@inheritDoc} */ - @Override public String name() { - return dep.configuration().getName(); - } - - /** {@inheritDoc} */ - @Override public Class<? extends GridService> serviceClass() { - return dep.configuration().getService().getClass(); - } - - /** {@inheritDoc} */ - @Override public int totalCount() { - return dep.configuration().getTotalCount(); - } - - /** {@inheritDoc} */ - @Override public int maxPerNodeCount() { - return dep.configuration().getMaxPerNodeCount(); - } - - /** {@inheritDoc} */ - @Nullable @Override public String cacheName() { - return dep.configuration().getCacheName(); - } - - /** {@inheritDoc} */ - @SuppressWarnings("unchecked") - @Nullable @Override public <K> K affinityKey() { - return (K)dep.configuration().getAffinityKey(); - } - - /** {@inheritDoc} */ - @Override public UUID originNodeId() { - return dep.nodeId(); - } - - /** {@inheritDoc} */ - @Override public Map<UUID, Integer> topologySnapshot() { - return top; - } - - /** - * @param top Topology snapshot. - */ - void topologySnapshot(Map<UUID, Integer> top) { - this.top = top; - } - - /** {@inheritDoc} */ - @Override public String toString() { - return S.toString(GridServiceDescriptorImpl.class, this); - } -}