|
|||||||||
| Home >> All >> java >> [ net overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.net
Class Connector

java.lang.Objectjava.net.Connector
- All Implemented Interfaces:
- java.lang.Runnable
- public class Connector
- extends java.lang.Object
- implements java.lang.Runnable
- extends java.lang.Object
This class manage the compression layer for the stream (connected) scenario. It's a thread responsible for packet receiving and handling. It can guess if the packet is compressed and so should be decompressed or if it's an ack for a previously sent packet and should be used to compute statistics.
- Version:
- 1.0
| Field Summary | |
protected Compressor |
compressor
Reference to the real compression engine that must follow the Compressor interface. |
protected Decompressor |
decompressor
Reference to the real decompression engine that must follow the Decompressor interface. |
protected java.io.InputStream |
in
Reference to the real input stream as provided by the plain-old socket factory, tipically PlainSocketImpl. |
protected Interpolator |
interpolator
Reference to the real statistical modeler that must follow the Interpolator interface. |
protected java.util.Hashtable |
listeners
List of objects waiting for ack. |
protected java.lang.Thread |
myself
|
protected boolean |
notStop
This variable drive the main loop: a false value will stop the thread and prepare for exit. |
protected java.io.OutputStream |
out
Reference to the real output stream as provided by the plain-old socket factory, tipically PlainSocketImpl. |
protected ZInputStream |
zin
This input stream represents the input to the compression engine. |
protected ZOutputStream |
zout
This output stream represents the output coming from the compression engine. |
| Constructor Summary | |
Connector(java.io.InputStream in,
java.io.OutputStream out)
This constructor is used when the connector is not yet started and it is request by the method getInputStream 55 of our socket implementation. |
|
Connector(java.io.OutputStream out,
java.io.InputStream in)
See the previous constructor keeping in mind this one works for getOutputStream 55 |
|
| Method Summary | |
protected byte[] |
compress(byte[] buf)
This method is responsible for data compression. |
protected void |
create()
This internal method is the common part of constructors. |
protected byte[] |
decompress(byte[] buf)
This method is responsible for data decompression. |
java.io.InputStream |
getInputStream()
|
java.io.OutputStream |
getOutputStream()
|
void |
run()
The main loop. |
void |
send(byte[] data)
This method is invoked by the ZoutputStream.flush 55 method to perform the real data sending. |
void |
sendAck(ZObject zobj)
An ack is sent through this method, based on the passed ZObject that's the received one. |
void |
stop()
|
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
compressor
protected Compressor compressor
- Reference to the real compression engine that must follow the
Compressor interface.
- See Also:
- Compressor, DeflatingCompressor
decompressor
protected Decompressor decompressor
- Reference to the real decompression engine that must follow the
Decompressor interface.
- See Also:
- Decompressor, InflatingDecompressor
interpolator
protected Interpolator interpolator
- Reference to the real statistical modeler that must follow the
Interpolator interface.
- See Also:
- Interpolator, LinearInterpolator
in
protected java.io.InputStream in
- Reference to the real input stream as provided by the plain-old
socket factory, tipically PlainSocketImpl.
out
protected java.io.OutputStream out
- Reference to the real output stream as provided by the plain-old
socket factory, tipically PlainSocketImpl.
zin
protected ZInputStream zin
- This input stream represents the input to the compression engine.
It is the reference passed when getInputStream 55 is invoked.
IMHO it's interesting to see how it is realized because it's an infinite data queue.
- See Also:
- ZInputStream
zout
protected ZOutputStream zout
- This output stream represents the output coming from the compression engine.
It is the reference passed when getOutputStream 55 is invoked.
- See Also:
- ZOutputStream
listeners
protected java.util.Hashtable listeners
- List of objects waiting for ack. This hashtable is indexed by sequence number
and contains objects of Listener type.
Every Listener waits for a single ack packet and is responsible for the update
of the statistical interpolator.
myself
protected java.lang.Thread myself
notStop
protected boolean notStop
- This variable drive the main loop: a false value will stop the thread and prepare for exit.
The value can be changed using the stop 55 method.
| Constructor Detail |
Connector
public Connector(java.io.InputStream in, java.io.OutputStream out) throws java.lang.Exception
- This constructor is used when the connector is not yet started and it is request by
the method getInputStream 55 of our socket
implementation.
It's perfectly specular (but non identical) to the next constructor.
Here the question is that, like with Object{Input | Output}Stream class, on client side
you should open output then input streams and on server side you should do the converse,
because the stream opening causes handshaking packet to be exchanged between the ObjectOutputStream
on client and ObjectInputStream on server.
If you open the two output (on both client and server) they'll send handshacking packets that nobody
receive and answer because no input stream is opened yet.
Connector
public Connector(java.io.OutputStream out, java.io.InputStream in) throws java.lang.Exception
- See the previous constructor keeping in mind this one works for
getOutputStream 55
| Method Detail |
create
protected void create()
throws java.lang.Exception
- This internal method is the common part of constructors. It's responsible for command-line options
gathering through the properties set.
Actually recognized property set is:
- compressor - to load a different compression engine (default: DeflatingCompressor)
- decompressor - to load a different decompression engine (default: InflatingDecompressor)
- interpolator - to load a different statistical modeler (default: LinearInterpolator) Classes referenced through properties must be present into the classpath or must be loadable through invocation of the standard method {#link java.lang.Class#forName(String) forName}. The method getLevels() 55 is used to retrieve the number of supported compression level and to initialize the interpolator using the appropriate number of levels. Finally, the main loop is started through thread creation.
decompress
protected byte[] decompress(byte[] buf)
throws java.io.IOException
- This method is responsible for data decompression. It uses the loaded decompression engine
(or InflatingDecompressor if not provided) and
a ByteArrayInputStream (that renders a byte array as an input stream) to build an
InflaterInputStream that "reads" compressed data and write "uncompressed data".
compress
protected byte[] compress(byte[] buf)
throws java.io.IOException
- This method is responsible for data compression. It uses the loaded compression engine
(or DeflatingCompressor if not provided) and
a ByteArrayOutputStream (that renders an output stream as a byte array) to build a
DeflaterOutputStream that "writes" uncompressed data and read "compressed data".
run
public void run()
- The main loop. Here packets get captured and converted into ZObjects
to see if they are normal compressed or ack. In the first case, data gets decompressed and queued
into the ZInputStream that can be given out as the primary input stream (through the method
getInputStream 55 and an ack packet is immediately sent back.
In the case of a received ack, the appropriate listener gets notified of the arriving ack and it will
provide to update the interpolator.
- Specified by:
runin interfacejava.lang.Runnable
sendAck
public void sendAck(ZObject zobj) throws java.io.IOException
- An ack is sent through this method, based on the passed ZObject that's the received one.
From that object it gets the sequence number and use it to build an ack-type ZObject.
Then the latter is "serialized" and transformed into a byte array , ready to be sent through the
real output stream (as provided by the previous socket factory).
We don't use standard serialization because the object's type domain is really limited (only one
class) and the resulting overhead would not be justified.
send
public void send(byte[] data)
throws java.io.IOException
- This method is invoked by the ZoutputStream.flush 55 method
to perform the real data sending.
Basically it performs the following tasks:
- ask the interpolator to compute a suitable compression level based on data buffer dimension,
- set the compression engine to work at that level
- compress data and acquire compression time
- build ZObject, serialize it and send
- install a new Listener object, waiting for ack to update the interpolator
getInputStream
public java.io.InputStream getInputStream()
getOutputStream
public java.io.OutputStream getOutputStream()
stop
public void stop()
|
|||||||||
| Home >> All >> java >> [ net overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC
java.net.Connector