Search in sources :

Example 1 with SubscriptionNotEnabledException

use of org.apache.geode.cache.client.SubscriptionNotEnabledException in project geode by apache.

the class LocalRegion method processSingleInterest.

// TODO: this is distressingly similar to code in the client.internal package
private void processSingleInterest(Object key, int interestType, InterestResultPolicy interestResultPolicy, boolean isDurable, boolean receiveUpdatesAsInvalidates) {
    final ServerRegionProxy proxy = getServerProxy();
    if (proxy == null) {
        throw new UnsupportedOperationException(LocalizedStrings.LocalRegion_INTEREST_REGISTRATION_REQUIRES_A_POOL.toLocalizedString());
    }
    if (isDurable && !proxy.getPool().isDurableClient()) {
        throw new IllegalStateException(LocalizedStrings.LocalRegion_DURABLE_FLAG_ONLY_APPLICABLE_FOR_DURABLE_CLIENTS.toLocalizedString());
    }
    if (!proxy.getPool().getSubscriptionEnabled()) {
        String msg = "Interest registration requires a pool whose queue is enabled.";
        throw new SubscriptionNotEnabledException(msg);
    }
    if (// fix for bug 36185
    getAttributes().getDataPolicy().withReplication() && !getAttributes().getScope().isLocal()) {
        // fix for bug 37692
        throw new UnsupportedOperationException(LocalizedStrings.LocalRegion_INTEREST_REGISTRATION_NOT_SUPPORTED_ON_REPLICATED_REGIONS.toLocalizedString());
    }
    if (key == null) {
        throw new IllegalArgumentException(LocalizedStrings.LocalRegion_INTEREST_KEY_MUST_NOT_BE_NULL.toLocalizedString());
    }
    // Sequence of events, on a single entry:
    // 1. Client puts value (a).
    // 2. Server updates with value (b). Client never gets the update,
    // because it isn't interested in that key.
    // 3. Client registers interest.
    // At this point, there is an entry in the local cache, but it is
    // inconsistent with the server.
    //
    // Because of this, we must _always_ destroy and refetch affected values
    // during registerInterest.
    startRegisterInterest();
    try {
        this.clearKeysOfInterest(key, interestType, interestResultPolicy);
        // Checking for the Dunit test(testRegisterInterst_Destroy_Concurrent) flag
        if (PoolImpl.BEFORE_REGISTER_CALLBACK_FLAG) {
            ClientServerObserver bo = ClientServerObserverHolder.getInstance();
            bo.beforeInterestRegistration();
        }
        // Test Code Ends
        final byte regionDataPolicy = getAttributes().getDataPolicy().ordinal;
        List serverKeys;
        switch(interestType) {
            case InterestType.FILTER_CLASS:
                serverKeys = proxy.registerInterest(key, interestType, interestResultPolicy, isDurable, receiveUpdatesAsInvalidates, regionDataPolicy);
                break;
            case InterestType.KEY:
                if (key instanceof String && key.equals("ALL_KEYS")) {
                    serverKeys = proxy.registerInterest(".*", InterestType.REGULAR_EXPRESSION, interestResultPolicy, isDurable, receiveUpdatesAsInvalidates, regionDataPolicy);
                } else {
                    if (key instanceof List) {
                        serverKeys = proxy.registerInterestList((List) key, interestResultPolicy, isDurable, receiveUpdatesAsInvalidates, regionDataPolicy);
                    } else {
                        serverKeys = proxy.registerInterest(key, InterestType.KEY, interestResultPolicy, isDurable, receiveUpdatesAsInvalidates, regionDataPolicy);
                    }
                }
                break;
            case InterestType.OQL_QUERY:
                serverKeys = proxy.registerInterest(key, InterestType.OQL_QUERY, interestResultPolicy, isDurable, receiveUpdatesAsInvalidates, regionDataPolicy);
                break;
            case InterestType.REGULAR_EXPRESSION:
                {
                    String regex = (String) key;
                    // compile regex throws java.util.regex.PatternSyntaxException if invalid
                    // we do this before sending to the server because it's more efficient
                    // and the client is not receiving exception messages properly
                    // TODO: result of Pattern.compile is ignored
                    Pattern.compile(regex);
                    serverKeys = proxy.registerInterest(regex, InterestType.REGULAR_EXPRESSION, interestResultPolicy, isDurable, receiveUpdatesAsInvalidates, regionDataPolicy);
                    break;
                }
            default:
                throw new InternalGemFireError(LocalizedStrings.LocalRegion_UNKNOWN_INTEREST_TYPE.toLocalizedString());
        }
        boolean finishedRefresh = false;
        try {
            refreshEntriesFromServerKeys(null, serverKeys, interestResultPolicy);
            finishedRefresh = true;
        } finally {
            if (!finishedRefresh) {
                // unregister before throwing the exception caused by the refresh
                switch(interestType) {
                    case InterestType.FILTER_CLASS:
                        proxy.unregisterInterest(key, interestType, false, false);
                        break;
                    case InterestType.KEY:
                        if (key instanceof String && key.equals("ALL_KEYS")) {
                            proxy.unregisterInterest(".*", InterestType.REGULAR_EXPRESSION, false, false);
                        } else if (key instanceof List) {
                            proxy.unregisterInterestList((List) key, false, false);
                        } else {
                            proxy.unregisterInterest(key, InterestType.KEY, false, false);
                        }
                        break;
                    case InterestType.OQL_QUERY:
                        proxy.unregisterInterest(key, InterestType.OQL_QUERY, false, false);
                        break;
                    case InterestType.REGULAR_EXPRESSION:
                        {
                            proxy.unregisterInterest(key, InterestType.REGULAR_EXPRESSION, false, false);
                            break;
                        }
                    default:
                        throw new InternalGemFireError(LocalizedStrings.LocalRegion_UNKNOWN_INTEREST_TYPE.toLocalizedString());
                }
            }
        }
    } finally {
        finishRegisterInterest();
    }
}
Also used : ServerRegionProxy(org.apache.geode.cache.client.internal.ServerRegionProxy) VersionedObjectList(org.apache.geode.internal.cache.tier.sockets.VersionedObjectList) ArrayList(java.util.ArrayList) List(java.util.List) SubscriptionNotEnabledException(org.apache.geode.cache.client.SubscriptionNotEnabledException) InternalGemFireError(org.apache.geode.InternalGemFireError)

Example 2 with SubscriptionNotEnabledException

use of org.apache.geode.cache.client.SubscriptionNotEnabledException in project geode by apache.

the class ClientRegisterInterestDUnitTest method testBug35381.

/**
   * Tests for Bug 35381 Calling register interest if establishCallbackConnection is not set causes
   * bridge server NPE.
   */
@Test
public void testBug35381() throws Exception {
    final Host host = Host.getHost(0);
    final String name = this.getUniqueName();
    // 1 server in this test
    final int[] ports = new int[1];
    final int whichVM = 0;
    final VM vm = Host.getHost(0).getVM(whichVM);
    vm.invoke(new CacheSerializableRunnable("Create bridge server") {

        public void run2() throws CacheException {
            LogWriterUtils.getLogWriter().info("[testBug35381] Create BridgeServer");
            getSystem();
            AttributesFactory factory = new AttributesFactory();
            factory.setScope(Scope.LOCAL);
            Region region = createRegion(name, factory.create());
            assertNotNull(region);
            assertNotNull(getRootRegion().getSubregion(name));
            region.put("KEY-1", "VAL-1");
            try {
                bridgeServerPort = startBridgeServer(0);
            } catch (IOException e) {
                LogWriterUtils.getLogWriter().error("startBridgeServer threw IOException", e);
                fail("startBridgeServer threw IOException ", e);
            }
            assertTrue(bridgeServerPort != 0);
            LogWriterUtils.getLogWriter().info("[testBug35381] port=" + bridgeServerPort);
            LogWriterUtils.getLogWriter().info("[testBug35381] serverMemberId=" + getMemberId());
        }
    });
    ports[whichVM] = vm.invoke(() -> ClientRegisterInterestDUnitTest.getBridgeServerPort());
    assertTrue(ports[whichVM] != 0);
    LogWriterUtils.getLogWriter().info("[testBug35381] create bridge client");
    Properties config = new Properties();
    config.setProperty(MCAST_PORT, "0");
    config.setProperty(LOCATORS, "");
    getSystem(config);
    getCache();
    AttributesFactory factory = new AttributesFactory();
    factory.setScope(Scope.LOCAL);
    LogWriterUtils.getLogWriter().info("[testBug35381] creating connection pool");
    // SOURCE OF BUG 35381
    boolean establishCallbackConnection = false;
    ClientServerTestCase.configureConnectionPool(factory, NetworkUtils.getServerHostName(host), ports, establishCallbackConnection, -1, -1, null);
    Region region = createRegion(name, factory.create());
    assertNotNull(getRootRegion().getSubregion(name));
    try {
        region.registerInterest("KEY-1");
        fail("registerInterest failed to throw SubscriptionNotEnabledException with establishCallbackConnection set to false");
    } catch (SubscriptionNotEnabledException expected) {
    }
}
Also used : CacheException(org.apache.geode.cache.CacheException) Host(org.apache.geode.test.dunit.Host) IOException(java.io.IOException) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) AttributesFactory(org.apache.geode.cache.AttributesFactory) VM(org.apache.geode.test.dunit.VM) Region(org.apache.geode.cache.Region) SubscriptionNotEnabledException(org.apache.geode.cache.client.SubscriptionNotEnabledException) ClientSubscriptionTest(org.apache.geode.test.junit.categories.ClientSubscriptionTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Aggregations

SubscriptionNotEnabledException (org.apache.geode.cache.client.SubscriptionNotEnabledException)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Properties (java.util.Properties)1 InternalGemFireError (org.apache.geode.InternalGemFireError)1 AttributesFactory (org.apache.geode.cache.AttributesFactory)1 CacheException (org.apache.geode.cache.CacheException)1 Region (org.apache.geode.cache.Region)1 ServerRegionProxy (org.apache.geode.cache.client.internal.ServerRegionProxy)1 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)1 VersionedObjectList (org.apache.geode.internal.cache.tier.sockets.VersionedObjectList)1 Host (org.apache.geode.test.dunit.Host)1 VM (org.apache.geode.test.dunit.VM)1 ClientSubscriptionTest (org.apache.geode.test.junit.categories.ClientSubscriptionTest)1 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)1 Test (org.junit.Test)1