View Javadoc

1   /*
2    * Copyright 2009 Red Hat, Inc.
3    *
4    * Red Hat licenses this file to you under the Apache License, version 2.0
5    * (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    *    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 org.jboss.netty.handler.timeout;
17  
18  import static org.jboss.netty.channel.Channels.*;
19  
20  import java.text.DateFormat;
21  import java.util.Date;
22  import java.util.Locale;
23  
24  import org.jboss.netty.channel.Channel;
25  import org.jboss.netty.channel.ChannelFuture;
26  
27  /**
28   * The default {@link IdleStateEvent} implementation.
29   *
30   * @author <a href="http://www.jboss.org/netty/">The Netty Project</a>
31   * @author <a href="http://gleamynode.net/">Trustin Lee</a>
32   * @version $Rev: 2080 $, $Date: 2010-01-26 18:04:19 +0900 (Tue, 26 Jan 2010) $
33   */
34  public class DefaultIdleStateEvent implements IdleStateEvent {
35  
36      private final Channel channel;
37      private final IdleState state;
38      private final long lastActivityTimeMillis;
39  
40      /**
41       * Creates a new instance.
42       */
43      public DefaultIdleStateEvent(
44              Channel channel, IdleState state, long lastActivityTimeMillis) {
45          if (channel == null) {
46              throw new NullPointerException("channel");
47          }
48          if (state == null) {
49              throw new NullPointerException("state");
50          }
51          this.channel = channel;
52          this.state = state;
53          this.lastActivityTimeMillis = lastActivityTimeMillis;
54      }
55  
56      public Channel getChannel() {
57          return channel;
58      }
59  
60      public ChannelFuture getFuture() {
61          return succeededFuture(getChannel());
62      }
63  
64      public IdleState getState() {
65          return state;
66      }
67  
68      public long getLastActivityTimeMillis() {
69          return lastActivityTimeMillis;
70      }
71  
72      @Override
73      public String toString() {
74          return getChannel().toString() + ' ' + getState() + " since " +
75                 DateFormat.getDateTimeInstance(
76                         DateFormat.SHORT, DateFormat.SHORT, Locale.US).format(
77                                 new Date(getLastActivityTimeMillis()));
78      }
79  }