@SuppressWarnings({"unchecked"}) private DataType getEventType(EventStream stream) { return new JavaType(stream.getEventType()); }
public static boolean isChannelEvent(ChannelConnection connection) { return ChannelEvent.class.isAssignableFrom(connection.getEventStream().getEventType()); }
private void addTypeTransformer(PhysicalChannelConnection connection, EventStream stream, ClassLoader loader) { if (transformerHandlerFactory == null) { return; // bootstrap } List<DataType> sourceTypes = connection.getSource().getDataTypes(); List<DataType> targetTypes = connection.getTarget().getDataTypes(); if (sourceTypes.isEmpty() || targetTypes.isEmpty()) { return; } if (sourceTypes.size() > 1 || targetTypes.size() > 1) { // for now, only support one data type throw new Fabric3Exception("Multi-type events are not supported"); } DataType sourceType = sourceTypes.get(0); DataType targetType = targetTypes.get(0); if (sourceType.equals(targetType)) { return; } List<Class<?>> eventTypes = Collections.singletonList(stream.getEventType()); EventStreamHandler handler = transformerHandlerFactory.createHandler(sourceType, targetType, eventTypes, loader); stream.addHandler(handler); }
private void addTypeTransformer(PhysicalChannelConnection connection, EventStream stream, ClassLoader loader) { if (transformerHandlerFactory == null) { return; // bootstrap } List<DataType> sourceTypes = connection.getSource().getDataTypes(); List<DataType> targetTypes = connection.getTarget().getDataTypes(); if (sourceTypes.isEmpty() || targetTypes.isEmpty()) { return; } if (sourceTypes.size() > 1 || targetTypes.size() > 1) { // for now, only support one data type throw new Fabric3Exception("Multi-type events are not supported"); } DataType sourceType = sourceTypes.get(0); DataType targetType = targetTypes.get(0); if (sourceType.equals(targetType)) { return; } List<Class<?>> eventTypes = Collections.singletonList(stream.getEventType()); EventStreamHandler handler = transformerHandlerFactory.createHandler(sourceType, targetType, eventTypes, loader); stream.addHandler(handler); }
public void attach(PhysicalConnectionSource source, NonManagedConnectionTarget target, ChannelConnection connection) { if (target.isDirectConnection()) { target.setCloseable(connection.getCloseable()); target.setProxy(connection.getDirectConnection().get().get()); } else { Consumer<Object> consumer = Cast.cast(target.getConsumer()); EventStream stream = connection.getEventStream(); Class<?> type = stream.getEventType(); if (!Object.class.equals(type)) { // add a filter if the event type is not Object stream.addHandler(new FilterHandler(type)); } stream.addHandler((event, endOfBatch) -> consumer.accept(event)); } }
public void attach(PhysicalConnectionSource source, NonManagedConnectionTarget target, ChannelConnection connection) { if (target.isDirectConnection()) { target.setCloseable(connection.getCloseable()); target.setProxy(connection.getDirectConnection().get().get()); } else { Consumer<Object> consumer = Cast.cast(target.getConsumer()); EventStream stream = connection.getEventStream(); Class<?> type = stream.getEventType(); if (!Object.class.equals(type)) { // add a filter if the event type is not Object stream.addHandler(new FilterHandler(type)); } stream.addHandler((event, endOfBatch) -> consumer.accept(event)); } }
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); } }