Improved dump of ManagedSelector.

Now also dumping the actions.

Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
This commit is contained in:
Simone Bordet 2017-11-16 11:34:59 +01:00
parent 918cf625cc
commit 131f46df64
2 changed files with 14 additions and 26 deletions

View File

@ -28,6 +28,7 @@ import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
@ -40,6 +41,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
import org.eclipse.jetty.util.component.ContainerLifeCycle;
import org.eclipse.jetty.util.component.Dumpable;
import org.eclipse.jetty.util.component.DumpableCollection;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.util.thread.ExecutionStrategy;
@ -226,29 +228,23 @@ public class ManagedSelector extends ContainerLifeCycle implements Dumpable
}
}
@Override
public String dump()
{
super.dump();
return ContainerLifeCycle.dump(this);
}
@Override
public void dump(Appendable out, String indent) throws IOException
{
super.dump(out, indent);
Selector selector = _selector;
if (selector == null || !selector.isOpen())
dumpBeans(out, indent);
else
if (selector != null && selector.isOpen())
{
final ArrayList<Object> dump = new ArrayList<>(selector.keys().size() * 2);
DumpKeys dumpKeys = new DumpKeys(dump);
List<Runnable> actions;
try (Locker.Lock lock = _locker.lock())
{
actions = new ArrayList<>(_actions);
}
List<Object> keys = new ArrayList<>(selector.keys().size());
DumpKeys dumpKeys = new DumpKeys(keys);
submit(dumpKeys);
dumpKeys.await(5, TimeUnit.SECONDS);
if (dump.isEmpty())
dumpBeans(out, indent);
else
dumpBeans(out, indent, dump);
dump(out, indent, Arrays.asList(new DumpableCollection("keys", keys), new DumpableCollection("actions", actions)));
}
}
@ -512,7 +508,7 @@ public class ManagedSelector extends ContainerLifeCycle implements Dumpable
}
catch (Throwable x)
{
_dumps.add(String.format("SelectionKey@%x[%s]", key.hashCode(), x));
_dumps.add(String.format("SelectionKey@%x[%s]->%s", key.hashCode(), x, key.attachment()));
}
}
}

View File

@ -660,13 +660,10 @@ public class ContainerLifeCycle extends AbstractLifeCycle implements Container,
int size = _beans.size();
for (Collection<?> c : collections)
size += c.size();
if (size == 0)
return;
int i = 0;
for (Bean b : _beans)
{
i++;
++i;
switch(b._managed)
{
case POJO:
@ -697,20 +694,15 @@ public class ContainerLifeCycle extends AbstractLifeCycle implements Container,
else
dumpObject(out, b._bean);
break;
}
}
if (i<size)
out.append(indent).append(" |\n");
for (Collection<?> c : collections)
{
for (Object o : c)
{
i++;
out.append(indent).append(" +> ");
if (o instanceof Dumpable)
((Dumpable)o).dump(out, indent + (i == size ? " " : " | "));
else