01: package it.unimi.dsi.mg4j.index.remote;
02:
03: /*
04: * MG4J: Managing Gigabytes for Java
05: *
06: * Copyright (C) 2006-2007 Sebastiano Vigna
07: *
08: * This library is free software; you can redistribute it and/or modify it
09: * under the terms of the GNU Lesser General Public License as published by the Free
10: * Software Foundation; either version 2.1 of the License, or (at your option)
11: * any later version.
12: *
13: * This library is distributed in the hope that it will be useful, but
14: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
16: * for more details.
17: *
18: * You should have received a copy of the GNU Lesser General Public License
19: * along with this program; if not, write to the Free Software
20: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21: *
22: */
23:
24: import java.io.BufferedInputStream;
25: import java.io.BufferedOutputStream;
26: import java.io.DataInputStream;
27: import java.io.DataOutputStream;
28: import java.io.IOException;
29: import java.net.Socket;
30:
31: /** A abstract class representing a thread that provides services inside an {@linkplain it.unimi.dsi.mg4j.index.remote.IndexServer index server}.
32: *
33: * <P>Implementing subclasses must just implement the {@link #run()} method,
34: * using the predefined {@linkplain #inputStream socket input stream} and {@linkplain #outputStream socket output stream}.
35: *
36: * @author Sebastiano Vigna
37: */
38: public abstract class ServerThread implements Runnable {
39: /** The socket associated to this server thread.*/
40: protected final Socket socket;
41: /** The input stream of {@link #socket}, buffered and wrapped inside a data input stream. */
42: protected final DataInputStream inputStream;
43: /** The output stream of {@link #socket}, buffered and wrapped inside a data output stream. */
44: protected final DataOutputStream outputStream;
45:
46: /** Creates a new server thread.
47: * @param socket a socket in listening mode that handles client connections.
48: */
49: public ServerThread(final Socket socket) throws IOException {
50: this .socket = socket;
51: inputStream = new DataInputStream(new BufferedInputStream(
52: socket.getInputStream()));
53: outputStream = new DataOutputStream(new BufferedOutputStream(
54: socket.getOutputStream()));
55: }
56: }
|