Package com.caucho.util

Examples of com.caucho.util.Alarm


    _isActive = true;

    assert(_task != null);

    _alarm = new Alarm("cron-resource", this, nextTime - now);

    if (log.isLoggable(Level.FINER))
      log.finer(this + " started. Next event at " + new Date(nextTime));
  }
View Full Code Here


  }

  private void stop()
  {
    _isActive = false;
    Alarm alarm = _alarm;
    _alarm = null;
   
    if (alarm != null)
      alarm.dequeue();

    if (_task instanceof Work)
      ((Work) _task).release();
    else if (_task instanceof TimerTask)
      ((TimerTask) _task).cancel();
View Full Code Here

  log.finer("[cgi] exec " + args[0]);
    }

    Runtime runtime = Runtime.getRuntime();
    Process process = null;
    Alarm alarm = null;

    try {
      File dir = new File(Vfs.lookup(realPath).getParent().getNativePath());

      if (log.isLoggable(Level.FINE)) {
        CharBuffer argsBuf = new CharBuffer();

        argsBuf.append('[');

        for (String arg : args) {
          if (argsBuf.length() > 1)
            argsBuf.append(", ");

          argsBuf.append('"');
          argsBuf.append(arg);
          argsBuf.append('"');
        }

        argsBuf.append(']');

        log.fine(L.l("exec {0} (pwd={1})", argsBuf, dir));

        if (log.isLoggable(Level.FINEST)) {
          for (String envElement : env)
            log.finest(envElement);
        }
      }

      process = runtime.exec(args, env, dir);

      InputStream inputStream = process.getInputStream();
      InputStream errorStream = process.getErrorStream();

      TimeoutAlarm timeout;
      timeout = new TimeoutAlarm(requestURI, process, inputStream);
      alarm = new Alarm(timeout, 360 * 1000);

      OutputStream outputStream = process.getOutputStream();

      TempBuffer tempBuf = TempBuffer.allocate();
      byte []buf = tempBuf.getBuffer();
     
      try {
  ServletInputStream sis = req.getInputStream();
  int len;

  while ((len = sis.read(buf, 0, buf.length)) > 0) {
    outputStream.write(buf, 0, len);
  }

  outputStream.flush();
      } catch (IOException e) {
  log.log(Level.FINER, e.toString(), e);
      } finally {
  outputStream.close();
      }
     
      TempBuffer.free(tempBuf);
      tempBuf = null;

      ReadStream rs = Vfs.openRead(inputStream);
      boolean hasStatus = false;

      try {
  hasStatus = parseHeaders(req, res, rs);

  OutputStream out = res.getOutputStream();

  rs.writeToStream(out);
      } finally {
  try {
    rs.close();
  } catch (Throwable e) {
    log.log(Level.FINER, e.toString(), e);

  }

  inputStream.close();
      }

      StringBuilder error = new StringBuilder();
      boolean hasContent = false;
      int ch;

      while (errorStream.available() > 0 && (ch = errorStream.read()) > 0) {
  error.append((char) ch);

  if (! Character.isWhitespace((char) ch))
    hasContent = true;
      }
      errorStream.close();

      if (hasContent) {
  String errorString = error.toString();

  log.warning(errorString);

  if (! hasStatus && _stderrIsException)
    throw new ServletException(errorString);
      }

      int exitCode = process.waitFor();

      if (exitCode != 0) {
        if (hasStatus) {
          if (log.isLoggable(Level.FINER))
            log.finer(L.l("exit code {0} (ignored, hasStatus)", exitCode));
        }
        else if (_ignoreExitCode) {
          if (log.isLoggable(Level.FINER))
            log.finer(L.l("exit code {0} (ignored)", exitCode));
        }
        else
    throw new ServletException(L.l("CGI execution failed.  Exit code {0}",
                 exitCode));
      }
    } catch (IOException e) {
      throw e;
    } catch (ServletException e) {
      throw e;
    } catch (Exception e) {
      throw new ServletException(e);
    } finally {
      if (alarm != null)
  alarm.dequeue();

      try {
  process.destroy();
      } catch (Throwable e) {
      }
View Full Code Here

  TransactionImpl(TransactionManagerImpl manager)
  {
    _transactionManager = manager;
    _timeout = _transactionManager.getTimeout();
    _status = Status.STATUS_NO_TRANSACTION;
    _alarm = new Alarm("xa-timeout", this, ClassLoader.getSystemClassLoader());
  }
View Full Code Here

    }

    if (_sessions == null)
      return;

    Alarm alarm = _alarm;
    _alarm = null;

    if (alarm != null)
      alarm.dequeue();

    ArrayList<SessionImpl> list = new ArrayList<SessionImpl>();

    // XXX: messy way of dealing with saveOnlyOnShutdown
    synchronized (_sessions) {
View Full Code Here

  {
    _hostContainer = new HostContainer();
    _hostContainer.setClassLoader(_classLoader);
    _hostContainer.setDispatchServer(this);

    _alarm = new Alarm(this);

    _webBeans = InjectManager.create();

    _brokerManager = createBrokerManager();
    _domainManager = createDomainManager();
View Full Code Here

        return;

      // notify other servers that we've stopped
      notifyStop();

      Alarm alarm = _alarm;
      _alarm = null;

      if (alarm != null)
        alarm.dequeue();

      if (getSelectManager() != null)
        getSelectManager().stop();

      ArrayList<SocketLinkListener> ports = _ports;
View Full Code Here

      stop();

    if (! _lifecycle.toDestroy())
      return false;

    Alarm alarm = _alarm;
    _alarm = null;

    if (alarm != null) {
      alarm.dequeue();
    }
   
    return true;
  }
View Full Code Here

    initDatabase();

    _serverVersion = initVersion();
    _startupLastUpdateTime = initLastUpdateTime();

    _alarm = new Alarm(this);
    handleAlarm(_alarm);
  }
View Full Code Here

    return 0;
  }

  public void close()
  {
    Alarm alarm = _alarm;
    _alarm = null;

    if (alarm != null)
      alarm.close();
  }
View Full Code Here

TOP

Related Classes of com.caucho.util.Alarm

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.