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);
}
}
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;
}
}
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();
}
}
Aggregations