Search in sources :

Example 11 with ServerRegionProxy

use of org.apache.geode.cache.client.internal.ServerRegionProxy in project geode by apache.

the class HAInterestTestCase method stopPrimaryAndUnregisterRegisterK1.

public static void stopPrimaryAndUnregisterRegisterK1() {
    LocalRegion r = (LocalRegion) cache.getRegion(Region.SEPARATOR + REGION_NAME);
    assertNotNull(r);
    ServerRegionProxy srp = new ServerRegionProxy(r);
    WaitCriterion wc = new WaitCriterion() {

        @Override
        public boolean done() {
            return pool.getConnectedServerCount() == 3;
        }

        @Override
        public String description() {
            return "connected server count never became 3";
        }
    };
    Wait.waitForCriterion(wc, TIMEOUT_MILLIS, INTERVAL_MILLIS, true);
    // close primaryEP
    getPrimaryVM().invoke(() -> HAInterestTestCase.stopServer());
    List list = new ArrayList();
    list.add(k1);
    srp.unregisterInterest(list, InterestType.KEY, false, false);
}
Also used : WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) ServerRegionProxy(org.apache.geode.cache.client.internal.ServerRegionProxy) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) LocalRegion(org.apache.geode.internal.cache.LocalRegion)

Example 12 with ServerRegionProxy

use of org.apache.geode.cache.client.internal.ServerRegionProxy in project geode by apache.

the class HAInterestTestCase method stopSecondaryAndUNregisterK1.

/**
   * returns the secondary that was stopped
   */
public static VM stopSecondaryAndUNregisterK1() {
    LocalRegion r = (LocalRegion) cache.getRegion(Region.SEPARATOR + REGION_NAME);
    assertNotNull(r);
    ServerRegionProxy srp = new ServerRegionProxy(r);
    WaitCriterion wc = new WaitCriterion() {

        @Override
        public boolean done() {
            return pool.getConnectedServerCount() == 3;
        }

        @Override
        public String description() {
            return "connected server count never became 3";
        }
    };
    Wait.waitForCriterion(wc, TIMEOUT_MILLIS, INTERVAL_MILLIS, true);
    // close secondary EP
    VM result = getBackupVM();
    result.invoke(() -> HAInterestTestCase.stopServer());
    List list = new ArrayList();
    list.add(k1);
    srp.unregisterInterest(list, InterestType.KEY, false, false);
    return result;
}
Also used : WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) ServerRegionProxy(org.apache.geode.cache.client.internal.ServerRegionProxy) VM(org.apache.geode.test.dunit.VM) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) LocalRegion(org.apache.geode.internal.cache.LocalRegion)

Example 13 with ServerRegionProxy

use of org.apache.geode.cache.client.internal.ServerRegionProxy in project geode by apache.

the class ClientStatsManager method publishClientStats.

/**
   * This method publishes the client stats using the admin region.
   * 
   * @param pool Connection pool which may be used for admin region.
   */
public static synchronized void publishClientStats(PoolImpl pool) {
    InternalCache currentCache = GemFireCacheImpl.getInstance();
    if (!initializeStatistics(currentCache)) {
        // handles null case too
        return;
    }
    LogWriterI18n logger = currentCache.getLoggerI18n();
    if (logger.fineEnabled())
        logger.fine("Entering ClientStatsManager#publishClientStats...");
    ClientHealthStats stats = getClientHealthStats(currentCache, pool);
    try {
        InternalDistributedSystem ds = (InternalDistributedSystem) currentCache.getDistributedSystem();
        ServerRegionProxy regionProxy = new ServerRegionProxy(ClientHealthMonitoringRegion.ADMIN_REGION_NAME, pool);
        EventID eventId = new EventID(ds);
        @Released EntryEventImpl event = new EntryEventImpl((Object) null);
        try {
            event.setEventId(eventId);
            regionProxy.putForMetaRegion(ds.getMemberId(), stats, null, event, null, true);
        } finally {
            event.release();
        }
    } catch (DistributedSystemDisconnectedException e) {
        throw e;
    } catch (CacheWriterException cwx) {
        pool.getCancelCriterion().checkCancelInProgress(cwx);
        currentCache.getCancelCriterion().checkCancelInProgress(cwx);
        // TODO: Need to analyze these exception scenarios.
        logger.warning(LocalizedStrings.ClientStatsManager_FAILED_TO_SEND_CLIENT_HEALTH_STATS_TO_CACHESERVER, cwx);
    } catch (Exception e) {
        pool.getCancelCriterion().checkCancelInProgress(e);
        currentCache.getCancelCriterion().checkCancelInProgress(e);
        logger.info(LocalizedStrings.ClientStatsManager_FAILED_TO_PUBLISH_CLIENT_STATISTICS, e);
    }
    if (logger.fineEnabled()) {
        logger.fine("Exiting ClientStatsManager#publishClientStats.");
    }
}
Also used : DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) Released(org.apache.geode.internal.offheap.annotations.Released) EntryEventImpl(org.apache.geode.internal.cache.EntryEventImpl) ServerRegionProxy(org.apache.geode.cache.client.internal.ServerRegionProxy) InternalCache(org.apache.geode.internal.cache.InternalCache) EventID(org.apache.geode.internal.cache.EventID) LogWriterI18n(org.apache.geode.i18n.LogWriterI18n) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) ClientHealthStats(org.apache.geode.internal.admin.remote.ClientHealthStats) DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) CacheWriterException(org.apache.geode.cache.CacheWriterException) CacheWriterException(org.apache.geode.cache.CacheWriterException)

Example 14 with ServerRegionProxy

use of org.apache.geode.cache.client.internal.ServerRegionProxy 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 15 with ServerRegionProxy

use of org.apache.geode.cache.client.internal.ServerRegionProxy in project geode by apache.

the class LocalRegion method containsKeyOnServer.

@Override
public boolean containsKeyOnServer(Object key) {
    checkReadiness();
    checkForNoAccess();
    ServerRegionProxy proxy = getServerProxy();
    if (proxy != null) {
        return proxy.containsKey(key);
    } else {
        throw new UnsupportedOperationException(LocalizedStrings.LocalRegion_SERVER_KEYSET_REQUIRES_A_POOL.toLocalizedString());
    }
}
Also used : ServerRegionProxy(org.apache.geode.cache.client.internal.ServerRegionProxy)

Aggregations

ServerRegionProxy (org.apache.geode.cache.client.internal.ServerRegionProxy)34 Connection (org.apache.geode.cache.client.internal.Connection)10 LocalRegion (org.apache.geode.internal.cache.LocalRegion)8 ArrayList (java.util.ArrayList)7 List (java.util.List)7 EventID (org.apache.geode.internal.cache.EventID)7 FunctionException (org.apache.geode.cache.execute.FunctionException)6 WaitCriterion (org.apache.geode.test.dunit.WaitCriterion)6 PoolImpl (org.apache.geode.cache.client.internal.PoolImpl)5 StoredObject (org.apache.geode.internal.offheap.StoredObject)5 CacheClosedException (org.apache.geode.cache.CacheClosedException)4 Region (org.apache.geode.cache.Region)4 ServerLocation (org.apache.geode.distributed.internal.ServerLocation)4 CacheException (org.apache.geode.cache.CacheException)3 CacheWriterException (org.apache.geode.cache.CacheWriterException)3 Operation (org.apache.geode.cache.Operation)3 VM (org.apache.geode.test.dunit.VM)3 EntryNotFoundException (org.apache.geode.cache.EntryNotFoundException)2 EventIDHolder (org.apache.geode.internal.cache.EventIDHolder)2 ConcurrentCacheModificationException (org.apache.geode.internal.cache.versions.ConcurrentCacheModificationException)2