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.redhat.rhn.manager.system.BaseUpdateChannelCommand.java

/**
 * Private helper method to create a new UpdateErrataCacheEvent and publish it to the
 * MessageQueue.// w ww . j a va 2  s  . c  o  m
 * @param orgIn The org we're updating.
 */
private void publishUpdateErrataCacheEvent() {
    StopWatch sw = new StopWatch();
    if (log.isDebugEnabled()) {
        log.debug("Updating errata cache");
        sw.start();
    }

    UpdateErrataCacheEvent uece = new UpdateErrataCacheEvent(UpdateErrataCacheEvent.TYPE_ORG);
    uece.setOrgId(user.getOrg().getId());
    MessageQueue.publish(uece);

    if (log.isDebugEnabled()) {
        sw.stop();
        log.debug("Finished Updating errata cache. Took [" + sw.getTime() + "]");
    }
}

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

@Override
protected Client createClient(ImmutableSettings.Builder builder) {
    NodeBuilder nodeBuilder = NodeBuilder.nodeBuilder();

    builder.loadFromClasspath(PortletPropsValues.ELASTICSEARCH_EMBEDDED_CONFIG_LOCATION);

    nodeBuilder.settings(builder);/*from   w  w  w  .  j  a v a  2 s.c o m*/

    nodeBuilder.clusterName(getClusterName());
    nodeBuilder.client(false);
    nodeBuilder.data(true);

    _node = nodeBuilder.node();

    StopWatch stopWatch = null;

    if (_log.isDebugEnabled()) {
        stopWatch = new StopWatch();

        stopWatch.start();

        _log.debug("Starting embedded Elasticsearch cluster " + getClusterName());
    }

    _node.start();

    Client client = _node.client();

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

        _log.debug("Finished starting " + getClusterName() + " in " + stopWatch.getTime() + " ms");
    }

    return client;
}

From source file:com.sonyericsson.hudson.plugins.gerrit.trigger.GerritProjectListUpdaterFunctionalTest.java

/**
 * Test that Project List updates are active for Gerrit Version 2.11 upon
 * connection startup./*from w w  w .jav  a  2  s .c  om*/
 * @throws Exception if occurs.
 */
@Test
public void testProjectListUpdateActiveOnStartup() throws Exception {
    GerritServer gerritServer = new GerritServer("ABCDEF");
    Config config = (Config) gerritServer.getConfig();
    config.setGerritAuthKeyFile(sshKey.getPrivateKey());
    config.setProjectListFetchDelay(1);
    config.setProjectListRefreshInterval(1);
    config = SshdServerMock.getConfigFor(sshd, config);
    gerritServer.setConfig(config);
    PluginImpl.getInstance().addServer(gerritServer);

    gerritServer.start();
    gerritServer.startConnection();

    StopWatch watch = new StopWatch();
    watch.start();
    while (!gerritServer.isConnected()) {
        TimeUnit.SECONDS.sleep(SLEEPTIME);
        if (TimeUnit.MILLISECONDS.toSeconds(watch.getTime()) > MAXSLEEPTIME) {
            break;
        }
    }
    watch.stop();

    watch.reset();
    watch.start();
    while (gerritServer.getGerritProjects().size() == 0) {
        TimeUnit.SECONDS.sleep(SLEEPTIME);
        if (TimeUnit.MILLISECONDS.toSeconds(watch.getTime()) > MAXSLEEPTIME) {
            break;
        }
    }
    watch.stop();
    assertEquals(1, gerritServer.getGerritProjects().size());

    server.returnCommandFor("gerrit ls-projects", SshdServerMock.SendTwoProjectsCommand.class);

    TimeUnit.SECONDS.sleep(LONGSLEEPTIME);
    assertEquals(2, gerritServer.getGerritProjects().size());

}

From source file:ch.systemsx.cisd.openbis.generic.server.dataaccess.db.search.FullTextIndexerRunnable.java

public final void run() {
    final IndexMode indexMode = context.getIndexMode();
    if (indexMode == IndexMode.NO_INDEX) {
        return;//from  w w w.j  ava2s.  co  m
    }
    final Set<Class<?>> indexedEntities = indexedEntityFinder.getIndexedEntities();

    // final Set<Class<?>> indexedEntities = new HashSet<Class<?>>();
    // indexedEntities.add(ExternalDataPE.class);
    // indexedEntities.add(ExperimentPE.class);

    if (indexedEntities.size() == 0) {
        operationLog.info(
                String.format("No entity annotated with '%s' has been found.", Indexed.class.getSimpleName()));
        return;
    }
    Class<?> currentEntity = null;
    try {
        // timeout exceptions were observed for the default timeout when database was bigger
        IndexWriter.setDefaultWriteLockTimeout(3000);
        final File indexBase = new File(context.getIndexBase());
        final File markerFile = new File(indexBase, FULL_TEXT_INDEX_MARKER_FILENAME);
        if (indexMode == IndexMode.SKIP_IF_MARKER_FOUND && markerFile.exists()) {
            operationLog
                    .debug(String.format("Skipping indexing process as " + "marker file '%s' already exists.",
                            markerFile.getAbsolutePath()));
            return;
        }
        final Session session = getSession();
        final StopWatch stopWatch = new StopWatch();
        for (final Class<?> indexedEntity : indexedEntities) {
            currentEntity = indexedEntity;
            stopWatch.reset();
            stopWatch.start();
            fullTextIndexer.doFullTextIndex(session, indexedEntity);
            stopWatch.stop();
            operationLog
                    .info(String.format("Indexing entity '%s' took %s.", indexedEntity.getName(), stopWatch));
        }
        FileUtils.touch(markerFile);
        releaseSession(session);
    } catch (final Throwable th) {
        notificationLog
                .error(String.format("A problem has occurred while indexing entity '%s'.", currentEntity), th);
    }
}

From source file:com.couchbase.graph.CBGraphPerfTest.java

@Test
@RunIf(value = PerfEnabledChecker.class)
public void traverse50KEdges() {
    System.out.println("-- traverse50KEdges");

    int COUNT = 10000;
    String data = "123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790";

    //Create a graph of neighbors and second neighbors
    System.out.println("Creating graph ...");

    Vertex root = graph.addVertex(UUID.randomUUID().toString());

    for (int i = 0; i < COUNT; i++) {

        Vertex v = graph.addVertex(UUID.randomUUID().toString());
        System.out.println("id = " + v.getId());
        v.setProperty("data", data);

        graph.addEdge(null, root, v, "neighbor of");

    }// w  ww  .  jav  a2  s.  c o m

    //Traverse the graph
    System.out.println("Traversing graph ...");

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

    Iterable<Vertex> vertices = root.getVertices(Direction.OUT);

    for (Vertex v : vertices) {

        System.out.println(v.getId());

    }

    sw.stop();
    System.out.println("Traversed tree in " + sw.getTime() + " ms");
}

From source file:de.rinderle.softvis3d.VisualizationProcessor.java

public Map<Integer, ResultPlatform> visualize(final Settings settings, final VisualizationRequest requestDTO,
        final SnapshotTreeResult snapshotTreeResult) throws DotExecutorException {

    final StopWatch stopWatch = new StopWatch();
    stopWatch.start();//  w  w  w  . ja va 2 s.c  o  m

    final Map<Integer, ResultPlatform> resultGraphs = layoutProcessor.process(settings, requestDTO,
            snapshotTreeResult);

    LOGGER.info("Created " + resultGraphs.size() + " result graphs in " + stopWatch.getTime() + " ms");

    final int leavesCounter = this.calc.process(requestDTO.getViewType(), resultGraphs, snapshotTreeResult);

    stopWatch.stop();
    LOGGER.info("Calculation finished after " + stopWatch.getTime() + " ms with " + leavesCounter + " leaves");

    return resultGraphs;
}

From source file:com.mothsoft.alexis.engine.predictive.OpenNLPMaxentModelTrainerTask.java

@Transactional
@Override/*from www  .  jav a 2 s. co m*/
public void execute() {
    final Long modelId = findAndMark();

    if (modelId != null) {
        logger.info(String.format("Training model %d", modelId));

        final StopWatch stopWatch = new StopWatch();
        stopWatch.start();
        final Model model = this.modelDao.get(modelId);
        train(model);
        stopWatch.stop();

        logger.info(String.format("Training model %d took: %s", modelId, stopWatch.toString()));
    }
}

From source file:com.google.code.jerseyclients.httpclientfour.ApacheHttpClientFourHandler.java

public ClientResponse handle(final ClientRequest clientRequest) throws ClientHandlerException {

    if (this.jerseyHttpClientConfig.getApplicationCode() != null) {
        clientRequest.getHeaders().add(this.jerseyHttpClientConfig.getApplicationCodeHeader(),
                this.jerseyHttpClientConfig.getApplicationCode());
    }/*from w  ww .ja v  a  2  s . c om*/
    if (this.jerseyHttpClientConfig.getOptionnalHeaders() != null) {
        for (Entry<String, String> entry : this.jerseyHttpClientConfig.getOptionnalHeaders().entrySet()) {
            clientRequest.getHeaders().add(entry.getKey(), entry.getValue());
        }
    }
    // final Map<String, Object> props = cr.getProperties();

    final HttpRequestBase method = getHttpMethod(clientRequest);

    // Set the read timeout
    final Integer readTimeout = jerseyHttpClientConfig.getReadTimeOut();
    if (readTimeout != null) {
        HttpConnectionParams.setSoTimeout(method.getParams(), readTimeout.intValue());
    }

    // FIXME penser au header http
    // DEBUG|wire.header|>> "Cache-Control: no-cache[\r][\n]"
    // DEBUG|wire.header|>> "Pragma: no-cache[\r][\n]"
    if (method instanceof HttpEntityEnclosingRequestBase) {
        final HttpEntityEnclosingRequestBase entMethod = (HttpEntityEnclosingRequestBase) method;

        if (clientRequest.getEntity() != null) {
            final RequestEntityWriter re = getRequestEntityWriter(clientRequest);

            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            try {
                re.writeRequestEntity(new CommittingOutputStream(baos) {
                    @Override
                    protected void commit() throws IOException {
                        writeOutBoundHeaders(clientRequest.getHeaders(), method);
                    }
                });
            } catch (IOException ex) {
                throw new ClientHandlerException(ex);
            }

            final byte[] content = baos.toByteArray();
            HttpEntity httpEntity = new ByteArrayEntity(content);
            entMethod.setEntity(httpEntity);

        }
    } else {
        writeOutBoundHeaders(clientRequest.getHeaders(), method);
    }

    try {
        StopWatch stopWatch = new StopWatch();
        stopWatch.reset();
        stopWatch.start();
        HttpResponse httpResponse = client.execute(method);
        int httpReturnCode = httpResponse.getStatusLine().getStatusCode();
        stopWatch.stop();
        log.info("time to call rest url " + clientRequest.getURI() + ", " + stopWatch.getTime() + " ms");

        if (httpReturnCode == Status.NO_CONTENT.getStatusCode()) {
            return new ClientResponse(httpReturnCode, getInBoundHeaders(httpResponse),
                    IOUtils.toInputStream(""), getMessageBodyWorkers());
        }

        return new ClientResponse(httpReturnCode, getInBoundHeaders(httpResponse),
                httpResponse.getEntity() == null ? IOUtils.toInputStream("")
                        : httpResponse.getEntity().getContent(),
                getMessageBodyWorkers());
    } catch (Exception e) {
        throw new ClientHandlerException(e);
    }
}

From source file:io.cloudslang.lang.cli.SlangCli.java

@CliCommand(value = "run", help = RUN_HELP)
public String run(@CliOption(key = { "", "f", "file" }, mandatory = true, help = FILE_HELP) final File file,
        @CliOption(key = { "cp",
                "classpath" }, mandatory = false, help = CLASSPATH_HELP) final List<String> classPath,
        @CliOption(key = { "i",
                "inputs" }, mandatory = false, help = INPUTS_HELP) final Map<String, ? extends Serializable> inputs,
        @CliOption(key = { "if",
                "input-file" }, mandatory = false, help = INPUT_FILE_HELP) final List<String> inputFiles,
        @CliOption(key = { "v",
                "verbose" }, mandatory = false, help = "default, quiet, debug(print each step outputs). e.g. run --f c:/.../your_flow.sl --v quiet", specifiedDefaultValue = "debug", unspecifiedDefaultValue = "default") final String verbose,
        @CliOption(key = { "spf",
                "system-property-file" }, mandatory = false, help = SYSTEM_PROPERTY_FILE_HELP) final List<String> systemPropertyFiles) {

    if (invalidVerboseInput(verbose)) {
        throw new IllegalArgumentException("Verbose argument is invalid.");
    }// www. j a  v a2s .c om

    CompilationArtifact compilationArtifact = compilerHelper.compile(file.getAbsolutePath(), classPath);
    Set<SystemProperty> systemProperties = compilerHelper.loadSystemProperties(systemPropertyFiles);
    Map<String, Value> inputsFromFile = compilerHelper.loadInputsFromFile(inputFiles);
    Map<String, Value> mergedInputs = new HashMap<>();

    if (MapUtils.isNotEmpty(inputsFromFile)) {
        mergedInputs.putAll(inputsFromFile);
    }
    if (MapUtils.isNotEmpty(inputs)) {
        mergedInputs.putAll(io.cloudslang.lang.entities.utils.MapUtils.convertMapNonSensitiveValues(inputs));
    }
    boolean quiet = QUIET.equalsIgnoreCase(verbose);
    boolean debug = DEBUG.equalsIgnoreCase(verbose);

    Long id;
    if (!triggerAsync) {
        StopWatch stopWatch = new StopWatch();
        stopWatch.start();
        id = scoreServices.triggerSync(compilationArtifact, mergedInputs, systemProperties, quiet, debug);
        stopWatch.stop();
        return quiet ? StringUtils.EMPTY : triggerSyncMsg(id, stopWatch.toString());
    }
    id = scoreServices.trigger(compilationArtifact, mergedInputs, systemProperties);
    return quiet ? StringUtils.EMPTY : triggerAsyncMsg(id, compilationArtifact.getExecutionPlan().getName());
}

From source file:hrider.actions.RunnableAction.java

public void waitUntil(long timeout) {
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();/*  www  . j a va  2s  .  c o m*/

    long localTimeout = timeout / 10;

    while (this.isRunning) {
        try {
            Thread.sleep(localTimeout);

            if (stopWatch.getTime() > timeout) {
                break;
            }
        } catch (InterruptedException ignore) {
        }
    }

    stopWatch.stop();
}