View Javadoc

1   /*
2    *  Licensed to the Apache Software Foundation (ASF) under one
3    *  or more contributor license agreements.  See the NOTICE file
4    *  distributed with this work for additional information
5    *  regarding copyright ownership.  The ASF licenses this file
6    *  to you under the Apache License, Version 2.0 (the
7    *  "License"); you may not use this file except in compliance
8    *  with the License.  You may obtain a copy of the License at
9    *
10   *    http://www.apache.org/licenses/LICENSE-2.0
11   *
12   *  Unless required by applicable law or agreed to in writing,
13   *  software distributed under the License is distributed on an
14   *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   *  KIND, either express or implied.  See the License for the
16   *  specific language governing permissions and limitations
17   *  under the License.
18   *
19   */
20  package org.apache.mina.common;
21  
22  import org.apache.mina.common.IoFilter.NextFilter;
23  
24  /**
25   * An I/O event or an I/O request that MINA provides for {@link IoFilter}s.
26   * Most users won't need to use this class.  It is usually used by internal
27   * components to store I/O events.
28   *
29   * @author The Apache MINA Project (dev@mina.apache.org)
30   * @version $Rev: 591770 $, $Date: 2007-11-04 05:22:44 -0700 (Sun, 04 Nov 2007) $
31   */
32  public class IoFilterEvent extends IoEvent {
33  
34      private final NextFilter nextFilter;
35  
36      public IoFilterEvent(NextFilter nextFilter, IoEventType type,
37              IoSession session, Object parameter) {
38          super(type, session, parameter);
39  
40          if (nextFilter == null) {
41              throw new NullPointerException("nextFilter");
42          }
43          this.nextFilter = nextFilter;
44      }
45  
46      public NextFilter getNextFilter() {
47          return nextFilter;
48      }
49  
50      @Override
51      public void fire() {
52          switch (getType()) {
53          case MESSAGE_RECEIVED:
54              getNextFilter().messageReceived(getSession(), getParameter());
55              break;
56          case MESSAGE_SENT:
57              getNextFilter().messageSent(getSession(), (WriteRequest) getParameter());
58              break;
59          case WRITE:
60              getNextFilter().filterWrite(getSession(), (WriteRequest) getParameter());
61              break;
62          case SET_TRAFFIC_MASK:
63              getNextFilter().filterSetTrafficMask(getSession(), (TrafficMask) getParameter());
64              break;
65          case CLOSE:
66              getNextFilter().filterClose(getSession());
67              break;
68          case EXCEPTION_CAUGHT:
69              getNextFilter().exceptionCaught(getSession(), (Throwable) getParameter());
70              break;
71          case SESSION_IDLE:
72              getNextFilter().sessionIdle(getSession(), (IdleStatus) getParameter());
73              break;
74          case SESSION_OPENED:
75              getNextFilter().sessionOpened(getSession());
76              break;
77          case SESSION_CREATED:
78              getNextFilter().sessionCreated(getSession());
79              break;
80          case SESSION_CLOSED:
81              getNextFilter().sessionClosed(getSession());
82              break;
83          default:
84              throw new IllegalArgumentException("Unknown event type: " + getType());
85          }
86      }
87  }