本文整理汇总了Java中com.gemstone.gemfire.cache.client.ClientCache.close方法的典型用法代码示例。如果您正苦于以下问题:Java ClientCache.close方法的具体用法?Java ClientCache.close怎么用?Java ClientCache.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.gemstone.gemfire.cache.client.ClientCache
的用法示例。
在下文中一共展示了ClientCache.close方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import com.gemstone.gemfire.cache.client.ClientCache; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
writeToStdout("Connecting to the distributed system and creating the cache.");
// Create the cache which causes the cache-xml-file to be parsed
ClientCache cache = new ClientCacheFactory()
.set("name", "DeltaPropagationClientReceiver")
.set("cache-xml-file", "xml/DeltaClient2.xml")
.create();
Region<Object, Object> reg = cache.getRegion("exampleRegion");
reg.registerInterest("ALL_KEYS");
writeToStdout("Please press Enter to stop the receiver.");
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
bufferedReader.readLine();
cache.close();
}
示例2: main
import com.gemstone.gemfire.cache.client.ClientCache; //导入方法依赖的package包/类
public static void main(String [] args) throws Exception {
System.out.println("Connecting to the distributed system and creating the cache.");
// Create the cache which causes the cache-xml-file to be parsed
ClientCache cache = new ClientCacheFactory()
.set("name", "I18nClient")
.set("cache-xml-file", "xml/I18nClient.xml")
.create();
// Get the exampleRegion
Region<String, String> region = cache.getRegion("家具店");
System.out.println("Example region, " + region.getFullPath() + ", created in cache.");
System.out.println();
System.out.println("Getting values from the server...");
String query = "SELECT DISTINCT * FROM " + region.getFullPath() + ".keys";
SelectResults<String> results = region.query(query);
List<String> keys = results.asList();
for (String key : keys) {
String value = region.get(key);
System.out.println("item: " + key + " price: " + value);
}
System.out.println();
System.out.println("Closing the cache and disconnecting.");
cache.close();
}
示例3: main
import com.gemstone.gemfire.cache.client.ClientCache; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
writeToStdout("Connecting to the distributed system and creating the cache.");
// Create the cache which causes the cache-xml-file to be parsed
ClientCache cache = new ClientCacheFactory()
.set("name", "DeltaPropagationClientFeeder")
.set("cache-xml-file", "xml/DeltaClient1.xml")
.create();
Region<Object, Object> reg = cache.getRegion("exampleRegion");
/*int valueSize = 10;*/
/*int deltaPercent = 2;*/
writeToStdout("Delta is 50%.");
writeToStdout("Please press Enter to start the feeder.");
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
bufferedReader.readLine();
for (int i = 0; i < FEED_CYCLES; i++) {
for (int j = 0; j < PUT_KEY_RANGE; j++) {
DeltaObj value = new DeltaObj();
value.setObj(i);
if (firstCreate == 0) {
firstCreate = System.currentTimeMillis();
}
reg.put(j, value);
}
}
reg.put("LAST_KEY", firstCreate);
cache.close();
}
示例4: runPublisher
import com.gemstone.gemfire.cache.client.ClientCache; //导入方法依赖的package包/类
private static void runPublisher() {
/*
* To declare in a cache.xml do this:
<!DOCTYPE client-cache PUBLIC
"-//GemStone Systems, Inc.//GemFire Declarative Caching 6.5//EN"
"http://www.gemstone.com/dtd/cache6_5.dtd">
<client-cache>
<pool name="publisher">
<locator host="localhost" port="41111"/>
</pool>
</client-cache>
*/
ClientCacheFactory ccf = connectStandalone("publisher");
ClientCache cache = ccf.create();
/*
* To declare in a cache.xml do this:
<region name="DATA" refid="PROXY"/>
*/
ClientRegionFactory<String,String> regionFactory = cache.createClientRegionFactory(PROXY);
Region<String, String> region = regionFactory.create("DATA");
// now just do some puts in the publisher and confirm that they
// show up in the client
for (int i=1; i <= NUM_PUTS; i++) {
String key = "key"+i;
String value = "value"+i;
System.out.println("putting key " + key);
region.put(key, value);
}
cache.close();
}
示例5: closeCache
import com.gemstone.gemfire.cache.client.ClientCache; //导入方法依赖的package包/类
/**
* Closes the cache if it exists and is open.
*/
public static synchronized void closeCache() {
ClientCache cache = getCache();
if (cache != null) {
log("Closing cache: " + cacheToString(cache));
cache.close();
log("Closed cache");
TheCacheConfig = null; // so the next create can have a different config
}
}
示例6: closeClientCache
import com.gemstone.gemfire.cache.client.ClientCache; //导入方法依赖的package包/类
/**
* Closes client cache instance
* @param clientCache
*/
public void closeClientCache(ClientCache clientCache) {
if (clientCache != null && !clientCache.isClosed()) {
clientCache.close();
}
}
示例7: main
import com.gemstone.gemfire.cache.client.ClientCache; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
System.out.println("Connecting to the distributed system and creating the cache.");
// Create the cache which causes the cache-xml-file to be parsed
ClientCache cache = new ClientCacheFactory()
.set("name", "JSONClient")
.set("cache-xml-file", "xml/JsonClient.xml")
.create();
// Get the exampleRegion
Region<String, PdxInstance> exampleRegion = cache.getRegion(EXAMPLE_REGION_NAME);
System.out.println("Example region \"" + exampleRegion.getFullPath() + "\" created in cache.");
System.out.println();
System.out.println("Putting JSON documents.");
String jsonCustomer = "{"
+ "\"firstName\": \"John\","
+ "\"lastName\": \"Smith\","
+ " \"age\": 25,"
+ "\"address\":"
+ "{"
+ "\"streetAddress\": \"21 2nd Street\","
+ "\"city\": \"New York\","
+ "\"state\": \"NY\","
+ "\"postalCode\": \"10021\""
+ "},"
+ "\"phoneNumber\":"
+ "["
+ "{"
+ " \"type\": \"home\","
+ "\"number\": \"212 555-1234\""
+ "},"
+ "{"
+ " \"type\": \"fax\","
+ "\"number\": \"646 555-4567\""
+ "}"
+ "]"
+ "}";
System.out.println("JSON documents added into Cache: " + jsonCustomer);
System.out.println();
exampleRegion.put("jsondoc1", JSONFormatter.fromJSON(jsonCustomer));
String getJsonCustomer = JSONFormatter.toJSON(exampleRegion.get("jsondoc1"));
System.out.println("Got JSON documents from Cache: " + getJsonCustomer);
System.out.println();
System.out.println("Executed query on JSON doc with predicate \" age = 25 \"");
System.out.println();
SelectResults<PdxInstance> sr = exampleRegion.query("age = 25");
System.out.println("got expected result = " + sr.size());
System.out.println();
System.out.println("got expected result value = " + JSONFormatter.toJSON(sr.iterator().next()));
System.out.println();
// Close the cache and disconnect from GemFire distributed system
System.out.println("Closing the cache and disconnecting.");
cache.close();
System.out.println("In the other session, please hit Enter in the JSON client");
System.out.println("and then stop the cacheserver with 'gfsh stop server --dir=server_json'.");
}
示例8: main
import com.gemstone.gemfire.cache.client.ClientCache; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
writeToStdout("Connecting to the distributed system and creating the cache.");
// Create the cache which causes the cache-xml-file to be parsed
ClientCache cache = new ClientCacheFactory()
.set("name", "DurableClient")
.set("cache-xml-file", "xml/DurableClient.xml")
.set("durable-client-id", "DurableClientId")
.set("durable-client-timeout", "" + 300)
.create();
// Get the exampleRegion
Region<String, String> exampleRegion = cache.getRegion("exampleRegion");
if (exampleRegion == null) {
writeToStdout("Region /exampleRegion does not exist, exiting...");
return;
}
writeToStdout("Registering non-durable interest in keys key1 & key2.");
exampleRegion.registerInterest("key1", false);
exampleRegion.registerInterest("key2", false);
writeToStdout("Registering durable interest in keys key3 & key4.");
exampleRegion.registerInterest("key3", true);
exampleRegion.registerInterest("key4", true);
writeToStdout("Sending Client Ready...");
cache.readyForEvents();
writeToStdout();
writeToStdout("Press Enter in the server window to do an update on the server.");
writeToStdout("Then press Enter in the client window to continue.");
String inputString = new BufferedReader(new InputStreamReader(System.in)).readLine();
writeToStdout();
writeToStdout("After the update on the server, the region contains:");
writeToStdout("key1 => " + exampleRegion.get("key1"));
writeToStdout("key2 => " + exampleRegion.get("key2"));
writeToStdout("key3 => " + exampleRegion.get("key3"));
writeToStdout("key4 => " + exampleRegion.get("key4"));
writeToStdout();
writeToStdout("Closing the cache and disconnecting from the distributed system...");
if (inputString.equalsIgnoreCase("CloseCache")) {
cache.close(false);
}
else {
cache.close(true);
}
writeToStdout("Finished disconnecting from the distributed system. Exiting...");
}
示例9: main
import com.gemstone.gemfire.cache.client.ClientCache; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
if (args.length != 1) {
System.out.println(USAGE);
System.exit(1);
}
RegisterInterestType registerInterestType;
if (args[0].equals("all-keys")) {
registerInterestType = RegisterInterestType.ALL_KEYS;
}
else if (args[0].equals("keyset")) {
registerInterestType = RegisterInterestType.KEYSET;
}
else if (args[0].equals("regex")) {
registerInterestType = RegisterInterestType.REGEX;
}
else {
registerInterestType = null;
System.out.println(USAGE);
System.exit(2);
}
// Subscribe to the indicated key set
System.out.println("Connecting to the distributed system and creating the cache.");
// Create the cache which causes the cache-xml-file to be parsed
ClientCache cache = new ClientCacheFactory()
.set("name", "ClientConsumer")
.set("cache-xml-file", "xml/Client.xml")
.create();
// Get the exampleRegion which is a subregion of /root
Region<String, ?> exampleRegion = cache.getRegion(EXAMPLE_REGION_NAME);
System.out.println("Example region \"" + exampleRegion.getFullPath() + "\" created in cache. ");
switch (registerInterestType) {
case ALL_KEYS:
System.out.println("Asking the server to send me all data additions, updates, and destroys. ");
exampleRegion.registerInterest("ALL_KEYS");
break;
case KEYSET:
System.out.println("Asking the server to send me events for data with these keys: 'key0', 'key1'");
exampleRegion.registerInterest("key0");
exampleRegion.registerInterest("key1");
break;
case REGEX:
System.out.println("Asking the server to register interest in keys matching this");
System.out.println("regular expression: 'k.*2'");
exampleRegion.registerInterestRegex("k.*2");
break;
default:
// Can't happen
throw new RuntimeException();
}
System.out.println("The data region has a listener that reports all changes to standard out.");
System.out.println();
System.out.println("Please run the worker client in another session. It will update the");
System.out.println("cache and the server will forward the updates to me. Note the listener");
System.out.println("output in this session.");
System.out.println();
System.out.println("When the other client finishes, hit Enter to exit this program.");
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
bufferedReader.readLine();
System.out.println("Closing the cache and disconnecting.");
cache.close();
}
示例10: main
import com.gemstone.gemfire.cache.client.ClientCache; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
System.out.println("Connecting to the distributed system and creating the cache.");
// Create the cache which causes the cache-xml-file to be parsed
ClientCache cache = new ClientCacheFactory()
.set("name", "ClientWorker")
.set("cache-xml-file", "xml/Client.xml")
.create();
// Get the exampleRegion
Region<String, String> exampleRegion = cache.getRegion(EXAMPLE_REGION_NAME);
System.out.println("Example region \"" + exampleRegion.getFullPath() + "\" created in cache.");
System.out.println();
System.out.println("Getting three values from the cache server.");
System.out.println("This will cause the server's loader to run, which will add the values");
System.out.println("to the server cache and return them to me. The values will also be");
System.out.println("forwarded to any other client that has subscribed to the region.");
// Get three values from the cache
for (int count = 0; count < 3; count++) {
String key = "key" + count;
System.out.println("Getting key " + key);
exampleRegion.get(key);
}
System.out.println("Note the other client's region listener in response to these gets.");
System.out.println("Press Enter to continue.");
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
bufferedReader.readLine();
System.out.println("Changing the data in my cache - all destroys and updates are forwarded");
System.out.println("through the server to other clients. Invalidations are not forwarded.");
// Update one value in the cache
System.out.println("Putting new value for key0");
exampleRegion.put("key0", "ClientValue0");
// Invalidate one entry in the cache
System.out.println("Invalidating key1");
exampleRegion.invalidate("key1");
// Destroy one entry in the cache
System.out.println("Destroying key2");
exampleRegion.destroy("key2");
// Close the cache and disconnect from GemFire distributed system
System.out.println("Closing the cache and disconnecting.");
cache.close();
System.out.println("In the other session, please hit Enter in the Consumer client");
System.out.println("and then stop the cacheserver with 'gfsh stop server --dir=<serverDirectory>'.");
}
示例11: main
import com.gemstone.gemfire.cache.client.ClientCache; //导入方法依赖的package包/类
public static void main(String[] args) {
// Create client cache
ClientCache clientCache = new ClientCacheFactory()
.addPoolServer("localhost", SERVER1_PORT)
.addPoolServer("localhost", SERVER2_PORT).create();
log("Connected to servers on ports: " + SERVER1_PORT + " and " + SERVER2_PORT);
// Create Region
ClientRegionFactory<String, Portfolio> regionFactory = clientCache
.createClientRegionFactory(PROXY);
Region<String, Portfolio> region = regionFactory.create("exampleRegion");
// Insert data
// key is same as the id field of Portfolio
for (int i = 0; i < NUM_PUTS; i++) {
region.put("" + i, new Portfolio(i));
}
log("Inserted " + NUM_PUTS + " Portfolio objects");
Set<String> filter = new HashSet<String>();
// Filter data based on region key '1' for value Portfolio(1)
filter.add("1");
// Query to get Portfolio with id = '1'
String qStr = "SELECT * FROM /exampleRegion WHERE id = '1'";
Function func = new QueryingFunction();
log("Invoking funtion on server to execute query: SELECT * FROM /exampleRegion WHERE id = '1'");
// Function will be routed to one node containing the bucket
// for id = '1' and query will execute on that bucket.
ResultCollector rcollector = FunctionService.onRegion(region)
.withArgs(qStr).withFilter(filter).execute(func);
Object result = rcollector.getResult();
// Results from one or multiple nodes.
ArrayList resultList = (ArrayList) result;
List queryResults = new ArrayList();
if (resultList.size() != 0) {
for (Object obj : resultList) {
if (obj != null) {
queryResults.addAll((ArrayList) obj);
}
}
}
log("Query returned " + queryResults.size() + " results");
log("Query result:\t" + formatQueryResult(queryResults));
// Close the cache and disconnect from GemFire distributed system
clientCache.close();
}
示例12: runSubscriber
import com.gemstone.gemfire.cache.client.ClientCache; //导入方法依赖的package包/类
private static void runSubscriber() throws InterruptedException {
/*
* To declare in a cache.xml do this:
<!DOCTYPE client-cache PUBLIC
"-//GemStone Systems, Inc.//GemFire Declarative Caching 6.5//EN"
"http://www.gemstone.com/dtd/cache6_5.dtd">
<client-cache>
<pool name="subscriber" subscription-enabled="true">
<locator host="localhost" port="41111"/>
</pool>
</client-cache>
*/
ClientCacheFactory ccf = connectStandalone("subscriber");
ccf.setPoolSubscriptionEnabled(true);
ClientCache cache = ccf.create();
/*
* To declare in a cache.xml do this:
<region name="DATA" refid="PROXY">
<region-attributes>
<subscription-attributes interest-policy=all/>
<cache-listener>
<class-name>clientAPI.SubscriberListener</class-name>
</cache-listener>
</region-attributes>
</region>
*/
ClientRegionFactory<String,String> regionFactory = cache.createClientRegionFactory(PROXY);
Region<String, String> region = regionFactory
.addCacheListener(new SubscriberListener())
.create("DATA");
region.registerInterestRegex(".*", // everything
InterestResultPolicy.NONE,
false/*isDurable*/);
SubscriberListener myListener = (SubscriberListener)
region.getAttributes().getCacheListeners()[0];
System.out.println("waiting for publisher to do " + NUM_PUTS + " puts...");
myListener.waitForPuts(NUM_PUTS);
System.out.println("done waiting for publisher.");
cache.close();
}
示例13: main
import com.gemstone.gemfire.cache.client.ClientCache; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
ClientCacheFactory cf = new ClientCacheFactory();
cf.set("cache-xml-file", "client.xml");
ClientCache cache = cf.create();
System.out.println("Created the GemFire Cache");
// Get the example Region from the Cache which is declared in the Cache XML file.
Region<String, PortfolioPdx> region = cache.<String, PortfolioPdx>getRegion("Portfolios");
System.out.println("Obtained the Region from the Cache");
// Populate the Region with some PortfolioPdx objects.
PortfolioPdx port1 = new PortfolioPdx(1 /*ID*/, 10 /*size*/);
PortfolioPdx port2 = new PortfolioPdx(2 /*ID*/, 20 /*size*/);
PortfolioPdx port3 = new PortfolioPdx(3 /*ID*/, 30 /*size*/);
region.put("Key1", port1);
region.put("Key2", port2);
region.put("Key3", port3);
System.out.println("Populated some PortfolioPdx Objects");
//find the pool
Pool pool = PoolManager.find("examplePool");
// Get the QueryService from the pool
QueryService qrySvc = pool.getQueryService();
System.out.println("Got the QueryService from the Pool");
// Execute a Query which returns a ResultSet.
Query qry = qrySvc.newQuery("SELECT DISTINCT * FROM /Portfolios");
SelectResults<PortfolioPdx> results = (SelectResults<PortfolioPdx>) qry.execute();
System.out.println("ResultSet Query returned " + results.size() + " rows");
// Execute a Query which returns a StructSet.
QueryService qrySvc1 = pool.getQueryService();
Query qry1 = qrySvc1.newQuery("SELECT DISTINCT id, status FROM /Portfolios WHERE id > 1");
SelectResults<Struct> results1 = (SelectResults<Struct>) qry1.execute();
System.out.println("StructSet Query returned " + results1.size() + " rows");
// Iterate through the rows of the query result.
int rowCount = 0;
for (Struct si : results1) {
rowCount++;
System.out.println("Row " + rowCount + " Column 0 is named " + si.getStructType().getFieldNames()[0] + ", value is " + si.getFieldValues()[0]);
System.out.println("Row " + rowCount + " Column 1 is named " + si.getStructType().getFieldNames()[1] + ", value is " + si.getFieldValues()[1]);
}
// Close the GemFire Cache.
cache.close();
System.out.println("Closed the GemFire Cache");
}
示例14: closeClientCache
import com.gemstone.gemfire.cache.client.ClientCache; //导入方法依赖的package包/类
protected static void closeClientCache(final ClientCache cache) {
cache.close(true);
}