Make sure successful SslHandshakeCompletionEvent is a singleton

- Related: #1373
- This commit is an amendment to 2a7bea2ad3
This commit is contained in:
Trustin Lee 2013-05-18 05:50:58 +09:00
parent 620c3e025a
commit 50433f7b9a
2 changed files with 17 additions and 3 deletions

View File

@ -189,8 +189,6 @@ public class SslHandler
private volatile long handshakeTimeoutMillis = 10000; private volatile long handshakeTimeoutMillis = 10000;
private volatile long closeNotifyTimeoutMillis = 3000; private volatile long closeNotifyTimeoutMillis = 3000;
private static final SslHandshakeCompletionEvent HANDSHAKE_SUCCESS_EVENT = new SslHandshakeCompletionEvent(null);
/** /**
* Creates a new instance. * Creates a new instance.
* *
@ -908,7 +906,7 @@ public class SslHandler
*/ */
private void setHandshakeSuccess() { private void setHandshakeSuccess() {
if (handshakePromise.trySuccess(ctx.channel())) { if (handshakePromise.trySuccess(ctx.channel())) {
ctx.fireUserEventTriggered(HANDSHAKE_SUCCESS_EVENT); ctx.fireUserEventTriggered(SslHandshakeCompletionEvent.SUCCESS);
} }
} }

View File

@ -22,9 +22,25 @@ package io.netty.handler.ssl;
*/ */
public final class SslHandshakeCompletionEvent { public final class SslHandshakeCompletionEvent {
public static final SslHandshakeCompletionEvent SUCCESS = new SslHandshakeCompletionEvent();
private final Throwable cause; private final Throwable cause;
/**
* Creates a new event that indicates a successful handshake.
*/
private SslHandshakeCompletionEvent() {
cause = null;
}
/**
* Creates a new event that indicates an unsuccessful handshake.
* Use {@link #SUCCESS} to indicate a successful handshake.
*/
public SslHandshakeCompletionEvent(Throwable cause) { public SslHandshakeCompletionEvent(Throwable cause) {
if (cause == null) {
throw new NullPointerException("cause");
}
this.cause = cause; this.cause = cause;
} }