KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > net > sockets > TimeoutSocket


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.net.sockets;
23
24 import java.net.Socket JavaDoc;
25 import java.net.InetAddress JavaDoc;
26 import java.net.SocketAddress JavaDoc;
27 import java.net.SocketException JavaDoc;
28 import java.io.InputStream JavaDoc;
29 import java.io.IOException JavaDoc;
30 import java.io.OutputStream JavaDoc;
31 import java.nio.channels.SocketChannel JavaDoc;
32
33 /** A Socket that overrides the getInputStream to return a InterruptableInputStream
34  *
35  * @author Scott.Stark@jboss.org
36  * @version $Revision: 1958 $
37  */

38 public class TimeoutSocket extends Socket JavaDoc
39 {
40    private Socket JavaDoc s;
41
42    public TimeoutSocket(Socket JavaDoc s)
43    {
44       this.s = s;
45    }
46
47    public InetAddress JavaDoc getInetAddress()
48    {
49       return s.getInetAddress();
50    }
51
52    public InetAddress JavaDoc getLocalAddress()
53    {
54       return s.getLocalAddress();
55    }
56
57    public int getPort()
58    {
59       return s.getPort();
60    }
61
62    public int getLocalPort()
63    {
64       return s.getLocalPort();
65    }
66
67    public SocketAddress JavaDoc getRemoteSocketAddress()
68    {
69       return s.getRemoteSocketAddress();
70    }
71
72    public SocketAddress JavaDoc getLocalSocketAddress()
73    {
74       return s.getLocalSocketAddress();
75    }
76
77    public SocketChannel JavaDoc getChannel()
78    {
79       return s.getChannel();
80    }
81
82    public InputStream JavaDoc getInputStream() throws IOException JavaDoc
83    {
84       InputStream JavaDoc is = s.getInputStream();
85       InterruptableInputStream iis = new InterruptableInputStream(is);
86       return iis;
87    }
88
89    public OutputStream JavaDoc getOutputStream() throws IOException JavaDoc
90    {
91       return s.getOutputStream();
92    }
93
94    public void setTcpNoDelay(boolean on) throws SocketException JavaDoc
95    {
96       s.setTcpNoDelay(on);
97    }
98
99    public boolean getTcpNoDelay() throws SocketException JavaDoc
100    {
101       return s.getTcpNoDelay();
102    }
103
104    public void setSoLinger(boolean on, int linger) throws SocketException JavaDoc
105    {
106       s.setSoLinger(on, linger);
107    }
108
109    public int getSoLinger() throws SocketException JavaDoc
110    {
111       return s.getSoLinger();
112    }
113
114    public void sendUrgentData(int data) throws IOException JavaDoc
115    {
116       s.sendUrgentData(data);
117    }
118
119    public void setOOBInline(boolean on) throws SocketException JavaDoc
120    {
121       s.setOOBInline(on);
122    }
123
124    public boolean getOOBInline() throws SocketException JavaDoc
125    {
126       return s.getOOBInline();
127    }
128
129    public synchronized void setSoTimeout(int timeout) throws SocketException JavaDoc
130    {
131       s.setSoTimeout(1000);
132    }
133
134    public synchronized int getSoTimeout() throws SocketException JavaDoc
135    {
136       return s.getSoTimeout();
137    }
138
139    public synchronized void setSendBufferSize(int size) throws SocketException JavaDoc
140    {
141       s.setSendBufferSize(size);
142    }
143
144    public synchronized int getSendBufferSize() throws SocketException JavaDoc
145    {
146       return s.getSendBufferSize();
147    }
148
149    public synchronized void setReceiveBufferSize(int size) throws SocketException JavaDoc
150    {
151       s.setReceiveBufferSize(size);
152    }
153
154    public synchronized int getReceiveBufferSize() throws SocketException JavaDoc
155    {
156       return s.getReceiveBufferSize();
157    }
158
159    public void setKeepAlive(boolean on) throws SocketException JavaDoc
160    {
161       s.setKeepAlive(on);
162    }
163
164    public boolean getKeepAlive() throws SocketException JavaDoc
165    {
166       return s.getKeepAlive();
167    }
168
169    public void setTrafficClass(int tc) throws SocketException JavaDoc
170    {
171       s.setTrafficClass(tc);
172    }
173
174    public int getTrafficClass() throws SocketException JavaDoc
175    {
176       return s.getTrafficClass();
177    }
178
179    public void setReuseAddress(boolean on) throws SocketException JavaDoc
180    {
181       s.setReuseAddress(on);
182    }
183
184    public boolean getReuseAddress() throws SocketException JavaDoc
185    {
186       return s.getReuseAddress();
187    }
188
189    public synchronized void close() throws IOException JavaDoc
190    {
191       s.close();
192    }
193
194    public void shutdownInput() throws IOException JavaDoc
195    {
196       s.shutdownInput();
197    }
198
199    public void shutdownOutput() throws IOException JavaDoc
200    {
201       s.shutdownOutput();
202    }
203
204    public String JavaDoc toString()
205    {
206       return s.toString();
207    }
208
209    public boolean isConnected()
210    {
211       return s.isConnected();
212    }
213
214    public boolean isBound()
215    {
216       return s.isBound();
217    }
218
219    public boolean isClosed()
220    {
221       return s.isClosed();
222    }
223
224    public boolean isInputShutdown()
225    {
226       return s.isInputShutdown();
227    }
228
229    public boolean isOutputShutdown()
230    {
231       return s.isOutputShutdown();
232    }
233 }
234
Popular Tags