saker.util Documentation TaskDoc JavaDoc Packages
public class RMIByteRegionWrapper implements ByteRegion, RMIWrapper
RMIWrapper implementation for caching the length of the remotely transferred ByteRegion.

This wrapper will query the length of the transferred ByteRegion, and write that alongside the remote region object. When it is deserialized, an instance of this wrapper will take place of the transferred object.

The purpose of this wrapper is to spare the remote method call cost of getLength(). As that is a very commonly called method, using this wrapper can increase performance.

The target type for this wrapper should be ByteRegion.

Constructors
public
Creates a new instance.
public
Creates a new instance for the given region.
Methods
public byte[]
Copies underlying contents of this byte region and returns it as a byte array.
public byte[]
copyArrayRegion(int offset, int length)
Copies contents from a subregion of this byte region and returns it as an array.
public byte
get(int index)
Gets the byte at the specified index.
public int
Gets the length of this byte region.
public Object
Gets the wrapped object which should be serialized during RMI transfer.
public void
put(int index, byte b)
Puts a byte into the region at the given index.
public void
put(int index, ByteArrayRegion bytes)
Puts the given bytes into the byte region starting at the given offset.
public void
Reads the wrapped object from the RMI object input stream.
public Object
Resolves the wrapped object during deserialization.
public String
Returns a string representation of the object.
public void
Writes the wrapped object to the RMI object output stream.
Creates a new instance.

Users shouldn't instantiate this class manually, but leave that to the RMI runtime.

Creates a new instance for the given region.

Users shouldn't instantiate this class manually, but leave that to the RMI runtime.

regionThe byte region.
NullPointerExceptionIf the region is null.
public byte[] copy()
Overridden from: ByteRegion
Copies underlying contents of this byte region and returns it as a byte array.

Modifying the returned array will have no effect on the contents of this byte region.

The byte contents of this byte region.
public byte[] copyArrayRegion(int offset, int length)
Overridden from: ByteRegion
Copies contents from a subregion of this byte region and returns it as an array.

Modifying the returned array will have no effect on the contents of this byte region.

offsetThe offset to start copying the bytes from.
lengthThe number of bytes to copy from the byte region.
An array of bytes specified by the argument region.
public byte get(int index)
Overridden from: ByteRegion
Gets the byte at the specified index.
indexThe index to get the byte at.
The byte at the given index.
public int getLength()
Overridden from: ByteRegion
Gets the length of this byte region.

The length of a region doesn't change over the lifetime of an object.

The length.
Overridden from: RMIWrapper
Gets the wrapped object which should be serialized during RMI transfer.

If RMIWrapper.resolveWrapped() returned this then this method will be called when the wrapper instance is serialized to an other endpoint. It is preferred to return a remote proxy to the previously wrapped object to pass back to the original endpoint when reverse request is made. Returning this from this method will result in the serialization of this wrapper through RMI.

If RMIWrapper.resolveWrapped() did not return this then this method can freely return null or throw exceptions (e.g. UnsupportedOperationException) because it will never be called.

The object to serialize instead of this.
public void put(int index, byte b)
Overridden from: ByteRegion
Puts a byte into the region at the given index.
indexThe index to put the byte to.
bThe byte to write into the region.
public void put(int index, ByteArrayRegion bytes)
Overridden from: ByteRegion
Puts the given bytes into the byte region starting at the given offset.

This method is the same as calling ByteRegion.put(int, byte) for each byte in the argument region and incrementing the index after each operation.

indexThe index to start putting the bytes from.
bytesThe bytes to put into the region.
Overridden from: RMIWrapper
Reads the wrapped object from the RMI object input stream.
inThe input stream to read from.
IOExceptionIn case of I/O error.
ClassNotFoundExceptionIf a class for a serialized object cannot be found.
Overridden from: RMIWrapper
Resolves the wrapped object during deserialization.

The result of this method will be returned to the caller, or used during the RMI request.

The result of the object transfer.
public String toString()
Overridden from: Object
Returns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method.

The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of:

 getClass().getName() + '@' + Integer.toHexString(hashCode())
 
a string representation of the object.
public void writeWrapped(RMIObjectOutput out) throws IOException
Overridden from: RMIWrapper
Writes the wrapped object to the RMI object output stream.

Important aspect of writing objects using wrappers is that in this method if any of the object writing method is called, then the non customizable aspects of the serializable will not be applied to the object that is being wrapped.

E.g. If an RMIWrapper is defined for an object type T, then calling RMIObjectOutput.writeRemoteObject(Object) will not cause the subject object with the type T to be written using an RMIWrapper again, but it will be actually written as a remote object.

outThe output stream to write to.
IOExceptionIn case of I/O error.