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