Search in sources :

Example 1 with PdxInitializationException

use of org.apache.geode.pdx.PdxInitializationException in project geode by apache.

the class CheckTypeRegistryState method send.

public static void send(DM dm) {
    Set recipients = dm.getOtherDistributionManagerIds();
    ReplyProcessor21 replyProcessor = new ReplyProcessor21(dm, recipients);
    CheckTypeRegistryState msg = new CheckTypeRegistryState(replyProcessor.getProcessorId());
    msg.setRecipients(recipients);
    dm.putOutgoing(msg);
    try {
        replyProcessor.waitForReplies();
    } catch (ReplyException e) {
        if (e.getCause() instanceof PdxInitializationException) {
            throw new PdxInitializationException("Bad PDX configuration on member " + e.getSender() + ": " + e.getCause().getMessage(), e.getCause());
        } else {
            throw new InternalGemFireError("Unexpected exception", e);
        }
    } catch (InterruptedException e) {
        throw new InternalGemFireError("Unexpected exception", e);
    }
}
Also used : Set(java.util.Set) ReplyException(org.apache.geode.distributed.internal.ReplyException) PdxInitializationException(org.apache.geode.pdx.PdxInitializationException) ReplyProcessor21(org.apache.geode.distributed.internal.ReplyProcessor21) InternalGemFireError(org.apache.geode.InternalGemFireError)

Example 2 with PdxInitializationException

use of org.apache.geode.pdx.PdxInitializationException in project geode by apache.

the class PeerTypeRegistration method verifyConfiguration.

void verifyConfiguration() {
    if (typeRegistryInUse) {
        return;
    } else {
        boolean hasPersistentRegions = hasPersistentRegions();
        checkAllowed(hasGatewaySender(), hasPersistentRegions);
        for (Pool pool : PoolManager.getAll().values()) {
            if (!((PoolImpl) pool).isUsedByGateway()) {
                throw new PdxInitializationException("The PDX metadata has already been " + "created as a peer metadata region. " + "Please use ClientCacheFactory to create clients.");
            }
        }
        typeRegistryInUse = true;
    }
}
Also used : Pool(org.apache.geode.cache.client.Pool) PdxInitializationException(org.apache.geode.pdx.PdxInitializationException)

Example 3 with PdxInitializationException

use of org.apache.geode.pdx.PdxInitializationException in project geode by apache.

the class PeerTypeRegistration method initialize.

public void initialize() {
    AttributesFactory<Object, Object> factory = new AttributesFactory<Object, Object>();
    factory.setScope(Scope.DISTRIBUTED_ACK);
    if (cache.getPdxPersistent()) {
        if (cache.getCacheConfig().pdxDiskStoreUserSet) {
            factory.setDiskStoreName(cache.getPdxDiskStore());
        } else {
            factory.setDiskStoreName(cache.getOrCreateDefaultDiskStore().getName());
        }
        factory.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE);
    } else {
        factory.setDataPolicy(DataPolicy.REPLICATE);
    }
    // Add a listener that makes sure that if anyone in the DS is using PDX
    // Our PDX configuration is valid for this member. This is important if
    // we are the gateway, we need to validate that we have a distributed system
    // id.
    factory.addCacheListener(new CacheListenerAdapter<Object, Object>() {

        @Override
        public void afterCreate(EntryEvent<Object, Object> event) {
            verifyConfiguration();
            // update a local map with the pdxtypes registered
            Object value = event.getNewValue();
            if (value instanceof PdxType) {
                updateClassToTypeMap((PdxType) value);
            }
        }
    });
    factory.setCacheWriter(new CacheWriterAdapter<Object, Object>() {

        @Override
        public void beforeCreate(EntryEvent<Object, Object> event) throws CacheWriterException {
            Object newValue = event.getNewValue();
            if (newValue instanceof PdxType) {
                logger.info("Adding new type: {}", ((PdxType) event.getNewValue()).toFormattedString());
            } else {
                logger.info("Adding new type: {} {}", event.getKey(), ((EnumInfo) newValue).toFormattedString());
            }
        }

        @Override
        public void beforeUpdate(EntryEvent<Object, Object> event) throws CacheWriterException {
            if (!event.getRegion().get(event.getKey()).equals(event.getNewValue())) {
                PdxRegistryMismatchException ex = new PdxRegistryMismatchException("Trying to add a PDXType with the same id as an existing PDX type. id=" + event.getKey() + ", existing pdx type " + event.getOldValue() + ", new type " + event.getNewValue());
                throw new CacheWriterException(ex);
            }
        }
    });
    RegionAttributes<Object, Object> regionAttrs = factory.create();
    InternalRegionArguments internalArgs = new InternalRegionArguments();
    internalArgs.setIsUsedForMetaRegion(true);
    internalArgs.setMetaRegionWithTransactions(true);
    try {
        this.idToType = cache.createVMRegion(REGION_NAME, regionAttrs, internalArgs);
    } catch (IOException ex) {
        throw new PdxInitializationException("Could not create pdx registry", ex);
    } catch (TimeoutException ex) {
        throw new PdxInitializationException("Could not create pdx registry", ex);
    } catch (RegionExistsException ex) {
        throw new PdxInitializationException("Could not create pdx registry", ex);
    } catch (ClassNotFoundException ex) {
        throw new PdxInitializationException("Could not create pdx registry", ex);
    }
    // And send those types to any existing gateways.
    if (!getIdToType().isEmpty()) {
        verifyConfiguration();
    }
}
Also used : InternalRegionArguments(org.apache.geode.internal.cache.InternalRegionArguments) RegionExistsException(org.apache.geode.cache.RegionExistsException) IOException(java.io.IOException) PdxInitializationException(org.apache.geode.pdx.PdxInitializationException) AttributesFactory(org.apache.geode.cache.AttributesFactory) PdxRegistryMismatchException(org.apache.geode.pdx.PdxRegistryMismatchException) CacheWriterException(org.apache.geode.cache.CacheWriterException) TimeoutException(org.apache.geode.cache.TimeoutException)

Aggregations

PdxInitializationException (org.apache.geode.pdx.PdxInitializationException)3 IOException (java.io.IOException)1 Set (java.util.Set)1 InternalGemFireError (org.apache.geode.InternalGemFireError)1 AttributesFactory (org.apache.geode.cache.AttributesFactory)1 CacheWriterException (org.apache.geode.cache.CacheWriterException)1 RegionExistsException (org.apache.geode.cache.RegionExistsException)1 TimeoutException (org.apache.geode.cache.TimeoutException)1 Pool (org.apache.geode.cache.client.Pool)1 ReplyException (org.apache.geode.distributed.internal.ReplyException)1 ReplyProcessor21 (org.apache.geode.distributed.internal.ReplyProcessor21)1 InternalRegionArguments (org.apache.geode.internal.cache.InternalRegionArguments)1 PdxRegistryMismatchException (org.apache.geode.pdx.PdxRegistryMismatchException)1