Search in sources :

Example 66 with EventID

use of org.apache.geode.internal.cache.EventID in project geode by apache.

the class Put61 method cmdExecute.

@Override
public void cmdExecute(Message clientMessage, ServerConnection serverConnection, long p_start) throws IOException, InterruptedException {
    long start = p_start;
    Part regionNamePart = null, keyPart = null, valuePart = null, callbackArgPart = null;
    String regionName = null;
    Object callbackArg = null, key = null;
    Part eventPart = null;
    StringBuffer errMessage = new StringBuffer();
    boolean isDelta = false;
    CachedRegionHelper crHelper = serverConnection.getCachedRegionHelper();
    CacheServerStats stats = serverConnection.getCacheServerStats();
    // requiresResponse = true;
    serverConnection.setAsTrue(REQUIRES_RESPONSE);
    {
        long oldStart = start;
        start = DistributionStats.getStatTime();
        stats.incReadPutRequestTime(start - oldStart);
    }
    // Retrieve the data from the message parts
    regionNamePart = clientMessage.getPart(0);
    keyPart = clientMessage.getPart(1);
    try {
        isDelta = (Boolean) clientMessage.getPart(2).getObject();
    } catch (Exception e) {
        writeException(clientMessage, MessageType.PUT_DELTA_ERROR, e, false, serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        // CachePerfStats not available here.
        return;
    }
    valuePart = clientMessage.getPart(3);
    eventPart = clientMessage.getPart(4);
    if (clientMessage.getNumberOfParts() > 5) {
        callbackArgPart = clientMessage.getPart(5);
        try {
            callbackArg = callbackArgPart.getObject();
        } catch (Exception e) {
            writeException(clientMessage, e, false, serverConnection);
            serverConnection.setAsTrue(RESPONDED);
            return;
        }
    }
    regionName = regionNamePart.getString();
    try {
        key = keyPart.getStringOrObject();
    } catch (Exception e) {
        writeException(clientMessage, e, false, serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        return;
    }
    final boolean isDebugEnabled = logger.isDebugEnabled();
    if (isDebugEnabled) {
        logger.debug("{}: Received 6.1{}put request ({} bytes) from {} for region {} key {}", serverConnection.getName(), (isDelta ? " delta " : " "), clientMessage.getPayloadLength(), serverConnection.getSocketString(), regionName, key);
    }
    // Process the put request
    if (key == null || regionName == null) {
        if (key == null) {
            String putMsg = " The input key for the 6.1 put request is null";
            if (isDebugEnabled) {
                logger.debug("{}:{}", serverConnection.getName(), putMsg);
            }
            errMessage.append(putMsg);
        }
        if (regionName == null) {
            String putMsg = " The input region name for the 6.1 put request is null";
            if (isDebugEnabled) {
                logger.debug("{}:{}", serverConnection.getName(), putMsg);
            }
            errMessage.append(putMsg);
        }
        writeErrorResponse(clientMessage, MessageType.PUT_DATA_ERROR, errMessage.toString(), serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        return;
    }
    LocalRegion region = (LocalRegion) serverConnection.getCache().getRegion(regionName);
    if (region == null) {
        String reason = " was not found during 6.1 put request";
        writeRegionDestroyedEx(clientMessage, regionName, reason, serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        return;
    }
    if (valuePart.isNull() && region.containsKey(key)) {
        // Invalid to 'put' a null value in an existing key
        String putMsg = " Attempted to 6.1 put a null value for existing key " + key;
        if (isDebugEnabled) {
            logger.debug("{}:{}", serverConnection.getName(), putMsg);
        }
        errMessage.append(putMsg);
        writeErrorResponse(clientMessage, MessageType.PUT_DATA_ERROR, errMessage.toString(), serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        return;
    }
    // try {
    // this.eventId = (EventID)eventPart.getObject();
    ByteBuffer eventIdPartsBuffer = ByteBuffer.wrap(eventPart.getSerializedForm());
    long threadId = EventID.readEventIdPartsFromOptmizedByteArray(eventIdPartsBuffer);
    long sequenceId = EventID.readEventIdPartsFromOptmizedByteArray(eventIdPartsBuffer);
    EventID eventId = new EventID(serverConnection.getEventMemberIDByteArray(), threadId, sequenceId);
    try {
        Object value = null;
        if (!isDelta) {
            value = valuePart.getSerializedForm();
        }
        boolean isObject = valuePart.isObject();
        boolean isMetaRegion = region.isUsedForMetaRegion();
        clientMessage.setMetaRegion(isMetaRegion);
        this.securityService.authorizeRegionWrite(regionName, key.toString());
        AuthorizeRequest authzRequest = null;
        if (!isMetaRegion) {
            authzRequest = serverConnection.getAuthzRequest();
        }
        if (authzRequest != null) {
            if (DynamicRegionFactory.regionIsDynamicRegionList(regionName)) {
                authzRequest.createRegionAuthorize((String) key);
            } else // Allow PUT operations on meta regions (bug #38961)
            {
                PutOperationContext putContext = authzRequest.putAuthorize(regionName, key, value, isObject, callbackArg);
                value = putContext.getValue();
                isObject = putContext.isObject();
                callbackArg = putContext.getCallbackArg();
            }
        }
        // If the value is 1 byte and the byte represents null,
        // attempt to create the entry. This test needs to be
        // moved to DataSerializer or DataSerializer.NULL needs
        // to be publicly accessible.
        boolean result = false;
        if (value == null && !isDelta) {
            // Create the null entry. Since the value is null, the value of the
            // isObject
            // the true after null doesn't matter and is not used.
            result = region.basicBridgeCreate(key, null, true, callbackArg, serverConnection.getProxyID(), true, new EventIDHolder(eventId), false);
        } else {
            // Put the entry
            byte[] delta = null;
            if (isDelta) {
                delta = valuePart.getSerializedForm();
            }
            result = region.basicBridgePut(key, value, delta, isObject, callbackArg, serverConnection.getProxyID(), true, new EventIDHolder(eventId));
        }
        if (result) {
            serverConnection.setModificationInfo(true, regionName, key);
        } else {
            String message = serverConnection.getName() + ": Failed to 6.1 put entry for region " + regionName + " key " + key + " value " + valuePart;
            if (isDebugEnabled) {
                logger.debug(message);
            }
            throw new Exception(message);
        }
    } catch (RegionDestroyedException rde) {
        writeException(clientMessage, rde, false, serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        return;
    } catch (ResourceException re) {
        writeException(clientMessage, re, false, serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        return;
    } catch (InvalidDeltaException ide) {
        logger.info(LocalizedMessage.create(LocalizedStrings.UpdateOperation_ERROR_APPLYING_DELTA_FOR_KEY_0_OF_REGION_1, new Object[] { key, regionName }));
        writeException(clientMessage, MessageType.PUT_DELTA_ERROR, ide, false, serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        region.getCachePerfStats().incDeltaFullValuesRequested();
        return;
    } catch (Exception ce) {
        // If an interrupted exception is thrown , rethrow it
        checkForInterrupt(serverConnection, ce);
        // If an exception occurs during the put, preserve the connection
        writeException(clientMessage, ce, false, serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        if (ce instanceof GemFireSecurityException) {
            // logged by the security logger
            if (isDebugEnabled) {
                logger.debug("{}: Unexpected Security exception", serverConnection.getName(), ce);
            }
        } else if (isDebugEnabled) {
            logger.debug("{}: Unexpected Exception", serverConnection.getName(), ce);
        }
        return;
    } finally {
        long oldStart = start;
        start = DistributionStats.getStatTime();
        stats.incProcessPutTime(start - oldStart);
    }
    // Increment statistics and write the reply
    if (region instanceof PartitionedRegion) {
        PartitionedRegion pr = (PartitionedRegion) region;
        if (pr.getNetworkHopType() != PartitionedRegion.NETWORK_HOP_NONE) {
            writeReplyWithRefreshMetadata(clientMessage, serverConnection, pr, pr.getNetworkHopType());
            pr.clearNetworkHopData();
        } else {
            writeReply(clientMessage, serverConnection);
        }
    } else {
        writeReply(clientMessage, serverConnection);
    }
    serverConnection.setAsTrue(RESPONDED);
    if (isDebugEnabled) {
        logger.debug("{}: Sent 6.1 put response back to {} for region {} key {} value {}", serverConnection.getName(), serverConnection.getSocketString(), regionName, key, valuePart);
    }
    stats.incWritePutResponseTime(DistributionStats.getStatTime() - start);
}
Also used : InvalidDeltaException(org.apache.geode.InvalidDeltaException) AuthorizeRequest(org.apache.geode.internal.security.AuthorizeRequest) EventIDHolder(org.apache.geode.internal.cache.EventIDHolder) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) LocalRegion(org.apache.geode.internal.cache.LocalRegion) ByteBuffer(java.nio.ByteBuffer) InvalidDeltaException(org.apache.geode.InvalidDeltaException) IOException(java.io.IOException) ResourceException(org.apache.geode.cache.ResourceException) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) GemFireSecurityException(org.apache.geode.security.GemFireSecurityException) CachedRegionHelper(org.apache.geode.internal.cache.tier.CachedRegionHelper) GemFireSecurityException(org.apache.geode.security.GemFireSecurityException) CacheServerStats(org.apache.geode.internal.cache.tier.sockets.CacheServerStats) Part(org.apache.geode.internal.cache.tier.sockets.Part) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) EventID(org.apache.geode.internal.cache.EventID) ResourceException(org.apache.geode.cache.ResourceException) PutOperationContext(org.apache.geode.cache.operations.PutOperationContext)

Example 67 with EventID

use of org.apache.geode.internal.cache.EventID in project geode by apache.

the class Invalidate method cmdExecute.

@Override
public void cmdExecute(Message clientMessage, ServerConnection serverConnection, long start) throws IOException, InterruptedException {
    Part regionNamePart = null, keyPart = null, callbackArgPart = null;
    String regionName = null;
    Object callbackArg = null, key = null;
    Part eventPart = null;
    StringBuffer errMessage = new StringBuffer();
    CacheServerStats stats = serverConnection.getCacheServerStats();
    serverConnection.setAsTrue(REQUIRES_RESPONSE);
    {
        long oldStart = start;
        start = DistributionStats.getStatTime();
        stats.incReadInvalidateRequestTime(start - oldStart);
    }
    // Retrieve the data from the message parts
    regionNamePart = clientMessage.getPart(0);
    keyPart = clientMessage.getPart(1);
    eventPart = clientMessage.getPart(2);
    // callbackArgPart = null; (redundant assignment)
    if (clientMessage.getNumberOfParts() > 3) {
        callbackArgPart = clientMessage.getPart(3);
        try {
            callbackArg = callbackArgPart.getObject();
        } catch (Exception e) {
            writeException(clientMessage, e, false, serverConnection);
            serverConnection.setAsTrue(RESPONDED);
            return;
        }
    }
    regionName = regionNamePart.getString();
    try {
        key = keyPart.getStringOrObject();
    } catch (Exception e) {
        writeException(clientMessage, e, false, serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        return;
    }
    if (logger.isDebugEnabled()) {
        logger.debug(serverConnection.getName() + ": Received invalidate request (" + clientMessage.getPayloadLength() + " bytes) from " + serverConnection.getSocketString() + " for region " + regionName + " key " + key);
    }
    // Process the invalidate request
    if (key == null || regionName == null) {
        if (key == null) {
            logger.warn(LocalizedMessage.create(LocalizedStrings.BaseCommand__THE_INPUT_KEY_FOR_THE_0_REQUEST_IS_NULL, "invalidate"));
            errMessage.append(LocalizedStrings.BaseCommand__THE_INPUT_KEY_FOR_THE_0_REQUEST_IS_NULL.toLocalizedString("invalidate"));
        }
        if (regionName == null) {
            logger.warn(LocalizedMessage.create(LocalizedStrings.BaseCommand__THE_INPUT_REGION_NAME_FOR_THE_0_REQUEST_IS_NULL, "invalidate"));
            errMessage.append(LocalizedStrings.BaseCommand__THE_INPUT_REGION_NAME_FOR_THE_0_REQUEST_IS_NULL.toLocalizedString("invalidate"));
        }
        writeErrorResponse(clientMessage, MessageType.DESTROY_DATA_ERROR, errMessage.toString(), serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        return;
    }
    LocalRegion region = (LocalRegion) serverConnection.getCache().getRegion(regionName);
    if (region == null) {
        String reason = LocalizedStrings.BaseCommand__0_WAS_NOT_FOUND_DURING_1_REQUEST.toLocalizedString(regionName, "invalidate");
        writeRegionDestroyedEx(clientMessage, regionName, reason, serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        return;
    }
    // Invalidate the entry
    ByteBuffer eventIdPartsBuffer = ByteBuffer.wrap(eventPart.getSerializedForm());
    long threadId = EventID.readEventIdPartsFromOptmizedByteArray(eventIdPartsBuffer);
    long sequenceId = EventID.readEventIdPartsFromOptmizedByteArray(eventIdPartsBuffer);
    EventID eventId = new EventID(serverConnection.getEventMemberIDByteArray(), threadId, sequenceId);
    Breadcrumbs.setEventId(eventId);
    VersionTag tag = null;
    try {
        // for integrated security
        this.securityService.authorizeRegionWrite(regionName, key.toString());
        AuthorizeRequest authzRequest = serverConnection.getAuthzRequest();
        if (authzRequest != null) {
            InvalidateOperationContext invalidateContext = authzRequest.invalidateAuthorize(regionName, key, callbackArg);
            callbackArg = invalidateContext.getCallbackArg();
        }
        EventIDHolder clientEvent = new EventIDHolder(eventId);
        // msg.isRetry might be set by v7.0 and later clients
        if (clientMessage.isRetry()) {
            // if (logger.isDebugEnabled()) {
            // logger.debug("DEBUG: encountered isRetry in Invalidate");
            // }
            clientEvent.setPossibleDuplicate(true);
            if (region.getAttributes().getConcurrencyChecksEnabled()) {
                // recover the version tag from other servers
                clientEvent.setRegion(region);
                if (!recoverVersionTagForRetriedOperation(clientEvent)) {
                    // no-one has seen this event
                    clientEvent.setPossibleDuplicate(false);
                }
            }
        }
        region.basicBridgeInvalidate(key, callbackArg, serverConnection.getProxyID(), true, clientEvent);
        tag = clientEvent.getVersionTag();
        serverConnection.setModificationInfo(true, regionName, key);
    } catch (EntryNotFoundException e) {
        // Don't send an exception back to the client if this
        // exception happens. Just log it and continue.
        logger.info(LocalizedMessage.create(LocalizedStrings.BaseCommand_DURING_0_NO_ENTRY_WAS_FOUND_FOR_KEY_1, new Object[] { "invalidate", key }));
    } catch (RegionDestroyedException rde) {
        writeException(clientMessage, rde, false, serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        return;
    } catch (Exception e) {
        // If an interrupted exception is thrown , rethrow it
        checkForInterrupt(serverConnection, e);
        // If an exception occurs during the destroy, preserve the connection
        writeException(clientMessage, e, false, serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        if (e instanceof GemFireSecurityException) {
            // logged by the security logger
            if (logger.isDebugEnabled()) {
                logger.debug("{}: Unexpected Security exception", serverConnection.getName(), e);
            }
        } else {
            logger.warn(LocalizedMessage.create(LocalizedStrings.BaseCommand_0_UNEXPECTED_EXCEPTION, serverConnection.getName()), e);
        }
        return;
    }
    // Update the statistics and write the reply
    {
        long oldStart = start;
        start = DistributionStats.getStatTime();
        stats.incProcessInvalidateTime(start - oldStart);
    }
    if (region instanceof PartitionedRegion) {
        PartitionedRegion pr = (PartitionedRegion) region;
        if (pr.getNetworkHopType() != PartitionedRegion.NETWORK_HOP_NONE) {
            writeReplyWithRefreshMetadata(clientMessage, serverConnection, pr, pr.getNetworkHopType(), tag);
            pr.clearNetworkHopData();
        } else {
            writeReply(clientMessage, serverConnection, tag);
        }
    } else {
        writeReply(clientMessage, serverConnection, tag);
    }
    serverConnection.setAsTrue(RESPONDED);
    if (logger.isDebugEnabled()) {
        logger.debug("{}: Sent invalidate response for region {} key {}", serverConnection.getName(), regionName, key);
    }
    stats.incWriteInvalidateResponseTime(DistributionStats.getStatTime() - start);
}
Also used : AuthorizeRequest(org.apache.geode.internal.security.AuthorizeRequest) EventIDHolder(org.apache.geode.internal.cache.EventIDHolder) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) LocalRegion(org.apache.geode.internal.cache.LocalRegion) ByteBuffer(java.nio.ByteBuffer) IOException(java.io.IOException) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) GemFireSecurityException(org.apache.geode.security.GemFireSecurityException) InvalidateOperationContext(org.apache.geode.cache.operations.InvalidateOperationContext) GemFireSecurityException(org.apache.geode.security.GemFireSecurityException) CacheServerStats(org.apache.geode.internal.cache.tier.sockets.CacheServerStats) Part(org.apache.geode.internal.cache.tier.sockets.Part) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) VersionTag(org.apache.geode.internal.cache.versions.VersionTag) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) EventID(org.apache.geode.internal.cache.EventID)

Example 68 with EventID

use of org.apache.geode.internal.cache.EventID in project geode by apache.

the class RegisterDataSerializers method cmdExecute.

public void cmdExecute(Message clientMessage, ServerConnection serverConnection, long start) throws IOException, ClassNotFoundException {
    if (logger.isDebugEnabled()) {
        logger.debug("{}: Received register dataserializer request ({} parts) from {}", serverConnection.getName(), clientMessage.getNumberOfParts(), serverConnection.getSocketString());
    }
    int noOfParts = clientMessage.getNumberOfParts();
    // 2 parts per instantiator and one eventId part
    int noOfDataSerializers = (noOfParts - 1) / 2;
    // retrieve eventID from the last Part
    ByteBuffer eventIdPartsBuffer = ByteBuffer.wrap(clientMessage.getPart(noOfParts - 1).getSerializedForm());
    long threadId = EventID.readEventIdPartsFromOptmizedByteArray(eventIdPartsBuffer);
    long sequenceId = EventID.readEventIdPartsFromOptmizedByteArray(eventIdPartsBuffer);
    EventID eventId = new EventID(serverConnection.getEventMemberIDByteArray(), threadId, sequenceId);
    byte[][] serializedDataSerializers = new byte[noOfDataSerializers * 2][];
    boolean caughtCNFE = false;
    Exception cnfe = null;
    try {
        for (int i = 0; i < noOfParts - 1; i = i + 2) {
            Part dataSerializerClassNamePart = clientMessage.getPart(i);
            serializedDataSerializers[i] = dataSerializerClassNamePart.getSerializedForm();
            String dataSerializerClassName = (String) CacheServerHelper.deserialize(serializedDataSerializers[i]);
            Part idPart = clientMessage.getPart(i + 1);
            serializedDataSerializers[i + 1] = idPart.getSerializedForm();
            int id = idPart.getInt();
            Class dataSerializerClass = null;
            try {
                dataSerializerClass = InternalDataSerializer.getCachedClass(dataSerializerClassName);
                InternalDataSerializer.register(dataSerializerClass, true, eventId, serverConnection.getProxyID());
            } catch (ClassNotFoundException e) {
                // If a ClassNotFoundException is caught, store it, but continue
                // processing other instantiators
                caughtCNFE = true;
                cnfe = e;
            }
        }
    } catch (Exception e) {
        writeException(clientMessage, e, false, serverConnection);
        serverConnection.setAsTrue(RESPONDED);
    }
    // the last CNFE.
    if (caughtCNFE) {
        writeException(clientMessage, cnfe, false, serverConnection);
        serverConnection.setAsTrue(RESPONDED);
    }
    // code, then the reply has already been sent.
    if (!serverConnection.getTransientFlag(RESPONDED)) {
        writeReply(clientMessage, serverConnection);
    }
    if (logger.isDebugEnabled()) {
        logger.debug("Registered dataserializer for MembershipId = {}", serverConnection.getMembershipID());
    }
}
Also used : Part(org.apache.geode.internal.cache.tier.sockets.Part) EventID(org.apache.geode.internal.cache.EventID) ByteBuffer(java.nio.ByteBuffer) IOException(java.io.IOException)

Example 69 with EventID

use of org.apache.geode.internal.cache.EventID in project geode by apache.

the class RegisterInstantiators method cmdExecute.

@Override
public void cmdExecute(Message clientMessage, ServerConnection serverConnection, long start) throws IOException, ClassNotFoundException {
    if (logger.isDebugEnabled()) {
        logger.debug("{}: Received register instantiator request ({} parts) from {}", serverConnection.getName(), clientMessage.getNumberOfParts(), serverConnection.getSocketString());
    }
    int noOfParts = clientMessage.getNumberOfParts();
    // Assert parts
    Assert.assertTrue((noOfParts - 1) % 3 == 0);
    // 3 parts per instantiator and one eventId part
    int noOfInstantiators = (noOfParts - 1) / 3;
    // retrieve eventID from the last Part
    ByteBuffer eventIdPartsBuffer = ByteBuffer.wrap(clientMessage.getPart(noOfParts - 1).getSerializedForm());
    long threadId = EventID.readEventIdPartsFromOptmizedByteArray(eventIdPartsBuffer);
    long sequenceId = EventID.readEventIdPartsFromOptmizedByteArray(eventIdPartsBuffer);
    EventID eventId = new EventID(serverConnection.getEventMemberIDByteArray(), threadId, sequenceId);
    byte[][] serializedInstantiators = new byte[noOfInstantiators * 3][];
    boolean caughtCNFE = false;
    Exception cnfe = null;
    try {
        for (int i = 0; i < noOfParts - 1; i = i + 3) {
            Part instantiatorPart = clientMessage.getPart(i);
            serializedInstantiators[i] = instantiatorPart.getSerializedForm();
            String instantiatorClassName = (String) CacheServerHelper.deserialize(serializedInstantiators[i]);
            Part instantiatedPart = clientMessage.getPart(i + 1);
            serializedInstantiators[i + 1] = instantiatedPart.getSerializedForm();
            String instantiatedClassName = (String) CacheServerHelper.deserialize(serializedInstantiators[i + 1]);
            Part idPart = clientMessage.getPart(i + 2);
            serializedInstantiators[i + 2] = idPart.getSerializedForm();
            int id = idPart.getInt();
            Class instantiatorClass = null, instantiatedClass = null;
            try {
                instantiatorClass = InternalDataSerializer.getCachedClass(instantiatorClassName);
                instantiatedClass = InternalDataSerializer.getCachedClass(instantiatedClassName);
                InternalInstantiator.register(instantiatorClass, instantiatedClass, id, true, eventId, serverConnection.getProxyID());
            } catch (ClassNotFoundException e) {
                // If a ClassNotFoundException is caught, store it, but continue
                // processing other instantiators
                caughtCNFE = true;
                cnfe = e;
            }
        }
    } catch (Exception e) {
        logger.warn(LocalizedMessage.create(LocalizedStrings.RegisterInstantiators_BAD_CLIENT, new Object[] { serverConnection.getMembershipID(), e.getLocalizedMessage() }));
        writeException(clientMessage, e, false, serverConnection);
        serverConnection.setAsTrue(RESPONDED);
    }
    // the last CNFE.
    if (caughtCNFE) {
        writeException(clientMessage, cnfe, false, serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        // Send the instantiators on to other clients if we hit an error
        // due to a missing class, because they were not distributed
        // in InternalInstantiator.register. Otherwise they will have
        // been distributed if successfully registered.
        ClientInstantiatorMessage clientInstantiatorMessage = new ClientInstantiatorMessage(EnumListenerEvent.AFTER_REGISTER_INSTANTIATOR, serializedInstantiators, serverConnection.getProxyID(), eventId);
        // Notify other clients
        CacheClientNotifier.routeClientMessage(clientInstantiatorMessage);
    }
    // code, then the reply has already been sent.
    if (!serverConnection.getTransientFlag(RESPONDED)) {
        writeReply(clientMessage, serverConnection);
    }
    if (logger.isDebugEnabled()) {
        logger.debug("Registered instantiators for MembershipId = {}", serverConnection.getMembershipID());
    }
}
Also used : Part(org.apache.geode.internal.cache.tier.sockets.Part) EventID(org.apache.geode.internal.cache.EventID) ClientInstantiatorMessage(org.apache.geode.internal.cache.tier.sockets.ClientInstantiatorMessage) ByteBuffer(java.nio.ByteBuffer) IOException(java.io.IOException)

Example 70 with EventID

use of org.apache.geode.internal.cache.EventID in project geode by apache.

the class HARegionQueue method remove.

/**
   * Removes the events that were peeked by this thread. The events are destroyed from the queue and
   * conflation map and DispatchedAndCurrentEvents are updated accordingly.
   */
public void remove() throws InterruptedException {
    List peekedIds = (List) HARegionQueue.peekedEventsContext.get();
    if (peekedIds == null) {
        if (logger.isDebugEnabled()) {
            logger.debug("Remove() called before peek(), nothing to remove.");
        }
        return;
    }
    if (!this.checkPrevAcks()) {
        return;
    }
    Map groupedThreadIDs = new HashMap();
    for (Iterator iter = peekedIds.iterator(); iter.hasNext(); ) {
        Long counter = (Long) iter.next();
        Conflatable event = (Conflatable) this.region.get(counter);
        if (event != null) {
            EventID eventid = event.getEventId();
            long sequenceId = eventid.getSequenceID();
            ThreadIdentifier threadid = getThreadIdentifier(eventid);
            if (!checkEventForRemoval(counter, threadid, sequenceId)) {
                continue;
            }
            Object key = null;
            String r = null;
            if (shouldBeConflated(event)) {
                key = event.getKeyToConflate();
                r = event.getRegionToConflate();
            }
            RemovedEventInfo info = new RemovedEventInfo(counter, r, key);
            List countersList;
            if ((countersList = (List) groupedThreadIDs.get(threadid)) != null) {
                countersList.add(info);
                countersList.set(0, sequenceId);
            } else {
                countersList = new ArrayList();
                countersList.add(sequenceId);
                countersList.add(info);
                groupedThreadIDs.put(threadid, countersList);
            }
            event = null;
            info = null;
        } else {
            // if (logger.isDebugEnabled()) {
            HARegionQueue.this.stats.incNumVoidRemovals();
        // }
        }
    }
    for (Iterator iter = groupedThreadIDs.entrySet().iterator(); iter.hasNext(); ) {
        Map.Entry element = (Map.Entry) iter.next();
        ThreadIdentifier tid = (ThreadIdentifier) element.getKey();
        List removedEvents = (List) element.getValue();
        long lastDispatchedId = (Long) removedEvents.remove(0);
        DispatchedAndCurrentEvents dace = (DispatchedAndCurrentEvents) this.eventsMap.get(tid);
        if (dace != null && dace.lastDispatchedSequenceId < lastDispatchedId) {
            try {
                dace.setLastDispatchedIDAndRemoveEvents(removedEvents, lastDispatchedId);
            } catch (CacheException e) {
                // ignore and log
                logger.error(LocalizedMessage.create(LocalizedStrings.HARegionQueue_EXCEPTION_OCCURRED_WHILE_TRYING_TO_SET_THE_LAST_DISPATCHED_ID), e);
            }
        }
    // Periodic ack from the client will add to the addDispatchMessage Map.
    // This method gets called from cacheClientNotifier upon receiving the ack from client.
    // addDispatchedMessage(tid, lastDispatchedId);
    }
    groupedThreadIDs = null;
    // removed the events from queue, now clear the peekedEventsContext
    setPeekedEvents();
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) CacheException(org.apache.geode.cache.CacheException) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) AtomicLong(java.util.concurrent.atomic.AtomicLong) EventID(org.apache.geode.internal.cache.EventID) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) Conflatable(org.apache.geode.internal.cache.Conflatable) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap)

Aggregations

EventID (org.apache.geode.internal.cache.EventID)147 Test (org.junit.Test)66 ClientSubscriptionTest (org.apache.geode.test.junit.categories.ClientSubscriptionTest)60 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)58 IOException (java.io.IOException)41 Map (java.util.Map)33 CacheException (org.apache.geode.cache.CacheException)31 Conflatable (org.apache.geode.internal.cache.Conflatable)29 LocalRegion (org.apache.geode.internal.cache.LocalRegion)23 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)20 HashMap (java.util.HashMap)16 Part (org.apache.geode.internal.cache.tier.sockets.Part)16 ByteBuffer (java.nio.ByteBuffer)14 Iterator (java.util.Iterator)14 List (java.util.List)14 LinkedHashMap (java.util.LinkedHashMap)13 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)13 EntryEventImpl (org.apache.geode.internal.cache.EntryEventImpl)13 AuthorizeRequest (org.apache.geode.internal.security.AuthorizeRequest)13 ConcurrentMap (java.util.concurrent.ConcurrentMap)12