org.apache.geode.cache.client.ClientCacheFactory Java Examples

The following examples show how to use org.apache.geode.cache.client.ClientCacheFactory. 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) 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 #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 in London cluster using port 10332
  ClientCache cache = new ClientCacheFactory().addPoolLocator("127.0.0.1", 10332)
      .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) {
  // 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<EmployeeKey, EmployeeData> region =
      cache.<EmployeeKey, EmployeeData>createClientRegionFactory(ClientRegionShortcut.PROXY)
          .create("example-region");

  Example example = new Example(region);
  example.insertValues(new String[] {"Alex Able", "Bertie Bell", "Chris Call", "Dale Driver",
      "Frankie Forth", "Jamie Jive", "Morgan Minnow", "Pat Pearson", "Ricky Reliable",
      "Taylor Tack", "Zelda Zankowski"});
  example.printValues(example.getValues());

  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().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 #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")
      .setPdxSerializer(
          new ReflectionBasedAutoSerializer("org.apache.geode_examples.serialization.Country"))
      .create();

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

  Example example = new Example(region);
  example.insertValues();
  example.printValues(example.getKeys());

  cache.close();
}
 
Example #6
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 #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) {
  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 #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();

  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 #9
Source File: Example.java    From geode-examples with Apache License 2.0 6 votes vote down vote up
private Example(String username) {
  Properties props = new Properties();
  props.setProperty("security-username", username);
  props.setProperty("security-client-auth-init", ExampleAuthInit.class.getName());
  props.setProperty("ssl-enabled-components", "all");
  props.setProperty("ssl-keystore", "keystore.jks");
  props.setProperty("ssl-keystore-password", "password");
  props.setProperty("ssl-truststore", "truststore.jks");
  props.setProperty("ssl-truststore-password", "password");

  // connect to the locator using default port 10334
  cache = new ClientCacheFactory(props).setPoolSubscriptionEnabled(true)
      .addPoolLocator("localhost", 10334).create();
  region1 = cache.<String, String>createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY)
      .create(REGION1);
  region2 = cache.<String, String>createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY)
      .create(REGION2);
}
 
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) {
  // 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 #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 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 #13
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);
  clientRegionFactory.addCacheListener(new ExampleCacheListener());
  Region<Integer, String> region = clientRegionFactory.create("example-region");

  example.putEntries(region);
  cache.close();
}
 
Example #14
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 #15
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 #16
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 in London cluster using port 10332
  ClientCache cache = new ClientCacheFactory().addPoolLocator("127.0.0.1", 10332)
      .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 #17
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<EmployeeKey, EmployeeData> region =
      cache.<EmployeeKey, EmployeeData>createClientRegionFactory(ClientRegionShortcut.PROXY)
          .create("example-region");

  Example example = new Example(region);
  example.insertValues(new String[] {"Alex Able", "Bertie Bell", "Chris Call", "Dale Driver",
      "Frankie Forth", "Jamie Jive", "Morgan Minnow", "Pat Pearson", "Ricky Reliable",
      "Taylor Tack", "Zelda Zankowski"});
  example.printValues(example.getValues());

  cache.close();
}
 
Example #18
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 #19
Source File: BookMasterRegionTest.java    From calcite with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {

    ClientCache clientCache = new ClientCacheFactory()
        .addPoolLocator("localhost", 10334)
        .setPdxSerializer(new ReflectionBasedAutoSerializer("org.apache.calcite.adapter.geode.*"))
        .create();

    // Using Key/Value
    Region bookMaster = clientCache
        .createClientRegionFactory(ClientRegionShortcut.PROXY)
        .create("BookMaster");

    System.out.println("BookMaster = " + bookMaster.get(789));

    // Using OQL
    QueryService queryService = clientCache.getQueryService();
    String oql = "select itemNumber, description, retailCost from /BookMaster";
    SelectResults result = (SelectResults) queryService.newQuery(oql).execute();
    System.out.println(result.asList());
  }
 
Example #20
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")
      .setPdxSerializer(
          new ReflectionBasedAutoSerializer("org.apache.geode_examples.serialization.Country"))
      .create();

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

  Example example = new Example(region);
  example.insertValues();
  example.printValues(example.getKeys());

  cache.close();
}
 
Example #21
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 #22
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 #23
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 #24
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 #25
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 #26
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 #27
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 #28
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);
  clientRegionFactory.addCacheListener(new ExampleCacheListener());
  Region<Integer, String> region = clientRegionFactory.create("example-region");

  example.putEntries(region);
  cache.close();
}
 
Example #29
Source File: Example.java    From geode-examples with Apache License 2.0 6 votes vote down vote up
private Example(String username) {
  Properties props = new Properties();
  props.setProperty("security-username", username);
  props.setProperty("security-client-auth-init", ExampleAuthInit.class.getName());
  props.setProperty("ssl-enabled-components", "all");
  props.setProperty("ssl-keystore", "keystore.jks");
  props.setProperty("ssl-keystore-password", "password");
  props.setProperty("ssl-truststore", "truststore.jks");
  props.setProperty("ssl-truststore-password", "password");

  // connect to the locator using default port 10334
  cache = new ClientCacheFactory(props).setPoolSubscriptionEnabled(true)
      .addPoolLocator("localhost", 10334).create();
  region1 = cache.<String, String>createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY)
      .create(REGION1);
  region2 = cache.<String, String>createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY)
      .create(REGION2);
}
 
Example #30
Source File: Example.java    From geode-examples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws 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<Integer, EmployeeData> region =
      cache.<Integer, EmployeeData>createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY)
          .create("example-region");

  insertValues(region);
  query(cache);
  queryNestedObject(cache);
  cache.close();
}