Ejemplo n.º 1
0
  @Override
  public String getFunctionValue(final Node node, final Parameters parameters) {
    if (log.isDebugEnabled()) {
      log.debug("node #" + node.getNumber());
      log.debug("params: " + parameters);
    }
    String status = getDownloadStatus(node);

    int timeout = 5;
    if (parameters.get(TIMEOUT) != null) {
      timeout = parameters.get(TIMEOUT);
    }

    if (status == null) {
      Action action = ActionRepository.getInstance().get("streams", "download_media");
      if (action == null) {
        throw new IllegalStateException("Action could not be found");
      }
      if (node.getCloud().may(action, null)) {
        synchronized (runningJobs) {
          Future<?> future = runningJobs.get(node.getNumber());
          if (future == null) {
            setDownloadStatus(node, "busy: " + System.currentTimeMillis());
            future = submit(node, parameters);

            ThreadPools.identify(
                future,
                DownloadFunction.class.getName()
                    + " downloading... for #"
                    + node.getNumber()
                    + " - status: "
                    + getDownloadStatus(node));
            String fname = ThreadPools.getString(future);
            log.info("Future name: " + fname);
            try {
              status = (String) future.get(timeout, TimeUnit.SECONDS);
              log.info("status: " + status);
            } catch (TimeoutException te) {
              status = ThreadPools.getString(future);
              log.info("TimeoutException: " + status);
            } catch (Exception e) {
              log.error(e);
            }

          } else {
            status = ThreadPools.getString(future);
          }
        }
        log.info("status: " + status);
        return status;
      } else {
        throw new org.mmbase.security.SecurityException("Not allowed");
      }
    }
    return status;
  }
Ejemplo n.º 2
0
  static {
    threadPools.put(
        Stage.TRANSCODER,
        new ThreadPoolExecutor(
            3,
            3,
            5 * 60,
            TimeUnit.SECONDS,
            new LinkedBlockingQueue<Runnable>(),
            new ThreadFactory() {
              public Thread newThread(Runnable r) {
                return ThreadPools.newThread(
                    r, "TranscoderThread-" + Stage.TRANSCODER + "-" + (transSeq++));
              }
            }));
    threadPools.put(
        Stage.RECOGNIZER,
        new ThreadPoolExecutor(
            3,
            3,
            5 * 60,
            TimeUnit.SECONDS,
            new LinkedBlockingQueue<Runnable>(),
            new ThreadFactory() {
              public Thread newThread(Runnable r) {
                return ThreadPools.newThread(
                    r, "TranscoderThread-" + Stage.RECOGNIZER + "-" + (transSeq++));
              }
            }));

    // register them too
    ThreadPools.getThreadPools()
        .put(Executors.class.getName() + "." + Stage.TRANSCODER, threadPools.get(Stage.TRANSCODER));
    ThreadPools.getThreadPools()
        .put(Executors.class.getName() + "." + Stage.RECOGNIZER, threadPools.get(Stage.RECOGNIZER));

    // fill the rest of the map too, so we don't have to think about it any more later on.
    for (Stage s : Stage.values()) {
      if (!threadPools.containsKey(s)) {
        threadPools.put(s, ThreadPools.jobsExecutor);
      }
    }
    // default configuration, 5 + 1 executors.
    for (int i = 0; i < 5; i++) {
      executorsMap.put(new CommandExecutor.Method(), Stage.TRANSCODER);
    }
    executorsMap.put(new CommandExecutor.Method(), Stage.RECOGNIZER);
    readConfiguration();
  }