|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object it.unimi.di.mg4j.index.remote.IndexServer
public class IndexServer
A daemon exposing an index remotely.
MG4J provides remote access to indices using a client/server pair. A thread
running the start(Index, InetAddress, int, boolean)
method of this
class acts as a server.
Once a server is up and running, clients can connect by calling the
getIndex(String, int, boolean, boolean)
method, which sends to
the server a GET_INDEX
command and returns a (serialised) Index
that will handle all communication with the server transparently. The static
factory methods in Index
(such as Index.getInstance(CharSequence)
)
will turn URIs such as mg4j://localhost into calls
to getIndex(String, int, boolean, boolean)
.
Presently there are two main kinds of remote indices: those exposing the local
bitstream remotely, and those exposing the results of document iterators remotely.
In the first case, the bitstream is passed over the net, and it is decoded locally
(it is very advisable not using a compression method requiring document sizes in that case,
as the size list will be serialised into the returned Index
instance).
When started, an index server will by default try to expose the local bitstream,
if possible, but it can be forced not to do so with a suitable parameter. Depending
on the kind of access requested, the index server will return instances of
RemoteBitStreamIndex
or instances of RemoteIndex
. The two approaches vary
wildly in performance, and some profiling with specific applications is advisable
before choosing one method over the other.
All other server commands available spawn a new thread that will handle a specific
data structure over the newly created socket. Thus, after writing the command
GET_SIZE_LIST
the server will start a RemoteSizeList.ServerThread
and answer to queries about the size list, whereas after writing the command
GET_INDEX_READER
the server will start a
RemoteIndexReader.ServerThread
and answer to queries about the underlying local IndexReader
.
For simplicity and easiness in code editing, every client class starting a thread
(e.g., RemoteTermMap
, RemoteIndexReader
,
…) sports a nested static class called ServerThread
containing the code of the corresponding server thread. In this
way client and server code sit in the same source file, making editing and debugging simpler.
Field Summary | |
---|---|
static int |
DEFAULT_PORT
|
static byte |
GET_CLIENT_INPUT_STREAM
|
static byte |
GET_CLIENT_POS_INPUT_STREAM
|
static byte |
GET_INDEX
|
static byte |
GET_INDEX_READER
|
static byte |
GET_OFFSET_LIST
|
static byte |
GET_PREFIX_MAP
|
static byte |
GET_SIZE_LIST
|
static byte |
GET_TERM_MAP
|
static byte |
QUIT
|
Constructor Summary | |
---|---|
IndexServer()
|
Method Summary | |
---|---|
static Index |
getIndex(String host,
int port,
boolean randomAccess,
boolean documentSizes)
Returns an index object corresponding a given index server specified by host and port. |
static void |
main(String[] arg)
|
static void |
quit(String host,
int port)
|
static void |
start(Index index,
InetAddress address,
int port,
boolean forceRemoteIndex)
Starts an index-server daemon thread. |
static void |
start(Index index,
ServerSocket serverSocket,
boolean forceRemoteIndex)
Starts an index server. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int DEFAULT_PORT
public static final byte GET_INDEX
public static final byte GET_INDEX_READER
public static final byte GET_TERM_MAP
public static final byte GET_PREFIX_MAP
public static final byte GET_SIZE_LIST
public static final byte GET_OFFSET_LIST
public static final byte GET_CLIENT_INPUT_STREAM
public static final byte GET_CLIENT_POS_INPUT_STREAM
public static final byte QUIT
Constructor Detail |
---|
public IndexServer()
Method Detail |
---|
public static Index getIndex(String host, int port, boolean randomAccess, boolean documentSizes) throws IOException, ClassNotFoundException
host
- the server host.port
- the server port, or -1 for DEFAULT_PORT
.randomAccess
- whether the index should be accessible randomly.documentSizes
- if true, document sizes will be loaded (note that sometimes document sizes
might be loaded anyway because the compression method for positions requires it).
IOException
ClassNotFoundException
public static void quit(String host, int port) throws IOException
IOException
public static void start(Index index, ServerSocket serverSocket, boolean forceRemoteIndex) throws IOException
index
- the underlying index.serverSocket
- the daemon socket.forceRemoteIndex
- force the thread to use a RemoteIndex
instead
of a RemoteBitStreamIndex
, even if the latter would be usable.
IOException
public static void start(Index index, InetAddress address, int port, boolean forceRemoteIndex) throws IOException
index
- the underlying index.address
- the IP address for the daemon socket.port
- the IP port for the daemon socket.forceRemoteIndex
- force the thread to use a RemoteIndex
instead
of a RemoteBitStreamIndex
, even if the latter would be usable.
IOException
public static void main(String[] arg) throws ConfigurationException, IOException, URISyntaxException, ClassNotFoundException, com.martiansoftware.jsap.JSAPException, SecurityException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException
ConfigurationException
IOException
URISyntaxException
ClassNotFoundException
com.martiansoftware.jsap.JSAPException
SecurityException
InstantiationException
IllegalAccessException
InvocationTargetException
NoSuchMethodException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |