use of org.apache.geode.i18n.StringId in project geode by apache.
the class InternalDataSerializer method newInstance.
/**
* Instantiates an instance of {@code DataSerializer}
*
* @throws IllegalArgumentException If the class can't be instantiated
*
* @see DataSerializer#register(Class)
*/
private static DataSerializer newInstance(Class c) {
if (!DataSerializer.class.isAssignableFrom(c)) {
throw new IllegalArgumentException(LocalizedStrings.DataSerializer_0_DOES_NOT_EXTEND_DATASERIALIZER.toLocalizedString(c.getName()));
}
Constructor init;
try {
init = c.getDeclaredConstructor(new Class[0]);
} catch (NoSuchMethodException ignored) {
StringId s = LocalizedStrings.DataSerializer_CLASS_0_DOES_NOT_HAVE_A_ZEROARGUMENT_CONSTRUCTOR;
Object[] args = new Object[] { c.getName() };
if (c.getDeclaringClass() != null) {
s = LocalizedStrings.DataSerializer_CLASS_0_DOES_NOT_HAVE_A_ZEROARGUMENT_CONSTRUCTOR_IT_IS_AN_INNER_CLASS_OF_1_SHOULD_IT_BE_A_STATIC_INNER_CLASS;
args = new Object[] { c.getName(), c.getDeclaringClass() };
}
throw new IllegalArgumentException(s.toLocalizedString(args));
}
DataSerializer s;
try {
init.setAccessible(true);
s = (DataSerializer) init.newInstance(new Object[0]);
} catch (IllegalAccessException ignored) {
throw new IllegalArgumentException(LocalizedStrings.DataSerializer_COULD_NOT_INSTANTIATE_AN_INSTANCE_OF_0.toLocalizedString(c.getName()));
} catch (InstantiationException ex) {
throw new IllegalArgumentException(LocalizedStrings.DataSerializer_COULD_NOT_INSTANTIATE_AN_INSTANCE_OF_0.toLocalizedString(c.getName()), ex);
} catch (InvocationTargetException ex) {
throw new IllegalArgumentException(LocalizedStrings.DataSerializer_WHILE_INSTANTIATING_AN_INSTANCE_OF_0.toLocalizedString(c.getName()), ex);
}
return s;
}
use of org.apache.geode.i18n.StringId in project geode by apache.
the class InternalInstantiator method newInstance.
/**
* Reflectively instantiates an instance of {@code Instantiator}.
*
* @param instantiatorClass The implementation of {@code Instantiator} to instantiate
* @param instantiatedClass The implementation of {@code DataSerialization} that will be produced
* by the {@code Instantiator}
*
* @throws IllegalArgumentException If the class can't be instantiated
*/
protected static Instantiator newInstance(Class instantiatorClass, Class instantiatedClass, int id) {
if (!Instantiator.class.isAssignableFrom(instantiatorClass)) {
throw new IllegalArgumentException(LocalizedStrings.InternalInstantiator_0_DOES_NOT_EXTEND_INSTANTIATOR.toLocalizedString(instantiatorClass.getName()));
}
Constructor init;
boolean intConstructor = false;
Class[] types;
try {
types = new Class[] { Class.class, int.class };
init = instantiatorClass.getDeclaredConstructor(types);
intConstructor = true;
} catch (NoSuchMethodException ex) {
// for backwards compat check for (Class, byte)
try {
types = new Class[] { Class.class, byte.class };
init = instantiatorClass.getDeclaredConstructor(types);
} catch (NoSuchMethodException ex2) {
StringId msg = LocalizedStrings.InternalInstantiator_CLASS_0_DOES_NOT_HAVE_A_TWOARGUMENT_CLASS_INT_CONSTRUCTOR;
Object[] msgArgs = new Object[] { instantiatorClass.getName() };
if (instantiatorClass.getDeclaringClass() != null) {
msg = LocalizedStrings.InternalInstantiator_CLASS_0_DOES_NOT_HAVE_A_TWOARGUMENT_CLASS_INT_CONSTRUCTOR_IT_IS_AN_INNER_CLASS_OF_1_SHOULD_IT_BE_A_STATIC_INNER_CLASS;
msgArgs = new Object[] { instantiatorClass.getName(), instantiatorClass.getDeclaringClass() };
}
throw new IllegalArgumentException(msg.toLocalizedString(msgArgs));
}
}
Instantiator s;
try {
init.setAccessible(true);
Object[] args = new Object[] { instantiatedClass, intConstructor ? (Object) Integer.valueOf(id) : (Object) Byte.valueOf((byte) id) };
s = (Instantiator) init.newInstance(args);
} catch (IllegalAccessException ex) {
throw new IllegalArgumentException(LocalizedStrings.InternalInstantiator_COULD_NOT_ACCESS_ZEROARGUMENT_CONSTRUCTOR_OF_0.toLocalizedString(instantiatorClass.getName()));
} catch (InstantiationException ex) {
RuntimeException ex2 = new IllegalArgumentException(LocalizedStrings.InternalInstantiator_COULD_NOT_INSTANTIATE_AN_INSTANCE_OF_0.toLocalizedString(instantiatorClass.getName()));
ex2.initCause(ex);
throw ex2;
} catch (InvocationTargetException ex) {
RuntimeException ex2 = new IllegalArgumentException(LocalizedStrings.InternalInstantiator_WHILE_INSTANTIATING_AN_INSTANCE_OF_0.toLocalizedString(instantiatorClass.getName()));
ex2.initCause(ex);
throw ex2;
}
return s;
}
use of org.apache.geode.i18n.StringId in project geode by apache.
the class LocalRegion method handleDiskAccessException.
/**
* @param dae DiskAccessException encountered by the thread
* @param duringInitialization indicates that this exception occurred during region
* initialization. Instead of closing the cache here, we rely on the region initialization
* to clean things up.
* @see DistributedRegion#initialize(InputStream, InternalDistributedMember,
* InternalRegionArguments)
* @see LocalRegion#initialize(InputStream, InternalDistributedMember, InternalRegionArguments)
* @see InitialImageOperation#processChunk
*/
public void handleDiskAccessException(DiskAccessException dae, boolean duringInitialization) {
if (duringInitialization && !(dae instanceof ConflictingPersistentDataException)) {
return;
}
if (causedByRDE(dae)) {
return;
}
// log the error
StringId sid = LocalizedStrings.LocalRegion_A_DISKACCESSEXCEPTION_HAS_OCCURRED_WHILE_WRITING_TO_THE_DISK_FOR_REGION_0_THE_CACHE_WILL_BE_CLOSED;
logger.error(LocalizedMessage.create(sid, this.fullPath), dae);
// forward the error to the disk store
getDiskStore().handleDiskAccessException(dae);
}
use of org.apache.geode.i18n.StringId in project geode by apache.
the class GatewaySenderEventCallbackDispatcher method dispatchBatch.
/**
* Sends a batch of messages to the registered <code>AsyncEventListener</code>s.
*
* @param events The <code>List</code> of events to send
*
* @throws GatewaySenderException
*/
protected boolean dispatchBatch(List events) throws GatewaySenderException {
if (events.isEmpty()) {
return true;
}
int batchId = this.eventProcessor.getBatchId();
boolean successAll = true;
try {
for (AsyncEventListener listener : this.eventListeners) {
boolean successOne = listener.processEvents(events);
if (!successOne) {
successAll = false;
}
}
} catch (Exception e) {
final StringId alias = LocalizedStrings.SerialGatewayEventCallbackDispatcher__0___EXCEPTION_DURING_PROCESSING_BATCH__1_;
final Object[] aliasArgs = new Object[] { this, Integer.valueOf(batchId) };
String exMsg = alias.toLocalizedString(aliasArgs);
GatewaySenderException ge = new GatewaySenderException(exMsg, e);
logger.warn(LocalizedMessage.create(alias, aliasArgs), ge);
throw ge;
}
return successAll;
}
use of org.apache.geode.i18n.StringId in project geode by apache.
the class LocalizedMessageJUnitTest method testZeroParams.
@Test
public void testZeroParams() {
final StringId stringId = new StringId(100, "This is a message for testZeroParams");
final LocalizedMessage message = LocalizedMessage.create(stringId);
assertNull(message.getParameters());
}
Aggregations