Java Code Examples for org.apache.geode.pdx.ReflectionBasedAutoSerializer

The following examples show how to use org.apache.geode.pdx.ReflectionBasedAutoSerializer. These examples are extracted from open source projects. 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 Project: geode-examples   Source File: Example.java    License: 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 2
Source Project: geode-examples   Source File: Example.java    License: 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 3
Source Project: calcite   Source File: BookMasterRegionTest.java    License: 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 4
Source Project: geode-examples   Source File: Example.java    License: 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)
          .setPdxSerializer(
              new ReflectionBasedAutoSerializer("org.apache.geode_examples.jdbc.Parent"))
          .create();

  // create a local region that connects to the server region
  Region<Long, Parent> region =
      cache.<Long, Parent>createClientRegionFactory(ClientRegionShortcut.PROXY).create("Parent");
  System.out.println("Region=" + region.getFullPath());

  Example example = new Example(region);

  // Put entry in Parent region to verify it propagates to the external RDBMS table
  Long key = Long.valueOf(1);
  Parent value = new Parent(key, "Parent_1", Double.valueOf(123456789.0));
  region.put(key, value);
  System.out.println("Region.put() added an entry into Parent region. The key is " + key
      + ", and the value is " + value + ".");
  System.out.println(
      "If JDBC Connector is configured, the value will be persisted to external data source.");
  // Get an entry from Parent region that will trigger the cache loader to
  // retrieve the entry from the external table
  System.out.println(
      "Calling Region.get(). If JDBC Connector is configured, it will retrieve data from external data source and return a non-null value.");
  key = Long.valueOf(2);
  Parent parent = (Parent) region.get(key);
  System.out.println("The returned value of Region.get(" + key + ") is " + parent + ".");

  // Print the current entries in the region
  System.out.println("All entries currently in Parent region");
  example.printValues(example.getKeys());

  cache.close();
}
 
Example 5
Source Project: geode-examples   Source File: Example.java    License: 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)
          .setPdxSerializer(
              new ReflectionBasedAutoSerializer("org.apache.geode_examples.jdbc.Parent"))
          .create();

  // create a local region that connects to the server region
  Region<Long, Parent> region =
      cache.<Long, Parent>createClientRegionFactory(ClientRegionShortcut.PROXY).create("Parent");
  System.out.println("Region=" + region.getFullPath());

  Example example = new Example(region);

  // Put entry in Parent region to verify it propagates to the external RDBMS table
  Long key = Long.valueOf(1);
  Parent value = new Parent(key, "Parent_1", Double.valueOf(123456789.0));
  region.put(key, value);
  System.out.println("Region.put() added an entry into Parent region. The key is " + key
      + ", and the value is " + value + ".");
  System.out.println(
      "If JDBC Connector is configured, the value will be persisted to external data source.");
  // Get an entry from Parent region that will trigger the cache loader to
  // retrieve the entry from the external table
  System.out.println(
      "Calling Region.get(). If JDBC Connector is configured, it will retrieve data from external data source and return a non-null value.");
  key = Long.valueOf(2);
  Parent parent = (Parent) region.get(key);
  System.out.println("The returned value of Region.get(" + key + ") is " + parent + ".");

  // Print the current entries in the region
  System.out.println("All entries currently in Parent region");
  example.printValues(example.getKeys());

  cache.close();
}
 
Example 6
Source Project: calcite   Source File: GeodeUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Creates a Geode client instance connected to locator and configured to
 * support PDX instances.
 *
 * <p>If an old instance exists, it will be destroyed and re-created.
 *
 * @param locatorHost               Locator's host address
 * @param locatorPort               Locator's port
 * @param autoSerializerPackagePath package name of the Domain classes loaded in the regions
 * @return Returns a Geode {@link ClientCache} instance connected to Geode cluster
 */
public static synchronized ClientCache createClientCache(String locatorHost,
    int locatorPort, String autoSerializerPackagePath,
    boolean readSerialized) {
  if (locatorPort != currentLocatorPort
      || !StringUtils.equalsIgnoreCase(currentLocatorHost, locatorHost)) {
    LOGGER.info("Close existing ClientCache ["
        + currentLocatorHost + ":" + currentLocatorPort + "] for new Locator connection at: ["
        + locatorHost + ":" + locatorPort + "]");
    currentLocatorHost = locatorHost;
    currentLocatorPort = locatorPort;
    closeClientCache();
  }

  try {
    // If exists returns the existing client cache. This requires that the pre-created
    // client proxy regions can also be resolved from the regionMap
    return ClientCacheFactory.getAnyInstance();
  } catch (CacheClosedException cce) {
    // Do nothing if there is no existing instance
  }

  return new ClientCacheFactory()
      .addPoolLocator(locatorHost, locatorPort)
      .setPdxSerializer(new ReflectionBasedAutoSerializer(autoSerializerPackagePath))
      .setPdxReadSerialized(readSerialized)
      .create();
}
 
Example 7
Source Project: immutables   Source File: GeodeCqTest.java    License: Apache License 2.0 5 votes vote down vote up
@BeforeEach
public void setUp() throws Exception {
  this.clientCache = new ClientCacheFactory()
          .addPoolLocator("127.0.0.1", 10334)
          .setPdxSerializer(new ReflectionBasedAutoSerializer(Person.class.getPackage().getName()))
          .setPoolSubscriptionEnabled(true)
          .create();

  this.region = clientCache
          .<String, Person>createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY)
          .create("persons");

  region.clear();
}