1 /* 2 * Copyright 2013 The Netty Project 3 * 4 * The Netty Project licenses this file to you under the Apache License, 5 * version 2.0 (the "License"); you may not use this file except in compliance 6 * with the License. You may obtain a copy of the License at: 7 * 8 * https://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 * License for the specific language governing permissions and limitations 14 * under the License. 15 */ 16 package io.netty5.handler.ssl; 17 18 import javax.net.ssl.SSLSession; 19 20 /** 21 * Event that is fired once the SSL handshake is complete, which may be because it was successful or there 22 * was an error. 23 */ 24 public final class SslHandshakeCompletionEvent extends SslCompletionEvent { 25 private final String applicationProtocol; 26 27 /** 28 * Creates a new event that indicates a successful handshake. 29 * 30 * @param session the {@link SSLSession} for the handshake. 31 * @param applicationProtocol the application protocol that was selected (if any). 32 */ 33 public SslHandshakeCompletionEvent(SSLSession session, String applicationProtocol) { 34 super(session); 35 this.applicationProtocol = applicationProtocol; 36 } 37 38 /** 39 * Creates a new event that indicates an unsuccessful handshake. 40 * 41 * @param session the {@link SSLSession} for the handshake. 42 * @param applicationProtocol the application protocol that was selected (if any). 43 * @param cause the cause of the failure. 44 */ 45 public SslHandshakeCompletionEvent(SSLSession session, String applicationProtocol, Throwable cause) { 46 super(session, cause); 47 this.applicationProtocol = applicationProtocol; 48 } 49 50 /** 51 * Creates a new event that indicates an unsuccessful handshake. 52 * 53 * @param cause the cause of the failure. 54 */ 55 public SslHandshakeCompletionEvent(Throwable cause) { 56 this(null, null, cause); 57 } 58 59 /** 60 * Returns the {@link SSLSession} in case of {@link #isSuccess()} to be {@code true}, {@code null} in case of a 61 * failure. 62 * 63 * @return the session. 64 */ 65 @Override 66 public SSLSession session() { 67 return super.session(); 68 } 69 70 /** 71 * Return the application protocol that was selected or {@code null} if none was selected. 72 * 73 * @return the application protocol. 74 */ 75 public String applicationProtocol() { 76 return applicationProtocol; 77 } 78 }