Search in sources :

Example 36 with StringId

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;
}
Also used : StringId(org.apache.geode.i18n.StringId) Constructor(java.lang.reflect.Constructor) ObjectStreamClass(java.io.ObjectStreamClass) InvocationTargetException(java.lang.reflect.InvocationTargetException) DataSerializer(org.apache.geode.DataSerializer)

Example 37 with StringId

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;
}
Also used : Constructor(java.lang.reflect.Constructor) Instantiator(org.apache.geode.Instantiator) InvocationTargetException(java.lang.reflect.InvocationTargetException) StringId(org.apache.geode.i18n.StringId)

Example 38 with StringId

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);
}
Also used : StringId(org.apache.geode.i18n.StringId) ConflictingPersistentDataException(org.apache.geode.cache.persistence.ConflictingPersistentDataException)

Example 39 with StringId

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;
}
Also used : StringId(org.apache.geode.i18n.StringId) CancelException(org.apache.geode.CancelException) AsyncEventListener(org.apache.geode.cache.asyncqueue.AsyncEventListener)

Example 40 with StringId

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());
}
Also used : StringId(org.apache.geode.i18n.StringId) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Aggregations

StringId (org.apache.geode.i18n.StringId)43 IOException (java.io.IOException)14 AuthorizeRequest (org.apache.geode.internal.security.AuthorizeRequest)11 LocalRegion (org.apache.geode.internal.cache.LocalRegion)10 CachedRegionHelper (org.apache.geode.internal.cache.tier.CachedRegionHelper)8 Part (org.apache.geode.internal.cache.tier.sockets.Part)8 TimeoutException (org.apache.geode.cache.TimeoutException)6 HashSet (java.util.HashSet)5 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 CancelException (org.apache.geode.CancelException)4 InterestResultPolicy (org.apache.geode.cache.InterestResultPolicy)4 RegisterInterestOperationContext (org.apache.geode.cache.operations.RegisterInterestOperationContext)4 CqClosedException (org.apache.geode.cache.query.CqClosedException)4 CqException (org.apache.geode.cache.query.CqException)4 CqExistsException (org.apache.geode.cache.query.CqExistsException)4 QueryException (org.apache.geode.cache.query.QueryException)4 RegionNotFoundException (org.apache.geode.cache.query.RegionNotFoundException)4 LinkedHashSet (java.util.LinkedHashSet)3