Merged branch 'jetty-9.4.x' into 'master'.

This commit is contained in:
Simone Bordet 2016-08-08 23:25:54 +02:00
commit 7bb0a00ff4
2 changed files with 32 additions and 56 deletions

View File

@ -117,7 +117,7 @@ public abstract class HTTP2Session extends ContainerLifeCycle implements ISessio
protected void doStop() throws Exception protected void doStop() throws Exception
{ {
super.doStop(); super.doStop();
close(ErrorCode.NO_ERROR.code, "stop", new Callback.NonBlocking() close(ErrorCode.NO_ERROR.code, "stop", new Callback()
{ {
@Override @Override
public void succeeded() public void succeeded()
@ -130,6 +130,12 @@ public abstract class HTTP2Session extends ContainerLifeCycle implements ISessio
{ {
disconnect(); disconnect();
} }
@Override
public InvocationType getInvocationType()
{
return InvocationType.NON_BLOCKING;
}
}); });
} }

View File

@ -21,14 +21,20 @@ package org.eclipse.jetty.util.thread;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
/** /**
* An object (typically either a {@link Runnable} or {@link Callable} * <p>A task (typically either a {@link Runnable} or {@link Callable}
* that can declare how it will behaive when invoked: blocking, non-blocking * that declares how it will behave when invoked:</p>
* or either. * <ul>
* * <li>blocking, the invocation will certainly block (e.g. performs blocking I/O)</li>
* <li>non-blocking, the invocation will certainly <strong>not</strong> block</li>
* <li>either, the invocation <em>may</em> block</li>
* </ul>
*/ */
public interface Invocable public interface Invocable
{ {
enum InvocationType { BLOCKING, NON_BLOCKING, EITHER }; enum InvocationType
{
BLOCKING, NON_BLOCKING, EITHER
}
static ThreadLocal<Boolean> __nonBlocking = new ThreadLocal<Boolean>() static ThreadLocal<Boolean> __nonBlocking = new ThreadLocal<Boolean>()
{ {
@ -59,27 +65,9 @@ public interface Invocable
} }
} }
public static void invokeOnlyNonBlocking(Runnable task)
{
switch(getInvocationType(task))
{
case BLOCKING:
throw new IllegalArgumentException("Cannot invoke nonblocking: "+task);
case NON_BLOCKING:
task.run();
break;
case EITHER:
// a Choice exists, so we must indicate NonBlocking
invokeNonBlocking(task);
break;
}
}
public static void invokePreferNonBlocking(Runnable task) public static void invokePreferNonBlocking(Runnable task)
{ {
switch(getInvocationType(task)) switch (getInvocationType(task))
{ {
case BLOCKING: case BLOCKING:
case NON_BLOCKING: case NON_BLOCKING:
@ -95,7 +83,7 @@ public interface Invocable
public static void invokePreferred(Runnable task, InvocationType preferredInvocationType) public static void invokePreferred(Runnable task, InvocationType preferredInvocationType)
{ {
switch(getInvocationType(task)) switch (getInvocationType(task))
{ {
case BLOCKING: case BLOCKING:
case NON_BLOCKING: case NON_BLOCKING:
@ -103,7 +91,7 @@ public interface Invocable
break; break;
case EITHER: case EITHER:
if (getInvocationType(task)==InvocationType.EITHER && preferredInvocationType==InvocationType.NON_BLOCKING) if (getInvocationType(task) == InvocationType.EITHER && preferredInvocationType == InvocationType.NON_BLOCKING)
invokeNonBlocking(task); invokeNonBlocking(task);
else else
task.run(); task.run();
@ -113,35 +101,21 @@ public interface Invocable
public static Runnable asPreferred(Runnable task, InvocationType preferredInvocationType) public static Runnable asPreferred(Runnable task, InvocationType preferredInvocationType)
{ {
switch(getInvocationType(task)) switch (getInvocationType(task))
{ {
case BLOCKING: case BLOCKING:
case NON_BLOCKING: case NON_BLOCKING:
break; break;
case EITHER: case EITHER:
if (getInvocationType(task)==InvocationType.EITHER && preferredInvocationType==InvocationType.NON_BLOCKING) if (getInvocationType(task) == InvocationType.EITHER && preferredInvocationType == InvocationType.NON_BLOCKING)
return new Runnable() return () -> invokeNonBlocking(task);
{
@Override
public void run()
{
invokeNonBlocking(task);
}
};
break; break;
} }
return task; return task;
} }
public static void invokePreferBlocking(Runnable task)
{
task.run();
}
public static InvocationType getInvocationType(Object o) public static InvocationType getInvocationType(Object o)
{ {
if (o instanceof Invocable) if (o instanceof Invocable)
@ -153,8 +127,4 @@ public interface Invocable
{ {
return InvocationType.BLOCKING; return InvocationType.BLOCKING;
} }
} }