Search in sources :

Example 6 with ReflectionBasedAutoSerializer

use of org.apache.geode.pdx.ReflectionBasedAutoSerializer in project geode by apache.

the class CacheXmlGenerator method generate.

/**
   * Generates XML for a <code>CacheCallback</code>
   */
private void generate(String kind, Object callback) throws SAXException {
    if (callback == null) {
        return;
    }
    handler.startElement("", kind, kind, EMPTY);
    String className = callback.getClass().getName();
    handler.startElement("", CLASS_NAME, CLASS_NAME, EMPTY);
    handler.characters(className.toCharArray(), 0, className.length());
    handler.endElement("", CLASS_NAME, CLASS_NAME);
    Properties props = null;
    if (callback instanceof Declarable2) {
        props = ((Declarable2) callback).getConfig();
    } else if (callback instanceof ReflectionBasedAutoSerializer) {
        props = ((ReflectionBasedAutoSerializer) callback).getConfig();
    } else if (callback instanceof Declarable && cache instanceof GemFireCacheImpl) {
        props = ((InternalCache) cache).getDeclarableProperties((Declarable) callback);
    }
    generate(props, null);
    handler.endElement("", kind, kind);
}
Also used : Declarable(org.apache.geode.cache.Declarable) ReflectionBasedAutoSerializer(org.apache.geode.pdx.ReflectionBasedAutoSerializer) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) Properties(java.util.Properties)

Example 7 with ReflectionBasedAutoSerializer

use of org.apache.geode.pdx.ReflectionBasedAutoSerializer in project calcite by apache.

the class GeodeUtils method createClientCache.

/**
 * 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 {
        // 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).setPdxPersistent(false).create();
}
Also used : ReflectionBasedAutoSerializer(org.apache.geode.pdx.ReflectionBasedAutoSerializer) CacheClosedException(org.apache.geode.cache.CacheClosedException) ClientCacheFactory(org.apache.geode.cache.client.ClientCacheFactory)

Example 8 with ReflectionBasedAutoSerializer

use of org.apache.geode.pdx.ReflectionBasedAutoSerializer in project calcite by apache.

the class BookMasterRegionTest method main.

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());
}
Also used : SelectResults(org.apache.geode.cache.query.SelectResults) QueryService(org.apache.geode.cache.query.QueryService) ReflectionBasedAutoSerializer(org.apache.geode.pdx.ReflectionBasedAutoSerializer) Region(org.apache.geode.cache.Region) ClientCache(org.apache.geode.cache.client.ClientCache) ClientCacheFactory(org.apache.geode.cache.client.ClientCacheFactory)

Aggregations

ReflectionBasedAutoSerializer (org.apache.geode.pdx.ReflectionBasedAutoSerializer)8 ClientCacheFactory (org.apache.geode.cache.client.ClientCacheFactory)3 Properties (java.util.Properties)2 CacheFactory (org.apache.geode.cache.CacheFactory)2 Region (org.apache.geode.cache.Region)2 QueryService (org.apache.geode.cache.query.QueryService)2 SelectResults (org.apache.geode.cache.query.SelectResults)2 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 ArrayList (java.util.ArrayList)1 CacheClosedException (org.apache.geode.cache.CacheClosedException)1 Declarable (org.apache.geode.cache.Declarable)1 ClientCache (org.apache.geode.cache.client.ClientCache)1 Query (org.apache.geode.cache.query.Query)1 PortfolioPdx (org.apache.geode.cache.query.data.PortfolioPdx)1 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)1 GemFireCacheImpl (org.apache.geode.internal.cache.GemFireCacheImpl)1 CacheCreation (org.apache.geode.internal.cache.xmlcache.CacheCreation)1 CliMetaData (org.apache.geode.management.cli.CliMetaData)1 Result (org.apache.geode.management.cli.Result)1