Search in sources :

Example 1 with MyObjectPdx

use of com.examples.snapshot.MyObjectPdx in project geode by apache.

the class PdxTypeExportDUnitTest method loadCache.

@SuppressWarnings("serial")
public void loadCache() throws Exception {
    SerializableCallable peer = new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            CacheFactory cf = new CacheFactory().setPdxSerializer(new MyPdxSerializer());
            Cache cache = getCache(cf);
            Region r = cache.createRegionFactory(RegionShortcut.REPLICATE).create("pdxtest");
            r.put(1, new MyObjectPdx(1, "test", MyEnumPdx.const1));
            return null;
        }
    };
    final Host host = Host.getHost(0);
    host.getVM(1).invoke(peer);
    SerializableCallable server = new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            CacheFactory cf = new CacheFactory().setPdxSerializer(new MyPdxSerializer());
            CacheServer server = getCache().addCacheServer();
            int port = AvailablePortHelper.getRandomAvailableTCPPort();
            server.setPort(port);
            server.start();
            Region r = getCache().createRegionFactory(RegionShortcut.REPLICATE).create("pdxtest");
            return port;
        }
    };
    final int port = (Integer) host.getVM(2).invoke(server);
    SerializableCallable client = new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            ClientCacheFactory cf = new ClientCacheFactory().setPdxSerializer(new MyPdxSerializer()).addPoolServer(NetworkUtils.getServerHostName(host), port);
            ClientCache cache = getClientCache(cf);
            Region r = cache.createClientRegionFactory(ClientRegionShortcut.PROXY).create("pdxtest");
            return null;
        }
    };
    host.getVM(3).invoke(client);
    peer.call();
}
Also used : MyPdxSerializer(com.examples.snapshot.MyPdxSerializer) MyObjectPdx(com.examples.snapshot.MyObjectPdx) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) Region(org.apache.geode.cache.Region) CacheServer(org.apache.geode.cache.server.CacheServer) Host(org.apache.geode.test.dunit.Host) ClientCache(org.apache.geode.cache.client.ClientCache) CacheFactory(org.apache.geode.cache.CacheFactory) ClientCacheFactory(org.apache.geode.cache.client.ClientCacheFactory) Cache(org.apache.geode.cache.Cache) ClientCache(org.apache.geode.cache.client.ClientCache) ClientCacheFactory(org.apache.geode.cache.client.ClientCacheFactory)

Aggregations

MyObjectPdx (com.examples.snapshot.MyObjectPdx)1 MyPdxSerializer (com.examples.snapshot.MyPdxSerializer)1 Cache (org.apache.geode.cache.Cache)1 CacheFactory (org.apache.geode.cache.CacheFactory)1 Region (org.apache.geode.cache.Region)1 ClientCache (org.apache.geode.cache.client.ClientCache)1 ClientCacheFactory (org.apache.geode.cache.client.ClientCacheFactory)1 CacheServer (org.apache.geode.cache.server.CacheServer)1 Host (org.apache.geode.test.dunit.Host)1 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)1