@Override public void send( int channel, Message message ) { if( log.isLoggable(Level.FINER) ) { log.log(Level.FINER, "send({0}, {1})", new Object[]{channel, message}); } if( channel >= 0 ) { // Make sure we aren't still connecting. Channels // won't be valid until we are fully connected since // we receive the channel list from the server. // The default channels don't require the connection // to be fully up before sending. waitForConnected(); } if( channel < CHANNEL_DEFAULT_RELIABLE || channel + CH_FIRST >= channels.size() ) { throw new IllegalArgumentException( "Channel is undefined:" + channel ); } send(channel + CH_FIRST, message, true); }
protected void send( int channel, Message message, boolean waitForConnected ) { checkRunning(); if( waitForConnected ) { // Make sure we aren't still connecting waitForConnected(); } ByteBuffer buffer = dataBuffer.get(); if( buffer == null ) { buffer = ByteBuffer.allocate( 65536 + 2 ); dataBuffer.set(buffer); } buffer.clear(); // Convert the message to bytes buffer = MessageProtocol.messageToBuffer(message, buffer); // Since we share the buffer between invocations, we will need to // copy this message's part out of it. This is because we actually // do the send on a background thread. byte[] temp = new byte[buffer.remaining()]; System.arraycopy(buffer.array(), buffer.position(), temp, 0, buffer.remaining()); buffer = ByteBuffer.wrap(temp); channels.get(channel).write(buffer); }
@Override public void send( int channel, Message message ) { if( log.isLoggable(Level.FINER) ) { log.log(Level.FINER, "send({0}, {1})", new Object[]{channel, message}); } if( channel >= 0 ) { // Make sure we aren't still connecting. Channels // won't be valid until we are fully connected since // we receive the channel list from the server. // The default channels don't require the connection // to be fully up before sending. waitForConnected(); } if( channel < CHANNEL_DEFAULT_RELIABLE || channel + CH_FIRST >= channels.size() ) { throw new IllegalArgumentException( "Channel is undefined:" + channel ); } send(channel + CH_FIRST, message, true); }
protected void send( int channel, Message message, boolean waitForConnected ) { checkRunning(); if( waitForConnected ) { // Make sure we aren't still connecting waitForConnected(); } ByteBuffer buffer = dataBuffer.get(); if( buffer == null ) { buffer = ByteBuffer.allocate( 65536 + 2 ); dataBuffer.set(buffer); } buffer.clear(); // Convert the message to bytes buffer = MessageProtocol.messageToBuffer(message, buffer); // Since we share the buffer between invocations, we will need to // copy this message's part out of it. This is because we actually // do the send on a background thread. byte[] temp = new byte[buffer.remaining()]; System.arraycopy(buffer.array(), buffer.position(), temp, 0, buffer.remaining()); buffer = ByteBuffer.wrap(temp); channels.get(channel).write(buffer); }