KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > ubik > net > nio > acceptor > AcceptorCycleListener


1 package org.sapia.ubik.net.nio.acceptor;
2
3 import org.sapia.ubik.net.nio.Cycle;
4 import org.sapia.ubik.net.nio.CycleListener;
5
6 /**
7  * @author Yanick Duchesne
8  *
9  * <dl>
10  * <dt><b>Copyright: </b>
11  * <dd>Copyright &#169; 2002-2005 <a HREF="http://www.sapia-oss.org">Sapia Open
12  * Source Software </a>. All Rights Reserved.</dd>
13  * </dt>
14  * <dt><b>License: </b>
15  * <dd>Read the license.txt file of the jar or visit the <a
16  * HREF="http://www.sapia-oss.org/license.html">license page </a> at the Sapia
17  * OSS web site</dd>
18  * </dt>
19  * </dl>
20  */

21 public class AcceptorCycleListener implements CycleListener {
22
23   private AcceptorConfig _config;
24
25   public AcceptorCycleListener(AcceptorConfig config) {
26     _config = config;
27   }
28
29   /**
30    * @see org.sapia.ubik.net.nio.CycleListener#onNextState(org.sapia.ubik.net.nio.Cycle)
31    */

32   public void onNextState(Cycle cycle) {
33     switch(cycle.state()){
34     case Cycle.STATE_READ:
35       _config.queue.add(cycle, false);
36       break;
37     case Cycle.STATE_WRITE:
38       _config.queue.add(cycle, false);
39       break;
40     default:
41       try {
42         _config.handlers[cycle.state()].handle(cycle);
43       } catch(HandlerException e) {
44         _config.debug.out(getClass(), e.getMessage(), e);
45         handleError((AcceptorCycle) cycle, e);
46       } catch(RuntimeException JavaDoc e) {
47         _config.debug.out(getClass(), e.getMessage(), e);
48         handleError((AcceptorCycle) cycle, e);
49       }
50     }
51   }
52
53   private void handleError(AcceptorCycle cycle, Throwable JavaDoc t) {
54     if(cycle != null) {
55       cycle.error(t);
56       cycle.next();
57     }
58   }
59
60 }
61
Popular Tags