Search in sources :

Example 11 with InternalCache

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

the class InternalLocator method startCache.

private void startCache(DistributedSystem ds) {
    InternalCache internalCache = GemFireCacheImpl.getInstance();
    if (internalCache == null) {
        logger.info("Creating cache for locator.");
        this.myCache = (InternalCache) new CacheFactory(ds.getProperties()).create();
        internalCache = this.myCache;
    } else {
        logger.info("Using existing cache for locator.");
        ((InternalDistributedSystem) ds).handleResourceEvent(ResourceEvent.LOCATOR_START, this);
    }
    startJmxManagerLocationService(internalCache);
    startSharedConfigurationService(internalCache);
}
Also used : InternalCache(org.apache.geode.internal.cache.InternalCache) CacheFactory(org.apache.geode.cache.CacheFactory)

Example 12 with InternalCache

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

the class InternalDataSerializer method readPdxSerializable.

private static Object readPdxSerializable(final DataInput in) throws IOException, ClassNotFoundException {
    int len = in.readInt();
    int typeId = in.readInt();
    InternalCache internalCache = GemFireCacheImpl.getForPdx("PDX registry is unavailable because the Cache has been closed.");
    PdxType pdxType = internalCache.getPdxRegistry().getType(typeId);
    if (logger.isTraceEnabled(LogMarker.SERIALIZER)) {
        logger.trace(LogMarker.SERIALIZER, "readPdxSerializable pdxType={}", pdxType);
    }
    if (pdxType == null) {
        throw new IllegalStateException("Unknown pdx type=" + typeId);
    }
    DMStats dmStats = getDMStats(internalCache);
    dmStats.incPdxDeserialization(len + 9);
    // check if PdxInstance needs to be returned.
    if (pdxType.getNoDomainClass() || internalCache.getPdxReadSerializedByAnyGemFireServices()) {
        dmStats.incPdxInstanceCreations();
        return new PdxInstanceImpl(pdxType, in, len);
    } else {
        PdxReaderImpl pdxReader = new PdxReaderImpl(pdxType, in, len);
        return pdxReader.getObject();
    }
}
Also used : DMStats(org.apache.geode.distributed.internal.DMStats) PdxReaderImpl(org.apache.geode.pdx.internal.PdxReaderImpl) PdxType(org.apache.geode.pdx.internal.PdxType) PdxInstanceImpl(org.apache.geode.pdx.internal.PdxInstanceImpl) InternalCache(org.apache.geode.internal.cache.InternalCache)

Example 13 with InternalCache

use of org.apache.geode.internal.cache.InternalCache 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)

Example 14 with InternalCache

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

the class ClientStatsManager method publishClientStats.

/**
   * This method publishes the client stats using the admin region.
   * 
   * @param pool Connection pool which may be used for admin region.
   */
public static synchronized void publishClientStats(PoolImpl pool) {
    InternalCache currentCache = GemFireCacheImpl.getInstance();
    if (!initializeStatistics(currentCache)) {
        // handles null case too
        return;
    }
    LogWriterI18n logger = currentCache.getLoggerI18n();
    if (logger.fineEnabled())
        logger.fine("Entering ClientStatsManager#publishClientStats...");
    ClientHealthStats stats = getClientHealthStats(currentCache, pool);
    try {
        InternalDistributedSystem ds = (InternalDistributedSystem) currentCache.getDistributedSystem();
        ServerRegionProxy regionProxy = new ServerRegionProxy(ClientHealthMonitoringRegion.ADMIN_REGION_NAME, pool);
        EventID eventId = new EventID(ds);
        @Released EntryEventImpl event = new EntryEventImpl((Object) null);
        try {
            event.setEventId(eventId);
            regionProxy.putForMetaRegion(ds.getMemberId(), stats, null, event, null, true);
        } finally {
            event.release();
        }
    } catch (DistributedSystemDisconnectedException e) {
        throw e;
    } catch (CacheWriterException cwx) {
        pool.getCancelCriterion().checkCancelInProgress(cwx);
        currentCache.getCancelCriterion().checkCancelInProgress(cwx);
        // TODO: Need to analyze these exception scenarios.
        logger.warning(LocalizedStrings.ClientStatsManager_FAILED_TO_SEND_CLIENT_HEALTH_STATS_TO_CACHESERVER, cwx);
    } catch (Exception e) {
        pool.getCancelCriterion().checkCancelInProgress(e);
        currentCache.getCancelCriterion().checkCancelInProgress(e);
        logger.info(LocalizedStrings.ClientStatsManager_FAILED_TO_PUBLISH_CLIENT_STATISTICS, e);
    }
    if (logger.fineEnabled()) {
        logger.fine("Exiting ClientStatsManager#publishClientStats.");
    }
}
Also used : DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) Released(org.apache.geode.internal.offheap.annotations.Released) EntryEventImpl(org.apache.geode.internal.cache.EntryEventImpl) ServerRegionProxy(org.apache.geode.cache.client.internal.ServerRegionProxy) InternalCache(org.apache.geode.internal.cache.InternalCache) EventID(org.apache.geode.internal.cache.EventID) LogWriterI18n(org.apache.geode.i18n.LogWriterI18n) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) ClientHealthStats(org.apache.geode.internal.admin.remote.ClientHealthStats) DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) CacheWriterException(org.apache.geode.cache.CacheWriterException) CacheWriterException(org.apache.geode.cache.CacheWriterException)

Example 15 with InternalCache

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

the class InternalDataSerializer method readPdxEnum.

/**
   * @throws IOException since 6.6.2
   */
private static Object readPdxEnum(DataInput in) throws IOException {
    int dsId = in.readByte();
    int tmp = readArrayLength(in);
    int enumId = dsId << 24 | tmp & 0xFFFFFF;
    if (logger.isTraceEnabled(LogMarker.SERIALIZER)) {
        logger.trace(LogMarker.SERIALIZER, "read PdxEnum id={}", enumId);
    }
    InternalCache internalCache = GemFireCacheImpl.getForPdx("PDX registry is unavailable because the Cache has been closed.");
    TypeRegistry tr = internalCache.getPdxRegistry();
    Object result = tr.getEnumById(enumId);
    if (result instanceof PdxInstance) {
        getDMStats(internalCache).incPdxInstanceCreations();
    }
    return result;
}
Also used : PdxInstance(org.apache.geode.pdx.PdxInstance) InternalCache(org.apache.geode.internal.cache.InternalCache) TypeRegistry(org.apache.geode.pdx.internal.TypeRegistry)

Aggregations

InternalCache (org.apache.geode.internal.cache.InternalCache)267 DistributedMember (org.apache.geode.distributed.DistributedMember)78 Test (org.junit.Test)64 UnitTest (org.apache.geode.test.junit.categories.UnitTest)52 IOException (java.io.IOException)48 ArrayList (java.util.ArrayList)35 HashSet (java.util.HashSet)35 CliMetaData (org.apache.geode.management.cli.CliMetaData)34 CliCommand (org.springframework.shell.core.annotation.CliCommand)34 TabularResultData (org.apache.geode.management.internal.cli.result.TabularResultData)32 Region (org.apache.geode.cache.Region)31 Result (org.apache.geode.management.cli.Result)30 ResourceOperation (org.apache.geode.management.internal.security.ResourceOperation)30 Expectations (org.jmock.Expectations)30 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)26 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)25 CliFunctionResult (org.apache.geode.management.internal.cli.functions.CliFunctionResult)24 Set (java.util.Set)23 ResultCollector (org.apache.geode.cache.execute.ResultCollector)22 CommandResultException (org.apache.geode.management.internal.cli.result.CommandResultException)20