View Javadoc
1   /*
2    * Copyright 2022 The Netty Project
3    *
4    * The Netty Project licenses this file to you under the Apache License, version
5    * 2.0 (the "License"); you may not use this file except in compliance with the
6    * 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 under
14   * the License.
15   */
16  package io.netty5.handler.codec;
17  
18  import io.netty5.channel.ChannelPipeline;
19  
20  /**
21   * An application-level event propagated via an {@link ChannelPipeline}, such as a TLS or WebSocket handshake event.
22   */
23  public interface ProtocolEvent {
24  
25      /**
26       * Returns {@code true} if the event was sent because of some successful protocol event.
27       *
28       * @return {@code true} when success, {@code false} otherwise.
29       */
30      default boolean isSuccess() {
31          return cause() == null;
32      }
33  
34      /**
35       * Returns {@code true} if the event was sent because of some unsuccessful protocol event.
36       *
37       * @return {@code true} when unsuccessful, {@code false} otherwise.
38       */
39      default boolean isFailed() {
40          return cause() != null;
41      }
42  
43      /**
44       * Returns the cause of the failure, or {@code null} if {@link #isSuccess()}.
45       *
46       * @return the {@link Throwable} if {@link #isFailed()}  or {@code null} if {@link #isSuccess()}.
47       */
48      Throwable cause();
49  }