Search in sources :

Example 1 with CqNameToOp

use of org.apache.geode.internal.cache.tier.sockets.ClientUpdateMessageImpl.CqNameToOp in project geode by apache.

the class HARegionQueue method maintainCqStats.

private void maintainCqStats(Object event, long incrementAmount) {
    CqService cqService = region.getGemFireCache().getCqService();
    if (cqService != null) {
        try {
            if (event instanceof HAEventWrapper) {
                HAEventWrapper hw = (HAEventWrapper) event;
                if (hw.getClientUpdateMessage() != null) {
                    event = hw.getClientUpdateMessage();
                } else {
                    event = (Conflatable) this.haContainer.get(event);
                }
                if (event instanceof ClientUpdateMessage) {
                    if (((ClientUpdateMessage) event).hasCqs() && ((ClientUpdateMessage) event).hasCqs(clientProxyID)) {
                        CqNameToOp cqNames = ((ClientUpdateMessage) event).getClientCq(clientProxyID);
                        if (cqNames != null) {
                            for (String cqName : cqNames.getNames()) {
                                InternalCqQuery cq = ((InternalCqQuery) cqService.getClientCqFromServer(clientProxyID, cqName));
                                CqQueryVsdStats cqStats = cq.getVsdStats();
                                if (cq != null && cqStats != null) {
                                    cqStats.incNumHAQueuedEvents(incrementAmount);
                                }
                            }
                        }
                    }
                }
            }
        } catch (Exception e) {
            // as maintaining cq stats should not affect the system.
            if (logger.isTraceEnabled()) {
                logger.trace("Exception while maintaining cq events stats.", e);
            }
        }
    }
}
Also used : ClientUpdateMessage(org.apache.geode.internal.cache.tier.sockets.ClientUpdateMessage) CqNameToOp(org.apache.geode.internal.cache.tier.sockets.ClientUpdateMessageImpl.CqNameToOp) InternalCqQuery(org.apache.geode.cache.query.internal.cq.InternalCqQuery) CqService(org.apache.geode.cache.query.internal.cq.CqService) TimeoutException(org.apache.geode.cache.TimeoutException) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) CancelException(org.apache.geode.CancelException) InternalGemFireException(org.apache.geode.InternalGemFireException) CacheWriterException(org.apache.geode.cache.CacheWriterException) ConcurrentModificationException(java.util.ConcurrentModificationException) NoSuchElementException(java.util.NoSuchElementException) IOException(java.io.IOException) CacheException(org.apache.geode.cache.CacheException) HAEventWrapper(org.apache.geode.internal.cache.tier.sockets.HAEventWrapper) CqQueryVsdStats(org.apache.geode.cache.query.internal.CqQueryVsdStats)

Example 2 with CqNameToOp

use of org.apache.geode.internal.cache.tier.sockets.ClientUpdateMessageImpl.CqNameToOp in project geode by apache.

the class HAEventWrapper method fromData.

/**
   * Calls fromData() on ClientUpdateMessage and sets it as its member variable. Also, sets the
   * referenceCount to zero.
   * 
   * @param in The input stream from which the object should be constructed.
   */
public void fromData(DataInput in) throws IOException, ClassNotFoundException {
    if (DataSerializer.readPrimitiveBoolean(in)) {
        // Indicates that we have a ClientUpdateMessage along with the HAEW instance in inputstream.
        this.eventIdentifier = (EventID) DataSerializer.readObject(in);
        this.clientUpdateMessage = new ClientUpdateMessageImpl();
        InternalDataSerializer.invokeFromData(this.clientUpdateMessage, in);
        ((ClientUpdateMessageImpl) this.clientUpdateMessage).setEventIdentifier(this.eventIdentifier);
        if (this.clientUpdateMessage.hasCqs()) {
            {
                ClientCqConcurrentMap cqMap;
                int size = InternalDataSerializer.readArrayLength(in);
                if (size == -1) {
                    cqMap = null;
                } else {
                    cqMap = new ClientCqConcurrentMap(size, 1.0f, 1);
                    for (int i = 0; i < size; i++) {
                        ClientProxyMembershipID key = DataSerializer.<ClientProxyMembershipID>readObject(in);
                        CqNameToOp value;
                        {
                            byte typeByte = in.readByte();
                            if (typeByte == DSCODE.HASH_MAP) {
                                int cqNamesSize = InternalDataSerializer.readArrayLength(in);
                                if (cqNamesSize == -1) {
                                    throw new IllegalStateException("The value of a ConcurrentHashMap is not allowed to be null.");
                                } else if (cqNamesSize == 1) {
                                    String cqNamesKey = DataSerializer.<String>readObject(in);
                                    Integer cqNamesValue = DataSerializer.<Integer>readObject(in);
                                    value = new CqNameToOpSingleEntry(cqNamesKey, cqNamesValue);
                                } else if (cqNamesSize == 0) {
                                    value = new CqNameToOpSingleEntry(null, 0);
                                } else {
                                    value = new CqNameToOpHashMap(cqNamesSize);
                                    for (int j = 0; j < cqNamesSize; j++) {
                                        String cqNamesKey = DataSerializer.<String>readObject(in);
                                        Integer cqNamesValue = DataSerializer.<Integer>readObject(in);
                                        value.add(cqNamesKey, cqNamesValue);
                                    }
                                }
                            } else if (typeByte == DSCODE.NULL) {
                                throw new IllegalStateException("The value of a ConcurrentHashMap is not allowed to be null.");
                            } else {
                                throw new IllegalStateException("Expected DSCODE.NULL or DSCODE.HASH_MAP but read " + typeByte);
                            }
                        }
                        cqMap.put(key, value);
                    }
                }
                this.clientCqs = cqMap;
            }
            ((ClientUpdateMessageImpl) this.clientUpdateMessage).setClientCqs(this.clientCqs);
        }
        this.regionName = this.clientUpdateMessage.getRegionName();
        this.keyOfInterest = this.clientUpdateMessage.getKeyOfInterest();
        this.shouldConflate = this.clientUpdateMessage.shouldBeConflated();
        rcUpdater.set(this, 0);
    } else {
        // Read and ignore dummy eventIdentifier instance.
        DataSerializer.readObject(in);
        // Read and ignore dummy ClientUpdateMessageImpl instance.
        InternalDataSerializer.invokeFromData(new ClientUpdateMessageImpl(), in);
        // stream.
        if (logger.isDebugEnabled()) {
            logger.debug("HAEventWrapper.fromData(): The event has already been sent to the client by the primary server.");
        }
    }
}
Also used : CqNameToOpHashMap(org.apache.geode.internal.cache.tier.sockets.ClientUpdateMessageImpl.CqNameToOpHashMap) CqNameToOp(org.apache.geode.internal.cache.tier.sockets.ClientUpdateMessageImpl.CqNameToOp) ClientCqConcurrentMap(org.apache.geode.internal.cache.tier.sockets.ClientUpdateMessageImpl.ClientCqConcurrentMap) CqNameToOpSingleEntry(org.apache.geode.internal.cache.tier.sockets.ClientUpdateMessageImpl.CqNameToOpSingleEntry)

Example 3 with CqNameToOp

use of org.apache.geode.internal.cache.tier.sockets.ClientUpdateMessageImpl.CqNameToOp in project geode by apache.

the class HARegionQueue method addClientCQsAndInterestList.

public static void addClientCQsAndInterestList(ClientUpdateMessageImpl msg, HAEventWrapper haEventWrapper, Map haContainer, String regionName) {
    ClientProxyMembershipID proxyID = ((HAContainerWrapper) haContainer).getProxyID(regionName);
    if (haEventWrapper.getClientCqs() != null) {
        CqNameToOp clientCQ = haEventWrapper.getClientCqs().get(proxyID);
        if (clientCQ != null) {
            msg.addClientCqs(proxyID, clientCQ);
        }
    }
    // if (haEventWrapper.getPutInProgress()) {
    // ((HAEventWrapper)entry.getKey()).setPutInProgress(true);
    // }
    // This is a remote HAEventWrapper.
    // Add new Interested client lists.
    ClientUpdateMessageImpl clientMsg = (ClientUpdateMessageImpl) haEventWrapper.getClientUpdateMessage();
    if (clientMsg.isClientInterestedInUpdates(proxyID)) {
        msg.addClientInterestList(proxyID, true);
    } else if (clientMsg.isClientInterestedInInvalidates(proxyID)) {
        msg.addClientInterestList(proxyID, false);
    }
}
Also used : ClientProxyMembershipID(org.apache.geode.internal.cache.tier.sockets.ClientProxyMembershipID) ClientUpdateMessageImpl(org.apache.geode.internal.cache.tier.sockets.ClientUpdateMessageImpl) CqNameToOp(org.apache.geode.internal.cache.tier.sockets.ClientUpdateMessageImpl.CqNameToOp)

Example 4 with CqNameToOp

use of org.apache.geode.internal.cache.tier.sockets.ClientUpdateMessageImpl.CqNameToOp in project geode by apache.

the class CacheClientProxy method postDeliverAuthCheckPassed.

private boolean postDeliverAuthCheckPassed(ClientUpdateMessage clientMessage) {
    // process authorization
    if (AcceptorImpl.isAuthenticationRequired() && this.postAuthzCallback == null && AcceptorImpl.isPostAuthzCallbackPresent()) {
        // security is on and callback is null: it means multiuser mode.
        ClientUpdateMessageImpl cumi = (ClientUpdateMessageImpl) clientMessage;
        CqNameToOp clientCq = cumi.getClientCq(this.proxyID);
        if (clientCq != null && !clientCq.isEmpty()) {
            if (logger.isDebugEnabled()) {
                logger.debug("CCP clientCq size before processing auth {}", clientCq.size());
            }
            String[] regionNameHolder = new String[1];
            OperationContext opctxt = getOperationContext(clientMessage, regionNameHolder);
            if (opctxt == null) {
                logger.warn(LocalizedMessage.create(LocalizedStrings.CacheClientProxy__0_NOT_ADDING_MESSAGE_TO_QUEUE_1_BECAUSE_THE_OPERATION_CONTEXT_OBJECT_COULD_NOT_BE_OBTAINED_FOR_THIS_CLIENT_MESSAGE, new Object[] { this, clientMessage }));
                return false;
            }
            String[] cqNames = clientCq.getNames();
            if (logger.isDebugEnabled()) {
                logger.debug("CCP clientCq names array size {}", cqNames.length);
            }
            for (int i = 0; i < cqNames.length; i++) {
                try {
                    if (logger.isDebugEnabled()) {
                        logger.debug("CCP clientCq name {}", cqNames[i]);
                    }
                    boolean isAuthorized = false;
                    if (this.proxyID.isDurable() && this.getDurableKeepAlive() && this._isPaused) {
                        // need to take lock as we may be reinitializing proxy cache
                        synchronized (this.clientUserAuthsLock) {
                            AuthorizeRequestPP postAuthCallback = this.clientUserAuths.getUserAuthAttributes(cqNames[i]).getPostAuthzRequest();
                            if (logger.isDebugEnabled() && postAuthCallback == null) {
                                logger.debug("CCP clientCq post callback is null");
                            }
                            if (postAuthCallback != null && postAuthCallback.getPostAuthzCallback().authorizeOperation(regionNameHolder[0], opctxt)) {
                                isAuthorized = true;
                            }
                        }
                    } else {
                        UserAuthAttributes userAuthAttributes = this.clientUserAuths.getUserAuthAttributes(cqNames[i]);
                        AuthorizeRequestPP postAuthCallback = userAuthAttributes.getPostAuthzRequest();
                        if (postAuthCallback == null && logger.isDebugEnabled()) {
                            logger.debug("CCP clientCq post callback is null");
                        }
                        if (postAuthCallback != null && postAuthCallback.getPostAuthzCallback().authorizeOperation(regionNameHolder[0], opctxt)) {
                            isAuthorized = true;
                        }
                    }
                    if (!isAuthorized) {
                        logger.warn(LocalizedMessage.create(LocalizedStrings.CacheClientProxy__0_NOT_ADDING_CQ_MESSAGE_TO_QUEUE_1_BECAUSE_AUTHORIZATION_FAILED, new Object[] { this, clientMessage }));
                        clientCq.delete(cqNames[i]);
                    }
                } catch (Exception ex) {
                // ignore...
                }
                if (logger.isDebugEnabled()) {
                    logger.debug("CCP clientCq size after processing auth {}", clientCq.size());
                }
            }
            // again need to check as there may be no CQ available
            if (!clientMessage.hasCqs(this.proxyID)) {
                this._statistics.incMessagesNotQueuedNotInterested();
                if (logger.isTraceEnabled(LogMarker.BRIDGE_SERVER)) {
                    logger.debug("{}: Not adding message to queue. It is not interested in this region and key: {}", clientMessage);
                }
                return false;
            }
        }
    } else if (this.postAuthzCallback != null) {
        String[] regionNameHolder = new String[1];
        boolean isAuthorize = false;
        OperationContext opctxt = getOperationContext(clientMessage, regionNameHolder);
        if (opctxt == null) {
            logger.warn(LocalizedMessage.create(LocalizedStrings.CacheClientProxy__0_NOT_ADDING_MESSAGE_TO_QUEUE_1_BECAUSE_THE_OPERATION_CONTEXT_OBJECT_COULD_NOT_BE_OBTAINED_FOR_THIS_CLIENT_MESSAGE, new Object[] { this, clientMessage }));
            return false;
        }
        if (logger.isTraceEnabled()) {
            logger.trace("{}: Invoking authorizeOperation for message: {}", this, clientMessage);
        }
        if (this.proxyID.isDurable() && this.getDurableKeepAlive() && this._isPaused) {
            synchronized (this.clientUserAuthsLock) {
                isAuthorize = this.postAuthzCallback.authorizeOperation(regionNameHolder[0], opctxt);
            }
        } else {
            isAuthorize = this.postAuthzCallback.authorizeOperation(regionNameHolder[0], opctxt);
        }
        if (!isAuthorize) {
            logger.warn(LocalizedMessage.create(LocalizedStrings.CacheClientProxy__0_NOT_ADDING_MESSAGE_TO_QUEUE_1_BECAUSE_AUTHORIZATION_FAILED, new Object[] { this, clientMessage }));
            return false;
        }
    }
    return true;
}
Also used : RegionCreateOperationContext(org.apache.geode.cache.operations.RegionCreateOperationContext) DestroyOperationContext(org.apache.geode.cache.operations.DestroyOperationContext) PutOperationContext(org.apache.geode.cache.operations.PutOperationContext) InvalidateOperationContext(org.apache.geode.cache.operations.InvalidateOperationContext) RegionClearOperationContext(org.apache.geode.cache.operations.RegionClearOperationContext) RegionDestroyOperationContext(org.apache.geode.cache.operations.RegionDestroyOperationContext) OperationContext(org.apache.geode.cache.operations.OperationContext) CqNameToOp(org.apache.geode.internal.cache.tier.sockets.ClientUpdateMessageImpl.CqNameToOp) AuthorizeRequestPP(org.apache.geode.internal.security.AuthorizeRequestPP) RegionExistsException(org.apache.geode.cache.RegionExistsException) CqException(org.apache.geode.cache.query.CqException) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) CancelException(org.apache.geode.CancelException) SocketException(java.net.SocketException) IOException(java.io.IOException) CacheException(org.apache.geode.cache.CacheException)

Aggregations

CqNameToOp (org.apache.geode.internal.cache.tier.sockets.ClientUpdateMessageImpl.CqNameToOp)4 IOException (java.io.IOException)2 CancelException (org.apache.geode.CancelException)2 CacheException (org.apache.geode.cache.CacheException)2 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)2 SocketException (java.net.SocketException)1 ConcurrentModificationException (java.util.ConcurrentModificationException)1 NoSuchElementException (java.util.NoSuchElementException)1 InternalGemFireException (org.apache.geode.InternalGemFireException)1 CacheWriterException (org.apache.geode.cache.CacheWriterException)1 EntryNotFoundException (org.apache.geode.cache.EntryNotFoundException)1 RegionExistsException (org.apache.geode.cache.RegionExistsException)1 TimeoutException (org.apache.geode.cache.TimeoutException)1 DestroyOperationContext (org.apache.geode.cache.operations.DestroyOperationContext)1 InvalidateOperationContext (org.apache.geode.cache.operations.InvalidateOperationContext)1 OperationContext (org.apache.geode.cache.operations.OperationContext)1 PutOperationContext (org.apache.geode.cache.operations.PutOperationContext)1 RegionClearOperationContext (org.apache.geode.cache.operations.RegionClearOperationContext)1 RegionCreateOperationContext (org.apache.geode.cache.operations.RegionCreateOperationContext)1 RegionDestroyOperationContext (org.apache.geode.cache.operations.RegionDestroyOperationContext)1