Exemple #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());
    }
  }
Exemple #2
0
  private void createOutputClient(final String id) {
    Log.debug("createOutputClient : " + id);
    this.clients.put(
        id,
        new WSMsgBrokerClient(id, host, port, path, true) {
          @Override
          public void onUnregistered(String s) {
            Log.debug("{} unregistered from remote server", id);
          }

          @Override
          public void onRegistered(String s) {
            Log.debug("{} registered on remote server", id);
          }

          @Override
          public void onMessage(Object o, final Response response) {}

          @Override
          public void onClose(int code, String reason) {
            Log.debug("Connection closed by remote server for {}", id);
          }

          @Override
          public void onError(Exception e) {}
        });
  }
 private void buildCache() {
   StringBuilder slideListBuilder = new StringBuilder();
   StringBuilder menuBuilder = new StringBuilder();
   boolean isFirst = true;
   for (String componentName : slidesList.keySet()) {
     menuBuilder
         .append("<li><a onclick=\"document.querySelector('#presentation').innerHTML = '")
         .append(componentName);
     if (!"".equals(slidesList.get(componentName)[1])) {
       menuBuilder
           .append(" - <a href=\\'")
           .append(slidesList.get(componentName)[1])
           .append("\\'>Read the paper</a>");
     }
     menuBuilder
         .append("'; ks.sendEvent(null, {'type':'RELOAD', 'url':'")
         .append(slidesList.get(componentName)[0])
         .append("'});\">")
         .append(componentName)
         .append("</a></li>\n");
     if (isFirst) {
       isFirst = false;
       slideListBuilder
           .append("jQuery(document).ready(function ($) {\n")
           .append("document.querySelector('#presentation').innerHTML = '")
           .append(componentName)
           .append("';\n\t\t") /*.append("\t\tks.sendEvent(null, {'type':'RELOAD', 'url':'")
                       .append(slidesList.get(componentName)[0]).append("'});")*/
           .append("\n});");
       if (variables.get("embedder") != null) {
         variables.put(
             "embedder",
             variables.get("embedder").replace("{slideurl}", slidesList.get(componentName)[0]));
       }
     }
   }
   org.kevoree.log.Log.debug("menu = {}", menuBuilder.toString());
   org.kevoree.log.Log.debug("slides = {}", slideListBuilder.toString());
   variables.put("menu", menuBuilder.toString());
   variables.put("initSlides", slideListBuilder.toString());
 }
Exemple #4
0
 @Stop
 public void stop() {
   Log.debug("Stop WSChan");
   if (this.clients != null) {
     clients
         .values()
         .stream()
         .filter(client -> client != null)
         .forEach(fr.braindead.wsmsgbroker.WSMsgBrokerClient::close);
     this.clients = null;
   }
 }
 @Stop
 public void stopSystemComponent() throws Exception {
   Log.debug(
       "Stopping system component with command: {}",
       this.getDictionary().get("STOP_COMMAND").toString());
   Process p = Runtime.getRuntime().exec(this.getDictionary().get("STOP_COMMAND").toString());
   new Thread(new ProcessStreamFileLogger(p.getInputStream())).start();
   new Thread(new ProcessStreamFileLogger(p.getErrorStream())).start();
   if (p.waitFor() != 0) {
     throw new Exception(
         "Unable to execute command: " + this.getDictionary().get("STOP_COMMAND").toString());
   }
 }
Exemple #6
0
  private void createInputClient(final String id) {
    Log.debug("createInputClient : " + id);
    this.clients.put(
        id,
        new WSMsgBrokerClient(id, host, port, path, true) {
          @Override
          public void onUnregistered(String s) {
            Log.info("{} unregistered from remote server", id);
          }

          @Override
          public void onRegistered(String s) {
            Log.info("{} registered on remote server", id);
          }

          @Override
          public void onMessage(Object o, final Response response) {
            Callback cb = null;

            if (response != null) {
              cb =
                  new Callback() {
                    @Override
                    public void onSuccess(CallbackResult o) {
                      if (o != null) {
                        response.send(o);
                      }
                    }

                    @Override
                    public void onError(Throwable throwable) {
                      response.send(throwable);
                    }
                  };
            }

            List<Port> ports = channelContext.getLocalPorts();
            for (Port p : ports) {
              p.send(o.toString(), cb);
            }
          }

          @Override
          public void onClose(int code, String reason) {
            Log.error("Connection closed by remote server for {}", id);
          }

          @Override
          public void onError(Exception e) {}
        });
  }
 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;
 }
 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;
 }
 private void apply(KevScriptEngine kengine, int tries) {
   if (tries < 5) {
     try {
       mainSite.getModelService().unregisterModelListener(this);
       kengine.atomicInterpretDeploy();
       mainSite.getModelService().registerModelListener(this);
       buildCache();
       String pattern = mainSite.getDictionary().get("urlpattern").toString();
       if (pattern.endsWith("**")) {
         pattern = pattern.replace("**", "");
       }
       if (!pattern.endsWith("/")) {
         pattern = pattern + "/";
       }
       mainSite.invalidateCacheResponse(pattern + "talks");
     } catch (Exception ignored) {
       org.kevoree.log.Log.debug("Unable to define talks.", ignored);
     }
   } else {
     org.kevoree.log.Log.warn("Unable to define talks (see debug logs for more info");
   }
 }