@SuppressWarnings({"unchecked"}) public void disconnect(PhysicalChannelConnection physicalConnection) { PhysicalConnectionSource source = physicalConnection.getSource(); PhysicalConnectionTarget target = physicalConnection.getTarget(); Key key = new Key(source.getSourceId(), target.getTargetId()); Holder holder = cachedConnections.get(key); if (holder == null) { return; } if (holder.count.decrementAndGet() == 0) { cachedConnections.remove(key); } else { return; } SourceConnectionAttacher sourceAttacher = sourceAttachers.get(source.getClass()); if (sourceAttacher == null) { throw new Fabric3Exception("Attacher not found for type: " + source.getClass().getName()); } TargetConnectionAttacher targetAttacher = targetAttachers.get(target.getClass()); if (targetAttacher == null) { throw new Fabric3Exception("Attacher not found for type: " + target.getClass().getName()); } sourceAttacher.detach(source, target); targetAttacher.detach(source, target); }
@SuppressWarnings({"unchecked"}) public void disconnect(PhysicalChannelConnection physicalConnection) { PhysicalConnectionSource source = physicalConnection.getSource(); PhysicalConnectionTarget target = physicalConnection.getTarget(); Key key = new Key(source.getSourceId(), target.getTargetId()); Holder holder = cachedConnections.get(key); if (holder == null) { return; } if (holder.count.decrementAndGet() == 0) { cachedConnections.remove(key); } else { return; } SourceConnectionAttacher sourceAttacher = sourceAttachers.get(source.getClass()); if (sourceAttacher == null) { throw new Fabric3Exception("Attacher not found for type: " + source.getClass().getName()); } TargetConnectionAttacher targetAttacher = targetAttachers.get(target.getClass()); if (targetAttacher == null) { throw new Fabric3Exception("Attacher not found for type: " + target.getClass().getName()); } sourceAttacher.detach(source, target); targetAttacher.detach(source, target); }
@SuppressWarnings({"unchecked"}) public ChannelConnection connect(PhysicalChannelConnection physicalConnection) { PhysicalConnectionSource source = physicalConnection.getSource(); PhysicalConnectionTarget target = physicalConnection.getTarget(); Key key = new Key(source.getSourceId(), target.getTargetId()); Holder holder = cachedConnections.get(key); if (holder != null) { // connection is cached; don't engage a second one holder.count.incrementAndGet(); return holder.connection; } SourceConnectionAttacher sourceAttacher = sourceAttachers.get(source.getClass()); if (sourceAttacher == null) { throw new Fabric3Exception("Attacher not found for type: " + source.getClass().getName()); } TargetConnectionAttacher targetAttacher = targetAttachers.get(target.getClass()); if (targetAttacher == null) { throw new Fabric3Exception("Attacher not found for type: " + target.getClass().getName()); } ChannelConnection connection = createConnection(physicalConnection); sourceAttacher.attach(source, target, connection); targetAttacher.attach(source, target, connection); cachedConnections.put(key, new Holder(connection)); return connection; }
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); }
@SuppressWarnings({"unchecked"}) public ChannelConnection connect(PhysicalChannelConnection physicalConnection) { PhysicalConnectionSource source = physicalConnection.getSource(); PhysicalConnectionTarget target = physicalConnection.getTarget(); Key key = new Key(source.getSourceId(), target.getTargetId()); Holder holder = cachedConnections.get(key); if (holder != null) { // connection is cached; don't engage a second one holder.count.incrementAndGet(); return holder.connection; } SourceConnectionAttacher sourceAttacher = sourceAttachers.get(source.getClass()); if (sourceAttacher == null) { throw new Fabric3Exception("Attacher not found for type: " + source.getClass().getName()); } TargetConnectionAttacher targetAttacher = targetAttachers.get(target.getClass()); if (targetAttacher == null) { throw new Fabric3Exception("Attacher not found for type: " + target.getClass().getName()); } ChannelConnection connection = createConnection(physicalConnection); sourceAttacher.attach(source, target, connection); targetAttacher.attach(source, target, connection); cachedConnections.put(key, new Holder(connection)); return connection; }
public <T> T getConsumer(Class<T> interfaze, String name, String topic) { LogicalChannel logicalChannel = getChannel(name); LogicalConsumer consumer = createConsumer(interfaze, 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(consumer, channels); PhysicalChannelConnection connection = connections.get(0); // safe as there is only one connection connection.setTopic(topic); connection.getSource().setTopic(topic); connection.getTarget().setTopic(topic); channelConnector.connect(connection); NonManagedConnectionTarget target = (NonManagedConnectionTarget) connection.getTarget(); return interfaze.cast(target.getProxy()); }
public <T> T getConsumer(Class<T> interfaze, String name, String topic) { LogicalChannel logicalChannel = getChannel(name); LogicalConsumer consumer = createConsumer(interfaze, 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(consumer, channels); PhysicalChannelConnection connection = connections.get(0); // safe as there is only one connection connection.setTopic(topic); connection.getSource().setTopic(topic); connection.getTarget().setTopic(topic); channelConnector.connect(connection); NonManagedConnectionTarget target = (NonManagedConnectionTarget) connection.getTarget(); return interfaze.cast(target.getProxy()); }
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 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; }
private NonManagedConnectionSource connect(String topic, List<PhysicalChannelConnection> connections) { NonManagedConnectionSource source = null; for (PhysicalChannelConnection connection : connections) { connection.setTopic(topic); connection.getSource().setTopic(topic); connection.getTarget().setTopic(topic); channelConnector.connect(connection); if (connection.getSource() instanceof NonManagedConnectionSource) { source = (NonManagedConnectionSource) connection.getSource(); } } if (source == null) { throw new Fabric3Exception("NonManagedConnectionSource not found publishing to topic: " + topic); } return source; }
private NonManagedConnectionSource connect(String topic, List<PhysicalChannelConnection> connections) { NonManagedConnectionSource source = null; for (PhysicalChannelConnection connection : connections) { connection.setTopic(topic); connection.getSource().setTopic(topic); connection.getTarget().setTopic(topic); channelConnector.connect(connection); if (connection.getSource() instanceof NonManagedConnectionSource) { source = (NonManagedConnectionSource) connection.getSource(); } } if (source == null) { throw new Fabric3Exception("NonManagedConnectionSource not found publishing to topic: " + topic); } return source; }
PhysicalConnectionTarget target = physicalConnection.getTarget(); if (source.isDirectConnection() || target.isDirectConnection()) { } else { ClassLoader loader = physicalConnection.getTarget().getClassLoader(); Class<?> eventType = physicalConnection.getEventType(); EventStream stream = new EventStreamImpl(eventType);
PhysicalConnectionTarget target = physicalConnection.getTarget(); if (source.isDirectConnection() || target.isDirectConnection()) { } else { ClassLoader loader = physicalConnection.getTarget().getClassLoader(); Class<?> eventType = physicalConnection.getEventType(); EventStream stream = new EventStreamImpl(eventType);