ByteBuffer initial_data = ByteBuffer.wrap( msg_id.getBytes());
if ( upper_initial_data != null ){
GenericMessage gm = new GenericMessage( msg_id, msg_desc, new DirectByteBuffer( upper_initial_data ), false );
DirectByteBuffer[] payload = new GenericMessageEncoder().encodeMessage( gm )[0].getRawData();
int size = initial_data.remaining();
for (int i=0;i<payload.length;i++){
size += payload[i].remaining( DirectByteBuffer.SS_MSG );
}
ByteBuffer temp = ByteBuffer.allocate( size );
temp.put( initial_data );
for (int i=0;i<payload.length;i++){
temp.put( payload[i].getBuffer( DirectByteBuffer.SS_MSG ));
}
temp.rewind();
initial_data = temp;
}
connection.connect(
initial_data,
ProtocolEndpoint.CONNECT_PRIORITY_MEDIUM,
new NetworkConnection.ConnectionListener()
{
public int
connectStarted(
int default_connect_timeout )
{
return( default_connect_timeout );
}
public void
connectSuccess(
ByteBuffer remaining_initial_data )
{
connected = true;
try{
if ( remaining_initial_data != null && remaining_initial_data.remaining() > 0){
// queue as a *raw* message as already encoded
connection.getOutgoingMessageQueue().addMessage(
new GenericMessage( msg_id, msg_desc, new DirectByteBuffer( remaining_initial_data ), true), false );
}
listener.connectSuccess();
startProcessing();