Set<Class<?>> providedFlavors = new HashSet<Class<?>>();
for (MessageReference providedMessage : providedMessages) {
try {
providedFlavors.add(getFactory().loadClass(providedMessage.getJavaType()));
} catch (ClassNotFoundException e) {
throw new ConfigurationException(e.getLocalizedMessage());
}
}
isRegisteredProducer = !providedFlavors.isEmpty();
messageFlavors = providedFlavors.toArray(new Class[providedFlavors.size()]);
producerId = NAME+"["+getInstanceManager().getInstanceName()+"]";
sessionId = Long.toString(System.currentTimeMillis());
wires.clear();
ApamAtomicComponentFactory implementation = (ApamAtomicComponentFactory) getFactory();
ImplementationDeclaration declaration = implementation.getDeclaration();
if (! (declaration instanceof AtomicImplementationDeclaration))
return;
/*
* Register instrumentation for message push at the provider side
*/
PojoMetadata manipulation = getFactory().getPojoMetadata();
AtomicImplementationDeclaration primitive = (AtomicImplementationDeclaration) declaration;
for (ProviderInstrumentation providerInstrumentation : primitive.getProviderInstrumentation()) {
MessageReference messageReference = providerInstrumentation.getProvidedResource().as(MessageReference.class);
if (messageReference == null)
continue;
if (! (providerInstrumentation instanceof ProviderInstrumentation.MessageProviderMethodInterception))
continue;
ProviderInstrumentation.MessageProviderMethodInterception interception =
(ProviderInstrumentation.MessageProviderMethodInterception) providerInstrumentation;
/*
* Search for the specified method to intercept, we always look for a perfect match of the
* specified signature, and do not allow ambiguous method names
*/
MethodMetadata candidate = null;
for (MethodMetadata method : manipulation.getMethods(interception.getMethodName())) {
if (interception.getMethodSignature() == null) {
candidate = method;
break;
}
String signature[] = Util.split(interception.getMethodSignature());
String arguments[] = method.getMethodArguments();
boolean match = (signature.length == arguments.length);
for (int i = 0; match && i < signature.length; i++) {
if (!signature[i].equals(arguments[i]))
match = false;
}
match = match && method.getMethodReturn().equals(messageReference.getJavaType());
if (match) {
candidate = method;
break;
}
}
if (candidate != null) {
getInstanceManager().register(candidate,this);
continue;
}
throw new ConfigurationException("Message producer intercepted methdod not found "+interception.getMethodName()+
"("+interception.getMethodSignature() != null ? interception.getMethodSignature(): ""+")");
}
}