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  
21  package org.apache.mina.service.executor;
22  
23  import org.apache.mina.api.IoHandler;
24  import org.apache.mina.api.IoSession;
25  
26  /**
27   * In charge of calling the {@link IoHandler} for a given {@link Event}
28   * 
29   * @author <a href="http://mina.apache.org">Apache MINA Project</a>
30   */
31  class HandlerCaller implements EventVisitor {
32  
33      @Override
34      public void visit(CloseEvent event) {
35          IoSession session = event.getSession();
36          try {
37              session.getService().getIoHandler().sessionClosed(session);
38          } catch (Exception e) {
39              session.getService().getIoHandler().exceptionCaught(session, e);
40          }
41      }
42  
43      @Override
44      public void visit(IdleEvent event) {
45          IoSession session = event.getSession();
46          try {
47              session.getService().getIoHandler().sessionIdle(session, event.getIdleStatus());
48          } catch (Exception e) {
49              session.getService().getIoHandler().exceptionCaught(session, e);
50          }
51  
52      }
53  
54      @Override
55      public void visit(OpenEvent event) {
56          IoSession session = event.getSession();
57          try {
58              session.getService().getIoHandler().sessionOpened(session);
59          } catch (Exception e) {
60              session.getService().getIoHandler().exceptionCaught(session, e);
61          }
62  
63      }
64  
65      @Override
66      public void visit(ReceiveEvent event) {
67          IoSession session = event.getSession();
68          try {
69              session.getService().getIoHandler().messageReceived(session, event.getMessage());
70          } catch (Exception e) {
71              session.getService().getIoHandler().exceptionCaught(session, e);
72          }
73      }
74  
75      @Override
76      public void visit(SentEvent event) {
77          IoSession session = event.getSession();
78          try {
79              session.getService().getIoHandler().messageSent(session, event.getMessage());
80          } catch (Exception e) {
81              session.getService().getIoHandler().exceptionCaught(session, e);
82          }
83      }
84  }