Examples of TimerContext


Examples of com.yammer.metrics.core.TimerContext

        return get;
    }

    @Override
    public void map(Result result, SolrUpdateWriter solrUpdateWriter) {
        TimerContext timerContext = mappingTimer.time();
        try {
            SolrInputDocument solrInputDocument = new SolrInputDocument();
            for (SolrDocumentExtractor documentExtractor : resultDocumentExtractors) {
                documentExtractor.extractDocument(result, solrInputDocument);
            }
            solrUpdateWriter.add(solrInputDocument);
        } finally {
            timerContext.stop();
        }
    }
View Full Code Here

Examples of com.yammer.metrics.core.TimerContext

     *
     * @param rowDataList list of RowData instances to be considered for indexing
     */
    public void indexRowData(List<RowData> rowDataList) throws IOException, SolrServerException, SharderException {
        SolrUpdateCollector updateCollector = new SolrUpdateCollector(rowDataList.size());
        TimerContext timerContext = indexingTimer.time();
        try {
            calculateIndexUpdates(rowDataList, updateCollector);
        } finally {
            timerContext.stop();
        }
        if (log.isDebugEnabled()) {
            log.debug(String.format("Indexer %s will send to Solr %s adds and %s deletes", getName(),
                    updateCollector.getDocumentsToAdd().size(), updateCollector.getIdsToDelete().size()));
        }
View Full Code Here

Examples of com.yammer.metrics.core.TimerContext

            rowReadTimer = Metrics.newTimer(metricName(getClass(), "Row read timer", indexerName), TimeUnit.MILLISECONDS,
                    TimeUnit.SECONDS);
        }

        private Result readRow(RowData rowData) throws IOException {
            TimerContext timerContext = rowReadTimer.time();
            try {
                HTableInterface table = tablePool.getTable(rowData.getTable());
                try {
                    Get get = mapper.getGet(rowData.getRow());
                    return table.get(get);
                } finally {
                    table.close();
                }
            } finally {
                timerContext.stop();
            }
        }
View Full Code Here

Examples of com.yammer.metrics.core.TimerContext

    }

    @Override
    public Context start()
    {
        final TimerContext context = timer.time();
        return new Context()
        {
            @Override
            public void stop()
            {
                context.stop();
            }
        };
    }
View Full Code Here

Examples of com.yammer.metrics.core.TimerContext

        }

        //---------------------------------------------------------------------
        //--- check access

                TimerContext timerContext = getMonitorManager().getTimer(ServiceManagerServicesTimer.class).time();
                try {
            response = srvInfo.execServices(req.getParams(), context);
                } finally {
                    timerContext.stop();
                }

                // Did we change some header on the service?
                for (Entry<String, String> entry : context.getResponseHeaders()
                        .entrySet()) {
View Full Code Here

Examples of com.yammer.metrics.core.TimerContext

      if (outPage.getContentType().equals("application/pdf") && !outPage.getStyleSheet().equals("")) {

        //--- build the xml data for the XSL/FO translation
        String styleSheet = outPage.getStyleSheet();
                Element guiElem;
                TimerContext guiServicesTimerContext = context.getMonitorManager().getTimer(ServiceManagerGuiServicesTimer.class).time();
                try {
            guiElem = outPage.invokeGuiServices(context, response, vDefaultGui);
                } finally {
                    guiServicesTimerContext.stop();
                }

                addPrefixes(guiElem, context.getLanguage(), req.getService(), context.getApplicationContext().getBean(NodeInfo.class)
                        .getId());

        Element rootElem = new Element(Jeeves.Elem.ROOT)
                        .addContent(guiElem)
                        .addContent(response);

        Element reqElem = (Element) req.getParams().clone();
        reqElem.setName(Jeeves.Elem.REQUEST);

        rootElem.addContent(reqElem);

        //--- do an XSL transformation

        styleSheet = appPath + Jeeves.Path.XSL + styleSheet;

        if (!new File(styleSheet).exists())
                    error(" -> stylesheet not found on disk, aborting : " + styleSheet);
                else {
                    info(" -> transforming with stylesheet : " + styleSheet);

                    try {
                        TimerContext timerContext = context.getMonitorManager().getTimer(ServiceManagerXslOutputTransformTimer.class)
                                .time();
                        String file;
                        try {
                            //--- first we do the transformation
                            file = Xml.transformFOP(uploadDir, rootElem, styleSheet);
                        } finally {
                            timerContext.stop();
                        }
                        response = BinaryFile.encode(200, file, "document.pdf", true);
                    } catch (Exception e) {
                        error(" -> exception during XSL/FO transformation for : " + req.getService());
                        error(" -> (C) stylesheet : " + styleSheet);
                        error(" -> (C) message : " + e.getMessage());
                        error(" -> (C) exception : " + e.getClass().getSimpleName());

            throw e;
          }

                    info(" -> end transformation for : " + req.getService());
        }

       
      }
      String contentType = BinaryFile.getContentType(response);

      if (contentType == null)
        contentType = "application/octet-stream";

      String contentDisposition = BinaryFile.getContentDisposition(response);
            String contentLength = BinaryFile.getContentLength(response);

      int cl = (contentLength == null) ? -1 : Integer.parseInt(contentLength);

            // Did we set up a status code for the response?
            if (context.getStatusCode() != null) {
                ((ServiceRequest) req).setStatusCode(context.getStatusCode());
            }
      req.beginStream(contentType, cl, contentDisposition, cache);
      BinaryFile.write(response, req.getOutputStream());
      req.endStream();
      BinaryFile.removeIfTheCase(response);
    }

    //--- BLOB output

        else if (outPage.isBLOB()) {
      String contentType = BLOB.getContentType(response);

      if (contentType == null)
        contentType = "application/octet-stream";

      String contentDisposition = BLOB.getContentDisposition(response);
            String contentLength = BLOB.getContentLength(response);

      int cl = (contentLength == null) ? -1 : Integer.parseInt(contentLength);

      req.beginStream(contentType, cl, contentDisposition, cache);
      BLOB.write(response, req.getOutputStream());
      req.endStream();
    }

    //--- HTML/XML output

        else {
      //--- build the xml data for the XSL translation

            String styleSheet = outPage.getStyleSheet();
      Element guiElem;
            TimerContext guiServicesTimerContext = getMonitorManager().getTimer(ServiceManagerGuiServicesTimer.class).time();
            try {
                guiElem = outPage.invokeGuiServices(context, response, vDefaultGui);
            } finally {
                guiServicesTimerContext.stop();
            }

            addPrefixes(guiElem, context.getLanguage(), req.getService(), context.getApplicationContext().getBean(NodeInfo.class).getId
                    ());

      Element rootElem = new Element(Jeeves.Elem.ROOT)
                      .addContent(guiElem)
                      .addContent(response);

      Element reqElem = (Element) req.getParams().clone();
      reqElem.setName(Jeeves.Elem.REQUEST);

      rootElem.addContent(reqElem);

      //--- do an XSL translation or send xml data to a debug routine

            if (req.hasDebug()) {
        req.beginStream("application/xml; charset=UTF-8", cache);
        req.write(rootElem);
            } else {
        //--- do an XSL transformation

        styleSheet = appPath + Jeeves.Path.XSL + styleSheet;

        if (!new File(styleSheet).exists())
                    error("     -> stylesheet not found on disk, aborting : " + styleSheet);
                else {
                    info("     -> transforming with stylesheet : " + styleSheet);
                    try {
            //--- then we set the content-type and output the result
              // If JSON output requested, run the XSLT transformation and the JSON
                        if (req.hasJSONOutput()) {
                            Element xsltResponse = null;
                            TimerContext timerContext = context.getMonitorManager().getTimer(ServiceManagerXslOutputTransformTimer
                                    .class).time();
                            try {
                                //--- first we do the transformation
                                xsltResponse = Xml.transform(rootElem, styleSheet);
                            } finally {
                                timerContext.stop();
                            }
                            req.beginStream("application/json; charset=UTF-8", cache);
                            req.getOutputStream().write(Xml.getJSON(xsltResponse).getBytes(Constants.ENCODING));
                            req.endStream();
                        } else {
                            ByteArrayOutputStream baos = new ByteArrayOutputStream();
                            TimerContext timerContext = context.getMonitorManager().getTimer(ServiceManagerXslOutputTransformTimer
                                    .class).time();
                            try {
                                //--- first we do the transformation
                                Xml.transform(rootElem, styleSheet, baos);
                            } finally {
                                timerContext.stop();
                            }
                            req.beginStream(outPage.getContentType(), cache);
                            req.getOutputStream().write(baos.toByteArray());
                            req.endStream();
                        }
View Full Code Here

Examples of com.yammer.metrics.core.TimerContext

      // When pre-preparing statements, we can send the same one multiple times
      // in this case, we should just return the one from the cache and not prepare again
      return preparedStatementCache.get(cql.getQuery());
    } else {
      Long currentTime = System.currentTimeMillis();
      TimerContext prepareTimer = Metrics.defaultRegistry().newTimer(CQLExecutor.class, "statement.prepared").time();
      PreparedStatement ret = session.prepare(cql.getQuery());
      prepareTimer.stop();
      ret.setConsistencyLevel(consistencyLevel);
      preparedStatementCache.put(cql.getQuery(), ret);
      return ret;
    }
    }
View Full Code Here

Examples of com.yammer.metrics.core.TimerContext

    if(firstSpace > 0) {
      methodName = cql.substring(0, firstSpace);
    }
    String timerName = "asyncExec." + methodName + "." + statement.getObjectName();
    final Timer asyncExecTimer = Metrics.defaultRegistry().newTimer(StatementIteratorConsumer.class, timerName);
    final TimerContext asyncExecTimerContext = asyncExecTimer.time();
    final long startTime = System.nanoTime();
    ResultSetFuture future = null;
    try {
      future = this.cqlExecutor.executeAsync(statement);
    } catch (RuntimeException re) {
      logger.error("RuntimeException while executing statement {}\n {}", statement.getQuery(), re);
      shutdownLatch.countDown();
      return;
    }
    futures.add(future);
    Futures.addCallback(future, new FutureCallback<ResultSet>() {
      @Override
      public void onSuccess(final ResultSet result) {
        Host queriedHost = result.getExecutionInfo().getQueriedHost();
        Metrics.defaultRegistry().newMeter(StatementIteratorConsumer.class, "queriedhost." + queriedHost.getDatacenter(), queriedHost.getDatacenter(), TimeUnit.SECONDS).mark();
        asyncExecTimerContext.stop();
        logger.debug("Async exec time {}us", (System.nanoTime() - startTime) / 1000);
        shutdownLatch.countDown();
      }

      @Override
      public void onFailure(final Throwable t) {
        asyncExecTimerContext.stop();
        logger.debug("Async failure time {}us", (System.nanoTime() - startTime) / 1000);
        executionExceptions.add(t);
        shutdownLatch.countDown();
      }
    }
View Full Code Here

Examples of com.yammer.metrics.core.TimerContext

    @Override
    public final void handleGet(ServletServiceRequest request, ServletServiceResponse response,
            OperationDiagnostics stats) throws IOException
    {
        final OperationMetrics metrics = _getMetrics;
        TimerContext timer = (metrics == null) ? null : metrics.start();
        try {
            K key = _findKey(request, response);
            if (key != null) { // null means trouble; response has all we need
                _handleGet(request, response, stats, key);
            }
View Full Code Here

Examples of com.yammer.metrics.core.TimerContext

    @Override
    public final void handlePut(ServletServiceRequest request, ServletServiceResponse response,
            OperationDiagnostics stats) throws IOException
    {
        final OperationMetrics metrics = _putMetrics;
        TimerContext timer = (metrics == null) ? null : metrics.start();

        try {
            K key = _findKey(request, response);
            if (key != null) {
                _handlePut(request, response, stats, key);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.