001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: *
019: */
020: package org.apache.mina.common;
021:
022: /**
023: * An I/O event or an I/O request that MINA provides.
024: * Most users won't need to use this class. It is usually used by internal
025: * components to store I/O events.
026: *
027: * @author The Apache MINA Project (dev@mina.apache.org)
028: * @version $Rev: 592965 $, $Date: 2007-11-07 17:15:00 -0700 (Wed, 07 Nov 2007) $
029: */
030: public class IoEvent implements Runnable {
031: private final IoEventType type;
032:
033: private final IoSession session;
034:
035: private final Object parameter;
036:
037: public IoEvent(IoEventType type, IoSession session, Object parameter) {
038: if (type == null) {
039: throw new NullPointerException("type");
040: }
041: if (session == null) {
042: throw new NullPointerException("session");
043: }
044: this .type = type;
045: this .session = session;
046: this .parameter = parameter;
047: }
048:
049: public IoEventType getType() {
050: return type;
051: }
052:
053: public IoSession getSession() {
054: return session;
055: }
056:
057: public Object getParameter() {
058: return parameter;
059: }
060:
061: public void run() {
062: fire();
063: }
064:
065: public void fire() {
066: switch (getType()) {
067: case MESSAGE_RECEIVED:
068: getSession().getFilterChain().fireMessageReceived(
069: getParameter());
070: break;
071: case MESSAGE_SENT:
072: getSession().getFilterChain().fireMessageSent(
073: (WriteRequest) getParameter());
074: break;
075: case WRITE:
076: getSession().getFilterChain().fireFilterWrite(
077: (WriteRequest) getParameter());
078: break;
079: case SET_TRAFFIC_MASK:
080: getSession().getFilterChain().fireFilterSetTrafficMask(
081: (TrafficMask) getParameter());
082: break;
083: case CLOSE:
084: getSession().getFilterChain().fireFilterClose();
085: break;
086: case EXCEPTION_CAUGHT:
087: getSession().getFilterChain().fireExceptionCaught(
088: (Throwable) getParameter());
089: break;
090: case SESSION_IDLE:
091: getSession().getFilterChain().fireSessionIdle(
092: (IdleStatus) getParameter());
093: break;
094: case SESSION_OPENED:
095: getSession().getFilterChain().fireSessionOpened();
096: break;
097: case SESSION_CREATED:
098: getSession().getFilterChain().fireSessionCreated();
099: break;
100: case SESSION_CLOSED:
101: getSession().getFilterChain().fireSessionClosed();
102: break;
103: default:
104: throw new IllegalArgumentException("Unknown event type: "
105: + getType());
106: }
107: }
108:
109: @Override
110: public String toString() {
111: if (getParameter() == null) {
112: return "[" + getSession() + "] " + getType().name();
113: } else {
114: return "[" + getSession() + "] " + getType().name() + ": "
115: + getParameter();
116: }
117: }
118: }
|