public ChannelEventHandler(ChannelConnection connection, boolean channelEvent) { this.channelEvent = channelEvent; stream = connection.getEventStream(); }
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(ChannelConnection connection) { EventStream stream = connection.getEventStream(); String topic = connection.getTopic(); TopicHandlers topicHandlers = getTopicHandlers(topic, true); stream.getTailHandler().setNext(topicHandlers.inHandler); }
public JDKEventHandler(ChannelConnection connection) { this.stream = connection.getEventStream(); this.closeable = connection.getCloseable(); }
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); } }
@SuppressWarnings("unchecked") public void attach(PhysicalConnectionSource source, NATSConnectionTarget target, ChannelConnection connection) { Nats nats = connectionManager.getNats(target); if (!source.isDirectConnection()) { String topic = target.getTopic() != null ? target.getTopic() : target.getDefaultTopic(); String serializerName = target.getData().getSerializer(); Function<Object, String> serializer = serializerName != null ? InstanceResolver.getInstance(serializerName, info, cm) : null; connection.getEventStream().addHandler((event, batch) -> { String serialized = serializer != null ? serializer.apply(event) : event.toString(); nats.publish(topic, serialized); }); connection.setCloseable(() -> connectionManager.release(target.getChannelUri(), topic)); } }
public void attach(NonManagedConnectionSource source, PhysicalConnectionTarget target, ChannelConnection connection) { if (source.isDirectConnection()) { source.setProxy(connection.getDirectConnection().get().get()); } else { Class<?> interfaze = source.getInterface(); Object proxy = proxyService.createSupplier(interfaze, connection).get(); source.setProxy(proxy); } }
public void attach(PhysicalConnectionSource source, ChannelTarget target, ChannelConnection connection) { if (source.isDirectConnection()) { // no event stream to attach since this is a direct connection return; } URI uri = target.getUri(); Channel channel = getChannel(uri, target.getChannelSide()); channel.attach(connection); connection.setCloseable(() -> { // no-op }); }
public Object subscribe(Class<?> type, String name, String id, String topic, java.util.function.Consumer<?> consumer) { LogicalChannel logicalChannel = getChannel(name); LogicalConsumer logicalConsumer = createConsumer(type, logicalChannel.getUri()); PhysicalChannel physicalChannel = channelGenerator.generate(logicalChannel, SYNTHETIC_CONTRIBUTION, CONSUMER); channelBuilderRegistry.build(physicalChannel); Map<LogicalChannel, DeliveryType> channels = Collections.singletonMap(logicalChannel, DeliveryType.DEFAULT); List<PhysicalChannelConnection> connections = connectionGenerator.generateConsumer(logicalConsumer, channels); // Two connections will be created: one from the binding to the channel, the other from the channel to the component // the closeable will be set on the connection from the binding to the channel; it must be passed to the component Closeable closeable = null; for (PhysicalChannelConnection connection : connections) { connection.setTopic(topic); connection.getSource().setTopic(topic); connection.getTarget().setTopic(topic); connection.getTarget().setConsumer(consumer); ChannelConnection channelConnection = channelConnector.connect(connection); if (channelConnection.getCloseable() != null) { closeable = channelConnection.getCloseable(); } } return closeable; }
public void subscribe(URI uri, ChannelConnection connection) { String topic = connection.getTopic(); TopicHandlers topicHandlers = getTopicHandlers(topic, true); topicHandlers.fanOutHandler.addConnection(uri, connection); }
public JDKEventHandler(ChannelConnection connection) { this.stream = connection.getEventStream(); this.closeable = connection.getCloseable(); }
public void attach(NATSConnectionSource source, PhysicalConnectionTarget target, ChannelConnection connection) { String topic = source.getTopic() != null ? source.getTopic() : source.getDefaultTopic(); connection.setCloseable(() -> connectionManager.release(source.getChannelUri(), topic)); if (target.isDirectConnection()) { Class<?> type = target.getServiceInterface(); connectionManager.createDirectConsumer(type, source); // create consumer, which will be returned by the direct connection factory } else { String deserializerName = source.getData().getDeserializer(); Function deserializer = deserializerName != null ? InstanceResolver.getInstance(deserializerName, info, cm) : null; connection.getEventStream().addHandler(0, new EventStreamHandler() { private EventStreamHandler next; @SuppressWarnings("unchecked") public void handle(Object message, boolean batch) { Object body = deserializer != null ? deserializer.apply(message) : message; next.handle(body, batch); } public void setNext(EventStreamHandler next) { this.next = next; } public EventStreamHandler getNext() { return next; } }); connectionManager.subscribe(source, connection); } }
public void attach(NonManagedConnectionSource source, PhysicalConnectionTarget target, ChannelConnection connection) { if (source.isDirectConnection()) { source.setProxy(connection.getDirectConnection().get().get()); } else { Class<?> interfaze = source.getInterface(); Object proxy = proxyService.createSupplier(interfaze, connection).get(); source.setProxy(proxy); } }
public void attach(PhysicalConnectionSource source, ChannelTarget target, ChannelConnection connection) { if (source.isDirectConnection()) { // no event stream to attach since this is a direct connection return; } URI uri = target.getUri(); Channel channel = getChannel(uri, target.getChannelSide()); channel.attach(connection); connection.setCloseable(() -> { // no-op }); }
public Object subscribe(Class<?> type, String name, String id, String topic, java.util.function.Consumer<?> consumer) { LogicalChannel logicalChannel = getChannel(name); LogicalConsumer logicalConsumer = createConsumer(type, logicalChannel.getUri()); PhysicalChannel physicalChannel = channelGenerator.generate(logicalChannel, SYNTHETIC_CONTRIBUTION, CONSUMER); channelBuilderRegistry.build(physicalChannel); Map<LogicalChannel, DeliveryType> channels = Collections.singletonMap(logicalChannel, DeliveryType.DEFAULT); List<PhysicalChannelConnection> connections = connectionGenerator.generateConsumer(logicalConsumer, channels); // Two connections will be created: one from the binding to the channel, the other from the channel to the component // the closeable will be set on the connection from the binding to the channel; it must be passed to the component Closeable closeable = null; for (PhysicalChannelConnection connection : connections) { connection.setTopic(topic); connection.getSource().setTopic(topic); connection.getTarget().setTopic(topic); connection.getTarget().setConsumer(consumer); ChannelConnection channelConnection = channelConnector.connect(connection); if (channelConnection.getCloseable() != null) { closeable = channelConnection.getCloseable(); } } return closeable; }
public void subscribe(URI uri, ChannelConnection connection) { String topic = connection.getTopic(); TopicHandlers topicHandlers = getTopicHandlers(topic, true); topicHandlers.fanOutHandler.addConnection(uri, connection); }
public static boolean isChannelEvent(ChannelConnection connection) { return ChannelEvent.class.isAssignableFrom(connection.getEventStream().getEventType()); }
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(ChannelConnection connection) { EventStream stream = connection.getEventStream(); String topic = connection.getTopic(); TopicHandlers topicHandlers = getTopicHandlers(topic, true); stream.getTailHandler().setNext(topicHandlers.inHandler); }
public void attach(SystemConnectionSource source, PhysicalConnectionTarget target, ChannelConnection connection) { URI sourceUri = source.getUri(); URI sourceName = UriHelper.getDefragmentedName(sourceUri); SystemComponent component = (SystemComponent) manager.getComponent(sourceName); Injectable injectable = source.getInjectable(); Class<?> type = source.getServiceInterface(); Supplier<?> supplier; if (source.isDirectConnection()) { supplier = connection.getDirectConnection().get(); } else { supplier = proxyService.createSupplier(type, connection); } component.setSupplier(injectable, supplier); }