Package pt.opensoft.util

Examples of pt.opensoft.util.Timer


        final InetSocketAddress address = new InetSocketAddress(_host, _port);
        final CGISocket protocol = new CGISocket(address, CONNECT_TIMEOUT);
        protocol.setTimeout(CONNECT_TIMEOUT);
        String response = "";
        try {
          Timer timer = new Timer();
          timer.start();
          // write message request to server
          String request = (String) iterator.next();
          if (request != null) _logger.info(timer.ellapsed(), "[SENT] {" + request + "}");
          protocol.write(request);
          // read message response from server
          response = protocol.read();
          if (response != null) _logger.info(timer.ellapsed(), "[RCVD] {" + response + "}");
        } finally {
          protocol.close();
        }
      }
    } catch (IOException e) {
View Full Code Here


    this.logger.push("HttpConnection");
   
    HttpResponse response = null;
    Exception ex = null;
   
    Timer timer = new Timer();
    timer.start();

    boolean timeout = false;
    try {
      if (isDebug()) {
        this.logger.setLevel(Level.DEBUG);
      } else {
        this.logger.setLevel(Level.INFO);
      }
     
      this.logger.debug("BEFORE SEND " + timer.ellapsed() + " ms");

      if (this.isJavaHttpConnection) {
        response = this.javaHttpConnection.send();
      } else {
        response = this.httpConnection.send();
      }
     
      this.logger.debug("AFTER  SEND " + timer.ellapsed() + " ms");
     
      // n�o basta o debug estar ligado para se mostrar a resposta do servidor. nesse caso o logger ter� de estar em finer
      this.logger.finer("RECEIVED    \n" + response);
    } catch (ConnectionTimeoutException e) {
      ex = e;
      throw e;
    } catch (SocketTimeoutException e) {
      timeout = true;
      ex = e;
      throw e;
    } catch (InterruptedIOException e) {
      ex = e;
      throw e;
    } catch (IOException e) {
      if (e.getLocalizedMessage().equals("java.net.SocketTimeoutException: Read timed out")) {
        timeout = true;
        throw new SocketTimeoutException();
      }
      ex = e;
      throw e;
    } finally {
      timer.stop();
      boolean tooLong = (this.threshold > 0 && timer.ellapsed() > this.threshold);
      if (tooLong) {
        this.logger.push("too long");
      }
      if (timeout) {
        this.logger.push("timeout");
      }
      if (ex != null && !timeout) {
        this.logger.error(timer.ellapsed(), ex.getMessage());
      } else if (tooLong || timeout) {
        logger.warning(timer.ellapsed(), this.user + " " + this.application + " [" + this.url + "]");
      } else {
        logger.debug(timer.ellapsed(), this.user + " " + this.application + " [" + this.url + "]");
      }
      this.logger.pop();
      if (tooLong) {
        this.logger.pop();
      }
View Full Code Here

    this(DEFAULT_APP_NAME, name);
  }

  public JSFTransaction(String app, String name) {
    super(name, true);
    processTimer = new Timer();
    logger = Logger.getDefault().getWrapper();
    if (app != null) {
      application = app;
    } else {
      application = DEFAULT_APP_NAME;
View Full Code Here

    protected Exception exception = null;
    protected Thread thread = null;

    protected Daemon(String name) {
        super(name);
        timer = new Timer();
        logger = Logger.getDefault().getWrapper();
        logger.push("DAEMON");
        logger.push(name);
//    setStartedAt(new DateTime());
    }
View Full Code Here

      while (hasTime()) {
        if (!storage.hasProductsToConsume()) {
          logger.info("FINISHED: NO MORE PRODUCTS");
          return;
        }
        Timer timer = new Timer();
        timer.start();
        Object product = storage.retrieve();
        if (product == null) {
          logger.info("FINISHED: NO MORE PRODUCTS TO CONSUME");
          return;
        }
        Exception exception = null;
        do {
          if (exception != null) timer.start();
          try {
            consume(product);
            exception = null;
          } catch (Exception e) {
            exception = e;
            logger.error(timer.ellapsed(), "INTERRUPTED FOR " + new Time(sleepOnError) + ": " + e.getMessage());
            sleep(sleepOnError);
            reset();
          } catch (Throwable e) {
            storage.recycle(product);
            throw e;
          }
        } while (exception != null);
        logger.debug(timer.ellapsed(), "CONSUMED " + product);
        stats.add();
      }
    } catch (Throwable e) {
      logger.error("ABORTED: " + e.getMessage(), e);
      error(e);
View Full Code Here

   * @see     java.lang.Thread#Thread(java.lang.ThreadGroup,
   *          java.lang.Runnable, java.lang.String)
   * @see     java.lang.Runnable#run()
   */
  public void run () {
    Timer timer = new Timer();
    try {
      String response = null;
      try {
        timer.start();
        _socket.setTimeout(timeout);
        String request = _socket.read();
        request = StringUtil.toString_ISO_8859_1(request);
        //request = StringUtil.toString_CP_850(request);
       
        _logger.info("[RCVD] {" + request + "}");

                String reqCode = parseReqCode(request);
                String respCode = getRespCodeFromReqCode(reqCode);

                boolean exists = (new File(_dir, respCode + ".txt")).exists();
               
                if (!exists) {
                  response = send(request);
                } else {
                  if (_removesLineBreaks) {
                    response = readFile(respCode + ".txt");
                  } else {
                    response = readFile2(respCode + ".txt");
                  }
                  response = StringUtil.toString_CP_850(response);
                }

                _socket.write(response);

      } finally {
        if (response != null) _logger.info(timer.ellapsed(), "[SENT] {" + response+"}");
        _socket.close();
      }
    } catch (Exception e) {
      _logger.error("N�o foi poss�vel processar o pedido" + e.getMessage(), e);
    }
View Full Code Here

        return "" + reqCode.charAt(0) + numericPart + reqCode.substring(CODE_LENGTH);
    }
   
    protected String send (String request) throws HostException {
    Timer totalTimer = new Timer();
    totalTimer.start();
    Timer sendTimer = new Timer();
    sendTimer.start();
    Timer receiveTimer = new Timer();
    String response = null;
    boolean tooLongAlreadyDumped = false;
       
    try {
      CGISocket socket = createSocket();

      try {
        socket.setTimeout(timeout);
        request = transformRequest(request);
        socket.write(request);
        sendTimer.stop();
        logger.finer(sendTimer.ellapsed(), "[SENT] {" + request + "} (len=" + request.length() + ")");
        receiveTimer.start();
        response = socket.read();
        response = transformResponse(response);
                receiveTimer.stop();
      } finally {
        socket.close();
                totalTimer.stop();
      }
    } catch (InterruptedIOException e) {
      logger.error(e);
      // s� mostra o erro se a mensagem n�o tiver dados confidenciais (ex: login)
        logger.error(sendTimer.ellapsed(), "[SENT] {" + request + "} (len=" + request.length() + ")");
      if (response != null && logger.getLevel().getLevel() < Level.FINER.getLevel()) {
                receiveTimer.stop();
                totalTimer.stop();
                if (threshold > 0 && !tooLongAlreadyDumped && totalTimer.ellapsed() > threshold){
                    logger.push("too long");
                    tooLongAlreadyDumped = true;
                }
                    logger.error(receiveTimer.ellapsed(), "[RCVD] {" + response + "} (len=" + response.length() + ")");
               
      }
     
      throw new HostUnavailableSystemException("SISTEMA CENTRAL INDISPONIVEL! ERRO COMUNICACOES! TIMEOUT!");

    } catch (Exception e) {
      logger.error(e);
      // s� mostra o erro se a mensagem n�o tiver dados confidenciais (ex: login)
   
      logger.error(sendTimer.ellapsed(), "[SENT] {" + request + "}");
   
      if (response != null && logger.getLevel().getLevel() < Level.FINER.getLevel()) {
                receiveTimer.stop();
                totalTimer.stop();
                if (threshold > 0 && !tooLongAlreadyDumped && totalTimer.ellapsed() > threshold){
                    logger.push("too long");
                    tooLongAlreadyDumped = true;
                }
        logger.error(receiveTimer.ellapsed(), "[RCVD] {" + response + "}");
      }
   
    throw new HostUnavailableSystemException("SISTEMA CENTRAL INDISPONIVEL! ERRO COMUNICACOES!");
    }
       
        if (threshold > 0 && !tooLongAlreadyDumped && totalTimer.ellapsed() > threshold){
            logger.push("too long");
            tooLongAlreadyDumped = true;
        }
        logger.finer(receiveTimer.ellapsed(), "[RCVD] {" + response + "} (len=" + response.length() + ")");
 
    return response;
  }
View Full Code Here

   *         query; never null
   * @throws java.sql.SQLException if a database-access error occurs.
   */

  public ResultSet executeQuery () throws SQLException {
    Timer timer = new Timer();
    timer.start();
    ResultSet results = null;
    Exception ex = null;
    Logger logger = _dbc.getLogger();
    logger.push("query");
    try {
      results = ((CallableStatement) _stmt).executeQuery();
    } catch (SQLException e) {
      ex = e;
      throw e;
    } finally {
      boolean tooLong = (_dbc.getThreshold() > 0 && timer.ellapsed() > _dbc.getThreshold());
      if (tooLong) logger.push("too long");
      if (ex != null) {
        logger.error(timer.ellapsed(), getSQLString() + " -> " + ex.getMessage());
      } else if (tooLong) {
        logger.warning(timer.ellapsed(), getSQLString());
      } else {
        logger.debug(timer.ellapsed(), getSQLString());
      }
    }
    return results;
  }
View Full Code Here

   *         for SQL statements that return nothing
   * @throws java.sql.SQLException if a database-access error occurs.
   */

  public int executeUpdate () throws SQLException {
    Timer timer = new Timer();
    timer.start();
    if(_doQueryTimeout)
    _stmt.setQueryTimeout(_queryTimeout);
    int count = 0;
    Exception ex = null;
    Logger logger = _dbc.getLogger();
    logger.push("update");
    try {
      count = ((CallableStatement) _stmt).executeUpdate();
    } catch (SQLException e) {
      ex = e;
      throw e;
    } finally {
            _dbc.setDbChanged(true);
            logger.push(count + " ROWS");
      boolean tooLong = (_dbc.getThreshold() > 0 && timer.ellapsed() > _dbc.getThreshold());
      if (ex != null) {
        logger.error(timer.ellapsed(), getSQLString() + " -> " + ex.getMessage());
      } else if (tooLong) {
        logger.warning(timer.ellapsed(), getSQLString());
      } else {
        logger.debug(timer.ellapsed(), getSQLString());
      }
    }
    return count;
  }
View Full Code Here

   * @throws java.sql.SQLException if a database-access error occurs.
   * @see java.sql.Statement#executeQuery(String)
   * @see java.sql.Statement#executeUpdate(String)
   */
  public boolean execute () throws SQLException {
    Timer timer = new Timer();
    timer.start();
    boolean result = false;
    Exception ex = null;
    Logger logger = _dbc.getLogger();
    logger.push("execute");
    try {
      result = ((CallableStatement) _stmt).execute();
        } catch (SQLException e) {
      ex = e;
      throw e;
    } finally {
            _dbc.setDbChanged(true);
      logger.push(String.valueOf(result));
      boolean tooLong = (_dbc.getThreshold() > 0 && timer.ellapsed() > _dbc.getThreshold());
            if (tooLong) logger.push("too long");
      if (ex != null) {
        logger.error(timer.ellapsed(), getSQLString() + " -> " + ex.getMessage());
      } else if (tooLong) {
        logger.warning(timer.ellapsed(), getSQLString());
      } else {
        logger.debug(timer.ellapsed(), getSQLString());
      }
    }
    return result;
  }
View Full Code Here

TOP

Related Classes of pt.opensoft.util.Timer

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.