Example usage for org.apache.commons.lang.time StopWatch stop

List of usage examples for org.apache.commons.lang.time StopWatch stop

Introduction

In this page you can find the example usage for org.apache.commons.lang.time StopWatch stop.

Prototype

public void stop() 

Source Link

Document

Stop the stopwatch.

This method ends a new timing session, allowing the time to be retrieved.

Usage

From source file:com.liferay.portal.search.elasticsearch.internal.connection.EmbeddedElasticsearchConnection.java

@Override
protected Client createClient() {
    StopWatch stopWatch = new StopWatch();

    stopWatch.start();//from w  w w  .  j  a  v  a  2  s  . com

    if (_log.isWarnEnabled()) {
        StringBundler sb = new StringBundler(6);

        sb.append("Liferay is configured to use embedded Elasticsearch ");
        sb.append("as its search engine. Do NOT use embedded ");
        sb.append("Elasticsearch in production. Embedded Elasticsearch ");
        sb.append("is useful for development and demonstration purposes. ");
        sb.append("Remote Elasticsearch connections can be configured in ");
        sb.append("the Control Panel.");

        _log.warn(sb.toString());
    }

    if (_log.isDebugEnabled()) {
        _log.debug("Starting embedded Elasticsearch cluster " + elasticsearchConfiguration.clusterName());
    }

    _node = createNode(settingsBuilder.build());

    _node.start();

    Client client = _node.client();

    if (_log.isDebugEnabled()) {
        stopWatch.stop();

        _log.debug(StringBundler.concat("Finished starting ", elasticsearchConfiguration.clusterName(), " in ",
                String.valueOf(stopWatch.getTime()), " ms"));
    }

    return client;
}

From source file:com.mothsoft.alexis.dao.DocumentDaoImpl.java

public DataRange<Document> listDocumentsInTopicsByOwner(final Long userId, final int first, final int count) {
    final StopWatch stopWatch = new StopWatch();
    stopWatch.start();// w w w  . j  a va 2  s . c  o  m

    final SortOrder sortOrder = SortOrder.DATE_DESC;
    final DataRange<DocumentScore> scoredRange = this.searchWithAllOptions(userId, true,
            DocumentState.MATCHED_TO_TOPICS, null, sortOrder, null, null, first, count);

    final List<Document> range = new ArrayList<Document>(scoredRange.getRange().size());

    for (final DocumentScore scoredDoc : scoredRange.getRange()) {
        range.add(scoredDoc.getDocument());
    }

    final DataRange<Document> dataRange = new DataRange<Document>(range, scoredRange.getFirstRow(),
            scoredRange.getTotalRowsAvailable());

    stopWatch.stop();
    logger.debug(stopWatch.toString());

    return dataRange;
}

From source file:net.nan21.dnet.core.web.controller.data.AbstractAsgnController.java

/**
 * //w w  w .j ava2 s.  c  o  m
 * @param resourceName
 * @param dataFormat
 * @param objectId
 * @param selectionId
 * @param response
 * @return
 * @throws Exception
 */
@RequestMapping(method = RequestMethod.POST, params = Constants.REQUEST_PARAM_ACTION + "="
        + Constants.ASGN_ACTION_MOVE_LEFT)
@ResponseBody
public String moveLeft(@PathVariable String resourceName, @PathVariable String dataFormat,
        @RequestParam(value = Constants.REQUEST_PARAM_ASGN_OBJECT_ID, required = true) String objectId,
        @RequestParam(value = Constants.REQUEST_PARAM_ASGN_SELECTION_ID, required = true) String selectionId,
        @RequestParam(value = "p_selected_ids", required = true) String selectedIds, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    try {

        StopWatch stopWatch = new StopWatch();
        stopWatch.start();

        if (logger.isInfoEnabled()) {
            logger.info("Processing request: {}.{} -> action = {} ",
                    new String[] { resourceName, dataFormat, Constants.ASGN_ACTION_MOVE_LEFT });
        }

        if (logger.isDebugEnabled()) {
            logger.debug("  --> request-filter: objectId={}, selectionId={}, selectedIds={} ",
                    new String[] { objectId, selectionId, selectedIds });
        }

        this.prepareRequest(request, response);

        this.authorizeAsgnAction(resourceName, "update");

        IAsgnService<M, F, P> service = this.findAsgnService(this.serviceNameFromResourceName(resourceName));

        service.moveLeft(selectionId, this.selectedIdsAsList(selectedIds));
        stopWatch.stop();

        return "";
    } catch (Exception e) {
        return this.handleException(e, response);
    } finally {
        this.finishRequest();
    }

}

From source file:net.nan21.dnet.core.web.controller.data.AbstractAsgnController.java

/**
 * //www.  j ava2s  . c  o m
 * @param resourceName
 * @param dataFormat
 * @param objectId
 * @param selectionId
 * @param response
 * @return
 * @throws Exception
 */
@RequestMapping(method = RequestMethod.POST, params = Constants.REQUEST_PARAM_ACTION + "="
        + Constants.ASGN_ACTION_MOVE_RIGHT)
@ResponseBody
public String moveRight(@PathVariable String resourceName, @PathVariable String dataFormat,
        @RequestParam(value = Constants.REQUEST_PARAM_ASGN_OBJECT_ID, required = true) String objectId,
        @RequestParam(value = Constants.REQUEST_PARAM_ASGN_SELECTION_ID, required = true) String selectionId,
        @RequestParam(value = "p_selected_ids", required = true) String selectedIds, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    try {

        StopWatch stopWatch = new StopWatch();
        stopWatch.start();

        if (logger.isInfoEnabled()) {
            logger.info("Processing request: {}.{} -> action = {} ",
                    new String[] { resourceName, dataFormat, Constants.ASGN_ACTION_MOVE_RIGHT });
        }

        if (logger.isDebugEnabled()) {
            logger.debug("  --> request-filter: objectId={}, selectionId={}, selectedIds={} ",
                    new String[] { objectId, selectionId, selectedIds });
        }

        this.prepareRequest(request, response);

        this.authorizeAsgnAction(resourceName, "update");

        IAsgnService<M, F, P> service = this.findAsgnService(this.serviceNameFromResourceName(resourceName));

        service.moveRight(selectionId, this.selectedIdsAsList(selectedIds));
        stopWatch.stop();

        return "";
    } catch (Exception e) {
        return this.handleException(e, response);
    } finally {
        this.finishRequest();
    }
}

From source file:de.pro.dbw.application.testdata.service.DreamService.java

@Override
protected Task<Void> createTask() {
    return new Task<Void>() {
        {//from  w  w w  .  ja v a2 s  . c  om
            updateProgress(0, saveMaxEntities);
        }

        @Override
        protected Void call() throws Exception {
            LoggerFacade.INSTANCE.deactivate(Boolean.TRUE);

            final StopWatch stopWatch = new StopWatch();
            stopWatch.start();

            final ICrudService crudService = DatabaseFacade.INSTANCE.getCrudService(entityName);
            long id = -1_000_000_000L + DatabaseFacade.INSTANCE.getCrudService().count(entityName);
            for (int i = 1; i <= saveMaxEntities; i++) {
                crudService.beginTransaction();

                final DreamModel model = new DreamModel();
                model.setGenerationTime(DreamService.this.createGenerationTime());
                model.setDescription(LoremIpsum.getDefault().getDescription());
                model.setId(id++);
                model.setTitle(LoremIpsum.getDefault().getTitle());
                model.setText(LoremIpsum.getDefault().getText());

                crudService.create(model, false);
                updateProgress(i - 1, saveMaxEntities);

                crudService.commitTransaction();
            }

            LoggerFacade.INSTANCE.deactivate(Boolean.FALSE);
            stopWatch.split();
            LoggerFacade.INSTANCE.debug(this.getClass(),
                    "  + " + stopWatch.toSplitString() + " for " + saveMaxEntities + " Dreams."); // NOI18N
            stopWatch.stop();

            return null;
        }
    };
}

From source file:net.nan21.dnet.core.web.controller.data.AbstractDsWriteController.java

/**
 * Default handler for delete action./*w  w w .  ja va 2 s  .c om*/
 * 
 * @param resourceName
 * @param dataformat
 * @param idsString
 * @param paramString
 * @return
 * @throws Exception
 */
@RequestMapping(method = RequestMethod.POST, params = Constants.REQUEST_PARAM_ACTION + "="
        + Constants.DS_ACTION_DELETE)
@ResponseBody
public String delete(@PathVariable String resourceName, @PathVariable String dataFormat,
        @RequestParam(value = Constants.REQUEST_PARAM_DATA, required = false, defaultValue = "{}") String dataString,
        @RequestParam(value = Constants.REQUEST_PARAM_PARAMS, required = false, defaultValue = "{}") String paramString,
        HttpServletRequest request, HttpServletResponse response) throws Exception {

    try {

        StopWatch stopWatch = new StopWatch();
        stopWatch.start();

        if (logger.isInfoEnabled()) {
            logger.info("Processing request: {}.{} -> action = {} ",
                    new String[] { resourceName, dataFormat, Constants.DS_ACTION_DELETE });
        }

        this.prepareRequest(request, response);

        this.authorizeDsAction(resourceName, Constants.DS_ACTION_DELETE, null);

        if (!dataString.startsWith("[")) {
            dataString = "[" + dataString + "]";
        }
        IDsService<M, F, P> service = this.findDsService(resourceName);
        IDsMarshaller<M, F, P> marshaller = service.createMarshaller(IDsMarshaller.JSON);

        List<M> list = marshaller.readListFromString(dataString);
        // P params = marshaller.readParamsFromString(paramString);

        List<Object> ids = new ArrayList<Object>();
        for (M ds : list) {
            ids.add(((IModelWithId) ds).getId());
        }
        service.deleteByIds(ids);

        IActionResultDelete result = this.packResultDelete();
        stopWatch.stop();
        result.setExecutionTime(stopWatch.getTime());

        String out = null;

        if (dataFormat.equals(IDsMarshaller.XML)) {
            IDsMarshaller<M, F, P> resultMarshaller = service.createMarshaller(dataFormat);
            out = resultMarshaller.writeResultToString(result);
            response.setContentType("text/xml; charset=UTF-8");
        } else {
            out = marshaller.writeResultToString(result);
            response.setContentType("text/plain; charset=UTF-8");
        }

        return out;

    } catch (Exception e) {
        this.handleException(e, response);
        return null;
    } finally {
        this.finishRequest();
    }
}

From source file:com.mothsoft.alexis.dao.DocumentDaoImpl.java

public DataRange<Document> listDocumentsByOwner(final Long userId, final int first, final int count) {
    final StopWatch stopWatch = new StopWatch();
    stopWatch.start();/*ww  w .  jav  a 2s .c  o  m*/

    final SortOrder sortOrder = SortOrder.DATE_DESC;
    final DataRange<DocumentScore> scoredRange = this.searchWithAllOptions(userId, false, null, null, sortOrder,
            null /* ignore start date */, null /* ignore end date */, first, count);

    final List<Document> range = new ArrayList<Document>(scoredRange.getRange().size());

    for (final DocumentScore scoredDoc : scoredRange.getRange()) {
        range.add(scoredDoc.getDocument());
    }

    final DataRange<Document> dataRange = new DataRange<Document>(range, scoredRange.getFirstRow(),
            scoredRange.getTotalRowsAvailable());

    stopWatch.stop();
    logger.debug(stopWatch.toString());

    return dataRange;
}

From source file:com.ecyrd.jspwiki.ReferenceManager.java

/**
 *  Serializes hashmaps to disk.  The format is private, don't touch it.
 *//*from w  ww . j av  a2 s.  c  o m*/
private synchronized void serializeToDisk() {
    ObjectOutputStream out = null;

    try {
        StopWatch sw = new StopWatch();
        sw.start();

        File f = new File(m_engine.getWorkDir(), SERIALIZATION_FILE);

        out = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(f)));

        out.writeLong(serialVersionUID);
        out.writeLong(System.currentTimeMillis()); // Timestamp
        out.writeObject(m_refersTo);
        out.writeObject(m_referredBy);

        out.close();

        sw.stop();

        log.debug("serialization done - took " + sw);
    } catch (IOException e) {
        log.error("Unable to serialize!");

        try {
            if (out != null)
                out.close();
        } catch (IOException ex) {
        }
    }
}

From source file:com.nabla.project.visma.selenium.tests.SimpleWebDriverSTest.java

@Test
@InSequence(2)/*from  w  ww.j  a  va 2  s .  c o  m*/
public void testWithWrongInputS() throws Exception {
    // Get the StopWatch Object and start the StopWatch
    final StopWatch pageLoad = new StopWatch();
    pageLoad.start();

    // Create an instance of Loan Page class
    // and provide the driver
    final LoanPage loanPage = new LoanPage(/* SeleniumHelper.getDriver() */);

    // Open the Loan Calculator Page
    loanPage.get();

    loanPage.He_enters_loan_amount("-10");
    loanPage.He_enters_payback_time("0");

    loanPage.calculatePayments("-10", "0");

    // loanPage.Ensure_a_transaction_failure_message(2, "Please enter the amount of your loan. Ex. 200000: Validation Error: Specified attribute is not between the expected values of 1 and 1,000,000,000.");
    loanPage.Ensure_loan_amount_failure_message(
            "Please enter the amount of your loan. Ex. 200000: Validation Error: Specified attribute is not between the expected values of 1 and 1,000,000,000.");
    // loanPage.Ensure_a_transaction_failure_message(3,
    // "Please enter the number of years you have to pay back your loan. Ex. 30: Validation Error: Specified attribute is not between the expected values of 1 and 120.");
    loanPage.Ensure_payback_time_failure_message(
            "Please enter the number of years you have to pay back your loan. Ex. 30: Validation Error: Specified attribute is not between the expected values of 1 and 120.");

    pageLoad.stop();

    LOGGER.info("Total Page Load Time : {} milliseconds", pageLoad);

    SeleniumHelper.testTakesScreenshot("testWithWrongInputS.png", SeleniumHelper.getDriver());
    // Thread.sleep(1000);

    SeleniumHelper.getSelenium().open("/visma/");
    SeleniumHelper.getSelenium().waitForPageToLoad(SeleniumHelper.PAGE_TO_LOAD_TIMEOUT);

    // loanPage.close();
}

From source file:eagle.service.generic.GenericEntityServiceResource.java

/**
 * TODO/* ww  w  . j a  v  a2  s. c  o  m*/
 *
 * Delete by query
 *
 * @return
 */
@DELETE
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public GenericServiceAPIResponseEntity deleteByQuery(@QueryParam("query") String query,
        @QueryParam("startTime") String startTime, @QueryParam("endTime") String endTime,
        @QueryParam("pageSize") int pageSize, @QueryParam("startRowkey") String startRowkey,
        @QueryParam("treeAgg") boolean treeAgg, @QueryParam("timeSeries") boolean timeSeries,
        @QueryParam("intervalmin") long intervalmin, @QueryParam("top") int top,
        @QueryParam("filterIfMissing") boolean filterIfMissing, @QueryParam("parallel") int parallel,
        @QueryParam("metricName") String metricName, @QueryParam("verbose") Boolean verbose) {
    RawQuery rawQuery = RawQuery.build().query(query).startTime(startTime).endTime(endTime).pageSize(pageSize)
            .startRowkey(startRowkey).treeAgg(treeAgg).timeSeries(timeSeries).intervalMin(intervalmin).top(top)
            .filerIfMissing(filterIfMissing).parallel(parallel).metricName(metricName).verbose(verbose).done();

    GenericServiceAPIResponseEntity response = new GenericServiceAPIResponseEntity();
    Map<String, Object> meta = new HashMap<String, Object>();
    DataStorage dataStorage = null;
    StopWatch stopWatch = new StopWatch();
    try {
        stopWatch.start();
        dataStorage = DataStorageManager.getDataStorageByEagleConfig();
        if (dataStorage == null) {
            LOG.error("Data storage is null");
            throw new IllegalDataStorageException("Data storage is null");
        }

        DeleteStatement deleteStatement = new DeleteStatement(rawQuery);
        ModifyResult<String> deleteResult = deleteStatement.execute(dataStorage);
        if (deleteResult.isSuccess()) {
            meta.put(ELAPSEDMS, stopWatch.getTime());
            response.setObj(deleteResult.getIdentifiers(), String.class);
            response.setSuccess(true);
            response.setMeta(meta);
        }
        return response;
    } catch (Exception e) {
        response.setException(e);
        LOG.error(e.getMessage(), e);
    } finally {
        stopWatch.stop();
    }
    return response;
}