Search in sources :

Example 11 with StringId

use of org.apache.geode.i18n.StringId in project geode by apache.

the class Get70 method cmdExecute.

@Override
public void cmdExecute(Message clientMessage, ServerConnection serverConnection, long startparam) throws IOException {
    long start = startparam;
    Part regionNamePart = null, keyPart = null, valuePart = null;
    String regionName = null;
    Object callbackArg = null, key = null;
    CachedRegionHelper crHelper = serverConnection.getCachedRegionHelper();
    CacheServerStats stats = serverConnection.getCacheServerStats();
    StringId errMessage = null;
    serverConnection.setAsTrue(REQUIRES_RESPONSE);
    // requiresResponse = true;
    {
        long oldStart = start;
        start = DistributionStats.getStatTime();
        stats.incReadGetRequestTime(start - oldStart);
    }
    // Retrieve the data from the message parts
    int parts = clientMessage.getNumberOfParts();
    regionNamePart = clientMessage.getPart(0);
    keyPart = clientMessage.getPart(1);
    // valuePart = null; (redundant assignment)
    if (parts > 2) {
        valuePart = clientMessage.getPart(2);
        try {
            callbackArg = valuePart.getObject();
        } catch (Exception e) {
            writeException(clientMessage, e, false, serverConnection);
            // responded = true;
            serverConnection.setAsTrue(RESPONDED);
            return;
        }
    }
    regionName = regionNamePart.getString();
    try {
        key = keyPart.getStringOrObject();
    } catch (Exception e) {
        writeException(clientMessage, e, false, serverConnection);
        // responded = true;
        serverConnection.setAsTrue(RESPONDED);
        return;
    }
    if (logger.isDebugEnabled()) {
        logger.debug("{}: Received 7.0 get request ({} bytes) from {} for region {} key {} txId {}", serverConnection.getName(), clientMessage.getPayloadLength(), serverConnection.getSocketString(), regionName, key, clientMessage.getTransactionId());
    }
    // Process the get request
    if (key == null || regionName == null) {
        if ((key == null) && (regionName == null)) {
            errMessage = LocalizedStrings.Request_THE_INPUT_REGION_NAME_AND_KEY_FOR_THE_GET_REQUEST_ARE_NULL;
        } else if (key == null) {
            errMessage = LocalizedStrings.Request_THE_INPUT_KEY_FOR_THE_GET_REQUEST_IS_NULL;
        } else if (regionName == null) {
            errMessage = LocalizedStrings.Request_THE_INPUT_REGION_NAME_FOR_THE_GET_REQUEST_IS_NULL;
        }
        String s = errMessage.toLocalizedString();
        logger.warn("{}: {}", serverConnection.getName(), s);
        writeErrorResponse(clientMessage, MessageType.REQUESTDATAERROR, s, serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        return;
    }
    Region region = serverConnection.getCache().getRegion(regionName);
    if (region == null) {
        String reason = LocalizedStrings.Request__0_WAS_NOT_FOUND_DURING_GET_REQUEST.toLocalizedString(regionName);
        writeRegionDestroyedEx(clientMessage, regionName, reason, serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        return;
    }
    GetOperationContext getContext = null;
    try {
        // for integrated security
        this.securityService.authorizeRegionRead(regionName, key.toString());
        AuthorizeRequest authzRequest = serverConnection.getAuthzRequest();
        if (authzRequest != null) {
            getContext = authzRequest.getAuthorize(regionName, key, callbackArg);
            callbackArg = getContext.getCallbackArg();
        }
    } catch (NotAuthorizedException ex) {
        writeException(clientMessage, ex, false, serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        return;
    }
    // Get the value and update the statistics. Do not deserialize
    // the value if it is a byte[].
    Entry entry;
    try {
        entry = getEntry(region, key, callbackArg, serverConnection);
    } catch (Exception e) {
        writeException(clientMessage, e, false, serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        return;
    }
    @Retained final Object originalData = entry.value;
    Object data = originalData;
    try {
        boolean isObject = entry.isObject;
        VersionTag versionTag = entry.versionTag;
        boolean keyNotPresent = entry.keyNotPresent;
        try {
            AuthorizeRequestPP postAuthzRequest = serverConnection.getPostAuthzRequest();
            if (postAuthzRequest != null) {
                try {
                    getContext = postAuthzRequest.getAuthorize(regionName, key, data, isObject, getContext);
                    GetOperationContextImpl gci = (GetOperationContextImpl) getContext;
                    Object newData = gci.getRawValue();
                    if (newData != data) {
                        // user changed the value
                        isObject = getContext.isObject();
                        data = newData;
                    }
                } finally {
                    if (getContext != null) {
                        ((GetOperationContextImpl) getContext).release();
                    }
                }
            }
        } catch (NotAuthorizedException ex) {
            writeException(clientMessage, ex, false, serverConnection);
            serverConnection.setAsTrue(RESPONDED);
            return;
        }
        // post process
        data = this.securityService.postProcess(regionName, key, data, entry.isObject);
        long oldStart = start;
        start = DistributionStats.getStatTime();
        stats.incProcessGetTime(start - oldStart);
        if (region instanceof PartitionedRegion) {
            PartitionedRegion pr = (PartitionedRegion) region;
            if (pr.getNetworkHopType() != PartitionedRegion.NETWORK_HOP_NONE) {
                writeResponseWithRefreshMetadata(data, callbackArg, clientMessage, isObject, serverConnection, pr, pr.getNetworkHopType(), versionTag, keyNotPresent);
                pr.clearNetworkHopData();
            } else {
                writeResponse(data, callbackArg, clientMessage, isObject, versionTag, keyNotPresent, serverConnection);
            }
        } else {
            writeResponse(data, callbackArg, clientMessage, isObject, versionTag, keyNotPresent, serverConnection);
        }
    } finally {
        OffHeapHelper.release(originalData);
    }
    serverConnection.setAsTrue(RESPONDED);
    if (logger.isDebugEnabled()) {
        logger.debug("{}: Wrote get response back to {} for region {} {}", serverConnection.getName(), serverConnection.getSocketString(), regionName, entry);
    }
    stats.incWriteGetResponseTime(DistributionStats.getStatTime() - start);
}
Also used : AuthorizeRequest(org.apache.geode.internal.security.AuthorizeRequest) AuthorizeRequestPP(org.apache.geode.internal.security.AuthorizeRequestPP) NotAuthorizedException(org.apache.geode.security.NotAuthorizedException) GetOperationContextImpl(org.apache.geode.cache.operations.internal.GetOperationContextImpl) NotAuthorizedException(org.apache.geode.security.NotAuthorizedException) IOException(java.io.IOException) GetOperationContext(org.apache.geode.cache.operations.GetOperationContext) CachedRegionHelper(org.apache.geode.internal.cache.tier.CachedRegionHelper) StringId(org.apache.geode.i18n.StringId) Retained(org.apache.geode.internal.offheap.annotations.Retained) 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) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Region(org.apache.geode.cache.Region) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion)

Example 12 with StringId

use of org.apache.geode.i18n.StringId in project geode by apache.

the class DistributionManager method handleConsoleShutdown.

/**
   * Makes note of a console that has shut down.
   * 
   * @param theId The id of the console shutting down
   * @param crashed only true if we detect this id to be gone from a javagroup view
   *
   * @see AdminConsoleDisconnectMessage#process
   */
public void handleConsoleShutdown(InternalDistributedMember theId, boolean crashed, String reason) {
    boolean removedConsole = false;
    boolean removedMember = false;
    synchronized (this.membersLock) {
        // In this case we need for the normal DS to shutdown or crash.
        if (!this.members.containsKey(theId)) {
            if (logger.isDebugEnabled())
                logger.debug("DistributionManager: removing admin member <{}>; crashed = {}; reason = {}", theId, crashed, reason);
            Set tmp = new HashSet(this.membersAndAdmin);
            if (tmp.remove(theId)) {
                // without locking.
                if (tmp.isEmpty()) {
                    tmp = Collections.EMPTY_SET;
                } else {
                    tmp = Collections.unmodifiableSet(tmp);
                }
                this.membersAndAdmin = tmp;
                removedMember = true;
            } else {
            // Don't get upset since this can happen twice due to
            // an explicit remove followed by an implicit one caused
            // by a JavaGroup view change
            }
        }
        removeHostedLocators(theId);
    }
    synchronized (this.adminConsolesLock) {
        if (this.adminConsoles.contains(theId)) {
            removedConsole = true;
            Set tmp = new HashSet(this.adminConsoles);
            tmp.remove(theId);
            if (tmp.isEmpty()) {
                tmp = Collections.EMPTY_SET;
            } else {
                tmp = Collections.unmodifiableSet(tmp);
            }
            this.adminConsoles = tmp;
        }
    }
    if (removedMember) {
        for (Iterator iter = allMembershipListeners.iterator(); iter.hasNext(); ) {
            MembershipListener listener = (MembershipListener) iter.next();
            listener.memberDeparted(theId, crashed);
        }
    }
    if (removedConsole) {
        StringId msg = null;
        if (crashed) {
            msg = LocalizedStrings.DistributionManager_ADMINISTRATION_MEMBER_AT_0_CRASHED_1;
        } else {
            msg = LocalizedStrings.DistributionManager_ADMINISTRATION_MEMBER_AT_0_CLOSED_1;
        }
        logger.info(LocalizedMessage.create(msg, new Object[] { theId, reason }));
    }
    redundancyZones.remove(theId);
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) StringId(org.apache.geode.i18n.StringId) Iterator(java.util.Iterator) DistributedMembershipListener(org.apache.geode.distributed.internal.membership.DistributedMembershipListener) HashSet(java.util.HashSet)

Example 13 with StringId

use of org.apache.geode.i18n.StringId in project geode by apache.

the class DistributionManager method handleManagerDeparture.

/**
   * used by the DistributedMembershipListener and startup and shutdown operations, this method
   * decrements the number of nodes and handles lower-level clean up of the resources used by the
   * departed manager
   */
public void handleManagerDeparture(InternalDistributedMember theId, boolean p_crashed, String p_reason) {
    boolean crashed = p_crashed;
    String reason = p_reason;
    AlertAppender.getInstance().removeAlertListener(theId);
    // but still in the javagroup view.
    try {
        selectElder();
    } catch (DistributedSystemDisconnectedException e) {
    // keep going
    }
    int vmType = theId.getVmKind();
    if (vmType == ADMIN_ONLY_DM_TYPE) {
        removeUnfinishedStartup(theId, true);
        handleConsoleShutdown(theId, crashed, reason);
        return;
    }
    // not an admin VM...
    if (!isCurrentMember(theId)) {
        // fault tolerance
        return;
    }
    removeUnfinishedStartup(theId, true);
    if (removeManager(theId, crashed, reason)) {
        if (theId.getVmKind() != DistributionManager.LOCATOR_DM_TYPE) {
            this.stats.incNodes(-1);
        }
        StringId msg;
        if (crashed && !isCloseInProgress()) {
            msg = LocalizedStrings.DistributionManager_MEMBER_AT_0_UNEXPECTEDLY_LEFT_THE_DISTRIBUTED_CACHE_1;
            addMemberEvent(new MemberCrashedEvent(theId, reason));
        } else {
            msg = LocalizedStrings.DistributionManager_MEMBER_AT_0_GRACEFULLY_LEFT_THE_DISTRIBUTED_CACHE_1;
            addMemberEvent(new MemberDepartedEvent(theId, reason));
        }
        logger.info(LocalizedMessage.create(msg, new Object[] { theId, prettifyReason(reason) }));
        // Remove this manager from the serialQueueExecutor.
        if (this.serialQueuedExecutorPool != null) {
            serialQueuedExecutorPool.handleMemberDeparture(theId);
        }
    }
}
Also used : DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) StringId(org.apache.geode.i18n.StringId)

Example 14 with StringId

use of org.apache.geode.i18n.StringId in project geode by apache.

the class GemFireBasicDataSource method loadDriver.

private void loadDriver() throws SQLException {
    try {
        Class driverClass = ClassPathLoader.getLatest().forName(jdbcDriver);
        driverObject = (Driver) driverClass.newInstance();
    } catch (Exception ex) {
        StringId msg = LocalizedStrings.GemFireBasicDataSource_AN_EXCEPTION_WAS_CAUGHT_WHILE_TRYING_TO_LOAD_THE_DRIVER;
        String msgArg = ex.getLocalizedMessage();
        logger.error(LocalizedMessage.create(msg, msgArg), ex);
        throw new SQLException(msg.toLocalizedString(msgArg));
    }
}
Also used : StringId(org.apache.geode.i18n.StringId) SQLException(java.sql.SQLException) SQLException(java.sql.SQLException)

Example 15 with StringId

use of org.apache.geode.i18n.StringId in project geode by apache.

the class InternalDataSerializer method _register.

public static DataSerializer _register(DataSerializer s, boolean distribute) {
    final int id = s.getId();
    DataSerializer dsForMarkers = s;
    if (id == 0) {
        throw new IllegalArgumentException(LocalizedStrings.InternalDataSerializer_CANNOT_CREATE_A_DATASERIALIZER_WITH_ID_0.toLocalizedString());
    }
    final Class[] classes = s.getSupportedClasses();
    if (classes == null || classes.length == 0) {
        final StringId msg = LocalizedStrings.InternalDataSerializer_THE_DATASERIALIZER_0_HAS_NO_SUPPORTED_CLASSES_ITS_GETSUPPORTEDCLASSES_METHOD_MUST_RETURN_AT_LEAST_ONE_CLASS;
        throw new IllegalArgumentException(msg.toLocalizedString(s.getClass().getName()));
    }
    for (Class aClass : classes) {
        if (aClass == null) {
            final StringId msg = LocalizedStrings.InternalDataSerializer_THE_DATASERIALIZER_GETSUPPORTEDCLASSES_METHOD_FOR_0_RETURNED_AN_ARRAY_THAT_CONTAINED_A_NULL_ELEMENT;
            throw new IllegalArgumentException(msg.toLocalizedString(s.getClass().getName()));
        } else if (aClass.isArray()) {
            final StringId msg = LocalizedStrings.InternalDataSerializer_THE_DATASERIALIZER_GETSUPPORTEDCLASSES_METHOD_FOR_0_RETURNED_AN_ARRAY_THAT_CONTAINED_AN_ARRAY_CLASS_WHICH_IS_NOT_ALLOWED_SINCE_ARRAYS_HAVE_BUILTIN_SUPPORT;
            throw new IllegalArgumentException(msg.toLocalizedString(s.getClass().getName()));
        }
    }
    final Integer idx = id;
    boolean retry;
    Marker oldMarker = null;
    final Marker m = new InitMarker();
    do {
        retry = false;
        Object oldSerializer = idsToSerializers.putIfAbsent(idx, m);
        if (oldSerializer != null) {
            if (oldSerializer instanceof Marker) {
                retry = !idsToSerializers.replace(idx, oldSerializer, m);
                if (!retry) {
                    oldMarker = (Marker) oldSerializer;
                }
            } else if (oldSerializer.getClass().equals(s.getClass())) {
                // We've already got one of these registered
                if (distribute) {
                    sendRegistrationMessage(s);
                }
                return (DataSerializer) oldSerializer;
            } else {
                DataSerializer other = (DataSerializer) oldSerializer;
                throw new IllegalStateException(LocalizedStrings.InternalDataSerializer_A_DATASERIALIZER_OF_CLASS_0_IS_ALREADY_REGISTERED_WITH_ID_1_SO_THE_DATASERIALIZER_OF_CLASS_2_COULD_NOT_BE_REGISTERED.toLocalizedString(new Object[] { other.getClass().getName(), other.getId() }));
            }
        }
    } while (retry);
    try {
        for (int i = 0; i < classes.length; i++) {
            DataSerializer oldS = classesToSerializers.putIfAbsent(classes[i].getName(), s);
            if (oldS != null) {
                if (!s.equals(oldS)) {
                    // cleanup the ones we have already added
                    for (int j = 0; j < i; j++) {
                        classesToSerializers.remove(classes[j].getName(), s);
                    }
                    dsForMarkers = null;
                    String oldMsg;
                    if (oldS.getId() == 0) {
                        oldMsg = "DataSerializer has built-in support for class ";
                    } else {
                        oldMsg = "A DataSerializer of class " + oldS.getClass().getName() + " is already registered to support class ";
                    }
                    String msg = oldMsg + classes[i].getName() + " so the DataSerializer of class " + s.getClass().getName() + " could not be registered.";
                    if (oldS.getId() == 0) {
                        throw new IllegalArgumentException(msg);
                    } else {
                        throw new IllegalStateException(msg);
                    }
                }
            }
        }
    } finally {
        if (dsForMarkers == null) {
            idsToSerializers.remove(idx, m);
        } else {
            idsToSerializers.replace(idx, m, dsForMarkers);
        }
        if (oldMarker != null) {
            oldMarker.setSerializer(dsForMarkers);
        }
        m.setSerializer(dsForMarkers);
    }
    // if dataserializer is getting registered for first time
    // its EventID will be null, so generate a new event id
    // the the distributed system is connected
    InternalCache cache = GemFireCacheImpl.getInstance();
    if (cache != null && s.getEventId() == null) {
        s.setEventId(new EventID(cache.getDistributedSystem()));
    }
    if (distribute) {
        // send a message to other peers telling them about a newly-registered
        // dataserializer, it also send event id of the originator along with the
        // dataserializer
        sendRegistrationMessage(s);
        // send it to cache servers if it is a client
        sendRegistrationMessageToServers(s);
    }
    // send it to all cache clients irrelevant of distribute
    // bridge servers send it all the clients irrelevant of
    // originator VM
    sendRegistrationMessageToClients(s);
    fireNewDataSerializer(s);
    return s;
}
Also used : InternalCache(org.apache.geode.internal.cache.InternalCache) LogMarker(org.apache.geode.internal.logging.log4j.LogMarker) BigInteger(java.math.BigInteger) StringId(org.apache.geode.i18n.StringId) EventID(org.apache.geode.internal.cache.EventID) ObjectStreamClass(java.io.ObjectStreamClass) DataSerializer(org.apache.geode.DataSerializer)

Aggregations

StringId (org.apache.geode.i18n.StringId)43 IOException (java.io.IOException)14 AuthorizeRequest (org.apache.geode.internal.security.AuthorizeRequest)11 LocalRegion (org.apache.geode.internal.cache.LocalRegion)10 CachedRegionHelper (org.apache.geode.internal.cache.tier.CachedRegionHelper)8 Part (org.apache.geode.internal.cache.tier.sockets.Part)8 TimeoutException (org.apache.geode.cache.TimeoutException)6 HashSet (java.util.HashSet)5 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 CancelException (org.apache.geode.CancelException)4 InterestResultPolicy (org.apache.geode.cache.InterestResultPolicy)4 RegisterInterestOperationContext (org.apache.geode.cache.operations.RegisterInterestOperationContext)4 CqClosedException (org.apache.geode.cache.query.CqClosedException)4 CqException (org.apache.geode.cache.query.CqException)4 CqExistsException (org.apache.geode.cache.query.CqExistsException)4 QueryException (org.apache.geode.cache.query.QueryException)4 RegionNotFoundException (org.apache.geode.cache.query.RegionNotFoundException)4 LinkedHashSet (java.util.LinkedHashSet)3