Search in sources :

Example 6 with InterestResultPolicy

use of org.apache.geode.cache.InterestResultPolicy in project geode by apache.

the class ClientAuthorizationTestCase method doOp.

protected static void doOp(OperationCode op, final int[] indices, final int flagsI, final int expectedResult) throws InterruptedException {
    boolean operationOmitted = false;
    final int flags = flagsI;
    Region region = getRegion();
    if ((flags & OpFlags.USE_SUBREGION) > 0) {
        assertNotNull(region);
        Region subregion = null;
        if ((flags & OpFlags.NO_CREATE_SUBREGION) > 0) {
            if ((flags & OpFlags.CHECK_NOREGION) > 0) {
                // Wait for some time for DRF update to come
                waitForCondition(() -> getSubregion() == null);
                subregion = getSubregion();
                assertNull(subregion);
                return;
            } else {
                // Wait for some time for DRF update to come
                waitForCondition(() -> getSubregion() != null);
                subregion = getSubregion();
                assertNotNull(subregion);
            }
        } else {
            subregion = createSubregion(region);
        }
        assertNotNull(subregion);
        region = subregion;
    } else if ((flags & OpFlags.CHECK_NOREGION) > 0) {
        // Wait for some time for region destroy update to come
        waitForCondition(() -> getRegion() == null);
        region = getRegion();
        assertNull(region);
        return;
    } else {
        assertNotNull(region);
    }
    final String[] keys = KEYS;
    final String[] vals;
    if ((flags & OpFlags.USE_NEWVAL) > 0) {
        vals = NVALUES;
    } else {
        vals = VALUES;
    }
    InterestResultPolicy policy = InterestResultPolicy.KEYS_VALUES;
    if ((flags & OpFlags.REGISTER_POLICY_NONE) > 0) {
        policy = InterestResultPolicy.NONE;
    }
    final int numOps = indices.length;
    System.out.println("Got doOp for op: " + op.toString() + ", numOps: " + numOps + ", indices: " + indicesToString(indices) + ", expect: " + expectedResult);
    boolean exceptionOccurred = false;
    boolean breakLoop = false;
    if (op.isGet() || op.isContainsKey() || op.isKeySet() || op.isQuery() || op.isExecuteCQ()) {
        Thread.sleep(PAUSE);
    }
    for (int indexIndex = 0; indexIndex < numOps; ++indexIndex) {
        if (breakLoop) {
            break;
        }
        int index = indices[indexIndex];
        try {
            final Object key = keys[index];
            final Object expectedVal = vals[index];
            if (op.isGet()) {
                Object value = null;
                // this is the case for testing GET_ALL
                if ((flags & OpFlags.USE_ALL_KEYS) > 0) {
                    breakLoop = true;
                    List keyList = new ArrayList(numOps);
                    Object searchKey;
                    for (int keyNumIndex = 0; keyNumIndex < numOps; ++keyNumIndex) {
                        int keyNum = indices[keyNumIndex];
                        searchKey = keys[keyNum];
                        keyList.add(searchKey);
                        // local invalidate some KEYS to force fetch of those KEYS from server
                        if ((flags & OpFlags.CHECK_NOKEY) > 0) {
                            AbstractRegionEntry entry = (AbstractRegionEntry) ((LocalRegion) region).getRegionEntry(searchKey);
                            System.out.println("" + keyNum + ": key is " + searchKey + " and entry is " + entry);
                            assertFalse(region.containsKey(searchKey));
                        } else {
                            if (keyNumIndex % 2 == 1) {
                                assertTrue(region.containsKey(searchKey));
                                region.localInvalidate(searchKey);
                            }
                        }
                    }
                    Map entries = region.getAll(keyList);
                    for (int keyNumIndex = 0; keyNumIndex < numOps; ++keyNumIndex) {
                        int keyNum = indices[keyNumIndex];
                        searchKey = keys[keyNum];
                        if ((flags & OpFlags.CHECK_FAIL) > 0) {
                            assertFalse(entries.containsKey(searchKey));
                        } else {
                            assertTrue(entries.containsKey(searchKey));
                            value = entries.get(searchKey);
                            assertEquals(vals[keyNum], value);
                        }
                    }
                    break;
                }
                if ((flags & OpFlags.LOCAL_OP) > 0) {
                    Callable<Boolean> condition = new Callable<Boolean>() {

                        private Region region;

                        @Override
                        public Boolean call() throws Exception {
                            Object value = getLocalValue(region, key);
                            return (flags & OpFlags.CHECK_FAIL) > 0 ? !expectedVal.equals(value) : expectedVal.equals(value);
                        }

                        public Callable<Boolean> init(Region region) {
                            this.region = region;
                            return this;
                        }
                    }.init(region);
                    waitForCondition(condition);
                    value = getLocalValue(region, key);
                } else if ((flags & OpFlags.USE_GET_ENTRY_IN_TX) > 0) {
                    getCache().getCacheTransactionManager().begin();
                    Entry e = region.getEntry(key);
                    // Also, check getAll()
                    ArrayList a = new ArrayList();
                    a.addAll(a);
                    region.getAll(a);
                    getCache().getCacheTransactionManager().commit();
                    value = e.getValue();
                } else {
                    if ((flags & OpFlags.CHECK_NOKEY) > 0) {
                        assertFalse(region.containsKey(key));
                    } else {
                        assertTrue(region.containsKey(key) || ((LocalRegion) region).getRegionEntry(key).isTombstone());
                        region.localInvalidate(key);
                    }
                    value = region.get(key);
                }
                if ((flags & OpFlags.CHECK_FAIL) > 0) {
                    assertFalse(expectedVal.equals(value));
                } else {
                    assertNotNull(value);
                    assertEquals(expectedVal, value);
                }
            } else if (op.isPut()) {
                region.put(key, expectedVal);
            } else if (op.isPutAll()) {
                HashMap map = new HashMap();
                for (int i = 0; i < indices.length; i++) {
                    map.put(keys[indices[i]], vals[indices[i]]);
                }
                region.putAll(map);
                breakLoop = true;
            } else if (op.isDestroy()) {
                // }
                if ((flags & OpFlags.LOCAL_OP) > 0) {
                    region.localDestroy(key);
                } else {
                    region.destroy(key);
                }
            } else if (op.isInvalidate()) {
                if (region.containsKey(key)) {
                    if ((flags & OpFlags.LOCAL_OP) > 0) {
                        region.localInvalidate(key);
                    } else {
                        region.invalidate(key);
                    }
                }
            } else if (op.isContainsKey()) {
                boolean result;
                if ((flags & OpFlags.LOCAL_OP) > 0) {
                    result = region.containsKey(key);
                } else {
                    result = region.containsKeyOnServer(key);
                }
                if ((flags & OpFlags.CHECK_FAIL) > 0) {
                    assertFalse(result);
                } else {
                    assertTrue(result);
                }
            } else if (op.isRegisterInterest()) {
                if ((flags & OpFlags.USE_LIST) > 0) {
                    breakLoop = true;
                    // Register interest list in this case
                    List keyList = new ArrayList(numOps);
                    for (int keyNumIndex = 0; keyNumIndex < numOps; ++keyNumIndex) {
                        int keyNum = indices[keyNumIndex];
                        keyList.add(keys[keyNum]);
                    }
                    region.registerInterest(keyList, policy);
                } else if ((flags & OpFlags.USE_REGEX) > 0) {
                    breakLoop = true;
                    region.registerInterestRegex("key[1-" + numOps + ']', policy);
                } else if ((flags & OpFlags.USE_ALL_KEYS) > 0) {
                    breakLoop = true;
                    region.registerInterest("ALL_KEYS", policy);
                } else {
                    region.registerInterest(key, policy);
                }
            } else if (op.isUnregisterInterest()) {
                if ((flags & OpFlags.USE_LIST) > 0) {
                    breakLoop = true;
                    // Register interest list in this case
                    List keyList = new ArrayList(numOps);
                    for (int keyNumIndex = 0; keyNumIndex < numOps; ++keyNumIndex) {
                        int keyNum = indices[keyNumIndex];
                        keyList.add(keys[keyNum]);
                    }
                    region.unregisterInterest(keyList);
                } else if ((flags & OpFlags.USE_REGEX) > 0) {
                    breakLoop = true;
                    region.unregisterInterestRegex("key[1-" + numOps + ']');
                } else if ((flags & OpFlags.USE_ALL_KEYS) > 0) {
                    breakLoop = true;
                    region.unregisterInterest("ALL_KEYS");
                } else {
                    region.unregisterInterest(key);
                }
            } else if (op.isKeySet()) {
                breakLoop = true;
                Set keySet;
                if ((flags & OpFlags.LOCAL_OP) > 0) {
                    keySet = region.keySet();
                } else {
                    keySet = region.keySetOnServer();
                }
                assertNotNull(keySet);
                if ((flags & OpFlags.CHECK_FAIL) == 0) {
                    assertEquals(numOps, keySet.size());
                }
                for (int keyNumIndex = 0; keyNumIndex < numOps; ++keyNumIndex) {
                    int keyNum = indices[keyNumIndex];
                    if ((flags & OpFlags.CHECK_FAIL) > 0) {
                        assertFalse(keySet.contains(keys[keyNum]));
                    } else {
                        assertTrue(keySet.contains(keys[keyNum]));
                    }
                }
            } else if (op.isQuery()) {
                breakLoop = true;
                SelectResults queryResults = region.query("SELECT DISTINCT * FROM " + region.getFullPath());
                assertNotNull(queryResults);
                Set queryResultSet = queryResults.asSet();
                if ((flags & OpFlags.CHECK_FAIL) == 0) {
                    assertEquals(numOps, queryResultSet.size());
                }
                for (int keyNumIndex = 0; keyNumIndex < numOps; ++keyNumIndex) {
                    int keyNum = indices[keyNumIndex];
                    if ((flags & OpFlags.CHECK_FAIL) > 0) {
                        assertFalse(queryResultSet.contains(vals[keyNum]));
                    } else {
                        assertTrue(queryResultSet.contains(vals[keyNum]));
                    }
                }
            } else if (op.isExecuteCQ()) {
                breakLoop = true;
                QueryService queryService = getCache().getQueryService();
                CqQuery cqQuery;
                if ((cqQuery = queryService.getCq("cq1")) == null) {
                    CqAttributesFactory cqFact = new CqAttributesFactory();
                    cqFact.addCqListener(new AuthzCqListener());
                    CqAttributes cqAttrs = cqFact.create();
                    cqQuery = queryService.newCq("cq1", "SELECT * FROM " + region.getFullPath(), cqAttrs);
                }
                if ((flags & OpFlags.LOCAL_OP) > 0) {
                    // Interpret this as testing results using CqListener
                    final AuthzCqListener listener = (AuthzCqListener) cqQuery.getCqAttributes().getCqListener();
                    WaitCriterion ev = new WaitCriterion() {

                        @Override
                        public boolean done() {
                            if ((flags & OpFlags.CHECK_FAIL) > 0) {
                                return 0 == listener.getNumUpdates();
                            } else {
                                return numOps == listener.getNumUpdates();
                            }
                        }

                        @Override
                        public String description() {
                            return null;
                        }
                    };
                    waitForCriterion(ev, 3 * 1000, 200, true);
                    if ((flags & OpFlags.CHECK_FAIL) > 0) {
                        assertEquals(0, listener.getNumUpdates());
                    } else {
                        assertEquals(numOps, listener.getNumUpdates());
                        listener.checkPuts(vals, indices);
                    }
                    assertEquals(0, listener.getNumCreates());
                    assertEquals(0, listener.getNumDestroys());
                    assertEquals(0, listener.getNumOtherOps());
                    assertEquals(0, listener.getNumErrors());
                } else {
                    SelectResults cqResults = cqQuery.executeWithInitialResults();
                    assertNotNull(cqResults);
                    Set cqResultValues = new HashSet();
                    for (Object o : cqResults.asList()) {
                        Struct s = (Struct) o;
                        cqResultValues.add(s.get("value"));
                    }
                    Set cqResultSet = cqResults.asSet();
                    if ((flags & OpFlags.CHECK_FAIL) == 0) {
                        assertEquals(numOps, cqResultSet.size());
                    }
                    for (int keyNumIndex = 0; keyNumIndex < numOps; ++keyNumIndex) {
                        int keyNum = indices[keyNumIndex];
                        if ((flags & OpFlags.CHECK_FAIL) > 0) {
                            assertFalse(cqResultValues.contains(vals[keyNum]));
                        } else {
                            assertTrue(cqResultValues.contains(vals[keyNum]));
                        }
                    }
                }
            } else if (op.isStopCQ()) {
                breakLoop = true;
                CqQuery cqQuery = getCache().getQueryService().getCq("cq1");
                ((AuthzCqListener) cqQuery.getCqAttributes().getCqListener()).reset();
                cqQuery.stop();
            } else if (op.isCloseCQ()) {
                breakLoop = true;
                CqQuery cqQuery = getCache().getQueryService().getCq("cq1");
                ((AuthzCqListener) cqQuery.getCqAttributes().getCqListener()).reset();
                cqQuery.close();
            } else if (op.isRegionClear()) {
                breakLoop = true;
                if ((flags & OpFlags.LOCAL_OP) > 0) {
                    region.localClear();
                } else {
                    region.clear();
                }
            } else if (op.isRegionCreate()) {
                breakLoop = true;
                // Region subregion = createSubregion(region);
                // subregion.createRegionOnServer();
                // Create region on server using the DynamicRegionFactory
                // Assume it has been already initialized
                DynamicRegionFactory drf = DynamicRegionFactory.get();
                Region subregion = drf.createDynamicRegion(regionName, SUBREGION_NAME);
                assertEquals('/' + regionName + '/' + SUBREGION_NAME, subregion.getFullPath());
            } else if (op.isRegionDestroy()) {
                breakLoop = true;
                if ((flags & OpFlags.LOCAL_OP) > 0) {
                    region.localDestroyRegion();
                } else {
                    if ((flags & OpFlags.USE_SUBREGION) > 0) {
                        try {
                            DynamicRegionFactory.get().destroyDynamicRegion(region.getFullPath());
                        } catch (RegionDestroyedException ex) {
                            // harmless to ignore this
                            System.out.println("doOp: sub-region " + region.getFullPath() + " already destroyed");
                            operationOmitted = true;
                        }
                    } else {
                        region.destroyRegion();
                    }
                }
            } else {
                fail("doOp: Unhandled operation " + op);
            }
            if (expectedResult != NO_EXCEPTION) {
                if (!operationOmitted && !op.isUnregisterInterest()) {
                    fail("Expected an exception while performing operation op =" + op + "flags = " + OpFlags.description(flags));
                }
            }
        } catch (Exception ex) {
            exceptionOccurred = true;
            if ((ex instanceof ServerConnectivityException || ex instanceof QueryInvocationTargetException || ex instanceof CqException) && (expectedResult == NOTAUTHZ_EXCEPTION) && (ex.getCause() instanceof NotAuthorizedException)) {
                System.out.println("doOp: Got expected NotAuthorizedException when doing operation [" + op + "] with flags " + OpFlags.description(flags) + ": " + ex.getCause());
                continue;
            } else if (expectedResult == OTHER_EXCEPTION) {
                System.out.println("doOp: Got expected exception when doing operation: " + ex.toString());
                continue;
            } else {
                fail("doOp: Got unexpected exception when doing operation. Policy = " + policy + " flags = " + OpFlags.description(flags), ex);
            }
        }
    }
    if (!exceptionOccurred && !operationOmitted && expectedResult != NO_EXCEPTION) {
        fail("Expected an exception while performing operation: " + op + " flags = " + OpFlags.description(flags));
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) ArrayList(java.util.ArrayList) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Callable(java.util.concurrent.Callable) Struct(org.apache.geode.cache.query.Struct) ServerConnectivityException(org.apache.geode.cache.client.ServerConnectivityException) InterestResultPolicy(org.apache.geode.cache.InterestResultPolicy) Entry(org.apache.geode.cache.Region.Entry) AbstractRegionEntry(org.apache.geode.internal.cache.AbstractRegionEntry) SelectResults(org.apache.geode.cache.query.SelectResults) ArrayList(java.util.ArrayList) List(java.util.List) CqQuery(org.apache.geode.cache.query.CqQuery) HashSet(java.util.HashSet) DynamicRegionFactory(org.apache.geode.cache.DynamicRegionFactory) CqException(org.apache.geode.cache.query.CqException) QueryInvocationTargetException(org.apache.geode.cache.query.QueryInvocationTargetException) CqException(org.apache.geode.cache.query.CqException) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) ServerConnectivityException(org.apache.geode.cache.client.ServerConnectivityException) QueryInvocationTargetException(org.apache.geode.cache.query.QueryInvocationTargetException) AbstractRegionEntry(org.apache.geode.internal.cache.AbstractRegionEntry) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) QueryService(org.apache.geode.cache.query.QueryService) CqAttributes(org.apache.geode.cache.query.CqAttributes) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Region(org.apache.geode.cache.Region) CqAttributesFactory(org.apache.geode.cache.query.CqAttributesFactory) HashMap(java.util.HashMap) Map(java.util.Map)

Example 7 with InterestResultPolicy

use of org.apache.geode.cache.InterestResultPolicy in project geode by apache.

the class RegisterInterest method cmdExecute.

@Override
public void cmdExecute(Message clientMessage, ServerConnection serverConnection, long start) throws IOException, InterruptedException {
    Part regionNamePart = null, keyPart = null;
    String regionName = null;
    Object key = null;
    serverConnection.setAsTrue(REQUIRES_RESPONSE);
    serverConnection.setAsTrue(REQUIRES_CHUNKED_RESPONSE);
    // bserverStats.incLong(readDestroyRequestTimeId,
    // DistributionStats.getStatTime() - start);
    // bserverStats.incInt(destroyRequestsId, 1);
    // start = DistributionStats.getStatTime();
    // Retrieve the data from the message parts
    regionNamePart = clientMessage.getPart(0);
    regionName = regionNamePart.getString();
    InterestResultPolicy policy = null;
    // Retrieve the interest type
    int interestType = clientMessage.getPart(1).getInt();
    // Retrieve the InterestResultPolicy
    try {
        policy = (InterestResultPolicy) clientMessage.getPart(2).getObject();
    } catch (Exception e) {
        writeChunkedException(clientMessage, e, serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        return;
    }
    boolean isDurable = false;
    try {
        Part durablePart = clientMessage.getPart(3);
        byte[] durablePartBytes = (byte[]) durablePart.getObject();
        isDurable = durablePartBytes[0] == 0x01;
    } catch (Exception e) {
        writeChunkedException(clientMessage, e, serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        return;
    }
    // Retrieve the key
    keyPart = clientMessage.getPart(4);
    regionName = regionNamePart.getString();
    try {
        key = keyPart.getStringOrObject();
    } catch (Exception e) {
        writeChunkedException(clientMessage, e, serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        return;
    }
    boolean sendUpdatesAsInvalidates = false;
    // time being until refactoring into a new command version.
    if (clientMessage.getNumberOfParts() > 5) {
        try {
            Part notifyPart = clientMessage.getPart(5);
            byte[] notifyPartBytes = (byte[]) notifyPart.getObject();
            sendUpdatesAsInvalidates = notifyPartBytes[0] == 0x01;
        } catch (Exception e) {
            writeChunkedException(clientMessage, e, serverConnection);
            serverConnection.setAsTrue(RESPONDED);
            return;
        }
    }
    if (logger.isDebugEnabled()) {
        logger.debug("{}: Received register interest request ({} bytes) from {} for region {} key {}", serverConnection.getName(), clientMessage.getPayloadLength(), serverConnection.getSocketString(), regionName, key);
    }
    // Process the register interest request
    if (key == null || regionName == null) {
        StringId message = null;
        if (key == null) {
            message = LocalizedStrings.RegisterInterest_THE_INPUT_KEY_FOR_THE_REGISTER_INTEREST_REQUEST_IS_NULL;
        }
        if (regionName == null) {
            message = LocalizedStrings.RegisterInterest_THE_INPUT_REGION_NAME_FOR_THE_REGISTER_INTEREST_REQUEST_IS_NULL;
        }
        logger.warn("{}: {}", serverConnection.getName(), message.toLocalizedString());
        writeChunkedErrorResponse(clientMessage, MessageType.REGISTER_INTEREST_DATA_ERROR, message.toLocalizedString(), serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        return;
    }
    // input key not null
    LocalRegion region = (LocalRegion) serverConnection.getCache().getRegion(regionName);
    if (region == null) {
        logger.info(LocalizedMessage.create(LocalizedStrings.RegisterInterest_0_REGION_NAMED_1_WAS_NOT_FOUND_DURING_REGISTER_INTEREST_REQUEST, new Object[] { serverConnection.getName(), regionName }));
    // writeChunkedErrorResponse(msg,
    // MessageType.REGISTER_INTEREST_DATA_ERROR, message);
    // responded = true;
    }
    // Register interest
    try {
        if (interestType == InterestType.REGULAR_EXPRESSION) {
            this.securityService.authorizeRegionRead(regionName);
        } else {
            this.securityService.authorizeRegionRead(regionName, key.toString());
        }
        AuthorizeRequest authzRequest = serverConnection.getAuthzRequest();
        if (authzRequest != null) {
            if (!DynamicRegionFactory.regionIsDynamicRegionList(regionName)) {
                RegisterInterestOperationContext registerContext = authzRequest.registerInterestAuthorize(regionName, key, interestType, policy);
                key = registerContext.getKey();
            }
        }
        serverConnection.getAcceptor().getCacheClientNotifier().registerClientInterest(regionName, key, serverConnection.getProxyID(), interestType, isDurable, sendUpdatesAsInvalidates, false, 0, true);
    } catch (Exception e) {
        // If an interrupted exception is thrown , rethrow it
        checkForInterrupt(serverConnection, e);
        // Otherwise, write an exception message and continue
        writeChunkedException(clientMessage, e, serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        return;
    }
    // System.out.println("Received register interest for " + regionName);
    // Update the statistics and write the reply
    // bserverStats.incLong(processDestroyTimeId,
    // DistributionStats.getStatTime() - start);
    // start = DistributionStats.getStatTime();
    CacheClientProxy ccp = serverConnection.getAcceptor().getCacheClientNotifier().getClientProxy(serverConnection.getProxyID());
    if (ccp == null) {
        // fix for 37593
        IOException ioex = new IOException(LocalizedStrings.RegisterInterest_CACHECLIENTPROXY_FOR_THIS_CLIENT_IS_NO_LONGER_ON_THE_SERVER_SO_REGISTERINTEREST_OPERATION_IS_UNSUCCESSFUL.toLocalizedString());
        writeChunkedException(clientMessage, ioex, serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        return;
    }
    boolean isPrimary = ccp.isPrimary();
    ChunkedMessage chunkedResponseMsg = serverConnection.getRegisterInterestResponseMessage();
    if (!isPrimary) {
        chunkedResponseMsg.setMessageType(MessageType.RESPONSE_FROM_SECONDARY);
        chunkedResponseMsg.setTransactionId(clientMessage.getTransactionId());
        chunkedResponseMsg.sendHeader();
        chunkedResponseMsg.setLastChunk(true);
        if (logger.isDebugEnabled()) {
            logger.debug("{}: Sending register interest response chunk from secondary for region: {} for key: {} chunk=<{}>", serverConnection.getName(), regionName, key, chunkedResponseMsg);
        }
        chunkedResponseMsg.sendChunk(serverConnection);
    } else // !isPrimary
    {
        // isPrimary
        // Send header which describes how many chunks will follow
        chunkedResponseMsg.setMessageType(MessageType.RESPONSE_FROM_PRIMARY);
        chunkedResponseMsg.setTransactionId(clientMessage.getTransactionId());
        chunkedResponseMsg.sendHeader();
        // Send chunk response
        try {
            fillAndSendRegisterInterestResponseChunks(region, key, interestType, policy, serverConnection);
            serverConnection.setAsTrue(RESPONDED);
        } catch (Exception e) {
            writeChunkedException(clientMessage, e, serverConnection, chunkedResponseMsg);
            serverConnection.setAsTrue(RESPONDED);
            return;
        }
        if (logger.isDebugEnabled()) {
            // logger.debug(getName() + ": Sent chunk (1 of 1) of register interest
            // response (" + chunkedResponseMsg.getBufferLength() + " bytes) for
            // region " + regionName + " key " + key);
            logger.debug("{}: Sent register interest response for region {} key {}", serverConnection.getName(), regionName, key);
        }
    // bserverStats.incLong(writeDestroyResponseTimeId,
    // DistributionStats.getStatTime() - start);
    // bserverStats.incInt(destroyResponsesId, 1);
    }
// isPrimary
}
Also used : CacheClientProxy(org.apache.geode.internal.cache.tier.sockets.CacheClientProxy) AuthorizeRequest(org.apache.geode.internal.security.AuthorizeRequest) RegisterInterestOperationContext(org.apache.geode.cache.operations.RegisterInterestOperationContext) LocalRegion(org.apache.geode.internal.cache.LocalRegion) IOException(java.io.IOException) IOException(java.io.IOException) InterestResultPolicy(org.apache.geode.cache.InterestResultPolicy) StringId(org.apache.geode.i18n.StringId) Part(org.apache.geode.internal.cache.tier.sockets.Part) ChunkedMessage(org.apache.geode.internal.cache.tier.sockets.ChunkedMessage)

Example 8 with InterestResultPolicy

use of org.apache.geode.cache.InterestResultPolicy in project geode by apache.

the class RegisterInterest61 method cmdExecute.

@Override
public void cmdExecute(Message clientMessage, ServerConnection serverConnection, long start) throws IOException, InterruptedException {
    Part regionNamePart = null, keyPart = null;
    String regionName = null;
    Object key = null;
    CachedRegionHelper crHelper = serverConnection.getCachedRegionHelper();
    serverConnection.setAsTrue(REQUIRES_RESPONSE);
    serverConnection.setAsTrue(REQUIRES_CHUNKED_RESPONSE);
    // bserverStats.incLong(readDestroyRequestTimeId,
    // DistributionStats.getStatTime() - start);
    // bserverStats.incInt(destroyRequestsId, 1);
    // start = DistributionStats.getStatTime();
    // Retrieve the data from the message parts
    regionNamePart = clientMessage.getPart(0);
    regionName = regionNamePart.getString();
    InterestResultPolicy policy = null;
    // Retrieve the interest type
    int interestType = clientMessage.getPart(1).getInt();
    // Retrieve the InterestResultPolicy
    try {
        policy = (InterestResultPolicy) clientMessage.getPart(2).getObject();
    } catch (Exception e) {
        writeChunkedException(clientMessage, e, serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        return;
    }
    boolean isDurable = false;
    try {
        Part durablePart = clientMessage.getPart(3);
        byte[] durablePartBytes = (byte[]) durablePart.getObject();
        isDurable = durablePartBytes[0] == 0x01;
    } catch (Exception e) {
        writeChunkedException(clientMessage, e, serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        return;
    }
    // region data policy
    byte[] regionDataPolicyPartBytes;
    boolean serializeValues = false;
    try {
        Part regionDataPolicyPart = clientMessage.getPart(clientMessage.getNumberOfParts() - 1);
        regionDataPolicyPartBytes = (byte[]) regionDataPolicyPart.getObject();
        if (serverConnection.getClientVersion().compareTo(Version.GFE_80) >= 0) {
            // The second byte here is serializeValues
            serializeValues = regionDataPolicyPartBytes[1] == (byte) 0x01;
        }
    } catch (Exception e) {
        writeChunkedException(clientMessage, e, serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        return;
    }
    // Retrieve the key
    keyPart = clientMessage.getPart(4);
    regionName = regionNamePart.getString();
    try {
        key = keyPart.getStringOrObject();
    } catch (Exception e) {
        writeChunkedException(clientMessage, e, serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        return;
    }
    boolean sendUpdatesAsInvalidates = false;
    // time being until refactoring into a new command version.
    if (clientMessage.getNumberOfParts() > 5) {
        try {
            Part notifyPart = clientMessage.getPart(5);
            byte[] notifyPartBytes = (byte[]) notifyPart.getObject();
            sendUpdatesAsInvalidates = notifyPartBytes[0] == 0x01;
        } catch (Exception e) {
            writeChunkedException(clientMessage, e, serverConnection);
            serverConnection.setAsTrue(RESPONDED);
            return;
        }
    }
    if (logger.isDebugEnabled()) {
        logger.debug("{}: Received register interest 61 request ({} bytes) from {} for region {} key {}", serverConnection.getName(), clientMessage.getPayloadLength(), serverConnection.getSocketString(), regionName, key);
    }
    if (VMOTION_DURING_REGISTER_INTEREST_FLAG) {
        VMotionObserver vmo = VMotionObserverHolder.getInstance();
        vmo.vMotionBeforeRegisterInterest();
    }
    // Process the register interest request
    if (key == null || regionName == null) {
        StringId message = null;
        if (key == null) {
            message = LocalizedStrings.RegisterInterest_THE_INPUT_KEY_FOR_THE_REGISTER_INTEREST_REQUEST_IS_NULL;
        }
        if (regionName == null) {
            message = LocalizedStrings.RegisterInterest_THE_INPUT_REGION_NAME_FOR_THE_REGISTER_INTEREST_REQUEST_IS_NULL;
        }
        logger.warn("{}: {}", serverConnection.getName(), message.toLocalizedString());
        writeChunkedErrorResponse(clientMessage, MessageType.REGISTER_INTEREST_DATA_ERROR, message.toLocalizedString(), serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        return;
    }
    // input key not null
    LocalRegion region = (LocalRegion) serverConnection.getCache().getRegion(regionName);
    if (region == null) {
        logger.info(LocalizedMessage.create(LocalizedStrings.RegisterInterest_0_REGION_NAMED_1_WAS_NOT_FOUND_DURING_REGISTER_INTEREST_REQUEST, new Object[] { serverConnection.getName(), regionName }));
    // writeChunkedErrorResponse(msg,
    // MessageType.REGISTER_INTEREST_DATA_ERROR, message);
    // responded = true;
    }
    // Register interest
    try {
        if (interestType == InterestType.REGULAR_EXPRESSION) {
            this.securityService.authorizeRegionRead(regionName);
        } else {
            this.securityService.authorizeRegionRead(regionName, key.toString());
        }
        AuthorizeRequest authzRequest = serverConnection.getAuthzRequest();
        if (authzRequest != null) {
            if (!DynamicRegionFactory.regionIsDynamicRegionList(regionName)) {
                RegisterInterestOperationContext registerContext = authzRequest.registerInterestAuthorize(regionName, key, interestType, policy);
                key = registerContext.getKey();
            }
        }
        serverConnection.getAcceptor().getCacheClientNotifier().registerClientInterest(regionName, key, serverConnection.getProxyID(), interestType, isDurable, sendUpdatesAsInvalidates, true, regionDataPolicyPartBytes[0], true);
    } catch (Exception e) {
        // If an interrupted exception is thrown , rethrow it
        checkForInterrupt(serverConnection, e);
        // Otherwise, write an exception message and continue
        writeChunkedException(clientMessage, e, serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        return;
    }
    // System.out.println("Received register interest for " + regionName);
    // Update the statistics and write the reply
    // bserverStats.incLong(processDestroyTimeId,
    // DistributionStats.getStatTime() - start);
    // start = DistributionStats.getStatTime();
    CacheClientProxy ccp = serverConnection.getAcceptor().getCacheClientNotifier().getClientProxy(serverConnection.getProxyID());
    if (ccp == null) {
        // fix for 37593
        IOException ioex = new IOException(LocalizedStrings.RegisterInterest_CACHECLIENTPROXY_FOR_THIS_CLIENT_IS_NO_LONGER_ON_THE_SERVER_SO_REGISTERINTEREST_OPERATION_IS_UNSUCCESSFUL.toLocalizedString());
        writeChunkedException(clientMessage, ioex, serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        return;
    }
    boolean isPrimary = ccp.isPrimary();
    ChunkedMessage chunkedResponseMsg = serverConnection.getRegisterInterestResponseMessage();
    if (!isPrimary) {
        chunkedResponseMsg.setMessageType(MessageType.RESPONSE_FROM_SECONDARY);
        chunkedResponseMsg.setTransactionId(clientMessage.getTransactionId());
        chunkedResponseMsg.sendHeader();
        chunkedResponseMsg.setLastChunk(true);
        if (logger.isDebugEnabled()) {
            logger.debug("{}: Sending register interest response chunk from secondary for region: {} for key: {} chunk=<{}>", serverConnection.getName(), regionName, key, chunkedResponseMsg);
        }
        chunkedResponseMsg.sendChunk(serverConnection);
    } else // !isPrimary
    {
        // isPrimary
        // Send header which describes how many chunks will follow
        chunkedResponseMsg.setMessageType(MessageType.RESPONSE_FROM_PRIMARY);
        chunkedResponseMsg.setTransactionId(clientMessage.getTransactionId());
        chunkedResponseMsg.sendHeader();
        // Send chunk response
        try {
            fillAndSendRegisterInterestResponseChunks(region, key, interestType, serializeValues, policy, serverConnection);
            serverConnection.setAsTrue(RESPONDED);
        } catch (Exception e) {
            writeChunkedException(clientMessage, e, serverConnection, chunkedResponseMsg);
            serverConnection.setAsTrue(RESPONDED);
            return;
        }
        if (logger.isDebugEnabled()) {
            // logger.debug(getName() + ": Sent chunk (1 of 1) of register interest
            // response (" + chunkedResponseMsg.getBufferLength() + " bytes) for
            // region " + regionName + " key " + key);
            logger.debug("{}: Sent register interest response for region {} key {}", serverConnection.getName(), regionName, key);
        }
    // bserverStats.incLong(writeDestroyResponseTimeId,
    // DistributionStats.getStatTime() - start);
    // bserverStats.incInt(destroyResponsesId, 1);
    }
// isPrimary
}
Also used : CacheClientProxy(org.apache.geode.internal.cache.tier.sockets.CacheClientProxy) AuthorizeRequest(org.apache.geode.internal.security.AuthorizeRequest) RegisterInterestOperationContext(org.apache.geode.cache.operations.RegisterInterestOperationContext) VMotionObserver(org.apache.geode.internal.cache.vmotion.VMotionObserver) LocalRegion(org.apache.geode.internal.cache.LocalRegion) IOException(java.io.IOException) IOException(java.io.IOException) CachedRegionHelper(org.apache.geode.internal.cache.tier.CachedRegionHelper) InterestResultPolicy(org.apache.geode.cache.InterestResultPolicy) StringId(org.apache.geode.i18n.StringId) Part(org.apache.geode.internal.cache.tier.sockets.Part) ChunkedMessage(org.apache.geode.internal.cache.tier.sockets.ChunkedMessage)

Example 9 with InterestResultPolicy

use of org.apache.geode.cache.InterestResultPolicy in project geode by apache.

the class RegisterInterestList method cmdExecute.

@Override
public void cmdExecute(Message clientMessage, ServerConnection serverConnection, long start) throws IOException, InterruptedException {
    Part regionNamePart = null, keyPart = null, numberOfKeysPart = null;
    String regionName = null;
    Object key = null;
    InterestResultPolicy policy;
    List keys = null;
    CachedRegionHelper crHelper = serverConnection.getCachedRegionHelper();
    int numberOfKeys = 0, partNumber = 0;
    serverConnection.setAsTrue(REQUIRES_RESPONSE);
    serverConnection.setAsTrue(REQUIRES_CHUNKED_RESPONSE);
    ChunkedMessage chunkedResponseMsg = serverConnection.getRegisterInterestResponseMessage();
    // bserverStats.incLong(readDestroyRequestTimeId,
    // DistributionStats.getStatTime() - start);
    // bserverStats.incInt(destroyRequestsId, 1);
    // start = DistributionStats.getStatTime();
    // Retrieve the data from the message parts
    regionNamePart = clientMessage.getPart(0);
    regionName = regionNamePart.getString();
    // Retrieve the InterestResultPolicy
    try {
        policy = (InterestResultPolicy) clientMessage.getPart(1).getObject();
    } catch (Exception e) {
        writeChunkedException(clientMessage, e, serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        return;
    }
    boolean isDurable = false;
    try {
        Part durablePart = clientMessage.getPart(2);
        byte[] durablePartBytes = (byte[]) durablePart.getObject();
        isDurable = durablePartBytes[0] == 0x01;
    } catch (Exception e) {
        writeChunkedException(clientMessage, e, serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        return;
    }
    numberOfKeysPart = clientMessage.getPart(3);
    numberOfKeys = numberOfKeysPart.getInt();
    partNumber = 4;
    keys = new ArrayList();
    for (int i = 0; i < numberOfKeys; i++) {
        keyPart = clientMessage.getPart(partNumber + i);
        try {
            key = keyPart.getStringOrObject();
        } catch (Exception e) {
            writeChunkedException(clientMessage, e, serverConnection);
            serverConnection.setAsTrue(RESPONDED);
            return;
        }
        keys.add(key);
    }
    boolean sendUpdatesAsInvalidates = false;
    // time being until refactoring into a new command version.
    if (clientMessage.getNumberOfParts() > (numberOfKeys + partNumber)) {
        try {
            Part notifyPart = clientMessage.getPart(numberOfKeys + partNumber);
            byte[] notifyPartBytes = (byte[]) notifyPart.getObject();
            sendUpdatesAsInvalidates = notifyPartBytes[0] == 0x01;
        } catch (Exception e) {
            writeChunkedException(clientMessage, e, serverConnection);
            serverConnection.setAsTrue(RESPONDED);
            return;
        }
    }
    if (logger.isDebugEnabled()) {
        logger.debug("{}: Received register interest request ({} bytes) from {} for the following {} keys in region {}: {}", serverConnection.getName(), clientMessage.getPayloadLength(), serverConnection.getSocketString(), numberOfKeys, regionName, keys);
    }
    // Process the register interest request
    if (keys.isEmpty() || regionName == null) {
        StringId errMessage = null;
        if (keys.isEmpty() && regionName == null) {
            errMessage = LocalizedStrings.RegisterInterestList_THE_INPUT_LIST_OF_KEYS_IS_EMPTY_AND_THE_INPUT_REGION_NAME_IS_NULL_FOR_THE_REGISTER_INTEREST_REQUEST;
        } else if (keys.isEmpty()) {
            errMessage = LocalizedStrings.RegisterInterestList_THE_INPUT_LIST_OF_KEYS_FOR_THE_REGISTER_INTEREST_REQUEST_IS_EMPTY;
        } else if (regionName == null) {
            errMessage = LocalizedStrings.RegisterInterest_THE_INPUT_REGION_NAME_FOR_THE_REGISTER_INTEREST_REQUEST_IS_NULL;
        }
        String s = errMessage.toLocalizedString();
        logger.warn("{}: {}", serverConnection.getName(), s);
        writeChunkedErrorResponse(clientMessage, MessageType.REGISTER_INTEREST_DATA_ERROR, s, serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        return;
    }
    // key not null
    LocalRegion region = (LocalRegion) serverConnection.getCache().getRegion(regionName);
    if (region == null) {
        logger.info(LocalizedMessage.create(LocalizedStrings.RegisterInterestList_0_REGION_NAMED_1_WAS_NOT_FOUND_DURING_REGISTER_INTEREST_LIST_REQUEST, new Object[] { serverConnection.getName(), regionName }));
    // writeChunkedErrorResponse(msg,
    // MessageType.REGISTER_INTEREST_DATA_ERROR, message);
    // responded = true;
    }
    // else { // region not null
    try {
        this.securityService.authorizeRegionRead(regionName);
        AuthorizeRequest authzRequest = serverConnection.getAuthzRequest();
        if (authzRequest != null) {
            if (!DynamicRegionFactory.regionIsDynamicRegionList(regionName)) {
                RegisterInterestOperationContext registerContext = authzRequest.registerInterestListAuthorize(regionName, keys, policy);
                keys = (List) registerContext.getKey();
            }
        }
        // Register interest
        serverConnection.getAcceptor().getCacheClientNotifier().registerClientInterest(regionName, keys, serverConnection.getProxyID(), isDurable, sendUpdatesAsInvalidates, false, 0, true);
    } catch (Exception ex) {
        // If an interrupted exception is thrown , rethrow it
        checkForInterrupt(serverConnection, ex);
        // Otherwise, write an exception message and continue
        writeChunkedException(clientMessage, ex, serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        return;
    }
    // Update the statistics and write the reply
    // bserverStats.incLong(processDestroyTimeId,
    // DistributionStats.getStatTime() - start);
    // start = DistributionStats.getStatTime();
    boolean isPrimary = serverConnection.getAcceptor().getCacheClientNotifier().getClientProxy(serverConnection.getProxyID()).isPrimary();
    if (!isPrimary) {
        chunkedResponseMsg.setMessageType(MessageType.RESPONSE_FROM_SECONDARY);
        chunkedResponseMsg.setTransactionId(clientMessage.getTransactionId());
        chunkedResponseMsg.sendHeader();
        chunkedResponseMsg.setLastChunk(true);
        if (logger.isDebugEnabled()) {
            logger.debug("{}: Sending register interest response chunk from secondary for region: {} for key: {} chunk=<{}>", serverConnection.getName(), regionName, key, chunkedResponseMsg);
        }
        chunkedResponseMsg.sendChunk(serverConnection);
    } else {
        // isPrimary
        // Send header which describes how many chunks will follow
        chunkedResponseMsg.setMessageType(MessageType.RESPONSE_FROM_PRIMARY);
        chunkedResponseMsg.setTransactionId(clientMessage.getTransactionId());
        chunkedResponseMsg.sendHeader();
        // Send chunk response
        try {
            fillAndSendRegisterInterestResponseChunks(region, keys, InterestType.KEY, policy, serverConnection);
            serverConnection.setAsTrue(RESPONDED);
        } catch (Exception e) {
            // If an interrupted exception is thrown , rethrow it
            checkForInterrupt(serverConnection, e);
            // otherwise send the exception back to client
            writeChunkedException(clientMessage, e, serverConnection);
            serverConnection.setAsTrue(RESPONDED);
            return;
        }
        if (logger.isDebugEnabled()) {
            // logger.debug(getName() + ": Sent chunk (1 of 1) of register interest
            // response (" + chunkedResponseMsg.getBufferLength() + " bytes) for
            // region " + regionName + " key " + key);
            logger.debug("{}: Sent register interest response for the following {} keys in region {}: {}", serverConnection.getName(), numberOfKeys, regionName, keys);
        }
    // bserverStats.incLong(writeDestroyResponseTimeId,
    // DistributionStats.getStatTime() - start);
    // bserverStats.incInt(destroyResponsesId, 1);
    }
// isPrimary
// } // region not null
}
Also used : AuthorizeRequest(org.apache.geode.internal.security.AuthorizeRequest) RegisterInterestOperationContext(org.apache.geode.cache.operations.RegisterInterestOperationContext) ArrayList(java.util.ArrayList) LocalRegion(org.apache.geode.internal.cache.LocalRegion) IOException(java.io.IOException) CachedRegionHelper(org.apache.geode.internal.cache.tier.CachedRegionHelper) InterestResultPolicy(org.apache.geode.cache.InterestResultPolicy) StringId(org.apache.geode.i18n.StringId) ArrayList(java.util.ArrayList) List(java.util.List)

Example 10 with InterestResultPolicy

use of org.apache.geode.cache.InterestResultPolicy in project geode by apache.

the class RegisterInterestList66 method cmdExecute.

@Override
public void cmdExecute(Message clientMessage, ServerConnection serverConnection, long start) throws IOException, InterruptedException {
    // numberOfKeysPart = null;
    Part regionNamePart = null, keyPart = null;
    String regionName = null;
    Object key = null;
    InterestResultPolicy policy;
    List keys = null;
    CachedRegionHelper crHelper = serverConnection.getCachedRegionHelper();
    int numberOfKeys = 0, partNumber = 0;
    serverConnection.setAsTrue(REQUIRES_RESPONSE);
    serverConnection.setAsTrue(REQUIRES_CHUNKED_RESPONSE);
    ChunkedMessage chunkedResponseMsg = serverConnection.getRegisterInterestResponseMessage();
    // bserverStats.incLong(readDestroyRequestTimeId,
    // DistributionStats.getStatTime() - start);
    // bserverStats.incInt(destroyRequestsId, 1);
    // start = DistributionStats.getStatTime();
    // Retrieve the data from the message parts
    regionNamePart = clientMessage.getPart(0);
    regionName = regionNamePart.getString();
    // Retrieve the InterestResultPolicy
    try {
        policy = (InterestResultPolicy) clientMessage.getPart(1).getObject();
    } catch (Exception e) {
        writeChunkedException(clientMessage, e, serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        return;
    }
    boolean isDurable = false;
    try {
        Part durablePart = clientMessage.getPart(2);
        byte[] durablePartBytes = (byte[]) durablePart.getObject();
        isDurable = durablePartBytes[0] == 0x01;
    } catch (Exception e) {
        writeChunkedException(clientMessage, e, serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        return;
    }
    // region data policy
    byte[] regionDataPolicyPartBytes;
    boolean serializeValues = false;
    try {
        Part regionDataPolicyPart = clientMessage.getPart(clientMessage.getNumberOfParts() - 1);
        regionDataPolicyPartBytes = (byte[]) regionDataPolicyPart.getObject();
        if (serverConnection.getClientVersion().compareTo(Version.GFE_80) >= 0) {
            // The second byte here is serializeValues
            serializeValues = regionDataPolicyPartBytes[1] == (byte) 0x01;
        }
    } catch (Exception e) {
        writeChunkedException(clientMessage, e, serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        return;
    }
    partNumber = 3;
    Part list = clientMessage.getPart(partNumber);
    try {
        keys = (List) list.getObject();
        numberOfKeys = keys.size();
    } catch (Exception e) {
        writeChunkedException(clientMessage, e, serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        return;
    }
    boolean sendUpdatesAsInvalidates = false;
    try {
        Part notifyPart = clientMessage.getPart(partNumber + 1);
        byte[] notifyPartBytes = (byte[]) notifyPart.getObject();
        sendUpdatesAsInvalidates = notifyPartBytes[0] == 0x01;
    } catch (Exception e) {
        writeChunkedException(clientMessage, e, serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        return;
    }
    if (logger.isDebugEnabled()) {
        logger.debug("{}: Received register interest 66 request ({} bytes) from {} for the following {} keys in region {}: {}", serverConnection.getName(), clientMessage.getPayloadLength(), serverConnection.getSocketString(), numberOfKeys, regionName, keys);
    }
    // Process the register interest request
    if (keys.isEmpty() || regionName == null) {
        StringId errMessage = null;
        if (keys.isEmpty() && regionName == null) {
            errMessage = LocalizedStrings.RegisterInterestList_THE_INPUT_LIST_OF_KEYS_IS_EMPTY_AND_THE_INPUT_REGION_NAME_IS_NULL_FOR_THE_REGISTER_INTEREST_REQUEST;
        } else if (keys.isEmpty()) {
            errMessage = LocalizedStrings.RegisterInterestList_THE_INPUT_LIST_OF_KEYS_FOR_THE_REGISTER_INTEREST_REQUEST_IS_EMPTY;
        } else if (regionName == null) {
            errMessage = LocalizedStrings.RegisterInterest_THE_INPUT_REGION_NAME_FOR_THE_REGISTER_INTEREST_REQUEST_IS_NULL;
        }
        String s = errMessage.toLocalizedString();
        logger.warn("{}: {}", serverConnection.getName(), s);
        writeChunkedErrorResponse(clientMessage, MessageType.REGISTER_INTEREST_DATA_ERROR, s, serverConnection);
        serverConnection.setAsTrue(RESPONDED);
    }
    // key not null
    LocalRegion region = (LocalRegion) serverConnection.getCache().getRegion(regionName);
    if (region == null) {
        logger.info(LocalizedMessage.create(LocalizedStrings.RegisterInterestList_0_REGION_NAMED_1_WAS_NOT_FOUND_DURING_REGISTER_INTEREST_LIST_REQUEST, new Object[] { serverConnection.getName(), regionName }));
    // writeChunkedErrorResponse(msg,
    // MessageType.REGISTER_INTEREST_DATA_ERROR, message);
    // responded = true;
    }
    // else { // region not null
    try {
        this.securityService.authorizeRegionRead(regionName);
        AuthorizeRequest authzRequest = serverConnection.getAuthzRequest();
        if (authzRequest != null) {
            if (!DynamicRegionFactory.regionIsDynamicRegionList(regionName)) {
                RegisterInterestOperationContext registerContext = authzRequest.registerInterestListAuthorize(regionName, keys, policy);
                keys = (List) registerContext.getKey();
            }
        }
        // Register interest
        serverConnection.getAcceptor().getCacheClientNotifier().registerClientInterest(regionName, keys, serverConnection.getProxyID(), isDurable, sendUpdatesAsInvalidates, true, regionDataPolicyPartBytes[0], true);
    } catch (Exception ex) {
        // If an interrupted exception is thrown , rethrow it
        checkForInterrupt(serverConnection, ex);
        // Otherwise, write an exception message and continue
        writeChunkedException(clientMessage, ex, serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        return;
    }
    // Update the statistics and write the reply
    // bserverStats.incLong(processDestroyTimeId,
    // DistributionStats.getStatTime() - start);
    // start = DistributionStats.getStatTime();
    boolean isPrimary = serverConnection.getAcceptor().getCacheClientNotifier().getClientProxy(serverConnection.getProxyID()).isPrimary();
    if (!isPrimary) {
        chunkedResponseMsg.setMessageType(MessageType.RESPONSE_FROM_SECONDARY);
        chunkedResponseMsg.setTransactionId(clientMessage.getTransactionId());
        chunkedResponseMsg.sendHeader();
        chunkedResponseMsg.setLastChunk(true);
        if (logger.isDebugEnabled()) {
            logger.debug("{}: Sending register interest response chunk from secondary for region: {} for key: {} chunk=<{}>", serverConnection.getName(), regionName, key, chunkedResponseMsg);
        }
        chunkedResponseMsg.sendChunk(serverConnection);
    } else {
        // isPrimary
        // Send header which describes how many chunks will follow
        chunkedResponseMsg.setMessageType(MessageType.RESPONSE_FROM_PRIMARY);
        chunkedResponseMsg.setTransactionId(clientMessage.getTransactionId());
        chunkedResponseMsg.sendHeader();
        // Send chunk response
        try {
            fillAndSendRegisterInterestResponseChunks(region, keys, InterestType.KEY, serializeValues, policy, serverConnection);
            serverConnection.setAsTrue(RESPONDED);
        } catch (Exception e) {
            // If an interrupted exception is thrown , rethrow it
            checkForInterrupt(serverConnection, e);
            // otherwise send the exception back to client
            writeChunkedException(clientMessage, e, serverConnection);
            serverConnection.setAsTrue(RESPONDED);
            return;
        }
        if (logger.isDebugEnabled()) {
            // logger.debug(getName() + ": Sent chunk (1 of 1) of register interest
            // response (" + chunkedResponseMsg.getBufferLength() + " bytes) for
            // region " + regionName + " key " + key);
            logger.debug("{}: Sent register interest response for the following {} keys in region {}: {}", serverConnection.getName(), numberOfKeys, regionName, keys);
        }
    // bserverStats.incLong(writeDestroyResponseTimeId,
    // DistributionStats.getStatTime() - start);
    // bserverStats.incInt(destroyResponsesId, 1);
    }
// isPrimary
// } // region not null
}
Also used : AuthorizeRequest(org.apache.geode.internal.security.AuthorizeRequest) RegisterInterestOperationContext(org.apache.geode.cache.operations.RegisterInterestOperationContext) LocalRegion(org.apache.geode.internal.cache.LocalRegion) IOException(java.io.IOException) CachedRegionHelper(org.apache.geode.internal.cache.tier.CachedRegionHelper) InterestResultPolicy(org.apache.geode.cache.InterestResultPolicy) StringId(org.apache.geode.i18n.StringId) List(java.util.List)

Aggregations

InterestResultPolicy (org.apache.geode.cache.InterestResultPolicy)10 List (java.util.List)6 LocalRegion (org.apache.geode.internal.cache.LocalRegion)6 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5 RegisterInterestOperationContext (org.apache.geode.cache.operations.RegisterInterestOperationContext)5 StringId (org.apache.geode.i18n.StringId)5 AuthorizeRequest (org.apache.geode.internal.security.AuthorizeRequest)5 Region (org.apache.geode.cache.Region)4 CachedRegionHelper (org.apache.geode.internal.cache.tier.CachedRegionHelper)4 HashMap (java.util.HashMap)2 Map (java.util.Map)2 LogWriter (org.apache.geode.LogWriter)2 CacheClientProxy (org.apache.geode.internal.cache.tier.sockets.CacheClientProxy)2 ChunkedMessage (org.apache.geode.internal.cache.tier.sockets.ChunkedMessage)2 Part (org.apache.geode.internal.cache.tier.sockets.Part)2 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 LinkedList (java.util.LinkedList)1 Set (java.util.Set)1