|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectde.root1.simon.RawChannel
public class RawChannel
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:
The result of the
// method in the server object
public int openFileChannel() throws SimonRemoteException {
return Simon.prepareRawChannel(myRawChannelDataListener, this);
}
prepareRawChannel()
call will be an integer,
called channelToken
, which, as the name implies, identifies the
prepared raw channel:
With this channel token, the client can now open the raw channel:
// called on the client
int channelToken = server.openFileChannel();
Now the client can send raw data (in shape of a
// called on the client
RawChannel rawChannel = Simon.openRawChannel(channelToken, server);
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 | |
---|---|
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 |
---|
protected RawChannel(Dispatcher dispatcher, org.apache.mina.core.session.IoSession session, int channelToken)
Simon.openRawChannel(int, Object)
.
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 |
---|
public void write(java.nio.ByteBuffer byteBuffer) throws java.lang.IllegalStateException, SimonRemoteException
byteBuffer
- the buffer who's content is written to the server
java.lang.IllegalStateException
- if the channel is already closed.
SimonRemoteException
public void close() throws SimonRemoteException
SimonRemoteException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |