@SuppressWarnings({"unchecked"}) public void disconnect(PhysicalChannelConnectionDefinition definition) throws BuilderException { PhysicalConnectionSourceDefinition source = definition.getSource(); PhysicalConnectionTargetDefinition target = definition.getTarget(); SourceConnectionAttacher sourceAttacher = sourceAttachers.get(source.getClass()); if (sourceAttacher == null) { throw new AttacherNotFoundException("Attacher not found for type: " + source.getClass().getName()); } TargetConnectionAttacher targetAttacher = targetAttachers.get(target.getClass()); if (targetAttacher == null) { throw new AttacherNotFoundException("Attacher not found for type: " + target.getClass().getName()); } sourceAttacher.detach(source, target); targetAttacher.detach(source, target); }
@SuppressWarnings({"unchecked"}) public void connect(PhysicalChannelConnectionDefinition definition) throws BuilderException { PhysicalConnectionSourceDefinition source = definition.getSource(); PhysicalConnectionTargetDefinition target = definition.getTarget(); SourceConnectionAttacher sourceAttacher = sourceAttachers.get(source.getClass()); if (sourceAttacher == null) { throw new AttacherNotFoundException("Attacher not found for type: " + source.getClass().getName()); } TargetConnectionAttacher targetAttacher = targetAttachers.get(target.getClass()); if (targetAttacher == null) { throw new AttacherNotFoundException("Attacher not found for type: " + target.getClass().getName()); } ChannelConnection connection = createConnection(definition); sourceAttacher.attach(source, target, connection); targetAttacher.attach(source, target, connection); }
public <T> T resolve(Class<T> interfaze, String name) throws ResolverException { try { LogicalChannel logicalChannel = getChannel(name); LogicalProducer producer = createProducer(interfaze, logicalChannel.getUri()); PhysicalChannelDefinition channelDefinition = channelGenerator.generateChannelDefinition(logicalChannel, SYNTHETIC_DEPLOYABLE, ChannelDirection.PRODUCER); channelBuilderRegistry.build(channelDefinition); Map<LogicalChannel, ChannelDeliveryType> channels = Collections.singletonMap(logicalChannel, ChannelDeliveryType.DEFAULT); List<PhysicalChannelConnectionDefinition> physicalDefinitions = connectionGenerator.generateProducer(producer, channels); for (PhysicalChannelConnectionDefinition physicalDefinition : physicalDefinitions) { channelConnector.connect(physicalDefinition); } for (PhysicalChannelConnectionDefinition physicalDefinition : physicalDefinitions) { PhysicalConnectionSourceDefinition source = physicalDefinition.getSource(); if (!(source instanceof NonManagedPhysicalConnectionSourceDefinition)) { continue; } NonManagedPhysicalConnectionSourceDefinition sourceDefinition = (NonManagedPhysicalConnectionSourceDefinition) source; return interfaze.cast(sourceDefinition.getProxy()); } throw new GenerationException("Source generator not found"); } catch (GenerationException | ContainerException e) { throw new ResolverException(e); } }
/** * Creates the connection. * * @param definition the connection definition * @return the connection * @throws BuilderException if there is an error creating the connection */ private ChannelConnection createConnection(PhysicalChannelConnectionDefinition definition) throws BuilderException { ClassLoader loader = classLoaderRegistry.getClassLoader(definition.getTarget().getClassLoaderId()); PhysicalEventStreamDefinition streamDefinition = definition.getEventStream(); EventStream stream = new EventStreamImpl(streamDefinition); addTransformer(streamDefinition, stream, loader); addFilters(streamDefinition, stream); addHandlers(streamDefinition, stream); int sequence = definition.getSource().getSequence(); return new ChannelConnectionImpl(stream, sequence); }