public void attach(PhysicalConnectionSource source, SystemConnectionTarget target, ChannelConnection connection) { URI targetUri = target.getUri(); URI targetName = UriHelper.getDefragmentedName(targetUri); SystemComponent component = (SystemComponent) manager.getComponent(targetName); if (component == null) { throw new Fabric3Exception("Target component not found: " + targetName); } ClassLoader loader = target.getClassLoader(); Method method = (Method) target.getConsumerObject(); // if the object is not a method, it is a programming error ConsumerInvoker invoker = reflectionFactory.createConsumerInvoker(method); EventStream stream = connection.getEventStream(); Class<?> type = connection.getEventStream().getEventType(); if (!Object.class.equals(type)) { // add a filter if the event type is not Object stream.addHandler(new FilterHandler(type)); } InvokerEventStreamHandler handler = new InvokerEventStreamHandler(invoker, component, loader); stream.addHandler(handler); }
public void attach(PhysicalConnectionSource source, JavaConnectionTarget target, ChannelConnection connection) { URI targetUri = target.getUri(); URI targetName = UriHelper.getDefragmentedName(targetUri); JavaComponent component = (JavaComponent) manager.getComponent(targetName); if (component == null) { throw new Fabric3Exception("Target component not found: " + targetName); } if (target.isDirectConnection()) { // A direct connection; create a setter that will inject the field, method or ctor param annotated with @Consumer component.setSupplier(target.getInjectable(), connection.getDirectConnection().get()); } else { // Not a direct connection; a consumer method that is invoked and passed an event from the channel via an event stream // Note that a null supplier must be injected in this case as the @Consumer annotation creates an injector for the case where the // method takes a direct connection to the channel. The null supplier forces the injector not to activate since the @Consumer method is used to // receive events and not serve as a setter for the direct connection component.setSupplier(target.getInjectable(), () -> null); ClassLoader loader = target.getClassLoader(); Method method = (Method) target.getConsumerObject(); // if the object is not a method, it is a programming error ConsumerInvoker invoker = reflectionFactory.createConsumerInvoker(method); EventStream stream = connection.getEventStream(); Class<?> type = connection.getEventStream().getEventType(); if (!Object.class.equals(type)) { // add a filter if the event type is not Object stream.addHandler(new FilterHandler(type)); } InvokerEventStreamHandler handler = new InvokerEventStreamHandler(invoker, component, loader); stream.addHandler(handler); } }