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