Пример #1
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());
    }
  }
Пример #2
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());
      }
    }
  }