/** * Convenience getter as channels can be configured with only one binding. * * @return the binding or null if the channel is not bound */ public LogicalBinding getBinding() { if (getBindings().isEmpty()) { return null; } return getBindings().get(0); }
@Override public void addBinding(LogicalBinding<?> binding) { if (!getBindings().isEmpty()) { throw new IllegalStateException("Channel is already configured with a binding"); } super.addBinding(binding); }
@SuppressWarnings("unchecked") public PhysicalChannel generate(LogicalChannel channel, URI contributionUri, ChannelDirection direction) { String type = channel.getDefinition().getType(); ChannelGeneratorExtension generator = extensions.get(type); if (generator == null) { throw new Fabric3Exception("Channel generator not found: " + type); } PhysicalChannel physicalChannel = generator.generate(channel, contributionUri); if (!channel.getBindings().isEmpty()) { // generate binding information physicalChannel.setBound(true); physicalChannel.setChannelSide(ChannelDirection.CONSUMER == direction ? ChannelSide.CONSUMER : ChannelSide.PRODUCER); } else { physicalChannel.setChannelSide(ChannelSide.COLLOCATED); } return physicalChannel; }
@SuppressWarnings("unchecked") public PhysicalChannel generate(LogicalChannel channel, URI contributionUri, ChannelDirection direction) { String type = channel.getDefinition().getType(); ChannelGeneratorExtension generator = extensions.get(type); if (generator == null) { throw new Fabric3Exception("Channel generator not found: " + type); } PhysicalChannel physicalChannel = generator.generate(channel, contributionUri); if (!channel.getBindings().isEmpty()) { // generate binding information physicalChannel.setBound(true); physicalChannel.setChannelSide(ChannelDirection.CONSUMER == direction ? ChannelSide.CONSUMER : ChannelSide.PRODUCER); } else { physicalChannel.setChannelSide(ChannelSide.COLLOCATED); } return physicalChannel; }
/** * Selects and configures a binding for a channel. * * @param channel the channel * @throws BindingSelectionException if an error occurs selecting a binding */ private void selectBinding(LogicalChannel channel) throws BindingSelectionException { if (channel.isConcreteBound()) { return; } List<BindingMatchResult> results = new ArrayList<BindingMatchResult>(); for (BindingProvider provider : providers) { BindingMatchResult result = provider.canBind(channel); if (result.isMatch()) { // clear binding.sca channel.clearBinding(); provider.bind(channel); if (channel.getBindings().isEmpty()) { QName type = result.getType(); throw new BindingSelectionException("Binding provider error. Provider did not set a binding for the channel: " + type); } return; } results.add(result); } URI uri = channel.getUri(); throw new NoSCABindingProviderException("No SCA binding provider suitable for channel " + uri, results); }
@SuppressWarnings({"unchecked"}) private PhysicalChannelDefinition generateChannelDefinition(LogicalChannel channel, QName deployable, Direction direction) throws GenerationException { LogicalBinding<?> binding = channel.getBinding(); String type = channel.getDefinition().getType(); ChannelGenerator generator = channelGenerators.get(type); if (generator == null) { throw new GenerationException("Channel generator not found: " + type); } PhysicalChannelDefinition definition = generator.generate(channel, deployable); if (!channel.getBindings().isEmpty()) { // generate binding information if (!(binding.getDefinition() instanceof SCABinding)) { // avoid generating SCABinding ConnectionBindingGenerator bindingGenerator = getGenerator(binding); ChannelDeliveryType deliveryType = definition.getDeliveryType(); PhysicalChannelBindingDefinition bindingDefinition = bindingGenerator.generateChannelBinding(binding, deliveryType); definition.setBindingDefinition(bindingDefinition); definition.setChannelSide(Direction.CONSUMER == direction ? ChannelSide.CONSUMER : ChannelSide.PRODUCER); } else { definition.setChannelSide(ChannelSide.COLLOCATED); } } else { definition.setChannelSide(ChannelSide.COLLOCATED); } return definition; }