Search in sources :

Example 1 with Start

use of com.nokia.dempsy.annotations.Start in project Dempsy by Dempsy.

the class MpContainer method preInitializePrototype.

/**
    * Run any methods annotated PreInitilze on the MessageProcessor prototype
    * @param prototype reference to MessageProcessor prototype
    */
private void preInitializePrototype(Object prototype) {
    for (Method method : prototype.getClass().getMethods()) {
        if (method.isAnnotationPresent(com.nokia.dempsy.annotations.Start.class)) {
            // if the start method takes a ClusterId or ClusterDefinition then pass it.
            Class<?>[] parameterTypes = method.getParameterTypes();
            boolean takesClusterId = false;
            if (parameterTypes != null && parameterTypes.length == 1) {
                if (ClusterId.class.isAssignableFrom(parameterTypes[0]))
                    takesClusterId = true;
                else {
                    logger.error("The method \"" + method.getName() + "\" on " + SafeString.objectDescription(prototype) + " is annotated with the @" + Start.class.getSimpleName() + " annotation but doesn't have the correct signature. " + "It needs to either take no parameters or take a single " + ClusterId.class.getSimpleName() + " parameter.");
                    // return without invoking start.
                    return;
                }
            } else if (parameterTypes != null && parameterTypes.length > 1) {
                logger.error("The method \"" + method.getName() + "\" on " + SafeString.objectDescription(prototype) + " is annotated with the @" + Start.class.getSimpleName() + " annotation but doesn't have the correct signature. " + "It needs to either take no parameters or take a single " + ClusterId.class.getSimpleName() + " parameter.");
                // return without invoking start.
                return;
            }
            try {
                if (takesClusterId)
                    method.invoke(prototype, clusterId);
                else
                    method.invoke(prototype);
                // Only allow one such method, which is checked during validation
                break;
            } catch (Exception e) {
                logger.error(MarkerFactory.getMarker("FATAL"), "can't run MP initializer " + method.getName(), e);
            }
        }
    }
}
Also used : ClusterId(com.nokia.dempsy.config.ClusterId) Start(com.nokia.dempsy.annotations.Start) Method(java.lang.reflect.Method) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) SerializationException(com.nokia.dempsy.serialization.SerializationException)

Aggregations

Start (com.nokia.dempsy.annotations.Start)1 ClusterId (com.nokia.dempsy.config.ClusterId)1 SerializationException (com.nokia.dempsy.serialization.SerializationException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1