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.core.filterchain;
21  
22  import org.apache.mina.core.filterchain.IoFilter.NextFilter;
23  import org.apache.mina.core.session.IdleStatus;
24  import org.apache.mina.core.session.IoEvent;
25  import org.apache.mina.core.session.IoEventType;
26  import org.apache.mina.core.session.IoSession;
27  import org.apache.mina.core.session.TrafficMask;
28  import org.apache.mina.core.write.WriteRequest;
29  
30  /**
31   * An I/O event or an I/O request that MINA provides for {@link IoFilter}s.
32   * Most users won't need to use this class.  It is usually used by internal
33   * components to store I/O events.
34   *
35   * @author The Apache MINA Project (dev@mina.apache.org)
36   * @version $Rev: 591770 $, $Date: 2007-11-04 13:22:44 +0100 (Sun, 04 Nov 2007) $
37   */
38  public class IoFilterEvent extends IoEvent {
39  
40      private final NextFilter nextFilter;
41  
42      public IoFilterEvent(NextFilter nextFilter, IoEventType type,
43              IoSession session, Object parameter) {
44          super(type, session, parameter);
45  
46          if (nextFilter == null) {
47              throw new NullPointerException("nextFilter");
48          }
49          this.nextFilter = nextFilter;
50      }
51  
52      public NextFilter getNextFilter() {
53          return nextFilter;
54      }
55  
56      @Override
57      public void fire() {
58          switch (getType()) {
59          case MESSAGE_RECEIVED:
60              getNextFilter().messageReceived(getSession(), getParameter());
61              break;
62          case MESSAGE_SENT:
63              getNextFilter().messageSent(getSession(), (WriteRequest) getParameter());
64              break;
65          case WRITE:
66              getNextFilter().filterWrite(getSession(), (WriteRequest) getParameter());
67              break;
68          case SET_TRAFFIC_MASK:
69              getNextFilter().filterSetTrafficMask(getSession(), (TrafficMask) getParameter());
70              break;
71          case CLOSE:
72              getNextFilter().filterClose(getSession());
73              break;
74          case EXCEPTION_CAUGHT:
75              getNextFilter().exceptionCaught(getSession(), (Throwable) getParameter());
76              break;
77          case SESSION_IDLE:
78              getNextFilter().sessionIdle(getSession(), (IdleStatus) getParameter());
79              break;
80          case SESSION_OPENED:
81              getNextFilter().sessionOpened(getSession());
82              break;
83          case SESSION_CREATED:
84              getNextFilter().sessionCreated(getSession());
85              break;
86          case SESSION_CLOSED:
87              getNextFilter().sessionClosed(getSession());
88              break;
89          default:
90              throw new IllegalArgumentException("Unknown event type: " + getType());
91          }
92      }
93  }