Java Code Examples for com.gemstone.gemfire.cache.Region#registerInterestRegex()
The following examples show how to use
com.gemstone.gemfire.cache.Region#registerInterestRegex() .
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: UnregisterInterestDUnitTest.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
public static void registerInterest(Integer interestType, Boolean receiveValues, String[] values) { Region region = cache.getRegion(regionname); switch (interestType) { case all_keys: region.registerInterest("ALL_KEYS", false, receiveValues); break; case list: ArrayList<String> keys = new ArrayList<String>(); for (Object key : values) { keys.add((String)key); } region.registerInterest(keys, false, receiveValues); break; case regex: region.registerInterestRegex((String)values[0], false, receiveValues); break; case filter: break; default: fail("Invalid interest type: " + interestType, new IllegalArgumentException("Invalid interest type: " + interestType)); } }
Example 2
Source File: UnregisterInterestDUnitTest.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
public static void registerInterest(Integer interestType, Boolean receiveValues, String[] values) { Region region = cache.getRegion(regionname); switch (interestType) { case all_keys: region.registerInterest("ALL_KEYS", false, receiveValues); break; case list: ArrayList<String> keys = new ArrayList<String>(); for (Object key : values) { keys.add((String)key); } region.registerInterest(keys, false, receiveValues); break; case regex: region.registerInterestRegex((String)values[0], false, receiveValues); break; case filter: break; default: fail("Invalid interest type: " + interestType, new IllegalArgumentException("Invalid interest type: " + interestType)); } }
Example 3
Source File: HAClientQueue.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * Initializes the test region in the cache client VM and registers * interest. */ public static void initCacheClient() { synchronized (HAClientQueue.class) { if (CacheHelper.getCache() == null) { // first thread // create the cache and region CacheHelper.createCache(ConfigPrms.getCacheConfig()); int numOfRegion = TestConfig.tab().intAt( hct.ha.HAClientQueuePrms.numberOfRegions,1); for (int i = 0; i < numOfRegion; i++) { Region region = RegionHelper.createRegion(REGION_NAME+i, ConfigPrms.getRegionConfig()); // set the loader and writer statics (same for all regions) mypool = ClientHelper.getPool(region); // register interest in one thread to avoid possible performance hit try { if (TestConfig.tab().booleanAt(HctPrms.receiveValuesAsInvalidates)){ Log.getLogWriter().info("Registering Interest for invalidates."); region.registerInterestRegex(".*", false, false); } else { region.registerInterest("ALL_KEYS"); } } catch (CacheWriterException e) { throw new TestException(TestHelper.getStackTrace(e)); } } } } }
Example 4
Source File: DeltaPropagation.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * Initializes the test region in the cache client VM and registers interest * only for non delta's. */ public static void initCacheClientOld() { synchronized (DeltaPropagation.class) { if (CacheHelper.getCache() == null) { // first thread // create the cache and region CacheHelper.createCache(ConfigPrms.getCacheConfig()); int numOfRegion = TestConfig.tab().intAt( delta.DeltaPropagationPrms.numberOfRegions, 1); for (int i = 0; i < numOfRegion; i++) { Region region = RegionHelper.createRegion(REGION_NAME + i, ConfigPrms .getRegionConfig()); // set the loader and writer statics (same for all regions) mypool = ClientHelper.getPool(region); try { region.registerInterestRegex(".*_n_d_o"); region.registerInterest("last_key"); } catch (CacheWriterException e) { throw new TestException(TestHelper.getStackTrace(e)); } } } } }
Example 5
Source File: ClientAuthenticationDUnitTest.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
public static void registerAllInterest() { Region region = SecurityTestUtil.getCache().getRegion( SecurityTestUtil.regionName); assertNotNull(region); region.registerInterestRegex(".*"); }
Example 6
Source File: ClientAuthenticationDUnitTest.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
public static void registerAllInterest() { Region region = SecurityTestUtil.getCache().getRegion( SecurityTestUtil.regionName); assertNotNull(region); region.registerInterestRegex(".*"); }
Example 7
Source File: DeltaPropagation.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * Initializes the test region in the cache client VM and registers interest * only for non delta's. */ public static void initCacheClientOld() { synchronized (DeltaPropagation.class) { if (CacheHelper.getCache() == null) { // first thread // create the cache and region CacheHelper.createCache(ConfigPrms.getCacheConfig()); int numOfRegion = TestConfig.tab().intAt( delta.DeltaPropagationPrms.numberOfRegions, 1); for (int i = 0; i < numOfRegion; i++) { Region region = RegionHelper.createRegion(REGION_NAME + i, ConfigPrms .getRegionConfig()); // set the loader and writer statics (same for all regions) mypool = ClientHelper.getPool(region); try { region.registerInterestRegex(".*_n_d_o"); region.registerInterest("last_key"); } catch (CacheWriterException e) { throw new TestException(TestHelper.getStackTrace(e)); } } } } }
Example 8
Source File: HAClientQueue.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * Initializes the test region in the cache client VM and registers * interest. */ public static void initCacheClient() { synchronized (HAClientQueue.class) { if (CacheHelper.getCache() == null) { // first thread // create the cache and region CacheHelper.createCache(ConfigPrms.getCacheConfig()); int numOfRegion = TestConfig.tab().intAt( hct.ha.HAClientQueuePrms.numberOfRegions,1); for (int i = 0; i < numOfRegion; i++) { Region region = RegionHelper.createRegion(REGION_NAME+i, ConfigPrms.getRegionConfig()); // set the loader and writer statics (same for all regions) mypool = ClientHelper.getPool(region); // register interest in one thread to avoid possible performance hit try { if (TestConfig.tab().booleanAt(HctPrms.receiveValuesAsInvalidates)){ Log.getLogWriter().info("Registering Interest for invalidates."); region.registerInterestRegex(".*", false, false); } else { region.registerInterest("ALL_KEYS"); } } catch (CacheWriterException e) { throw new TestException(TestHelper.getStackTrace(e)); } } } } }
Example 9
Source File: ClientConsumer.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
public static void main(String[] args) throws Exception { if (args.length != 1) { System.out.println(USAGE); System.exit(1); } RegisterInterestType registerInterestType; if (args[0].equals("all-keys")) { registerInterestType = RegisterInterestType.ALL_KEYS; } else if (args[0].equals("keyset")) { registerInterestType = RegisterInterestType.KEYSET; } else if (args[0].equals("regex")) { registerInterestType = RegisterInterestType.REGEX; } else { registerInterestType = null; System.out.println(USAGE); System.exit(2); } // Subscribe to the indicated key set System.out.println("Connecting to the distributed system and creating the cache."); // Create the cache which causes the cache-xml-file to be parsed ClientCache cache = new ClientCacheFactory() .set("name", "ClientConsumer") .set("cache-xml-file", "xml/Client.xml") .create(); // Get the exampleRegion which is a subregion of /root Region<String, ?> exampleRegion = cache.getRegion(EXAMPLE_REGION_NAME); System.out.println("Example region \"" + exampleRegion.getFullPath() + "\" created in cache. "); switch (registerInterestType) { case ALL_KEYS: System.out.println("Asking the server to send me all data additions, updates, and destroys. "); exampleRegion.registerInterest("ALL_KEYS"); break; case KEYSET: System.out.println("Asking the server to send me events for data with these keys: 'key0', 'key1'"); exampleRegion.registerInterest("key0"); exampleRegion.registerInterest("key1"); break; case REGEX: System.out.println("Asking the server to register interest in keys matching this"); System.out.println("regular expression: 'k.*2'"); exampleRegion.registerInterestRegex("k.*2"); break; default: // Can't happen throw new RuntimeException(); } System.out.println("The data region has a listener that reports all changes to standard out."); System.out.println(); System.out.println("Please run the worker client in another session. It will update the"); System.out.println("cache and the server will forward the updates to me. Note the listener"); System.out.println("output in this session."); System.out.println(); System.out.println("When the other client finishes, hit Enter to exit this program."); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); bufferedReader.readLine(); System.out.println("Closing the cache and disconnecting."); cache.close(); }
Example 10
Source File: DeltaToRegionRelationDUnitTest.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
public static void registerRegex(String regionName, String exp){ Region r = cache.getRegion(Region.SEPARATOR + regionName); assertNotNull(r); r.registerInterestRegex(exp); }
Example 11
Source File: MultiuserAPIDUnitTest.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
public static void registerAllInterest() { Region region = SecurityTestUtil.getCache().getRegion( SecurityTestUtil.regionName); assertNotNull(region); region.registerInterestRegex(".*"); }
Example 12
Source File: HierCache.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
/** * A Hydra INIT task that initialize the test region in an edge * client according to the configurations in {@link ConfigPrms}. */ public static void initEdgeRegion() { // create the cache boolean isPureJava = Boolean.getBoolean("gemfire.pureJavaMode"); Log.getLogWriter().info("Initializing cache, pureJava is " + isPureJava + "..."); CacheHelper.createCache(ConfigPrms.getCacheConfig()); // BridgeMembership & UniversalMembership Listeners must be registered // prior to the client's bridgeClient instantiation // Set-up UniversalMembershipListener (if configured) // Note that you wouldn't want this along with the BridgeMembershipListeners UniversalMembershipListener uListener = HctPrms.getUniversalMembershipListener(); if (uListener != null) { try { DistributedSystemConfig dsConfig = AdminDistributedSystemFactory.defineDistributedSystem( DistributedSystemHelper.getDistributedSystem(), null ); AdminDistributedSystem adminDS = AdminDistributedSystemFactory.getDistributedSystem( dsConfig ); Log.getLogWriter().info("initEdgeRegion: registering UniversalMembershipListener " + uListener + " with AdminDS " + adminDS + " with config " + dsConfig); uListener.registerMembershipListener( adminDS ); } catch (AdminException ae) { throw new TestException("Could not register UniversalMembershipListener " + ae); } } // Set-up the client to listen for server membership events BridgeMembershipListener membershipListener = HctPrms.getMembershipListener( HctPrms.edgeMembershipListener ); if (membershipListener != null) { BridgeMembership.registerBridgeMembershipListener( membershipListener ); Log.getLogWriter().info("Registered BridgeMembershipListener " + membershipListener); } Region region = RegionHelper.createRegion( regionName, ConfigPrms.getRegionConfig()); if (conftab.booleanAt(HctPrms.receiveValuesAsInvalidates)){ // Check if subscription enabled. PoolImpl pool = ClientHelper.getPool(region); if (pool.getSubscriptionEnabled()) { Log.getLogWriter().info("Registering Interest for invalidates."); region.registerInterestRegex(".*", false, false); } } // initialize CQService, if needed CQUtil.initialize(); CQUtil.initializeCQService(); CQUtil.registerCQ(region); }
Example 13
Source File: Client.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
private static void runSubscriber() throws InterruptedException { /* * To declare in a cache.xml do this: <!DOCTYPE client-cache PUBLIC "-//GemStone Systems, Inc.//GemFire Declarative Caching 6.5//EN" "http://www.gemstone.com/dtd/cache6_5.dtd"> <client-cache> <pool name="subscriber" subscription-enabled="true"> <locator host="localhost" port="41111"/> </pool> </client-cache> */ ClientCacheFactory ccf = connectStandalone("subscriber"); ccf.setPoolSubscriptionEnabled(true); ClientCache cache = ccf.create(); /* * To declare in a cache.xml do this: <region name="DATA" refid="PROXY"> <region-attributes> <subscription-attributes interest-policy=all/> <cache-listener> <class-name>clientAPI.SubscriberListener</class-name> </cache-listener> </region-attributes> </region> */ ClientRegionFactory<String,String> regionFactory = cache.createClientRegionFactory(PROXY); Region<String, String> region = regionFactory .addCacheListener(new SubscriberListener()) .create("DATA"); region.registerInterestRegex(".*", // everything InterestResultPolicy.NONE, false/*isDurable*/); SubscriberListener myListener = (SubscriberListener) region.getAttributes().getCacheListeners()[0]; System.out.println("waiting for publisher to do " + NUM_PUTS + " puts..."); myListener.waitForPuts(NUM_PUTS); System.out.println("done waiting for publisher."); cache.close(); }
Example 14
Source File: ClientConsumer.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
public static void main(String[] args) throws Exception { if (args.length != 1) { System.out.println(USAGE); System.exit(1); } RegisterInterestType registerInterestType; if (args[0].equals("all-keys")) { registerInterestType = RegisterInterestType.ALL_KEYS; } else if (args[0].equals("keyset")) { registerInterestType = RegisterInterestType.KEYSET; } else if (args[0].equals("regex")) { registerInterestType = RegisterInterestType.REGEX; } else { registerInterestType = null; System.out.println(USAGE); System.exit(2); } // Subscribe to the indicated key set System.out.println("Connecting to the distributed system and creating the cache."); // Create the cache which causes the cache-xml-file to be parsed ClientCache cache = new ClientCacheFactory() .set("name", "ClientConsumer") .set("cache-xml-file", "xml/Client.xml") .create(); // Get the exampleRegion which is a subregion of /root Region<String, ?> exampleRegion = cache.getRegion(EXAMPLE_REGION_NAME); System.out.println("Example region \"" + exampleRegion.getFullPath() + "\" created in cache. "); switch (registerInterestType) { case ALL_KEYS: System.out.println("Asking the server to send me all data additions, updates, and destroys. "); exampleRegion.registerInterest("ALL_KEYS"); break; case KEYSET: System.out.println("Asking the server to send me events for data with these keys: 'key0', 'key1'"); exampleRegion.registerInterest("key0"); exampleRegion.registerInterest("key1"); break; case REGEX: System.out.println("Asking the server to register interest in keys matching this"); System.out.println("regular expression: 'k.*2'"); exampleRegion.registerInterestRegex("k.*2"); break; default: // Can't happen throw new RuntimeException(); } System.out.println("The data region has a listener that reports all changes to standard out."); System.out.println(); System.out.println("Please run the worker client in another session. It will update the"); System.out.println("cache and the server will forward the updates to me. Note the listener"); System.out.println("output in this session."); System.out.println(); System.out.println("When the other client finishes, hit Enter to exit this program."); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); bufferedReader.readLine(); System.out.println("Closing the cache and disconnecting."); cache.close(); }
Example 15
Source File: DeltaToRegionRelationDUnitTest.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
public static void registerRegex(String regionName, String exp){ Region r = cache.getRegion(Region.SEPARATOR + regionName); assertNotNull(r); r.registerInterestRegex(exp); }
Example 16
Source File: MultiuserAPIDUnitTest.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
public static void registerAllInterest() { Region region = SecurityTestUtil.getCache().getRegion( SecurityTestUtil.regionName); assertNotNull(region); region.registerInterestRegex(".*"); }
Example 17
Source File: HierCache.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
/** * A Hydra INIT task that initialize the test region in an edge * client according to the configurations in {@link ConfigPrms}. */ public static void initEdgeRegion() { // create the cache boolean isPureJava = Boolean.getBoolean("gemfire.pureJavaMode"); Log.getLogWriter().info("Initializing cache, pureJava is " + isPureJava + "..."); CacheHelper.createCache(ConfigPrms.getCacheConfig()); // BridgeMembership & UniversalMembership Listeners must be registered // prior to the client's bridgeClient instantiation // Set-up UniversalMembershipListener (if configured) // Note that you wouldn't want this along with the BridgeMembershipListeners UniversalMembershipListener uListener = HctPrms.getUniversalMembershipListener(); if (uListener != null) { try { DistributedSystemConfig dsConfig = AdminDistributedSystemFactory.defineDistributedSystem( DistributedSystemHelper.getDistributedSystem(), null ); AdminDistributedSystem adminDS = AdminDistributedSystemFactory.getDistributedSystem( dsConfig ); Log.getLogWriter().info("initEdgeRegion: registering UniversalMembershipListener " + uListener + " with AdminDS " + adminDS + " with config " + dsConfig); uListener.registerMembershipListener( adminDS ); } catch (AdminException ae) { throw new TestException("Could not register UniversalMembershipListener " + ae); } } // Set-up the client to listen for server membership events BridgeMembershipListener membershipListener = HctPrms.getMembershipListener( HctPrms.edgeMembershipListener ); if (membershipListener != null) { BridgeMembership.registerBridgeMembershipListener( membershipListener ); Log.getLogWriter().info("Registered BridgeMembershipListener " + membershipListener); } Region region = RegionHelper.createRegion( regionName, ConfigPrms.getRegionConfig()); if (conftab.booleanAt(HctPrms.receiveValuesAsInvalidates)){ // Check if subscription enabled. PoolImpl pool = ClientHelper.getPool(region); if (pool.getSubscriptionEnabled()) { Log.getLogWriter().info("Registering Interest for invalidates."); region.registerInterestRegex(".*", false, false); } } // initialize CQService, if needed CQUtil.initialize(); CQUtil.initializeCQService(); CQUtil.registerCQ(region); }
Example 18
Source File: Client.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
private static void runSubscriber() throws InterruptedException { /* * To declare in a cache.xml do this: <!DOCTYPE client-cache PUBLIC "-//GemStone Systems, Inc.//GemFire Declarative Caching 6.5//EN" "http://www.gemstone.com/dtd/cache6_5.dtd"> <client-cache> <pool name="subscriber" subscription-enabled="true"> <locator host="localhost" port="41111"/> </pool> </client-cache> */ ClientCacheFactory ccf = connectStandalone("subscriber"); ccf.setPoolSubscriptionEnabled(true); ClientCache cache = ccf.create(); /* * To declare in a cache.xml do this: <region name="DATA" refid="PROXY"> <region-attributes> <subscription-attributes interest-policy=all/> <cache-listener> <class-name>clientAPI.SubscriberListener</class-name> </cache-listener> </region-attributes> </region> */ ClientRegionFactory<String,String> regionFactory = cache.createClientRegionFactory(PROXY); Region<String, String> region = regionFactory .addCacheListener(new SubscriberListener()) .create("DATA"); region.registerInterestRegex(".*", // everything InterestResultPolicy.NONE, false/*isDurable*/); SubscriberListener myListener = (SubscriberListener) region.getAttributes().getCacheListeners()[0]; System.out.println("waiting for publisher to do " + NUM_PUTS + " puts..."); myListener.waitForPuts(NUM_PUTS); System.out.println("done waiting for publisher."); cache.close(); }