你使用XML声明和应用程序编程接口结合的方式启动你的节点或服务器缓存。当完成时关闭缓存。
Geode节点是Geode分布式系统成员,它不作为连到另外一个Geode分布式系统的客户端。Geode服务器是监听和处理客户端请求的节点。
创建你的缓存:
启动一个集群和集群配置服务:
启动一个定位器,把 --enable-cluster-configuration
参数设为true(默认情况下是设为true)
gfsh>start locator --name=locator1
启动用于集群配置服务的成员进程(默认是可用的):
gfsh>start server --name=server1 --server-port=40404
创建区域:
gfsh>create region --name=customerRegion --type=REPLICATE
gfsh>create region --name=ordersRegion --type=PARTITION
或者如果你不使用集群配置服务,在每个成员中直接配置cache.xml。在你的cache.xml,使用cache文件类型并且在<cache>元素里
配置你的缓存。例如:
<?xml version="1.0" encoding="UTF-8"?>
<cache
xmlns="http://geode.incubator.apache.org/schema/cache"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://geode.incubator.apache.org/schema/cache http://geode.incubator.apache.org/schema/cache/cache-1.0.xsd"
version="1.0”>
// NOTE: Use this <cache-server> element only for server processes
<cache-server port="40404"/>
<region name="customerRegion" refid="REPLICATE" />
<region name="ordersRegion" refid="PARTITION" />
</cache>
用编程的方式来创建Cache实例
在你的应用中,使用CacheFactory的create方法
Cache cache = new CacheFactory().create();
如果你正在用geode的cacheserver进程来运行服务器,它会自动创建缓存并在启动连接,退出时关闭。
系统根据你的gemfire.properties
和 cache.xml说明来
创建分布式系统连接并初始化缓存。
在完成后使用cache实例继承的close方法来关闭你的缓存
cache.close();