Ejemplo n.º 1
0
 private boolean sendModel(ContainerRoot model, String urlPath, Boolean zip) {
   try {
     ByteArrayOutputStream outStream = new ByteArrayOutputStream();
     if (zip) {
       KevoreeXmiHelper.saveCompressedStream(outStream, model);
     } else {
       KevoreeXmiHelper.saveStream(outStream, model);
     }
     outStream.flush();
     logger.debug("Try URL PATH " + urlPath);
     URL url = new URL(urlPath);
     URLConnection conn = url.openConnection();
     conn.setConnectTimeout(3000);
     conn.setDoOutput(true);
     conn.getOutputStream().write(outStream.toByteArray());
     conn.getOutputStream().close();
     // Get the response
     BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
     String line = rd.readLine();
     while (line != null) {
       line = rd.readLine();
     }
     rd.close();
     return true;
   } catch (Exception e) {
     e.printStackTrace();
     return false;
   }
 }
Ejemplo n.º 2
0
  @Start
  public void start() {
    try {
      // todo check if not used
      ipc_key = gerRandom();
      ArrayList<String> repos = new ArrayList<String>();
      for (Repository repo : getModelService().getLastModel().getRepositoriesForJ()) {
        repos.add(repo.getUrl());
      }
      // loading model from jar
      ContainerRoot model =
          KevoreeXmiHelper.loadStream(getClass().getResourceAsStream("/KEV-INF/lib.kev"));
      File binary =
          getBootStrapperService()
              .resolveArtifact(
                  "org.kevoree.library.nativeN.faceDetection-wrapper" + getOs(),
                  "org.kevoree.library.nativeN",
                  "1.8.9-SNAPSHOT",
                  "uexe",
                  repos);
      if (binary != null) {
        if (!binary.canExecute()) {
          binary.setExecutable(true);
        }

        JarFile jarFile =
            new JarFile(
                getBootStrapperService()
                    .resolveArtifact(
                        "org.kevoree.library.nativeN.faceDetection-wrapper",
                        "org.kevoree.library.nativeN",
                        "1.8.9-SNAPSHOT",
                        "jar",
                        repos));

        final Enumeration<JarEntry> entries = jarFile.entries();
        while (entries.hasMoreElements()) {
          final JarEntry entry = entries.nextElement();
          if (entry.getName().contains(".")
              && !entry.getName().endsWith(".class")
              && !entry.getName().contains("META-INF")) {
            System.out.println("File : " + entry.getName());
            JarEntry fileEntry = jarFile.getJarEntry(entry.getName());
            InputStream input = jarFile.getInputStream(fileEntry);

            String file = System.getProperty("java.io.tmpdir") + entry.getName();
            File d = new File(file);
            d.mkdirs();
            FileManager.copyFileFromStream(
                input,
                System.getProperty("java.io.tmpdir") + "/FaceDetection/",
                entry.getName(),
                true);
          }
        }

        nativeManager = new NativeManager(ipc_key, binary.getPath(), model);

        nativeManager.addEventListener(
            new NativeListenerPorts() {
              @Override
              public void disptach(NativeEventPort event, String port_name, String msg) {
                MessagePort port = (MessagePort) getPortByName(port_name);
                port.process(msg);
              }
            });

        started = nativeManager.start();

        nativeManager.setDico("video", getDictionary().get("video").toString());

      } else {
        System.err.println(
            "The binary org.kevoree.library.nativeN.faceDetection-wrapper for the architecture "
                + getOs()
                + " is not found");
      }

    } catch (Exception e) {
      e.printStackTrace();
    }
  }