在之前的例子中, 我们的程序实现了分布式调用,这是一个最最基础的需求--能跑。随后我们的“野心”会更大,希望能精细化的控制我们的应用跑在哪里,某一个实例上或者某几个实例上。这就需要下层的分布式系统能对集群做精细化的管理,而在Ignite中,对集群的管理大致可以发分为两类
粗放化
- 远程节点分组
IgniteCluster cluster = ignite.cluster();
// Cluster group with remote nodes, i.e. other than this node.
ClusterGroup remoteGroup = cluster.forRemotes();
- client节点分组
IgniteCluster cluster = ignite.cluster();
// All client nodes.
ClusterGroup clientGroup = cluster.forClients();
- server节点分组
IgniteCluster cluster = ignite.cluster();
// All server nodes.
ClusterGroup serverGroup = cluster.forServers();
精细化
- 根据是否部署了特定cache分组
IgniteCluster cluster = ignite.cluster();
// All nodes on which cache with name "myCache" is deployed,
// either in client or server mode.
ClusterGroup cacheGroup = cluster.forCache("myCache");
- 根据部署了特定cache的server节点分组
IgniteCluster cluster = ignite.cluster();
// All data nodes responsible for caching data for "myCache".
ClusterGroup dataGroup = cluster.forDataNodes("myCache");
- 根据可访问特定cache的client节点分组
IgniteCluster cluster = ignite.cluster();
// All client nodes that access "myCache".
ClusterGroup clientGroup = cluster.forClientNodes("myCache");
- 根据节点属性分组
节点启动时可以配置特定的属性值
<bean class="org.apache.ignite.IgniteConfiguration">
...
<property name="userAttributes">
<map>
<entry key="ROLE" value="worker"/>
</map>
</property>
...
</bean>
之后可以根据属性值进行分组
IgniteCluster cluster = ignite.cluster();
// All nodes with attribute "ROLE" equal to "worker".
ClusterGroup attrGroup = cluster.forAttribute("ROLE", "worker");
如此,我们就可以将应用精确的部署到所需要的分组中了
IgniteCompute compute = ignite.compute(xxxGroup);