Search in sources :

Example 1 with EnumListenerEvent

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

the class PutMessage method operateOnPartitionedRegion.

/**
   * This method is called upon receipt and make the desired changes to the PartitionedRegion Note:
   * It is very important that this message does NOT cause any deadlocks as the sender will wait
   * indefinitely for the acknowledgement
   */
@Override
protected boolean operateOnPartitionedRegion(DistributionManager dm, PartitionedRegion r, long startTime) throws EntryExistsException, DataLocationException, IOException {
    // set the internal DS. Required to
    this.setInternalDs(r.getSystem());
    // checked DS level delta-enabled property
    // while sending delta
    PartitionedRegionDataStore ds = r.getDataStore();
    boolean sendReply = true;
    InternalDistributedMember eventSender = originalSender;
    if (eventSender == null) {
        eventSender = getSender();
    }
    @Released final EntryEventImpl ev = EntryEventImpl.create(r, getOperation(), getKey(), null, /* newValue */
    getCallbackArg(), false, /* originRemote - false to force distribution in buckets */
    eventSender, true, /* generateCallbacks */
    false);
    try {
        if (this.versionTag != null) {
            this.versionTag.replaceNullIDs(getSender());
            ev.setVersionTag(this.versionTag);
        }
        if (this.bridgeContext != null) {
            ev.setContext(this.bridgeContext);
        }
        Assert.assertTrue(eventId != null);
        ev.setEventId(eventId);
        ev.setCausedByMessage(this);
        ev.setInvokePRCallbacks(!notificationOnly);
        ev.setPossibleDuplicate(this.posDup);
        /*
       * if (this.hasOldValue) { if (this.oldValueIsSerialized) {
       * ev.setSerializedOldValue(getOldValueBytes()); } else { ev.setOldValue(getOldValueBytes());
       * } }
       */
        ev.setDeltaBytes(this.deltaBytes);
        if (this.hasDelta) {
            this.valObj = null;
            // New value will be set once it is generated with fromDelta() inside
            // EntryEventImpl.processDeltaBytes()
            ev.setNewValue(this.valObj);
        } else {
            switch(this.deserializationPolicy) {
                case DistributedCacheOperation.DESERIALIZATION_POLICY_LAZY:
                    ev.setSerializedNewValue(getValBytes());
                    break;
                case DistributedCacheOperation.DESERIALIZATION_POLICY_NONE:
                    ev.setNewValue(getValBytes());
                    break;
                default:
                    throw new AssertionError("unknown deserialization policy: " + deserializationPolicy);
            }
        }
        if (!notificationOnly) {
            if (ds == null) {
                throw new AssertionError("This process should have storage" + " for this operation: " + this.toString());
            }
            try {
                // the event must show it's true origin for cachewriter invocation
                // event.setOriginRemote(true);
                // this.op = r.doCacheWriteBeforePut(event, ifNew); // TODO fix this for bug 37072
                ev.setOriginRemote(false);
                result = r.getDataView().putEntryOnRemote(ev, this.ifNew, this.ifOld, this.expectedOldValue, this.requireOldValue, this.lastModified, true);
                if (!this.result) {
                    // make sure the region hasn't gone away
                    r.checkReadiness();
                // sbawaska: I cannot see how ifOld and ifNew can both be false, hence removing
                // if (!this.ifNew && !this.ifOld) {
                // // no reason to be throwing an exception, so let's retry
                // ForceReattemptException fre = new ForceReattemptException(
                // LocalizedStrings.PutMessage_UNABLE_TO_PERFORM_PUT_BUT_OPERATION_SHOULD_NOT_FAIL_0.toLocalizedString());
                // fre.setHash(key.hashCode());
                // sendReply(getSender(), getProcessorId(), dm,
                // new ReplyException(fre), r, startTime);
                // sendReply = false;
                // }
                }
            } catch (CacheWriterException cwe) {
                sendReply(getSender(), getProcessorId(), dm, new ReplyException(cwe), r, startTime);
                return false;
            } catch (PrimaryBucketException pbe) {
                sendReply(getSender(), getProcessorId(), dm, new ReplyException(pbe), r, startTime);
                return false;
            } catch (InvalidDeltaException ide) {
                sendReply(getSender(), getProcessorId(), dm, new ReplyException(ide), r, startTime);
                r.getCachePerfStats().incDeltaFullValuesRequested();
                return false;
            }
            if (logger.isTraceEnabled(LogMarker.DM)) {
                logger.trace(LogMarker.DM, "PutMessage {} with key: {} val: {}", (result ? "updated bucket" : "did not update bucket"), getKey(), (getValBytes() == null ? "null" : "(" + getValBytes().length + " bytes)"));
            }
        } else {
            // notificationOnly
            @Released EntryEventImpl e2 = createListenerEvent(ev, r, dm.getDistributionManagerId());
            final EnumListenerEvent le;
            try {
                if (e2.getOperation().isCreate()) {
                    le = EnumListenerEvent.AFTER_CREATE;
                } else {
                    le = EnumListenerEvent.AFTER_UPDATE;
                }
                r.invokePutCallbacks(le, e2, r.isInitialized(), true);
            } finally {
                // if e2 == ev then no need to free it here. The outer finally block will get it.
                if (e2 != ev) {
                    e2.release();
                }
            }
            result = true;
        }
        // set operation for reply message
        setOperation(ev.getOperation());
        if (sendReply) {
            sendReply(getSender(), getProcessorId(), dm, null, r, startTime, ev);
        }
        return false;
    } finally {
        ev.release();
    }
}
Also used : InvalidDeltaException(org.apache.geode.InvalidDeltaException) EnumListenerEvent(org.apache.geode.internal.cache.EnumListenerEvent) Released(org.apache.geode.internal.offheap.annotations.Released) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) EntryEventImpl(org.apache.geode.internal.cache.EntryEventImpl) PartitionedRegionDataStore(org.apache.geode.internal.cache.PartitionedRegionDataStore) PrimaryBucketException(org.apache.geode.internal.cache.PrimaryBucketException) ReplyException(org.apache.geode.distributed.internal.ReplyException) CacheWriterException(org.apache.geode.cache.CacheWriterException)

Example 2 with EnumListenerEvent

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

the class CacheClientNotifier method constructClientMessage.

private ClientUpdateMessageImpl constructClientMessage(InternalCacheEvent event) {
    ClientUpdateMessageImpl clientMessage = null;
    EnumListenerEvent operation = event.getEventType();
    try {
        clientMessage = initializeMessage(operation, event);
    } catch (Exception e) {
        logger.fatal(LocalizedMessage.create(LocalizedStrings.CacheClientNotifier_CANNOT_NOTIFY_CLIENTS_TO_PERFORM_OPERATION_0_ON_EVENT_1, new Object[] { operation, event }), e);
    }
    return clientMessage;
}
Also used : EnumListenerEvent(org.apache.geode.internal.cache.EnumListenerEvent) CqException(org.apache.geode.cache.query.CqException) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) AuthenticationFailedException(org.apache.geode.security.AuthenticationFailedException) IOException(java.io.IOException) CacheException(org.apache.geode.cache.CacheException) UnsupportedVersionException(org.apache.geode.cache.UnsupportedVersionException) RegionExistsException(org.apache.geode.cache.RegionExistsException) CancelException(org.apache.geode.CancelException) AuthenticationRequiredException(org.apache.geode.security.AuthenticationRequiredException)

Aggregations

EnumListenerEvent (org.apache.geode.internal.cache.EnumListenerEvent)2 IOException (java.io.IOException)1 CancelException (org.apache.geode.CancelException)1 InvalidDeltaException (org.apache.geode.InvalidDeltaException)1 CacheException (org.apache.geode.cache.CacheException)1 CacheWriterException (org.apache.geode.cache.CacheWriterException)1 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)1 RegionExistsException (org.apache.geode.cache.RegionExistsException)1 UnsupportedVersionException (org.apache.geode.cache.UnsupportedVersionException)1 CqException (org.apache.geode.cache.query.CqException)1 ReplyException (org.apache.geode.distributed.internal.ReplyException)1 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)1 EntryEventImpl (org.apache.geode.internal.cache.EntryEventImpl)1 PartitionedRegionDataStore (org.apache.geode.internal.cache.PartitionedRegionDataStore)1 PrimaryBucketException (org.apache.geode.internal.cache.PrimaryBucketException)1 Released (org.apache.geode.internal.offheap.annotations.Released)1 AuthenticationFailedException (org.apache.geode.security.AuthenticationFailedException)1 AuthenticationRequiredException (org.apache.geode.security.AuthenticationRequiredException)1