Java Code Examples for com.jcabi.log.Logger#format()

The following examples show how to use com.jcabi.log.Logger#format() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Futures.java    From jpeek with MIT License 6 votes vote down vote up
@Override
public String asString() throws IOException {
    return Logger.format(
        // @checkstyle LineLength (1 line)
        "Artifacts=%d, processors=%d, threads=%d, freeMemory=%dM, maxMemory=%dM, totalMemory=%dM, ETA=%[ms]s:\n%s\n\nThreads: %s",
        this.queue.size(),
        Runtime.getRuntime().availableProcessors(),
        Thread.getAllStackTraces().keySet().size(),
        // @checkstyle MagicNumber (3 lines)
        Runtime.getRuntime().freeMemory() / (1024L << 10),
        Runtime.getRuntime().maxMemory() / (1024L << 10),
        Runtime.getRuntime().totalMemory() / (1024L << 10),
        new AvgOf(
            this.times.toArray(new Long[this.times.size()])
        ).longValue() * (long) this.queue.size(),
        new Joined(", ", this.queue.keySet()).asString(),
        new Joined(
            ", ",
            new Mapped<>(
                Thread::getName,
                Thread.getAllStackTraces().keySet()
            )
        ).asString()
    );
}
 
Example 2
Source File: AsyncReports.java    From jpeek with MIT License 4 votes vote down vote up
@Override
public Func<String, Response> apply(final String group,
    final String artifact) throws IOException {
    final Future<Func<String, Response>> future = new IoCheckedBiFunc<>(
        this.cache
    ).apply(group, artifact);
    final Func<String, Response> output;
    if (future.isCancelled()) {
        output = input -> new RsPage(
            new RqFake(),
            "error",
            () -> new IterableOf<>(
                new XeAppend("group", group),
                new XeAppend("artifact", artifact),
                new XeAppend("future", future.toString())
            )
        );
    } else if (future.isDone()) {
        try {
            output = future.get();
        } catch (final InterruptedException | ExecutionException ex) {
            throw new IllegalStateException(ex);
        }
    } else {
        final long msec = System.currentTimeMillis()
            - this.starts.computeIfAbsent(
                String.format("%s:%s", group, artifact),
                s -> System.currentTimeMillis()
            );
        output = input -> new RsWithStatus(
            new RsPage(
                new RqFake(),
                "wait",
                () -> new IterableOf<>(
                    new XeAppend("group", group),
                    new XeAppend("artifact", artifact),
                    new XeAppend("future", future.toString()),
                    new XeAppend("msec", Long.toString(msec)),
                    new XeAppend(
                        "spent",
                        Logger.format("%[ms]s", msec)
                    )
                )
            ),
            HttpURLConnection.HTTP_NOT_FOUND
        );
    }
    return output;
}