Apache Geode 管理客户端缓存

       你有多个客户端缓存配置选项。用XML声明和应用程序编程接口调用结合的方式启动客户端缓存。当完成使用时关闭客户端缓存。

       Geode客户端是发送大多数或所有的数据请求到Geode服务器系统的进程。客户端作为独立的进程运行,它们没有自己的节点。

注意:Geode自动为你的ClientCache将分布式系统配置为独立的系统,这意味着客户端没有节点。不要试图为一个客户端设置gemfire.properties mcast-port 或locators否则系统会抛出一个异常。

创建你的客户端缓存:

在你的cache.xml文件中, 使用 client-cache DOCTYPE 并在<client-cache> 元素里配置cache. 配置你的服务器连接池和你的区域,如果有需要的话。例如:

<?xml version="1.0" encoding="UTF-8"?>
<client-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">
    <pool name="serverPool">
        <locator host="host1" port="44444"/>
    </pool>
    <region name="exampleRegion" refid="PROXY"/>
</client-cache>

注意: 使用client-cache的应用可能想要把 concurrency-checks-enabled设为false来实现查看区域的所有事件。Geode服务器成员可以持续使用并发检查,但他会将所有事件发送给客户端。这个配置确保客户端可以看到所有的区域事件,但它并不能阻止客户端区域与服务器缓存失去同步。查看《区域更新的一致性》

如果你使用多个服务器池,为每个客户端明确的配置池的名称。例如:

<pool name="svrPool1">
    <locator host="host1" port="40404"/>
</pool>
<pool name="svrPool2">
    <locator host="host2" port="40404"/>
</pool>
<region name="clientR1" refid="PROXY" pool-name="svrPool1"/>  
<region name="clientR2" refid="PROXY" pool-name="svrPool2"/>
<region name="clientsPrivateR" refid="LOCAL"/>

在你的java客户端应用中,用ClientCacheFactory的create方法创建缓存,例如:

ClientCache clientCache = new ClientCacheFactory().create();

这个会创建服务器连接,并按你的gemfire.propertiescache.xml声明来初始化客户端缓存。

当你使用完成,用你的Cache实例的close方法关闭你的缓存:

cache.close();

 如果客户端是持久的,并且希望在客户端缓存关闭时维护持久队列,使用:

clientCache.close(true);

猜你喜欢

转载自bewithme.iteye.com/blog/2353460