Search in sources :

Example 16 with TypeRegistry

use of org.apache.geode.pdx.internal.TypeRegistry in project geode by apache.

the class AddPdxType method cmdExecute.

@Override
public void cmdExecute(Message clientMessage, ServerConnection serverConnection, long start) throws IOException, ClassNotFoundException {
    serverConnection.setAsTrue(REQUIRES_RESPONSE);
    if (logger.isDebugEnabled()) {
        logger.debug("{}: Received get pdx id for type request ({} parts) from {}", serverConnection.getName(), clientMessage.getNumberOfParts(), serverConnection.getSocketString());
    }
    int noOfParts = clientMessage.getNumberOfParts();
    PdxType type = (PdxType) clientMessage.getPart(0).getObject();
    int typeId = clientMessage.getPart(1).getInt();
    // The native client needs this line
    // because it doesn't set the type id on the
    // client side.
    type.setTypeId(typeId);
    try {
        InternalCache cache = serverConnection.getCache();
        TypeRegistry registry = cache.getPdxRegistry();
        registry.addRemoteType(typeId, type);
    } catch (Exception e) {
        writeException(clientMessage, e, false, serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        return;
    }
    writeReply(clientMessage, serverConnection);
    serverConnection.setAsTrue(RESPONDED);
}
Also used : PdxType(org.apache.geode.pdx.internal.PdxType) InternalCache(org.apache.geode.internal.cache.InternalCache) TypeRegistry(org.apache.geode.pdx.internal.TypeRegistry) IOException(java.io.IOException)

Example 17 with TypeRegistry

use of org.apache.geode.pdx.internal.TypeRegistry in project geode by apache.

the class GetPDXEnumById method cmdExecute.

@Override
public void cmdExecute(Message clientMessage, ServerConnection serverConnection, long start) throws IOException, ClassNotFoundException {
    serverConnection.setAsTrue(REQUIRES_RESPONSE);
    if (logger.isDebugEnabled()) {
        logger.debug("{}: Received get pdx enum by id request ({} parts) from {}", serverConnection.getName(), clientMessage.getNumberOfParts(), serverConnection.getSocketString());
    }
    int enumId = clientMessage.getPart(0).getInt();
    EnumInfo result;
    try {
        InternalCache cache = serverConnection.getCache();
        TypeRegistry registry = cache.getPdxRegistry();
        result = registry.getEnumInfoById(enumId);
    } catch (Exception e) {
        writeException(clientMessage, e, false, serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        return;
    }
    Message responseMsg = serverConnection.getResponseMessage();
    responseMsg.setMessageType(MessageType.RESPONSE);
    responseMsg.setNumberOfParts(1);
    responseMsg.setTransactionId(clientMessage.getTransactionId());
    responseMsg.addObjPart(result);
    responseMsg.send(serverConnection);
    serverConnection.setAsTrue(RESPONDED);
}
Also used : Message(org.apache.geode.internal.cache.tier.sockets.Message) EnumInfo(org.apache.geode.pdx.internal.EnumInfo) InternalCache(org.apache.geode.internal.cache.InternalCache) TypeRegistry(org.apache.geode.pdx.internal.TypeRegistry) IOException(java.io.IOException)

Example 18 with TypeRegistry

use of org.apache.geode.pdx.internal.TypeRegistry in project geode by apache.

the class GetPDXIdForEnum method cmdExecute.

@Override
public void cmdExecute(Message clientMessage, ServerConnection serverConnection, long start) throws IOException, ClassNotFoundException {
    serverConnection.setAsTrue(REQUIRES_RESPONSE);
    if (logger.isDebugEnabled()) {
        logger.debug("{}: Received get pdx id for enum request ({} parts) from {}", serverConnection.getName(), clientMessage.getNumberOfParts(), serverConnection.getSocketString());
    }
    EnumInfo enumInfo = (EnumInfo) clientMessage.getPart(0).getObject();
    int enumId;
    try {
        InternalCache cache = serverConnection.getCache();
        TypeRegistry registry = cache.getPdxRegistry();
        enumId = registry.defineEnum(enumInfo);
    } catch (Exception e) {
        writeException(clientMessage, e, false, serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        return;
    }
    Message responseMsg = serverConnection.getResponseMessage();
    responseMsg.setMessageType(MessageType.RESPONSE);
    responseMsg.setNumberOfParts(1);
    responseMsg.setTransactionId(clientMessage.getTransactionId());
    responseMsg.addIntPart(enumId);
    responseMsg.send(serverConnection);
    serverConnection.setAsTrue(RESPONDED);
}
Also used : Message(org.apache.geode.internal.cache.tier.sockets.Message) EnumInfo(org.apache.geode.pdx.internal.EnumInfo) InternalCache(org.apache.geode.internal.cache.InternalCache) TypeRegistry(org.apache.geode.pdx.internal.TypeRegistry) IOException(java.io.IOException)

Example 19 with TypeRegistry

use of org.apache.geode.pdx.internal.TypeRegistry in project geode by apache.

the class DeployedJar method cleanUp.

/**
   * Unregisters all functions from this jar if it was undeployed (i.e. newVersion == null), or all
   * functions not present in the new version if it was redeployed.
   *
   * @param newVersion The new version of this jar that was deployed, or null if this jar was
   *        undeployed.
   */
protected synchronized void cleanUp(DeployedJar newVersion) {
    Stream<String> oldFunctions = this.registeredFunctions.stream().map(Function::getId);
    Stream<String> removedFunctions;
    if (newVersion == null) {
        removedFunctions = oldFunctions;
    } else {
        Predicate<String> isRemoved = (String oldFunctionId) -> !newVersion.hasFunctionWithId(oldFunctionId);
        removedFunctions = oldFunctions.filter(isRemoved);
    }
    removedFunctions.forEach(FunctionService::unregisterFunction);
    this.registeredFunctions.clear();
    try {
        TypeRegistry typeRegistry = ((InternalCache) CacheFactory.getAnyInstance()).getPdxRegistry();
        if (typeRegistry != null) {
            typeRegistry.flushCache();
        }
    } catch (CacheClosedException ignored) {
    // That's okay, it just means there was nothing to flush to begin with
    }
}
Also used : Function(org.apache.geode.cache.execute.Function) InternalCache(org.apache.geode.internal.cache.InternalCache) FunctionService(org.apache.geode.cache.execute.FunctionService) CacheClosedException(org.apache.geode.cache.CacheClosedException) TypeRegistry(org.apache.geode.pdx.internal.TypeRegistry)

Example 20 with TypeRegistry

use of org.apache.geode.pdx.internal.TypeRegistry in project geode by apache.

the class GemFireCacheImplTest method checkPurgeCCPTimer.

@Test
public void checkPurgeCCPTimer() {
    InternalDistributedSystem ds = Fakes.distributedSystem();
    CacheConfig cc = new CacheConfig();
    TypeRegistry typeRegistry = mock(TypeRegistry.class);
    SystemTimer ccpTimer = mock(SystemTimer.class);
    GemFireCacheImpl gfc = GemFireCacheImpl.createWithAsyncEventListeners(ds, cc, typeRegistry);
    try {
        gfc.setCCPTimer(ccpTimer);
        for (int i = 1; i < GemFireCacheImpl.PURGE_INTERVAL; i++) {
            gfc.purgeCCPTimer();
            verify(ccpTimer, times(0)).timerPurge();
        }
        gfc.purgeCCPTimer();
        verify(ccpTimer, times(1)).timerPurge();
        for (int i = 1; i < GemFireCacheImpl.PURGE_INTERVAL; i++) {
            gfc.purgeCCPTimer();
            verify(ccpTimer, times(1)).timerPurge();
        }
        gfc.purgeCCPTimer();
        verify(ccpTimer, times(2)).timerPurge();
    } finally {
        gfc.close();
    }
}
Also used : InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) TypeRegistry(org.apache.geode.pdx.internal.TypeRegistry) SystemTimer(org.apache.geode.internal.SystemTimer) Test(org.junit.Test) UnitTest(org.apache.geode.test.junit.categories.UnitTest)

Aggregations

TypeRegistry (org.apache.geode.pdx.internal.TypeRegistry)24 InternalCache (org.apache.geode.internal.cache.InternalCache)10 PdxType (org.apache.geode.pdx.internal.PdxType)10 Test (org.junit.Test)10 IOException (java.io.IOException)7 EnumInfo (org.apache.geode.pdx.internal.EnumInfo)6 UnitTest (org.apache.geode.test.junit.categories.UnitTest)6 GemFireCacheImpl (org.apache.geode.internal.cache.GemFireCacheImpl)5 Message (org.apache.geode.internal.cache.tier.sockets.Message)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 DataOutputStream (java.io.DataOutputStream)3 InternalDistributedSystem (org.apache.geode.distributed.internal.InternalDistributedSystem)3 CancelException (org.apache.geode.CancelException)2 GemFireRethrowable (org.apache.geode.GemFireRethrowable)2 ToDataException (org.apache.geode.ToDataException)2 SystemTimer (org.apache.geode.internal.SystemTimer)2 NonPortableClassException (org.apache.geode.pdx.NonPortableClassException)2 PdxInstance (org.apache.geode.pdx.PdxInstance)2 PdxInstanceImpl (org.apache.geode.pdx.internal.PdxInstanceImpl)2 PdxOutputStream (org.apache.geode.pdx.internal.PdxOutputStream)2