Issue #3361 thread safe addHandler
Improved names and javadoc. Signed-off-by: Greg Wilkins <gregw@webtide.com>
This commit is contained in:
parent
1accced62f
commit
338f56ea93
|
@ -260,12 +260,15 @@ public class ContextHandlerCollection extends HandlerCollection
|
|||
* This method is the equivalent of {@link #addHandler(Handler)},
|
||||
* but its execution is non-block and mutually excluded from all
|
||||
* other calls to {@link #deployHandler(Handler)} and
|
||||
* {@link #undeployHandler(Handler)}
|
||||
* {@link #undeployHandler(Handler)}.
|
||||
* The handler may be added after this call returns.
|
||||
* </p>
|
||||
* @param handler the handler to deploy
|
||||
*/
|
||||
public void deployHandler(Handler handler)
|
||||
{
|
||||
if (handler.getServer()!=getServer())
|
||||
handler.setServer(getServer());
|
||||
_serializedExecutor.execute(()-> addHandler(handler));
|
||||
}
|
||||
|
||||
|
@ -277,7 +280,8 @@ public class ContextHandlerCollection extends HandlerCollection
|
|||
* This method is the equivalent of {@link #removeHandler(Handler)},
|
||||
* but its execution is non-block and mutually excluded from all
|
||||
* other calls to {@link #deployHandler(Handler)} and
|
||||
* {@link #undeployHandler(Handler)}
|
||||
* {@link #undeployHandler(Handler)}.
|
||||
* The handler may be removed after this call returns.
|
||||
* </p>
|
||||
* @param handler The handler to undeploy
|
||||
*/
|
||||
|
|
|
@ -37,13 +37,13 @@ import org.eclipse.jetty.util.log.Log;
|
|||
*/
|
||||
public class SerializedExecutor implements Executor
|
||||
{
|
||||
final AtomicReference<Link> _tail = new AtomicReference<>();
|
||||
final AtomicReference<Link> _last = new AtomicReference<>();
|
||||
|
||||
@Override
|
||||
public void execute(Runnable task)
|
||||
{
|
||||
Link link = new Link(task);
|
||||
Link secondLast = _tail.getAndSet(link);
|
||||
Link secondLast = _last.getAndSet(link);
|
||||
if (secondLast==null)
|
||||
run(link);
|
||||
else
|
||||
|
@ -69,8 +69,8 @@ public class SerializedExecutor implements Executor
|
|||
}
|
||||
finally
|
||||
{
|
||||
// Are we the current the last Link?
|
||||
if (_tail.compareAndSet(link, null))
|
||||
// Are we the current last Link?
|
||||
if (_last.compareAndSet(link, null))
|
||||
return;
|
||||
|
||||
// not the last task, so its next link will eventually be set
|
||||
|
|
Loading…
Reference in New Issue