ActiveIO - 1.0

Clover coverage report - ActiveIO - 1.0 Coverage timestamp: Fri Apr 22 2005 14:27:22 PDT FRAMES NO FRAMES |
file stats: | LOC: | 90 |  | Methods: | 10
| NCLOC: | 52 |  | Classes: | 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
Source file | Conditionals | Statements | Methods | TOTAL
AsynchChannelToServerRequestChannel.java | 100% | 58.8% | 40% | 55.2% |

1 |  |
     /**
2 |  |
      *
3 |  |
      * Copyright 2004 Hiram Chirino
4 |  |
      *
5 |  |
      *  Licensed under the Apache License, Version 2.0 (the "License");
6 |  |
      *  you may not use this file except in compliance with the License.
7 |  |
      *  You may obtain a copy of the License at
8 |  |
      *
9 |  |
      *     http://www.apache.org/licenses/LICENSE-2.0
10 |  |
      *
11 |  |
      *  Unless required by applicable law or agreed to in writing, software
12 |  |
      *  distributed under the License is distributed on an "AS IS" BASIS,
13 |  |
      *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 |  |
      *  See the License for the specific language governing permissions and
15 |  |
      *  limitations under the License.
16 |  |
      */
17 |  |
     package org.activeio.adapter;
18 |  |
19 |  |
     import java.io.IOException;
20 |  |
21 |  |
     import org.activeio.AsynchChannel;
22 |  |
     import org.activeio.AsynchChannelListener;
23 |  |
     import org.activeio.Packet;
24 |  |
     import org.activeio.RequestChannel;
25 |  |
     import org.activeio.RequestListener;
26 |  |
     import org.activeio.packet.EOSPacket;
27 |  |
28 |  |
29 |  |
     /**
30 |  |
      * Creates a {@see org.activeio.RequestChannel} out of a {@see org.activeio.AsynchChannel}.
31 |  |
      * Does not support sending requests.  It can only be used to handle requests.
32 |  |
      *
33 |  |
      * @version $Revision$
34 |  |
      */
35 |  |
     public class AsynchChannelToServerRequestChannel implements RequestChannel, AsynchChannelListener {
36 |  |
37 |  |
         private final AsynchChannel next;
38 |  |
         private RequestListener requestListener;
39 |  |
40 | 2 |
         public AsynchChannelToServerRequestChannel(AsynchChannel next) throws IOException {
41 | 2 |
             this.next = next;
42 | 2 |
             next.setAsynchChannelListener(this);
43 |  |
         }
44 |  |
45 | 0 |
         public Packet request(Packet request, long timeout) throws IOException {
46 | 0 |
             throw new IOException("Operation not supported.");
47 |  |
         }
48 |  |
49 | 2 |
         public void setRequestListener(RequestListener requestListener) throws IOException {
50 | 2 |
             this.requestListener = requestListener;
51 |  |
         }
52 |  |
53 | 0 |
         public RequestListener getRequestListener() {
54 | 0 |
             return requestListener;
55 |  |
         }
56 |  |
57 | 0 |
         public Object narrow(Class target) {
58 | 0 |
             return next.narrow(target);
59 |  |
         }
60 |  |
61 | 0 |
         public void dispose() {
62 | 0 |
             next.dispose();
63 |  |
         }
64 |  |
65 | 2 |
         public void start() throws IOException {
66 | 2 |
             next.start();
67 |  |
         }
68 |  |
69 | 0 |
         public void stop(long timeout) throws IOException {
70 | 0 |
             next.stop(timeout);
71 |  |
         }
72 |  |
73 | 12 |
         public void onPacket(Packet packet) {
74 | 12 |
             if( packet == EOSPacket.EOS_PACKET ) {
75 | 2 |
                 return;
76 |  |
             }
77 | 10 |
             try {
78 | 10 |
                 Packet response = requestListener.onRequest(packet);
79 | 10 |
                 next.write(response);
80 | 10 |
                 next.flush();
81 |  |
             } catch (IOException e) {
82 | 0 |
                 requestListener.onRquestError(e);
83 |  |
             }
84 |  |
         }
85 |  |
86 | 0 |
         public void onPacketError(IOException error) {
87 | 0 |
             requestListener.onRquestError(error);
88 |  |
         }
89 |  |
     }
90 |  |