|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.hd.d.pg2k.svrCore.datasource.ExhibitDataTunnelSource.RawPacket
public static final class ExhibitDataTunnelSource.RawPacket
Immutable raw packet to send in either direction over a byte stream connection. This consists of an op-code byte, a byte-array payload, and a trailer byte (different to any op-code byte).
We informally attempt to keep a decent Hamming distance between different op-codes (ie more than one bit at a time should have to change to mutate one into another).
The byte array can be sent compressed (using the gzip algorithm), and this compression is adaptive, ie if compression does not save space then it is not used. The assumption if compression is requested is that it is worthwhile burning lots of CPU cycles to compress the data as far as possible, and so we may attempt very CPU-hungry settings. Compressed data is sent on the wire with the length actually -compressedDataLength.
This NOT intended to be directly Serializable.
NOTE: this is only guaranteed immutable if the payload is not tampered with after being passed to the constructor.
| Nested Class Summary | |
|---|---|
static class |
ExhibitDataTunnelSource.RawPacket.OpCode
|
| Field Summary | |
|---|---|
static int |
FRAME_OVERHEAD_BYTES
Frame overhead (header and trailer) in bytes; strictly positive. |
static int |
MAX_FRAME_SIZE
Maximum permitted total frame length including header/trailer; strictly positive power of two minus the frame overhead. |
static int |
MAX_PAYLOAD_SIZE
Maximum permitted payload length; strictly positive power of two minus the frame overhead. |
static int |
MIN_PLLENGTH_FOR_HEAVY_COMP_ALGS
Minimum size of payload for which we will try heaviest compression modes; strictly positive. |
static byte |
OP__INTEX
Reserved op-code for use in response packets to indicate that the operation was interrupted and can be retried (not an error). |
static byte |
OP__PGMNISEX
Reserved op-code for use in response packets to indicate a PGMasterNotInServiceException. |
static byte |
OP__REMEX
Reserved op-code for use in response packets to indicate a RemoteException. |
static byte |
OP__RUNTEX
Reserved op-code for use in response packets to indicate a RuntimeException. |
static byte |
OP_getAllExhibitImmutableData
Operation code: getAllExhibitImmutableData(). |
static byte |
OP_getAllExhibitProperties
Operation code: getAllExhibitProperties(). |
static byte |
OP_getAllExhibitPropertiesDiff
Operation code: getAllExhibitPropertiesDiff(). |
static byte |
OP_getEventValues
Operation code: getEventValues(). |
static byte |
OP_getGenProps
Operation code: getGenProps(). |
static byte |
OP_getGenSecProps
Operation code: getGenSecProps(). |
static byte |
OP_getRawFile
Operation code: getRawFile(). |
static byte |
OP_getStaticAttr
Operation code: getStaticAttr(). |
static byte |
OP_getStratum
Operation code: getStratum(). |
static byte |
OP_getThumbnails
Operation code: getThumbnails(). |
static byte |
OP_getVariable
Operation code: getVariable(). |
static byte |
OP_getVariables
Operation code: getVariables(). |
static byte |
OP_NOOP
Operation code: NO-OP (no operation). |
static byte |
OP_setVariables
Operation code: setVariables(). |
static byte |
OP_syncVariables
Operation code: syncVariables(). |
ExhibitDataTunnelSource.RawPacket.OpCode |
opCode
Opcode (single byte); never null. |
private byte[] |
payload
Payload data, non-null unless the data is stored compressed. |
private byte[] |
payloadCompressed
Compressed payload data, null unless the data is stored compressed. |
static byte |
trailer
Trailer byte; not a valid op-code. |
static byte |
TRAILER
Trailer byte; different to all valid op-code byte values. |
| Constructor Summary | |
|---|---|
|
ExhibitDataTunnelSource.RawPacket(ExhibitDataTunnelSource.RawPacket.OpCode opCode)
Construct a new raw packet with an empty payload. |
|
ExhibitDataTunnelSource.RawPacket(ExhibitDataTunnelSource.RawPacket.OpCode op,
byte[] data)
Construct a new raw packet with the whole data array as the payload. |
|
ExhibitDataTunnelSource.RawPacket(ExhibitDataTunnelSource.RawPacket.OpCode op,
byte[] data,
boolean attemptCompression)
Construct a new raw packet with the whole data array as the payload. |
private |
ExhibitDataTunnelSource.RawPacket(ExhibitDataTunnelSource.RawPacket.OpCode opCode,
byte[] payload,
byte[] payloadCompressed)
Construct a new raw packet with data provided. |
|
ExhibitDataTunnelSource.RawPacket(ExhibitDataTunnelSource.RawPacket.OpCode op,
byte[] data,
int initialPortion,
boolean attemptCompression)
Construct a new raw packet with the initial portion of the data array as the payload. |
|
ExhibitDataTunnelSource.RawPacket(ExhibitDataTunnelSource.RawPacket.OpCode op,
java.io.Serializable obj,
boolean attemptCompression)
Construct a new raw packet with a serialised object as the payload. |
| Method Summary | |
|---|---|
private static byte[] |
_serObjForPayload(java.io.Serializable obj)
Serialise object for payload. |
boolean |
equals(java.lang.Object obj)
Depends on the whole packet being identical. |
boolean |
equivalentTo(ExhibitDataTunnelSource.RawPacket other)
Checks for equivalent raw packets, ignoring internal representation details. |
int |
getActualPayloadLength()
Return the actual payload length; non-negative. |
int |
getFrameLength()
Computes the total number of bytes that would be written by writePacket(); strictly positive. |
(package private) byte[] |
getPayload()
Get direct access to the uncompressed payload; never null. |
java.io.InputStream |
getPayloadAsInputStream()
Get the payload data as an InputStream; never null. |
byte[] |
getPayloadCopy()
Get a copy of the payload data; never null. |
(package private) void |
getPayloadCopy(java.nio.ByteBuffer buf)
Copy the payload data into the supplied (trusted) buffer. |
java.lang.Object |
getSerializedObjectPayload()
Retrieves a single serialised Object from the payload. |
int |
hashCode()
Hash is based on just packet type and (actual) packet length. |
static ExhibitDataTunnelSource.RawPacket |
readPacket(java.io.InputStream is)
Reads a packet from the input stream, blocking until done. |
static ExhibitDataTunnelSource.RawPacket |
streamSerialiseObject(ExhibitDataTunnelSource.RawPacket.OpCode op,
java.io.Serializable obj)
Construct a new raw packet with a stream-serialised object as the payload. |
java.lang.String |
toString()
Create a human-readable summary (not including the payload data). |
void |
writePacket(java.io.OutputStream os)
Send the packet down the given OutputStream with header and trailer. |
void |
writePacket(java.io.OutputStream os,
boolean reduceWrites)
Send the packet down the given OutputStream with header and trailer. |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final byte OP_NOOP
public static final byte OP_getGenProps
public static final byte OP_getAllExhibitImmutableData
public static final byte OP_getStaticAttr
public static final byte OP_getRawFile
public static final byte OP_getGenSecProps
public static final byte OP_getAllExhibitProperties
public static final byte OP_getAllExhibitPropertiesDiff
public static final byte OP_getThumbnails
public static final byte OP_getVariable
public static final byte OP_getVariables
public static final byte OP_setVariables
public static final byte OP_syncVariables
public static final byte OP_getEventValues
public static final byte OP_getStratum
public static final byte OP__INTEX
public static final byte OP__PGMNISEX
public static final byte OP__REMEX
public static final byte OP__RUNTEX
public static final byte TRAILER
public static final int MIN_PLLENGTH_FOR_HEAVY_COMP_ALGS
Below this we assume that the absolute bandwidth savings are not worth the pain.
Probably bigger than a "bulk transfer" block too, so that the heavy guns are wielded only for the biggest frames.
public final ExhibitDataTunnelSource.RawPacket.OpCode opCode
Never numerically equal to TRAILER.
public static final int FRAME_OVERHEAD_BYTES
public static final int MAX_FRAME_SIZE
This limit mainly exists to prevent DoS-style out-of-memory problems arising from corrupt (huge) length values.
public static final int MAX_PAYLOAD_SIZE
This mainly exists to prevent DoS-style out-of-memory problems arising from corrupt (huge) length values.
private final byte[] payload
private final byte[] payloadCompressed
public static final byte trailer
| Constructor Detail |
|---|
public ExhibitDataTunnelSource.RawPacket(ExhibitDataTunnelSource.RawPacket.OpCode opCode)
op - the op-code of the RPC; never null
public ExhibitDataTunnelSource.RawPacket(ExhibitDataTunnelSource.RawPacket.OpCode op,
byte[] data)
This assumes that it is worth trying to compress the payload, if other conditions support it.
op - the op-code of the RPC; never nulldata - the payload bytes; never null
public ExhibitDataTunnelSource.RawPacket(ExhibitDataTunnelSource.RawPacket.OpCode op,
byte[] data,
boolean attemptCompression)
op - the op-code of the RPC; never nulldata - the payload bytes; never nullattemptCompression - if true, it is probably worth attempting
to compress the payload data unless very short
public ExhibitDataTunnelSource.RawPacket(ExhibitDataTunnelSource.RawPacket.OpCode op,
byte[] data,
int initialPortion,
boolean attemptCompression)
If compression is requested and is possible then the compression may be performed at construction time and the compressed form of the data held to save space.
op - the op-code of the RPC; never nulldata - the (uncompressed) payload bytes; never nullinitialPortion - the initial portion of data[] containing
payload data; never negative or larger than data.length or MAX_PAYLOAD_SIZEattemptCompression - if true, it is probably worth attempting
to compress the payload data unless very short
private ExhibitDataTunnelSource.RawPacket(ExhibitDataTunnelSource.RawPacket.OpCode opCode,
byte[] payload,
byte[] payloadCompressed)
op - the op-code of the RPC; never null
public ExhibitDataTunnelSource.RawPacket(ExhibitDataTunnelSource.RawPacket.OpCode op,
java.io.Serializable obj,
boolean attemptCompression)
throws java.io.IOException
This will have the entire uncompressed form in memory at peak, so may be unsuitable for very large (and highly-compressible) objects.
op - the op-code of the RPC; never nullobj - the Serializable object to send,
or null to send empty payloadattemptCompression - if true, it is probably worth attempting
to compress the payload data if not very short
java.io.IOException| Method Detail |
|---|
public boolean equals(java.lang.Object obj)
equals in class java.lang.Objectpublic boolean equivalentTo(ExhibitDataTunnelSource.RawPacket other)
May be very slow and memory intensive.
public int hashCode()
hashCode in class java.lang.Object
public static ExhibitDataTunnelSource.RawPacket streamSerialiseObject(ExhibitDataTunnelSource.RawPacket.OpCode op,
java.io.Serializable obj)
throws java.io.IOException
This will veto with an IOException any attempt to write more than MAX_PAYLOAD_SIZE pre-compression or pre-compression bytes.
op - the op-code of the RPC; one of the OP_XXX valuesobj - the Serializable object to send,
or null to send empty payloadattemptCompression - if true, it is probably worth attempting
to compress the payload data if not very short
java.io.IOException
private static byte[] _serObjForPayload(java.io.Serializable obj)
throws java.io.IOException
java.io.IOException
public java.lang.Object getSerializedObjectPayload()
throws java.io.IOException
For robustness, treats a class mismatch problem like a data problem, ie this will re-throw any ClassNotFoundException as an IOException.
java.io.IOExceptionpublic int getFrameLength()
public void writePacket(java.io.OutputStream os)
throws java.io.IOException
This does not close() the stream.
java.io.IOException
public void writePacket(java.io.OutputStream os,
boolean reduceWrites)
throws java.io.IOException
If the payload is not too large, then the entire packet will be buffered and sent in one write(), else it will be sent in LAN-packet-size chunks.
This does not close() the stream.
reduceWrites - if true then make an effort to reduce the number of writes done
(ie try to write fewer larger blocks)
since the output may be to a raw network stream or similar
which may require more copying of data first
java.io.IOException
public static ExhibitDataTunnelSource.RawPacket readPacket(java.io.InputStream is)
throws java.io.IOException
Compressed data is signalled by a negative length on the wire, where this is the negation of the compressed data size.
The ZLIB deflater with maximum compression and no checksum is used for any (de)compression.
To prevent unpleasantness such a OutOfMemoryError from a corrupt length value, we veto lengths greater than the maximum specified for this frame type.
java.io.IOExceptionpublic java.lang.String toString()
toString in class java.lang.Objectpublic java.io.InputStream getPayloadAsInputStream()
Each stream returned is independent.
This stream should be explicitly closed when finished with to release underlying memory and other resources ASAP.
public byte[] getPayloadCopy()
If the internal data is stored compressed then this will return the original uncompressed version.
byte[] getPayload()
If the internal data is stored compressed then this will return an uncompressed copy.
This is package-visible and is only for trusted callers that will not alter the content.
void getPayloadCopy(java.nio.ByteBuffer buf)
If the internal data is stored compressed then this will return the original uncompressed version.
public int getActualPayloadLength()
If the original payload is empty (zero length) and getUncompressedPayloadLength() returns 0 then this returns 0 also.
|
DHD Multimedia Gallery V1.60.69 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||