1 /*
2 * Copyright 2012 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 * http://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.netty.handler.timeout;
17
18 import io.netty.channel.Channel;
19 import io.netty.util.internal.ObjectUtil;
20
21 /**
22 * A user event triggered by {@link IdleStateHandler} when a {@link Channel} is idle.
23 */
24 public class IdleStateEvent {
25 public static final IdleStateEvent FIRST_READER_IDLE_STATE_EVENT = new IdleStateEvent(IdleState.READER_IDLE, true);
26 public static final IdleStateEvent READER_IDLE_STATE_EVENT = new IdleStateEvent(IdleState.READER_IDLE, false);
27 public static final IdleStateEvent FIRST_WRITER_IDLE_STATE_EVENT = new IdleStateEvent(IdleState.WRITER_IDLE, true);
28 public static final IdleStateEvent WRITER_IDLE_STATE_EVENT = new IdleStateEvent(IdleState.WRITER_IDLE, false);
29 public static final IdleStateEvent FIRST_ALL_IDLE_STATE_EVENT = new IdleStateEvent(IdleState.ALL_IDLE, true);
30 public static final IdleStateEvent ALL_IDLE_STATE_EVENT = new IdleStateEvent(IdleState.ALL_IDLE, false);
31
32 private final IdleState state;
33 private final boolean first;
34
35 /**
36 * Constructor for sub-classes.
37 *
38 * @param state the {@link IdleStateEvent} which triggered the event.
39 * @param first {@code true} if its the first idle event for the {@link IdleStateEvent}.
40 */
41 protected IdleStateEvent(IdleState state, boolean first) {
42 this.state = ObjectUtil.checkNotNull(state, "state");
43 this.first = first;
44 }
45
46 /**
47 * Returns the idle state.
48 */
49 public IdleState state() {
50 return state;
51 }
52
53 /**
54 * Returns {@code true} if this was the first event for the {@link IdleState}
55 */
56 public boolean isFirst() {
57 return first;
58 }
59 }