de.root1.simon
Class RawChannel

java.lang.Object
  extended by de.root1.simon.RawChannel

public class RawChannel
extends java.lang.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.

Author:
achr

Constructor Summary
protected RawChannel(Dispatcher dispatcher, org.apache.mina.core.session.IoSession session, int channelToken)
          Instantiates a new raw channel.
 
Method Summary
 void close()
          Signals on the remote station that the transmission has finished.
 void write(java.nio.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
 

Constructor Detail

RawChannel

protected RawChannel(Dispatcher dispatcher,
                     org.apache.mina.core.session.IoSession session,
                     int channelToken)
Instantiates a new raw channel. This is done by calling Simon.openRawChannel(int, Object).

Parameters:
dispatcher - the related Dispatcher
session - the related IoSession
channelToken - the channeltoken we got from the remote station by calling Simon.prepareRawChannel(RawChannelDataListener, Object)
Method Detail

write

public void write(java.nio.ByteBuffer byteBuffer)
           throws java.lang.IllegalStateException,
                  SimonRemoteException
Writes the given buffer (position 0 up to current position) to the server. This method can be called several times. The system ensures that the data receives in the order it was sent. Note: Each buffer has to be wrapped by the SIMON protocol. The overhead is about 9 byte per write() call. So you should not send too small packets, otherwise you have some bandwidth loss!
Note: Calling this method will block until the server received the data!

Parameters:
byteBuffer - the buffer who's content is written to the server
Throws:
java.lang.IllegalStateException - if the channel is already closed.
SimonRemoteException

close

public void close()
           throws SimonRemoteException
Signals on the remote station that the transmission has finished. This also closes the raw channel. So after calling this method, each write() call fails!

Throws:
SimonRemoteException


Copyright © 2011. All Rights Reserved.