Search in sources :

Example 1 with Dumpable

use of org.eclipse.jetty.util.component.Dumpable in project jetty.project by eclipse.

the class QueuedThreadPool method dump.

@Override
public void dump(Appendable out, String indent) throws IOException {
    List<Object> threads = new ArrayList<>(getMaxThreads());
    for (final Thread thread : _threads) {
        final StackTraceElement[] trace = thread.getStackTrace();
        boolean inIdleJobPoll = false;
        for (StackTraceElement t : trace) {
            if ("idleJobPoll".equals(t.getMethodName())) {
                inIdleJobPoll = true;
                break;
            }
        }
        final boolean idle = inIdleJobPoll;
        if (isDetailedDump()) {
            threads.add(new Dumpable() {

                @Override
                public void dump(Appendable out, String indent) throws IOException {
                    out.append(String.valueOf(thread.getId())).append(' ').append(thread.getName()).append(' ').append(thread.getState().toString()).append(idle ? " IDLE" : "");
                    if (thread.getPriority() != Thread.NORM_PRIORITY)
                        out.append(" prio=").append(String.valueOf(thread.getPriority()));
                    out.append(System.lineSeparator());
                    if (!idle)
                        ContainerLifeCycle.dump(out, indent, Arrays.asList(trace));
                }

                @Override
                public String dump() {
                    return null;
                }
            });
        } else {
            int p = thread.getPriority();
            threads.add(thread.getId() + " " + thread.getName() + " " + thread.getState() + " @ " + (trace.length > 0 ? trace[0] : "???") + (idle ? " IDLE" : "") + (p == Thread.NORM_PRIORITY ? "" : (" prio=" + p)));
        }
    }
    List<Runnable> jobs = Collections.emptyList();
    if (isDetailedDump())
        jobs = new ArrayList<>(getQueue());
    ContainerLifeCycle.dumpObject(out, this);
    ContainerLifeCycle.dump(out, indent, threads, Collections.singletonList(new DumpableCollection("jobs", jobs)));
}
Also used : ArrayList(java.util.ArrayList) IOException(java.io.IOException) DumpableCollection(org.eclipse.jetty.util.component.DumpableCollection) Dumpable(org.eclipse.jetty.util.component.Dumpable) ManagedObject(org.eclipse.jetty.util.annotation.ManagedObject)

Example 2 with Dumpable

use of org.eclipse.jetty.util.component.Dumpable in project jetty.project by eclipse.

the class ThreadMonitorTest method monitorTest.

@Ignore
@Test
public void monitorTest() throws Exception {
    try (StacklessLogging stackless = new StacklessLogging(ThreadMonitor.class)) {
        final AtomicInteger countLogs = new AtomicInteger(0);
        final AtomicInteger countSpin = new AtomicInteger(0);
        ThreadMonitor monitor = new ThreadMonitor(1000, 50, 1, 1) {

            @Override
            protected void logThreadInfo(boolean logAll) {
                if (logAll)
                    countLogs.incrementAndGet();
                else
                    countSpin.incrementAndGet();
                super.logThreadInfo(logAll);
            }
        };
        monitor.setDumpable(new Dumpable() {

            public void dump(Appendable out, String indent) throws IOException {
                out.append(dump());
            }

            public String dump() {
                return "Dump Spinning";
            }
        });
        monitor.logCpuUsage(2000, 0);
        monitor.start();
        Random rnd = new Random();
        for (long cnt = 0; cnt < 100; cnt++) {
            long value = rnd.nextLong() % 50 + 50;
            Sleeper sleeper = new Sleeper(value);
            Thread runner = new Thread(sleeper);
            runner.setDaemon(true);
            runner.start();
        }
        Spinner spinner = new Spinner();
        Thread runner = new Thread(spinner);
        runner.start();
        Thread.sleep(DURATION);
        spinner.setDone();
        monitor.stop();
        assertTrue(countLogs.get() >= 1);
        assertTrue(countSpin.get() >= 2);
    }
}
Also used : Random(java.util.Random) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) StacklessLogging(org.eclipse.jetty.util.log.StacklessLogging) IOException(java.io.IOException) Dumpable(org.eclipse.jetty.util.component.Dumpable) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 3 with Dumpable

use of org.eclipse.jetty.util.component.Dumpable in project jetty.project by eclipse.

the class NamingContext method dump.

/* ------------------------------------------------------------ */
public void dump(Appendable out, String indent) throws IOException {
    out.append(this.getClass().getSimpleName()).append("@").append(Long.toHexString(this.hashCode())).append("\n");
    int size = _bindings.size();
    int i = 0;
    for (Map.Entry<String, Binding> entry : ((Map<String, Binding>) _bindings).entrySet()) {
        boolean last = ++i == size;
        out.append(indent).append(" +- ").append(entry.getKey()).append(": ");
        Binding binding = entry.getValue();
        Object value = binding.getObject();
        if ("comp".equals(entry.getKey()) && value instanceof Reference && "org.eclipse.jetty.jndi.ContextFactory".equals(((Reference) value).getFactoryClassName())) {
            ContextFactory.dump(out, indent + (last ? "    " : " |  "));
        } else if (value instanceof Dumpable) {
            ((Dumpable) value).dump(out, indent + (last ? "    " : " |  "));
        } else {
            out.append(value.getClass().getSimpleName()).append("=");
            out.append(String.valueOf(value).replace('\n', '|').replace('\r', '|'));
            out.append("\n");
        }
    }
}
Also used : Binding(javax.naming.Binding) Reference(javax.naming.Reference) HashMap(java.util.HashMap) Map(java.util.Map) Dumpable(org.eclipse.jetty.util.component.Dumpable)

Aggregations

Dumpable (org.eclipse.jetty.util.component.Dumpable)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Random (java.util.Random)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Binding (javax.naming.Binding)1 Reference (javax.naming.Reference)1 ManagedObject (org.eclipse.jetty.util.annotation.ManagedObject)1 DumpableCollection (org.eclipse.jetty.util.component.DumpableCollection)1 StacklessLogging (org.eclipse.jetty.util.log.StacklessLogging)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1