Package com.google.common.base

Examples of com.google.common.base.Stopwatch


        shutdownCalled.set(false);
    }
   
    @Test(enabled=false)
    public void shouldCreateSingletonAndExitAfter1Second() throws Exception {
        Stopwatch sw = new Stopwatch().start();
       
        final TerminationEvent event = new SelfDestructingTerminationEvent(1, TimeUnit.SECONDS);
        LifecycleInjector.builder()
            // Example of a singleton that will be created
            .withAdditionalModules(new AbstractModule() {
                @Override
                protected void configure() {
                    bind(SomeSingleton.class).asEagerSingleton();
                }
            })
            .withAdditionalBootstrapModules(
                StandaloneRunnerModule.builder()
                    .withTerminateEvent(event)
                    .build())
            .build()
            .createInjector();
       
        event.await();
        long elapsed = sw.elapsed(TimeUnit.MILLISECONDS);
        LOG.info("Elapsed: " + elapsed);
        Assert.assertTrue(initCalled.get());
        Assert.assertTrue(shutdownCalled.get());
        Assert.assertTrue(elapsed > 1000);
       
View Full Code Here


            info("No indices, nothing to calculate.");
            return;
        }
        indicesToCalculate = indices.length;

        Stopwatch sw = Stopwatch.createStarted();
        for(String index : indices) {
            if (cancelRequested) {
                info("Stop requested. Not calculating next index range, not updating ranges.");
                sw.stop();
                return;
            }

            try {
                ranges.add(calculateRange(index));
            } catch (EmptyIndexException e) {
                LOG.info("Index [{}] is empty, inserting dummy index range.", index);
                Map<String, Object> emptyIndexRange = getDeflectorIndexRange(index);

                if (deflector.getCurrentActualTargetIndex().equals(index)) {
                    LOG.info("Index [{}] is empty but it is the current deflector target. Inserting dummy index range.", index);
                } else {
                    emptyIndexRange.put("start", 0);
                    emptyIndexRange.put("calculated_at", Tools.getUTCTimestamp());
                }

                ranges.add(emptyIndexRange);
            } catch (Exception e) {
                LOG.info("Could not calculate range of index [" + index + "]. Skipping.", e);
            } finally {
                indicesCalculated++;
            }
        }

        // Now that all is calculated we can replace the whole collection at once.
        updateCollection(ranges);

        info("Done calculating index ranges for " + indices.length + " indices. Took " + sw.stop().elapsed(TimeUnit.MILLISECONDS) + "ms.");
    }
View Full Code Here

    }

    protected Map<String, Object> calculateRange(String index) throws EmptyIndexException {
        Map<String, Object> range = Maps.newHashMap();

        Stopwatch x = Stopwatch.createStarted();
        SearchHit doc = searches.firstOfIndex(index);
        if (doc == null || doc.isSourceEmpty()) {
            x.stop();
            throw new EmptyIndexException();
        }

        int rangeStart = Tools.getTimestampOfMessage(doc);
        int took = (int) x.stop().elapsed(TimeUnit.MILLISECONDS);

        range.put("index", index);
        range.put("start", rangeStart);
        range.put("calculated_at", Tools.getUTCTimestamp());
        range.put("took_ms",  took);
View Full Code Here

    protected abstract void onMessage(Map<String, String> message);
    protected abstract boolean iterates();
    protected abstract Type getType();

    public void runStrategy(String indexName) {
        Stopwatch sw = Stopwatch.createStarted();

        if (iterates()) {
            // TODO: Run per message.
        }

        // Delete or close index.
        switch (getType()) {
            case DELETE:
                LOG.info("Strategy is deleting.");
                indexManagement.delete(indexName);
                break;
            case CLOSE:
                LOG.info("Strategy is closing.");
                indexManagement.close(indexName);
                break;
        }

        LOG.info("Finished index retention strategy [" + this.getClass().getCanonicalName() + "] for " +
                "index <{}> in {}ms.", indexName, sw.stop().elapsed(TimeUnit.MILLISECONDS));
    }
View Full Code Here

        for (InputState state : inputRegistry.getRunningInputs()) {
            MessageInput input = state.getMessageInput();

            LOG.info("Attempting to close input <{}> [{}].", input.getUniqueReadableId(), input.getName());

            Stopwatch s = Stopwatch.createStarted();
            try {
                input.stop();

                LOG.info("Input <{}> closed. Took [{}ms]", input.getUniqueReadableId(), s.elapsed(TimeUnit.MILLISECONDS));
            } catch (Exception e) {
                LOG.error("Unable to stop input <{}> [{}]: " + e.getMessage(), input.getUniqueReadableId(), input.getName());
            } finally {
                s.stop();
            }
        }
        LOG.debug("Stopped InputSetupService");
    }
View Full Code Here

    @Override
    protected void shutDown() throws Exception {
        for (Periodical periodical : periodicals.getAllStoppedOnGracefulShutdown()) {
            LOG.info("Shutting down periodical [{}].", periodical.getClass().getCanonicalName());
            Stopwatch s = Stopwatch.createStarted();

            // Cancel future executions.
            Map<Periodical,ScheduledFuture> futures = periodicals.getFutures();
            if (futures.containsKey(periodical)) {
                futures.get(periodical).cancel(false);

                s.stop();
                LOG.info("Shutdown of periodical [{}] complete, took <{}ms>.",
                        periodical.getClass().getCanonicalName(), s.elapsed(TimeUnit.MILLISECONDS));
            } else {
                LOG.error("Could not find periodical [{}] in futures list. Not stopping execution.",
                        periodical.getClass().getCanonicalName());
            }
        }
View Full Code Here

        executor.submit(new Runnable() {
            @Override
            public void run() {
                job.markStarted();

                Stopwatch x = Stopwatch.createStarted();

                job.execute()// ... blocks until it finishes.
                x.stop();

                jobs.remove(job.getId());

                String msg = "SystemJob <" + job.getId() + "> [" + jobClass + "] finished in " + x.elapsed(TimeUnit.MILLISECONDS) + "ms.";
                LOG.info(msg);
                activityWriter.write(new Activity(msg, SystemJobManager.class));
            }
        });
View Full Code Here

       
        return result;
    }

    private void downloadAndCopyJar(String url, String pluginType) throws Exception {
        final Stopwatch stopwatch = Stopwatch.createStarted();

        try (final InputStream reader = new URL(url).openConnection().getInputStream();
             final OutputStream writer = new FileOutputStream(jarPath(url, pluginType))) {
            long totalBytesRead = ByteStreams.copy(reader, writer);
            System.out.println("Done. " + totalBytesRead + " bytes read (took " + stopwatch.elapsed(TimeUnit.SECONDS) + "s).");
        }
    }
View Full Code Here

            if (element instanceof IErlExternalRoot || element instanceof IErlProject
                    || element instanceof IErlModel) {
                // we know these have children
                return true;
            }
            final Stopwatch clock = Stopwatch.createStarted();
            if (element instanceof IErlElement) {
                final IErlElement ErlElement = (IErlElement) element;
                try {
                    ErlElement.open(null);
                } catch (final ErlModelException e) {
                }
            }
            final IErlElement parent = (IErlElement) element;
            final boolean result = parent.hasChildrenOfKind(ErlElementKind.EXTERNAL_ROOT,
                    ErlElementKind.EXTERNAL_APP, ErlElementKind.EXTERNAL_FOLDER,
                    ErlElementKind.MODULE);
            if (clock.elapsed(TimeUnit.MILLISECONDS) > 100) {
                ErlLogger.debug("TIME open " + element.getClass() + " " + element + "  "
                        + clock.elapsed(TimeUnit.MILLISECONDS) + " ms");
            }
            return result;
        }
        return false;
    }
View Full Code Here

    public List<ExternalTreeEntry> getExternalModuleTree(final IOtpRpc backend,
            final String externalModules, final OtpErlangList pathVars) {
        if (ModelConfig.verbose) {
            ErlLogger.debug("open:external_module_tree -> " + externalModules);
        }
        final Stopwatch stopwatch = Stopwatch.createStarted();
        try {
            final OtpErlangObject res = backend.call(ERLIDE_OPEN,
                    "get_external_module_tree", "x",
                    mkContext(externalModules, null, pathVars, null, null));
            if (Util.isOk(res)) {
                OtpErlangTuple t = (OtpErlangTuple) res;
                final OtpErlangList l = (OtpErlangList) t.elementAt(1);
                final List<ExternalTreeEntry> result = Lists.newArrayListWithCapacity(l
                        .arity());
                for (final OtpErlangObject i : l) {
                    t = (OtpErlangTuple) i;
                    final String parentPath = Util.stringValue(t.elementAt(0));
                    final String path = Util.stringValue(t.elementAt(1));
                    final OtpErlangAtom isModuleA = (OtpErlangAtom) t.elementAt(2);
                    result.add(new ExternalTreeEntry(parentPath, path, isModuleA
                            .atomValue().equals("module")));
                }
                final String msg = "open:external_module_tree <- " + stopwatch;
                if (stopwatch.elapsed(TimeUnit.SECONDS) > 5) {
                    ErlLogger.warn("WARNING " + msg);
                } else {
                    if (ModelConfig.verbose) {
                        ErlLogger.debug(msg);
                    }
View Full Code Here

TOP

Related Classes of com.google.common.base.Stopwatch

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.