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.Packet;
22 import org.activeio.RequestChannel;
23 import org.activeio.RequestListener;
24 import org.activeio.SynchChannel;
25
26
27 /***
28 * Creates a {@see org.activeio.RequestChannel} out of a {@see org.activeio.SynchChannel}.
29 * Does not support handing requests. It can only be used to send requests.
30 *
31 * @version $Revision$
32 */
33 final public class AsynchChannelToClientRequestChannel implements RequestChannel {
34
35 private final SynchChannel next;
36
37 public AsynchChannelToClientRequestChannel(SynchChannel next) {
38 this.next = next;
39 }
40
41 public Packet request(Packet request, long timeout) throws IOException {
42 next.write(request);
43 next.flush();
44 return next.read(timeout);
45 }
46
47 public void setRequestListener(RequestListener requestListener) throws IOException {
48 throw new IOException("Operation not supported.");
49 }
50
51 public RequestListener getRequestListener() {
52 return null;
53 }
54
55 public Object narrow(Class target) {
56 return next.narrow(target);
57 }
58
59 public void dispose() {
60 next.dispose();
61 }
62
63 public void start() throws IOException {
64 next.start();
65 }
66
67 public void stop(long timeout) throws IOException {
68 next.stop(timeout);
69 }
70 }