예제 #1
0
  @Test
  public void testEventTrace() {
    KevoreeFactory factory = new DefaultKevoreeFactory();
    ContainerRoot model = factory.createContainerRoot();

    ContainerNode node0 = factory.createContainerNode();
    node0.setName("node0");
    model.addNodes(node0);

    ContainerNode web = factory.createContainerNode();
    web.setName("web");
    model.addNodes(web);
    node0.addHosts(web);

    try {

      ContainerRoot clonedModel = (ContainerRoot) cloner.clone(model);

      EventListenerImpl listener = new EventListenerImpl();
      model.addModelTreeListener(listener);

      ContainerNode newChildNode = factory.createContainerNode();
      newChildNode.setName("toto");
      model.addNodes(newChildNode);
      node0.addHosts(newChildNode);

      listener.traceSequence.applyOn(clonedModel);

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
예제 #2
0
  @Start
  public void start() {
    Log.debug("Start WSChan");
    clients = new HashMap<>();
    if (path == null) {
      path = "";
    }

    ContainerRoot model = modelService.getPendingModel();
    if (model == null) {
      model = modelService.getCurrentModel().getModel();
    }
    Channel thisChan = (Channel) model.findByPath(context.getPath());
    Set<String> inputPaths = Helper.getProvidedPortsPath(thisChan, context.getNodeName());
    Set<String> outputPaths = Helper.getRequiredPortsPath(thisChan, context.getNodeName());

    for (String path : inputPaths) {
      // create input WSMsgBroker clients
      createInputClient(path + "_" + context.getInstanceName());
    }

    for (String path : outputPaths) {
      // create output WSMsgBroker clients
      createOutputClient(path + "_" + context.getInstanceName());
    }
  }
예제 #3
0
  @Override
  public void dispatch(String o, final Callback callback) {
    ContainerRoot model = modelService.getCurrentModel().getModel();
    Channel thisChan = (Channel) model.findByPath(context.getPath());
    Set<String> outputPaths = Helper.getRequiredPortsPath(thisChan, context.getNodeName());

    // create a list of destination paths
    Set<String> destPaths = new HashSet<>();
    // process remote paths in order to add _<chanName> to the paths
    // (WsMsgBroker protocol)
    // add processed remote path to dest
    destPaths.addAll(
        channelContext
            .getRemotePortPaths()
            .stream()
            .map(remotePath -> remotePath + "_" + context.getInstanceName())
            .collect(Collectors.toList()));
    // add local connected inputs to dest
    Set<String> providedPaths =
        Helper.getProvidedPortsPath(thisChan, context.getNodeName())
            .stream()
            .map(s -> s + "_" + context.getInstanceName())
            .collect(Collectors.toSet());

    destPaths.addAll(providedPaths);
    // create the array that will store the dest
    String[] dest = new String[destPaths.size()];
    // convert list to array
    destPaths.toArray(dest);

    for (final String outputPath : outputPaths) {
      WSMsgBrokerClient client = this.clients.get(outputPath + "_" + context.getInstanceName());
      if (client != null) {
        if (callback != null) {
          client.send(
              o,
              dest,
              (from, o1) -> {
                CallbackResult result = new CallbackResult();
                result.setPayload(o1.toString());
                result.setOriginChannelPath(context.getPath());
                result.setOriginPortPath(outputPath);
                callback.onSuccess(result);
              });
        } else {
          client.send(o, dest);
        }
      } else {
        createInputClient(outputPath + "_" + context.getInstanceName());
      }
    }
  }
예제 #4
0
 private String findChannel(
     ContainerRoot model, String componentName, String portName, String nodeName) {
   for (MBinding mbinding : model.getMBindings()) {
     if (mbinding.getPort().getPortTypeRef().getName().equals(portName)
         && ((ComponentInstance) mbinding.getPort().eContainer()).getName().equals(componentName)
         && ((ContainerNode) mbinding.getPort().eContainer().eContainer())
             .getName()
             .equals(nodeName)) {
       org.kevoree.log.Log.debug(mbinding.getHub().getName());
       return mbinding.getHub().getName();
     }
   }
   return null;
 }
예제 #5
0
 private String[] getWebServerName(ContainerRoot model) {
   for (ContainerNode node : model.getNodes()) {
     for (ComponentInstance component : node.getComponents()) {
       //				for (TypeDefinition typeDefinition :
       // component.getTypeDefinition().getSuperTypesForJ()) {
       org.kevoree.log.Log.debug(component.getTypeDefinition().getName());
       if ("SprayWebServer"
           .equals(
               component
                   .getTypeDefinition()
                   .getName())) { // must be change if the webserver implementation is changed
         return new String[] {component.getName(), node.getName()};
       }
       //				}
     }
   }
   return null;
 }