Java Code Examples for org.apache.geode.cache.client.ClientCache#close()

The following examples show how to use org.apache.geode.cache.client.ClientCache#close() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Example.java    From geode-examples with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {
  // connect to the locator using default port 10334
  ClientCache cache = new ClientCacheFactory().addPoolLocator("127.0.0.1", 10334)
      .set("log-level", "WARN").create();

  // create a local region that matches the server region
  Region<String, Integer> region =
      cache.<String, Integer>createClientRegionFactory(ClientRegionShortcut.PROXY)
          .create("example-region");

  Example example = new Example(region);
  final int previous = example.getCounter();
  example.increment();
  final int current = example.getCounter();
  System.out.println(previous + " -> " + current);

  cache.close();
}
 
Example 2
Source File: Example.java    From geode-examples with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {
  // connect to the locator using default port 10334
  ClientCache cache = new ClientCacheFactory().addPoolLocator("127.0.0.1", 10334)
      .set("log-level", "WARN").create();

  // create a local region that matches the server region
  Region<Integer, String> region =
      cache.<Integer, String>createClientRegionFactory(ClientRegionShortcut.PROXY)
          .create("example-region");

  Example example = new Example(region);
  example.insertValues(10);
  example.printValues(example.getValues());

  cache.close();
}
 
Example 3
Source File: Example.java    From geode-examples with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {
  ClientCache cache = new ClientCacheFactory().addPoolLocator("127.0.0.1", 10334)
      .set("log-level", "WARN").create();

  Region<Integer, Customer> customerRegion =
      cache.<Integer, Customer>createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY)
          .create("customer");

  Region<OrderKey, Order> orderRegion =
      cache.<OrderKey, Order>createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY)
          .create("order");

  Map<Integer, Customer> customers = generateCustomers();

  for (int i : customers.keySet()) {
    Customer customer = customers.get(i);
    Order order = new Order(i * 10, customer.getId());
    customerRegion.put(customer.getId(), customer);
    orderRegion.put(order.getKey(), order);
  }
  cache.close();
}
 
Example 4
Source File: Example.java    From geode-examples with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {
  // connect to the locator using default port 10334
  ClientCache cache = new ClientCacheFactory().addPoolLocator("127.0.0.1", 10334)
      .set("log-level", "WARN").create();

  // create a local region that matches the server region
  Region<String, Integer> region =
      cache.<String, Integer>createClientRegionFactory(ClientRegionShortcut.PROXY)
          .create("example-region");

  Example example = new Example(region);
  final int previous = example.getCounter();
  example.increment();
  final int current = example.getCounter();
  System.out.println(previous + " -> " + current);

  cache.close();
}
 
Example 5
Source File: Example.java    From geode-examples with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {
  // connect to the locator using default port 10334
  ClientCache cache = new ClientCacheFactory().addPoolLocator("127.0.0.1", 10334)
      .set("log-level", "WARN").create();

  Example example = new Example();

  // create a local region that matches the server region
  ClientRegionFactory<Integer, String> clientRegionFactory =
      cache.createClientRegionFactory(ClientRegionShortcut.PROXY);
  Region<Integer, String> region = clientRegionFactory.create("example-region");

  example.insertValues(region, example.generateIntegers(10));
  example.monitorEntries(region);

  cache.close();
}
 
Example 6
Source File: Example.java    From geode-examples with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {
  // connect to the locator using default port 10334
  ClientCache cache = new ClientCacheFactory().set("log-level", "WARN").create();

  final String poolName = "subscriptionPool";
  PoolManager.createFactory().addLocator("127.0.0.1", 10334).setSubscriptionEnabled(true)
      .create(poolName);

  // create a local region that matches the server region
  final ClientRegionFactory<Integer, String> incomingRegionFactory =
      cache.<Integer, String>createClientRegionFactory(ClientRegionShortcut.PROXY);
  Region<Integer, String> incomingRegion =
      incomingRegionFactory.setPoolName(poolName).create(INCOMING_REGION_NAME);

  // create another local region that matches the server region
  final ClientRegionFactory<String, String> outgoingRegionFactory =
      cache.<String, String>createClientRegionFactory(ClientRegionShortcut.PROXY);
  Region<String, String> outgoingRegion =
      outgoingRegionFactory.setPoolName(poolName).create(OUTGOING_REGION_NAME);

  new Example().checkWords(incomingRegion, outgoingRegion,
      Arrays.asList(new String[] {"that", "teh", "wil", "i'"}));
  cache.close();
}
 
Example 7
Source File: Example.java    From geode-examples with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws InterruptedException, LuceneQueryException {
  // connect to the locator using default port 10334
  ClientCache cache = new ClientCacheFactory().addPoolLocator("127.0.0.1", 10334)
      .set("log-level", "WARN").create();

  // create a local region that matches the server region
  Region<String, TrainStop> region =
      cache.<String, TrainStop>createClientRegionFactory(ClientRegionShortcut.PROXY)
          .create("example-region");


  LuceneService luceneService = LuceneServiceProvider.get(cache);
  // Add some entries into the region
  putEntries(luceneService, region);
  findNearbyTrainStops(luceneService);
  cache.close();
}
 
Example 8
Source File: Example.java    From geode-examples with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {
  // connect to the locator using default port 10334
  ClientCache cache = new ClientCacheFactory().addPoolLocator("127.0.0.1", 10334)
      .set("log-level", "WARN").create();

  // create a local region that matches the server region
  ClientRegionFactory<String, Integer> clientRegionFactory =
      cache.createClientRegionFactory(ClientRegionShortcut.PROXY);
  Region<String, Integer> region = clientRegionFactory.create(REGION_NAME);

  Example example = new Example(region);
  example.initializeEntry();
  example.executeChildProcesses(5);

  cache.close();
}
 
Example 9
Source File: Example.java    From geode-examples with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {
  // connect to the locator using default port 10334
  ClientCache cache = new ClientCacheFactory().addPoolLocator("127.0.0.1", 10334)
      .set("log-level", "WARN").create();

  Example example = new Example();

  // create a local region that matches the server region
  ClientRegionFactory<Integer, String> clientRegionFactory =
      cache.createClientRegionFactory(ClientRegionShortcut.PROXY);
  Region<Integer, String> region = clientRegionFactory.create("example-region");

  example.insertValues(region, example.generateIntegers(10));
  example.monitorEntries(region);

  cache.close();
}
 
Example 10
Source File: Example.java    From geode-examples with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {
  ClientCache cache = new ClientCacheFactory().addPoolLocator("127.0.0.1", 10334)
      .set("log-level", "WARN").create();

  Region<Integer, Customer> customerRegion =
      cache.<Integer, Customer>createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY)
          .create("customer");

  Region<OrderKey, Order> orderRegion =
      cache.<OrderKey, Order>createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY)
          .create("order");

  Map<Integer, Customer> customers = generateCustomers();

  for (int i : customers.keySet()) {
    Customer customer = customers.get(i);
    Order order = new Order(i * 10, customer.getId());
    customerRegion.put(customer.getId(), customer);
    orderRegion.put(order.getKey(), order);
  }
  cache.close();
}
 
Example 11
Source File: Example.java    From geode-examples with Apache License 2.0 6 votes vote down vote up
private static void addCacheEntries() {
  // connect to the locator using default port
  ClientCache cache = new ClientCacheFactory().addPoolLocator("localhost", 10334)
      .set("log-level", "WARN").create();

  // create a local region that matches the server region
  Region<Integer, String> region =
      cache.<Integer, String>createClientRegionFactory(ClientRegionShortcut.PROXY)
          .create("example-region");

  // add entries to the region
  IntStream.rangeClosed(1, 10).forEach(i -> region.put(i, "value" + i));

  System.out.println(String.format("The entry count for region %s on the server is %d.",
      region.getName(), region.sizeOnServer()));

  cache.close();
}
 
Example 12
Source File: Example.java    From geode-examples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
  // connect to the locator using default port 10334
  ClientCache cache = new ClientCacheFactory().addPoolLocator("127.0.0.1", 10334)
      .set("log-level", "WARN").create();

  Example example = new Example();

  // create a local region that matches the server region
  ClientRegionFactory<String, Passenger> clientRegionFactory =
      cache.createClientRegionFactory(ClientRegionShortcut.PROXY);
  Region<String, Passenger> region = clientRegionFactory.create("example-region");
  QueryService queryService = cache.getQueryService();

  RegionPopulator populator = new RegionPopulator();
  populator.populateRegion(region);

  System.out.println("Total number of passengers: "
      + example.countResults(queryService, NON_INDEXED_QUERY, new Object[] {}));
  for (String lastName : populator.lastNames) {
    System.out.println("Flights for " + lastName + ": " + example.countResults(queryService,
        TOP_LEVEL_INDEX_QUERY, new Object[] {"%" + lastName}));
  }
  for (String airline : populator.airlines) {
    System.out.println("Flights for " + airline + ": "
        + example.countResults(queryService, NESTED_INDEX_QUERY, new Object[] {airline}));
  }

  cache.close();
}
 
Example 13
Source File: Example.java    From geode-examples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
  // connect to the locator using default port 10334
  ClientCache cache = new ClientCacheFactory().addPoolLocator("127.0.0.1", 10334)
      .set("log-level", "WARN").create();

  Example example = new Example();

  // create a local region that matches the server region
  ClientRegionFactory<String, Passenger> clientRegionFactory =
      cache.createClientRegionFactory(ClientRegionShortcut.PROXY);
  Region<String, Passenger> region = clientRegionFactory.create("example-region");
  QueryService queryService = cache.getQueryService();

  RegionPopulator populator = new RegionPopulator();
  populator.populateRegion(region);

  System.out.println("Total number of passengers: "
      + example.countResults(queryService, NON_INDEXED_QUERY, new Object[] {}));
  for (String lastName : populator.lastNames) {
    System.out.println("Flights for " + lastName + ": " + example.countResults(queryService,
        TOP_LEVEL_INDEX_QUERY, new Object[] {"%" + lastName}));
  }
  for (String airline : populator.airlines) {
    System.out.println("Flights for " + airline + ": "
        + example.countResults(queryService, NESTED_INDEX_QUERY, new Object[] {airline}));
  }

  cache.close();
}
 
Example 14
Source File: Example.java    From geode-examples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
  // connect to the locator using default port 10334
  ClientCache cache = new ClientCacheFactory().addPoolLocator("127.0.0.1", 10334)
      .set("log-level", "WARN").create();

  Example example = new Example();

  // create a local region that matches the server region
  ClientRegionFactory<Integer, String> clientRegionFactory =
      cache.createClientRegionFactory(ClientRegionShortcut.PROXY);
  Region<Integer, String> region = clientRegionFactory.create("example-region");

  example.putEntries(region);
  cache.close();
}
 
Example 15
Source File: Incrementer.java    From geode-examples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
  // connect to the locator using default port 10334
  ClientCache cache = new ClientCacheFactory().addPoolLocator("127.0.0.1", 10334)
      .set("log-level", "WARN").create();

  // create a local region that matches the server region
  ClientRegionFactory<String, Integer> clientRegionFactory =
      cache.createClientRegionFactory(ClientRegionShortcut.PROXY);
  Region<String, Integer> region = clientRegionFactory.create(Example.REGION_NAME);

  Incrementer incrementer = new Incrementer(Integer.parseInt(args[0]), cache, region);
  incrementer.incrementEntry();

  cache.close();
}
 
Example 16
Source File: Example.java    From geode-examples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
  // connect to the locator using default port 10334
  ClientCache cache = new ClientCacheFactory().addPoolLocator("127.0.0.1", 10334)
      .set("log-level", "WARN").create();

  // create a local region that matches the server region
  Region<Integer, String> region =
      cache.<Integer, String>createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY)
          .create("example-region");

  Execution execution = FunctionService.onRegion(region);
  new Example().getPrimes(region, execution);
  cache.close();
}
 
Example 17
Source File: Example.java    From geode-examples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
  // connect to the locator using default port 10334
  ClientCache cache = new ClientCacheFactory().addPoolLocator("127.0.0.1", 10334)
      .set("log-level", "WARN").create();

  // create a local region that matches the server region
  Region<Integer, String> region =
      cache.<Integer, String>createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY)
          .create("example-region");

  Execution execution = FunctionService.onRegion(region);
  new Example().getPrimes(region, execution);
  cache.close();
}
 
Example 18
Source File: Example.java    From geode-examples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
  // connect to the locator using default port 10334
  ClientCache cache = new ClientCacheFactory().addPoolLocator("127.0.0.1", 10334)
      .set("log-level", "WARN").create();

  Example example = new Example();

  // create a local region that matches the server region
  ClientRegionFactory<Integer, String> clientRegionFactory =
      cache.createClientRegionFactory(ClientRegionShortcut.PROXY);
  Region<Integer, String> region = clientRegionFactory.create("example-region");

  example.putEntries(region);
  cache.close();
}
 
Example 19
Source File: Example.java    From geode-examples with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
  ClientCache clientCacheOne = createDurableClient();

  final String regionName = "example-region";

  // Create a local caching proxy region that matches the server region
  ClientRegionFactory<Integer, String> clientOneRegionFactory =
      clientCacheOne.createClientRegionFactory(ClientRegionShortcut.PROXY);
  Region<Integer, String> exampleClientRegionOne = clientOneRegionFactory.create(regionName);

  // Register interest to create the durable client message queue
  exampleClientRegionOne.registerInterestForAllKeys(InterestResultPolicy.DEFAULT, true);

  // Close the client cache with keepalive set to true so
  // the durable client messages are preserved
  // for the duration of the configured timeout. In practice,
  // it is more likely the client would disconnect
  // due to a temporary network issue, but for this example the cache is explicitly closed.
  clientCacheOne.close(true);

  // Create a second client to do puts with while the first client is disconnected
  ClientCache clientCacheTwo = new ClientCacheFactory().addPoolLocator("127.0.0.1", 10334)
      .set("log-level", "WARN").create();

  ClientRegionFactory<Integer, String> clientTwoRegionFactory =
      clientCacheTwo.createClientRegionFactory(ClientRegionShortcut.PROXY);
  Region<Integer, String> exampleClientRegionTwo = clientTwoRegionFactory.create(regionName);

  for (int i = 0; i < numEvents; ++i) {
    exampleClientRegionTwo.put(i, "testValue" + i);
  }

  // Close the second client and restart the durable client
  clientCacheTwo.close(false);

  clientCacheOne = createDurableClient();

  // Add an example cache listener so this client can react
  // when the server sends this client's events from the
  // durable message queue. This isn't required but helps
  // illustrate that the events are delivered successfully.
  clientOneRegionFactory = clientCacheOne.createClientRegionFactory(ClientRegionShortcut.PROXY);
  exampleClientRegionOne = clientOneRegionFactory
      .addCacheListener(new ExampleCacheListener<Integer, String>()).create(regionName);

  // Signal to the server that this client is ready to receive events.
  // Events in this client's durable message queue
  // will then be delivered and trigger our example cache listener.
  clientCacheOne.readyForEvents();

  // Use a count down latch to ensure that this client receives all queued events from the server
  waitForEventsLatch.await();
}
 
Example 20
Source File: Example.java    From geode-examples with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
  ClientCache clientCacheOne = createDurableClient();

  final String regionName = "example-region";

  // Create a local caching proxy region that matches the server region
  ClientRegionFactory<Integer, String> clientOneRegionFactory =
      clientCacheOne.createClientRegionFactory(ClientRegionShortcut.PROXY);
  Region<Integer, String> exampleClientRegionOne = clientOneRegionFactory.create(regionName);

  // Register interest to create the durable client message queue
  exampleClientRegionOne.registerInterestForAllKeys(InterestResultPolicy.DEFAULT, true);

  // Close the client cache with keepalive set to true so
  // the durable client messages are preserved
  // for the duration of the configured timeout. In practice,
  // it is more likely the client would disconnect
  // due to a temporary network issue, but for this example the cache is explicitly closed.
  clientCacheOne.close(true);

  // Create a second client to do puts with while the first client is disconnected
  ClientCache clientCacheTwo = new ClientCacheFactory().addPoolLocator("127.0.0.1", 10334)
      .set("log-level", "WARN").create();

  ClientRegionFactory<Integer, String> clientTwoRegionFactory =
      clientCacheTwo.createClientRegionFactory(ClientRegionShortcut.PROXY);
  Region<Integer, String> exampleClientRegionTwo = clientTwoRegionFactory.create(regionName);

  for (int i = 0; i < numEvents; ++i) {
    exampleClientRegionTwo.put(i, "testValue" + i);
  }

  // Close the second client and restart the durable client
  clientCacheTwo.close(false);

  clientCacheOne = createDurableClient();

  // Add an example cache listener so this client can react
  // when the server sends this client's events from the
  // durable message queue. This isn't required but helps
  // illustrate that the events are delivered successfully.
  clientOneRegionFactory = clientCacheOne.createClientRegionFactory(ClientRegionShortcut.PROXY);
  exampleClientRegionOne = clientOneRegionFactory
      .addCacheListener(new ExampleCacheListener<Integer, String>()).create(regionName);

  // Signal to the server that this client is ready to receive events.
  // Events in this client's durable message queue
  // will then be delivered and trigger our example cache listener.
  clientCacheOne.readyForEvents();

  // Use a count down latch to ensure that this client receives all queued events from the server
  waitForEventsLatch.await();
}