Class RawChannel

java.lang.Object
host.anzo.simon.RawChannel

public class RawChannel extends Object
This class enables one to send raw data from one station to a remote station.
A simple example on how to transfer a file from a client to the server:
Let's assume that the client has already looked up a remote object. Let's call it server. The server needs to know that the client wants to transfer a file. So the server should offer a method like this:

 // method in the server object
 public int openFileChannel() throws SimonRemoteException {
    return Simon.prepareRawChannel(myRawChannelDataListener, this);
 }

The result of the prepareRawChannel() call will be an integer, called channelToken, which, as the name implies, identifies the prepared raw channel:


 // called on the client
 int channelToken = server.openFileChannel();

With this channel token, the client can now open the raw channel:


 // called on the client
 RawChannel rawChannel = Simon.openRawChannel(channelToken, server);

Now the client can send raw data (in shape of a ByteBuffer) to the server by calling rawChannel.write(), where the registered myRawChannelDataListener on the server side handles the received data. If the transmission has finished, just call rawChannel.close(), and the listener on the remote station will recognize it too and can finally close the file output stream.

A final word on"why do all this stress with this raw channel. Why don't send the data by just calling a server method?" : Each method call on a remote object involves a lot of reflection and serialization stuff, which results on a more or less time consuming behavior. Using the raw channel mechanism, there's almost no reflection and no serialization needed, and the data is transfered directly, without method lookups and so on. So the performance should be better, at least with an increasing amount of data that needs to be transferred.

  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    RawChannel(Dispatcher dispatcher, org.apache.mina.core.session.IoSession session, int channelToken)
    Instantiates a new raw channel.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Signals on the remote station that the transmission has finished.
    boolean
    Return true, is channel is already closed and false is still open and useable.
    void
    write(ByteBuffer byteBuffer)
    Writes the given buffer (position 0 up to current position) to the server.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait