public void addChannelWrapper(MBinding binding, ChannelWrapper chan) { delegate.put(binding.getHub().path()+"_"+binding.getPort().path(), chan); }
public void removeChannelWrapper(MBinding binding) { delegate.remove(binding.getHub().path()+"_"+binding.getPort().path()); } }
private void monkeyPatchKMF(ContainerRoot proposedModel) { for (MBinding possibleBinding : proposedModel.getmBindings()) { String chanPath = (possibleBinding.getHub() != null ? possibleBinding.getHub().path() : "UNDEFINED"); String portPath = (possibleBinding.getPort() != null ? possibleBinding.getPort().path() : "UNDEFINED"); String hash = hash(chanPath + "_" + portPath); possibleBinding.reflexiveMutator(ActionType.SET, "generated_KMF_ID", hash, true, false); } }
@Override public List<String> getRemotePortPaths() { ArrayList<String> result = new ArrayList<String>(); Channel channel = (Channel) modelService.getCurrentModel().getModel().findByPath(channelPath); if (channel != null) { for (MBinding binding : channel.getBindings()) { ContainerNode parentNode = (ContainerNode) binding.getPort().eContainer().eContainer(); if (parentNode != null) { if (!parentNode.getName().equals(localNodePath)) { org.kevoree.Port finalPort = binding.getPort(); if (finalPort != null) { result.add(finalPort.path()); } } } } } return result; } }
public static void interpret(IAST<Type> stmt, ContainerRoot model, Map<String, String> ctxVars) throws Exception { final List<Instance> channelsInstance2 = InstanceResolver.resolve(stmt.getChildren().get(1), model, ctxVars); final List<Port> ports = PortResolver.resolve(model, stmt.getChildren().get(0)); for (final Instance instance : channelsInstance2) { final Channel channel = (Channel) instance; MBinding toDrop = null; for (final MBinding mb : channel.getBindings()) { for (final Port p : ports) { if (mb.getPort().equals(p)) { toDrop = mb; } } } if (toDrop != null) { toDrop.delete(); } } } }
public static void interpret(IAST<Type> stmt, ContainerRoot model, Map<String, String> ctxVars) throws KevScriptException { final List<Instance> channelsInstance2 = InstanceResolver.resolve(stmt.getChildren().get(1), model, ctxVars); final List<Port> ports = PortResolver.resolve(model, stmt.getChildren().get(0)); for (final Instance instance : channelsInstance2) { final Channel channel = (Channel) instance; MBinding toDrop = null; for (final MBinding mb : channel.getBindings()) { for (final Port p : ports) { if (mb.getPort().equals(p)) { toDrop = mb; } } } if (toDrop != null) { toDrop.delete(); } } } }
public boolean execute() { try { Object kevoreeChannelFound = registry.lookup(c.getHub()); Object kevoreeComponentFound = registry.lookup(c.getPort().eContainer()); if(kevoreeChannelFound != null && kevoreeComponentFound != null && kevoreeComponentFound instanceof ComponentWrapper && kevoreeChannelFound instanceof ChannelWrapper){ String portName = c.getPort().getPortTypeRef().getName(); RequiredPortImpl foundNeedPort = ((ComponentWrapper) kevoreeComponentFound).getRequiredPorts().get(portName); ProvidedPortImpl foundHostedPort = ((ComponentWrapper) kevoreeComponentFound).getProvidedPorts().get(portName); if(foundNeedPort == null && foundHostedPort == null){ Log.info("Port instance not found in component"); return false; } if (foundNeedPort != null) { foundNeedPort.removeChannelWrapper(c); return true; } ((ChannelWrapper) kevoreeChannelFound).getContext().getPortsBinded().remove(foundHostedPort.getPath()); return true; } else { return false; } } catch (Exception e) { System.err.println("REMOVE BINDING FAILED"); e.printStackTrace(); } return false; }
private boolean isVirtual(KMFContainer element) { if (element instanceof Instance) { return isVirtual(((Instance) element).getTypeDefinition()); } else if (element instanceof TypeDefinition) { Value virtual = ((TypeDefinition) element).findMetaDataByID("virtual"); return virtual != null; } else if (element instanceof MBinding) { MBinding binding = (MBinding) element; if (binding.getHub() != null) { return isVirtual(binding.getHub().getTypeDefinition()); } if (binding.getPort() != null) { return isVirtual(binding.getPort().eContainer()); } } return false; }
@Override public boolean execute() { Object chan = registry.lookup(c.getHub()); Object comp = registry.lookup(c.getPort().eContainer()); if (chan != null && comp != null && comp instanceof ComponentWrapper && chan instanceof ChannelWrapper) { String portName = c.getPort().getPortTypeRef().getName(); RequiredPortImpl output = ((ComponentWrapper) comp).getRequiredPorts().get(portName); ProvidedPortImpl input = ((ComponentWrapper) comp).getProvidedPorts().get(portName); if (output == null && input == null) { Log.info("Port instance {} not found in component", portName); return false; } if (output != null) { output.addChannelWrapper(c, (ChannelWrapper) chan); Log.info("Bind {} {}", c.getPort().path(), c.getHub().path()); return true; } // Seems useless ((ChannelWrapper) chan).getContext().getBoundPorts().put(input.getPath(), input); Log.info("Bind {} {}", c.getPort().path(), c.getHub().path()); return true; } else { Log.error("Error while apply binding , channelFound=" + chan + ", componentFound=" + comp); return false; } }