/** * 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); }
@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); }
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); } }
private PhysicalChannelConnectionDefinition generateProducerConnection(LogicalProducer producer, LogicalChannel channel, PhysicalConnectionSourceDefinition sourceDefinition, URI classLoaderId, PhysicalEventStreamDefinition eventStream) throws GenerationException { if (!channel.getZone().equals(producer.getParent().getZone()) && !channel.isBound()) { String name = channel.getDefinition().getName(); throw new GenerationException("Binding not configured on a channel where the producer is in a different zone: " + name); } PhysicalConnectionTargetDefinition targetDefinition = new ChannelTargetDefinition(channel.getUri(), ChannelSide.PRODUCER); targetDefinition.setClassLoaderId(classLoaderId); return new PhysicalChannelConnectionDefinition(sourceDefinition, targetDefinition, eventStream); }
@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); }
@SuppressWarnings({"unchecked"}) private PhysicalChannelConnectionDefinition generateProducerBinding(LogicalProducer producer, LogicalChannel channel, ChannelDeliveryType deliveryType, URI classLoaderId, PhysicalEventStreamDefinition eventStream) throws GenerationException { LogicalBinding<?> binding = channel.getBinding(); ConnectionBindingGenerator bindingGenerator = getGenerator(binding); PhysicalConnectionTargetDefinition targetDefinition = bindingGenerator.generateConnectionTarget(producer, binding, deliveryType); targetDefinition.setClassLoaderId(classLoaderId); ChannelSourceDefinition sourceDefinition = new ChannelSourceDefinition(channel.getUri(), ChannelSide.PRODUCER); sourceDefinition.setClassLoaderId(classLoaderId); return new PhysicalChannelConnectionDefinition(sourceDefinition, targetDefinition, eventStream); }
private PhysicalChannelConnectionDefinition generateConsumerConnection(LogicalConsumer consumer, LogicalChannel channel, PhysicalConnectionTargetDefinition targetDefinition, URI classLoaderId, PhysicalEventStreamDefinition eventStream) throws GenerationException { // the channel does not have bindings, which means it is a local channel if (!channel.getZone().equals(consumer.getParent().getZone()) && !channel.isBound()) { String name = channel.getDefinition().getName(); throw new GenerationException("Binding not configured on a channel where the consumer is in a different zone: " + name); } // construct a local connection to the channel PhysicalConnectionSourceDefinition sourceDefinition = new ChannelSourceDefinition(channel.getUri(), ChannelSide.CONSUMER); sourceDefinition.setSequence(consumer.getDefinition().getSequence()); sourceDefinition.setClassLoaderId(classLoaderId); return new PhysicalChannelConnectionDefinition(sourceDefinition, targetDefinition, eventStream); }
@SuppressWarnings({"unchecked"}) private PhysicalChannelConnectionDefinition generateConsumerBinding(LogicalConsumer consumer, LogicalChannel channel, ChannelDeliveryType deliveryType, URI classLoaderId, PhysicalEventStreamDefinition eventStream) throws GenerationException { // use the bindings on the channel to create a consumer binding configuration LogicalBinding<?> binding = channel.getBinding(); ConnectionBindingGenerator bindingGenerator = getGenerator(binding); PhysicalConnectionSourceDefinition sourceDefinition = bindingGenerator.generateConnectionSource(consumer, binding, deliveryType); sourceDefinition.setSequence(consumer.getDefinition().getSequence()); sourceDefinition.setClassLoaderId(classLoaderId); ChannelTargetDefinition targetDefinition = new ChannelTargetDefinition(channel.getUri(), ChannelSide.CONSUMER); targetDefinition.setClassLoaderId(classLoaderId); return new PhysicalChannelConnectionDefinition(sourceDefinition, targetDefinition, eventStream); }