Author: david.lloyd(a)jboss.com
Date: 2010-03-26 14:38:10 -0400 (Fri, 26 Mar 2010)
New Revision: 5840
Added:
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/FramingChannelListener.java
Modified:
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/AbstractMessageHandler.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/ClientGreetingHandler.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/ClientOpenListener.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/InboundClient.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/InboundReplyInputHandler.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/InboundRequestInputHandler.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/InboundStream.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/OutboundReplyBufferWriter.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/OutboundReplyHandler.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/OutboundRequestBufferWriter.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/OutboundRequestHandler.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/OutboundStream.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/RemoteConnection.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/RemoteConnectionHandler.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/RemoteMessageHandler.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/RemoteProtocol.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/SaslUtils.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/ServerOpenListener.java
Log:
JBREM-1215 part 2: Use 2-byte message size; more efficient buffer handling
Modified:
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/AbstractMessageHandler.java
===================================================================
---
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/AbstractMessageHandler.java 2010-03-26
00:56:45 UTC (rev 5839)
+++
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/AbstractMessageHandler.java 2010-03-26
18:38:10 UTC (rev 5840)
@@ -23,17 +23,19 @@
package org.jboss.remoting3.remote;
import java.io.IOException;
+import java.nio.ByteBuffer;
import java.nio.channels.ClosedChannelException;
import org.jboss.xnio.IoUtils;
-import org.jboss.xnio.channels.MessageHandler;
-abstract class AbstractMessageHandler implements MessageHandler {
+abstract class AbstractMessageHandler {
protected final RemoteConnection remoteConnection;
protected AbstractMessageHandler(final RemoteConnection remoteConnection) {
this.remoteConnection = remoteConnection;
}
+ public abstract void handleMessage(ByteBuffer message);
+
public void handleEof() {
try {
remoteConnection.getChannel().shutdownReads();
Modified:
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/ClientGreetingHandler.java
===================================================================
---
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/ClientGreetingHandler.java 2010-03-26
00:56:45 UTC (rev 5839)
+++
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/ClientGreetingHandler.java 2010-03-26
18:38:10 UTC (rev 5840)
@@ -146,7 +146,7 @@
log.trace("Sasl mechanism selected: %s", mechanismName);
final ByteBuffer outBuf = connection.allocate();
try {
- outBuf.putInt(0);
+ outBuf.putShort(RemoteConnectionHandler.LENGTH_PLACEHOLDER);
outBuf.put(RemoteProtocol.AUTH_REQUEST);
Buffers.putModifiedUtf8(outBuf, mechanismName);
outBuf.flip();
Modified:
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/ClientOpenListener.java
===================================================================
---
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/ClientOpenListener.java 2010-03-26
00:56:45 UTC (rev 5839)
+++
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/ClientOpenListener.java 2010-03-26
18:38:10 UTC (rev 5840)
@@ -69,7 +69,7 @@
// Send client greeting packet...
final ByteBuffer buffer = connection.allocate();
// length placeholder
- buffer.putInt(0);
+ buffer.putShort(RemoteConnectionHandler.LENGTH_PLACEHOLDER);
buffer.put(RemoteProtocol.GREETING);
// marshaller versions
final int[] versions = providerDescriptor.getSupportedVersions();
@@ -80,7 +80,7 @@
GreetingUtils.writeByte(buffer, RemoteProtocol.GREETING_VERSION,
RemoteProtocol.VERSION);
// that's it!
buffer.flip();
- buffer.putInt(0, buffer.remaining() - 4);
+ buffer.putShort(0, (short) (buffer.remaining() - 2));
channel.getWriteSetter().set(new
ChannelListener<ConnectedStreamChannel<InetSocketAddress>>() {
public void handleEvent(final ConnectedStreamChannel<InetSocketAddress>
channel) {
for (;;) {
Added:
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/FramingChannelListener.java
===================================================================
---
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/FramingChannelListener.java
(rev 0)
+++
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/FramingChannelListener.java 2010-03-26
18:38:10 UTC (rev 5840)
@@ -0,0 +1,151 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.jboss.remoting3.remote;
+
+import java.io.IOException;
+import java.nio.BufferUnderflowException;
+import java.nio.ByteBuffer;
+import org.jboss.remoting3.RemotingOptions;
+import org.jboss.xnio.Buffers;
+import org.jboss.xnio.ChannelListener;
+import org.jboss.xnio.OptionMap;
+import org.jboss.xnio.Options;
+import org.jboss.xnio.channels.StreamChannel;
+
+final class FramingChannelListener implements ChannelListener<StreamChannel> {
+
+ private volatile int maxSize;
+ private final ByteBuffer receiveBuffer;
+ private volatile AbstractMessageHandler messageHandler;
+ private State state = State.SIZE;
+ private int nextSize;
+
+ FramingChannelListener(final OptionMap optionMap, final AbstractMessageHandler
messageHandler) {
+ this.messageHandler = messageHandler;
+ maxSize = optionMap.get(Options.MAX_INBOUND_MESSAGE_SIZE, 2048);
+ receiveBuffer =
ByteBuffer.allocate(Math.min(optionMap.get(RemotingOptions.BUFFER_SIZE, maxSize * 4),
4096));
+ }
+
+ private enum State {
+ SIZE,
+ BODY,
+ }
+
+ public void handleEvent(final StreamChannel streamChannel) {
+ final ByteBuffer receiveBuffer = this.receiveBuffer;
+ assert receiveBuffer.hasRemaining();
+ int res;
+ try {
+ res = streamChannel.read(receiveBuffer);
+ } catch (IOException e) {
+ messageHandler.handleException(e);
+ return;
+ }
+ if (res == 0) {
+ streamChannel.resumeReads();
+ return;
+ }
+ if (res == -1) {
+ messageHandler.handleEof();
+ return;
+ }
+ for (;;) {
+ while (receiveBuffer.hasRemaining()) {
+ try {
+ res = streamChannel.read(receiveBuffer);
+ } catch (IOException e) {
+ handleBufferedData();
+ messageHandler.handleException(e);
+ return;
+ }
+ if (res == 0) {
+ handleBufferedData();
+ streamChannel.resumeReads();
+ return;
+ }
+ if (res == -1) {
+ handleBufferedData();
+ messageHandler.handleEof();
+ return;
+ }
+ }
+ handleBufferedData();
+ }
+ }
+
+ private void handleBufferedData() {
+ final ByteBuffer receiveBuffer = this.receiveBuffer;
+ final State initial = state;
+ receiveBuffer.flip();
+ try {
+ if (initial == State.BODY) {
+ final int size = nextSize;
+ if (receiveBuffer.remaining() < size) {
+ return;
+ }
+ final ByteBuffer buffer = Buffers.slice(receiveBuffer, size);
+ try {
+ messageHandler.handleMessage(buffer);
+ } catch (BufferUnderflowException e) {
+ final IOException e1 = new IOException();
+ e1.initCause(e);
+ messageHandler.handleException(e1);
+ return;
+ }
+ }
+ int size;
+ for (;;) {
+ if (receiveBuffer.remaining() < 2) {
+ state = State.SIZE;
+ return;
+ }
+ size = receiveBuffer.getShort() & 0xffff;
+ if (receiveBuffer.remaining() < size) {
+ nextSize = size;
+ state = State.BODY;
+ return;
+ }
+ final ByteBuffer buffer = Buffers.slice(receiveBuffer, size);
+ try {
+ messageHandler.handleMessage(buffer);
+ } catch (BufferUnderflowException e) {
+ final IOException e1 = new IOException();
+ e1.initCause(e);
+ messageHandler.handleException(e1);
+ return;
+ }
+ }
+ } finally {
+ // we use TCP_NODELAY so this usually will clear the buffer with no bytes
copied
+ receiveBuffer.compact();
+ }
+ }
+
+ void setMaxSize(final int maxSize) {
+ this.maxSize = maxSize;
+ }
+
+ void setMessageHandler(final AbstractMessageHandler messageHandler) {
+ this.messageHandler = messageHandler;
+ }
+}
Modified:
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/InboundClient.java
===================================================================
---
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/InboundClient.java 2010-03-26
00:56:45 UTC (rev 5839)
+++
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/InboundClient.java 2010-03-26
18:38:10 UTC (rev 5840)
@@ -52,7 +52,7 @@
final RemoteConnection remoteConnection =
remoteConnectionHandler.getRemoteConnection();
final ByteBuffer buffer = remoteConnection.allocate();
try {
- buffer.position(4);
+ buffer.putShort(RemoteConnectionHandler.LENGTH_PLACEHOLDER);
buffer.put(RemoteProtocol.CLIENT_ASYNC_CLOSE);
buffer.putInt(id);
buffer.flip();
Modified:
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/InboundReplyInputHandler.java
===================================================================
---
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/InboundReplyInputHandler.java 2010-03-26
00:56:45 UTC (rev 5839)
+++
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/InboundReplyInputHandler.java 2010-03-26
18:38:10 UTC (rev 5840)
@@ -39,7 +39,7 @@
final RemoteConnectionHandler connectionHandler =
outboundRequest.getRemoteConnectionHandler();
final ByteBuffer buffer = connectionHandler.getBufferPool().allocate();
try {
- buffer.putInt(RemoteConnectionHandler.LENGTH_PLACEHOLDER);
+ buffer.putShort(RemoteConnectionHandler.LENGTH_PLACEHOLDER);
buffer.put(RemoteProtocol.REPLY_ACK_CHUNK);
buffer.putInt(rid);
buffer.flip();
Modified:
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/InboundRequestInputHandler.java
===================================================================
---
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/InboundRequestInputHandler.java 2010-03-26
00:56:45 UTC (rev 5839)
+++
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/InboundRequestInputHandler.java 2010-03-26
18:38:10 UTC (rev 5840)
@@ -44,7 +44,7 @@
final Pool<ByteBuffer> bufferPool = connectionHandler.getBufferPool();
final ByteBuffer buffer = bufferPool.allocate();
try {
- buffer.putInt(RemoteConnectionHandler.LENGTH_PLACEHOLDER);
+ buffer.putShort(RemoteConnectionHandler.LENGTH_PLACEHOLDER);
buffer.put(RemoteProtocol.REQUEST_ACK_CHUNK);
buffer.putInt(rid);
buffer.flip();
Modified:
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/InboundStream.java
===================================================================
---
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/InboundStream.java 2010-03-26
00:56:45 UTC (rev 5839)
+++
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/InboundStream.java 2010-03-26
18:38:10 UTC (rev 5840)
@@ -85,7 +85,7 @@
private void doSend(byte code) {
final ByteBuffer buffer = remoteConnection.allocate();
- buffer.position(4);
+ buffer.putShort(RemoteConnectionHandler.LENGTH_PLACEHOLDER);
buffer.put(code);
buffer.putInt(id);
buffer.flip();
Modified:
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/OutboundReplyBufferWriter.java
===================================================================
---
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/OutboundReplyBufferWriter.java 2010-03-26
00:56:45 UTC (rev 5839)
+++
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/OutboundReplyBufferWriter.java 2010-03-26
18:38:10 UTC (rev 5840)
@@ -49,7 +49,7 @@
final Pool<ByteBuffer> bufferPool = connectionHandler.getBufferPool();
final ByteBuffer buffer = bufferPool.allocate();
log.trace("Allocated buffer %s for %s", buffer, this);
- buffer.putInt(RemoteConnectionHandler.LENGTH_PLACEHOLDER);
+ buffer.putShort(RemoteConnectionHandler.LENGTH_PLACEHOLDER);
buffer.put(exception ? RemoteProtocol.REPLY_EXCEPTION : RemoteProtocol.REPLY);
buffer.putInt(id);
final boolean isFirst = first.getAndSet(false);
@@ -75,7 +75,7 @@
buffer.put(7, (byte) (buffer.get(3) | RemoteProtocol.MSG_FLAG_LAST));
}
log.trace("Sending buffer %s for %s", buffer, this);
- connectionHandler.getRemoteConnection().sendBlocking(buffer, eof);
+ connectionHandler.getRemoteConnection().sendBlocking(buffer, true);
} finally {
connectionHandler.getBufferPool().free(buffer);
}
Modified:
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/OutboundReplyHandler.java
===================================================================
---
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/OutboundReplyHandler.java 2010-03-26
00:56:45 UTC (rev 5839)
+++
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/OutboundReplyHandler.java 2010-03-26
18:38:10 UTC (rev 5840)
@@ -77,7 +77,7 @@
final Pool<ByteBuffer> bufferPool =
connectionHandler.getBufferPool();
final ByteBuffer buffer = bufferPool.allocate();
try {
- buffer.putInt(RemoteConnectionHandler.LENGTH_PLACEHOLDER);
+ buffer.putShort(RemoteConnectionHandler.LENGTH_PLACEHOLDER);
buffer.put(RemoteProtocol.REPLY_EXCEPTION_ABORT);
buffer.putInt(rid);
buffer.flip();
Modified:
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/OutboundRequestBufferWriter.java
===================================================================
---
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/OutboundRequestBufferWriter.java 2010-03-26
00:56:45 UTC (rev 5839)
+++
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/OutboundRequestBufferWriter.java 2010-03-26
18:38:10 UTC (rev 5840)
@@ -45,7 +45,7 @@
public ByteBuffer getBuffer() {
final ByteBuffer buffer =
outboundRequest.getRemoteConnectionHandler().getBufferPool().allocate();
log.trace("Allocated buffer %s for %s", buffer, this);
- buffer.putInt(RemoteConnectionHandler.LENGTH_PLACEHOLDER);
+ buffer.putShort(RemoteConnectionHandler.LENGTH_PLACEHOLDER);
buffer.put(RemoteProtocol.REQUEST);
buffer.putInt(rid);
final boolean isFirst = first.getAndSet(false);
@@ -76,7 +76,7 @@
}
}
log.trace("Sending buffer %s for %s", buffer, this);
- remoteConnectionHandler.getRemoteConnection().sendBlocking(buffer, eof);
+ remoteConnectionHandler.getRemoteConnection().sendBlocking(buffer, true);
} finally {
remoteConnectionHandler.getBufferPool().free(buffer);
}
Modified:
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/OutboundRequestHandler.java
===================================================================
---
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/OutboundRequestHandler.java 2010-03-26
00:56:45 UTC (rev 5839)
+++
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/OutboundRequestHandler.java 2010-03-26
18:38:10 UTC (rev 5840)
@@ -80,7 +80,7 @@
}
// send request abort msg
final ByteBuffer buf = connectionHandler.getBufferPool().allocate();
- buf.putInt(RemoteConnectionHandler.LENGTH_PLACEHOLDER);
+ buf.putShort(RemoteConnectionHandler.LENGTH_PLACEHOLDER);
buf.put(RemoteProtocol.REQUEST_ABORT);
buf.putInt(rid);
buf.flip();
@@ -102,7 +102,7 @@
final Pool<ByteBuffer> bufferPool = connectionHandler.getBufferPool();
final ByteBuffer buf = bufferPool.allocate();
try {
- buf.putInt(RemoteConnectionHandler.LENGTH_PLACEHOLDER);
+ buf.putShort(RemoteConnectionHandler.LENGTH_PLACEHOLDER);
buf.put(RemoteProtocol.CLIENT_CLOSE);
buf.putInt(outboundClient.getId());
buf.flip();
Modified:
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/OutboundStream.java
===================================================================
---
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/OutboundStream.java 2010-03-26
00:56:45 UTC (rev 5839)
+++
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/OutboundStream.java 2010-03-26
18:38:10 UTC (rev 5840)
@@ -59,7 +59,7 @@
*/
ByteBuffer getBuffer() {
final ByteBuffer buffer = remoteConnection.allocate();
- buffer.position(4);
+ buffer.putShort(RemoteConnectionHandler.LENGTH_PLACEHOLDER);
buffer.put(RemoteProtocol.STREAM_DATA);
buffer.putInt(id);
return buffer;
@@ -132,7 +132,7 @@
private void doSend(byte code) {
final ByteBuffer buffer = remoteConnection.allocate();
- buffer.position(4);
+ buffer.putShort(RemoteConnectionHandler.LENGTH_PLACEHOLDER);
buffer.put(code);
buffer.putInt(id);
buffer.flip();
Modified:
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/RemoteConnection.java
===================================================================
---
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/RemoteConnection.java 2010-03-26
00:56:45 UTC (rev 5839)
+++
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/RemoteConnection.java 2010-03-26
18:38:10 UTC (rev 5840)
@@ -35,16 +35,14 @@
import org.jboss.xnio.OptionMap;
import org.jboss.xnio.Options;
import org.jboss.xnio.Pool;
-import org.jboss.xnio.channels.Channels;
import org.jboss.xnio.channels.ConnectedStreamChannel;
-import org.jboss.xnio.channels.MessageHandler;
import org.jboss.xnio.log.Logger;
final class RemoteConnection extends AbstractHandleableCloseable<RemoteConnection>
implements Closeable {
private final ConnectedStreamChannel<InetSocketAddress> channel;
private final ProviderDescriptor providerDescriptor;
private final Pool<ByteBuffer> bufferPool;
- private final MessageHandler.Setter messageHandlerSetter;
+ private final FramingChannelListener framingChannelListener;
private final OptionMap optionMap;
private final Object writeLock = new Object();
private static final Logger log = Loggers.main;
@@ -53,7 +51,7 @@
super(executor);
this.channel = channel;
this.providerDescriptor = providerDescriptor;
- messageHandlerSetter = Channels.createMessageReader(channel, optionMap);
+ channel.getReadSetter().set(framingChannelListener = new
FramingChannelListener(optionMap, null));
bufferPool =
Buffers.createHeapByteBufferAllocator(optionMap.get(Options.MAX_INBOUND_MESSAGE_SIZE,
2048));
this.optionMap = optionMap;
}
@@ -85,14 +83,14 @@
bufferPool.free(buffer);
}
- void setMessageHandler(MessageHandler handler) {
- messageHandlerSetter.set(handler);
+ void setMessageHandler(AbstractMessageHandler handler) {
+ framingChannelListener.setMessageHandler(handler);
}
void sendBlocking(final ByteBuffer buffer, boolean flush) throws IOException {
try {
synchronized (writeLock) {
- buffer.putInt(0, buffer.remaining() - 4);
+ buffer.putShort(0, (short) (buffer.remaining() - 2));
boolean intr = false;
try {
while (buffer.hasRemaining()) {
@@ -177,7 +175,7 @@
void sendAuthReject(final String msg) throws IOException {
final ByteBuffer buf = allocate();
try {
- buf.putInt(0);
+ buf.putShort(RemoteConnectionHandler.LENGTH_PLACEHOLDER);
buf.put(RemoteProtocol.AUTH_REJECTED);
Buffers.putModifiedUtf8(buf, msg);
buf.flip();
@@ -190,7 +188,7 @@
void sendAuthMessage(final byte msgType, final byte[] message) throws IOException {
final ByteBuffer buf = allocate();
try {
- buf.putInt(0);
+ buf.putShort(RemoteConnectionHandler.LENGTH_PLACEHOLDER);
buf.put(msgType);
if (message != null) buf.put(message);
buf.flip();
Modified:
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/RemoteConnectionHandler.java
===================================================================
---
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/RemoteConnectionHandler.java 2010-03-26
00:56:45 UTC (rev 5839)
+++
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/RemoteConnectionHandler.java 2010-03-26
18:38:10 UTC (rev 5840)
@@ -51,7 +51,7 @@
final class RemoteConnectionHandler extends
AbstractHandleableCloseable<RemoteConnectionHandler> implements ConnectionHandler {
- static final int LENGTH_PLACEHOLDER = 0;
+ static final short LENGTH_PLACEHOLDER = 0;
private final Pool<ByteBuffer> bufferPool =
Buffers.createHeapByteBufferAllocator(4096);
private final MarshallerFactory marshallerFactory;
@@ -99,7 +99,7 @@
// compose & send message
final ByteBuffer buffer = bufferPool.allocate();
try {
- buffer.putInt(LENGTH_PLACEHOLDER);
+ buffer.putShort(LENGTH_PLACEHOLDER);
buffer.put(RemoteProtocol.SERVICE_REQUEST);
buffer.putInt(id);
Buffers.putModifiedUtf8(buffer, serviceType);
Modified:
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/RemoteMessageHandler.java
===================================================================
---
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/RemoteMessageHandler.java 2010-03-26
00:56:45 UTC (rev 5839)
+++
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/RemoteMessageHandler.java 2010-03-26
18:38:10 UTC (rev 5840)
@@ -80,7 +80,7 @@
}
} catch (Exception e) {
log.error("Failed to unmarshall service request option map:
%s", e);
- outBuf.putInt(RemoteConnectionHandler.LENGTH_PLACEHOLDER);
+ outBuf.putShort(RemoteConnectionHandler.LENGTH_PLACEHOLDER);
outBuf.put(RemoteProtocol.SERVICE_ERROR);
outBuf.putInt(id);
outBuf.flip();
@@ -94,7 +94,7 @@
}
final LocalRequestHandler handler;
handler =
connectionHandler.getConnectionContext().openService(serviceType, instanceName,
optionMap);
- outBuf.putInt(RemoteConnectionHandler.LENGTH_PLACEHOLDER);
+ outBuf.putShort(RemoteConnectionHandler.LENGTH_PLACEHOLDER);
if (handler == null) {
// no matching service found
outBuf.put(RemoteProtocol.SERVICE_NOT_FOUND);
Modified:
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/RemoteProtocol.java
===================================================================
---
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/RemoteProtocol.java 2010-03-26
00:56:45 UTC (rev 5839)
+++
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/RemoteProtocol.java 2010-03-26
18:38:10 UTC (rev 5840)
@@ -86,6 +86,9 @@
static final byte GREETING_SASL_MECH = 1; // sent by server
static final byte GREETING_ENDPOINT_NAME = 2; // sent by client & server
static final byte GREETING_MARSHALLER_VERSION = 3; // sent by client & server
+ static final byte GREETING_SERVER_MIN_MESSAGE_SIZE = 4; // sent by server
+ static final byte GREETING_SERVER_MAX_MESSAGE_SIZE = 5; // sent by server
+ static final byte GREETING_CLIENT_MESSAGE_SIZE = 6; // sent by client
// Object sink stream commands
Modified:
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/SaslUtils.java
===================================================================
---
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/SaslUtils.java 2010-03-26
00:56:45 UTC (rev 5839)
+++
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/SaslUtils.java 2010-03-26
18:38:10 UTC (rev 5840)
@@ -96,18 +96,4 @@
static boolean isSecureQop(Object qop) {
return SECURE_QOP.contains(qop);
}
-
- static void wrapFramed(SaslClient saslClient, ByteBuffer message) throws
SaslException {
- final byte[] result;
- if (message.hasArray()) {
- result = saslClient.wrap(message.array(), message.arrayOffset() + 4,
message.position());
- } else {
- final int end = message.position();
- message.position(4);
- final byte[] bytes = Buffers.take(message, end - 4);
- result = saslClient.wrap(bytes, 0, bytes.length);
- }
- message.position(4);
- message.put(result);
- }
}
Modified:
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/ServerOpenListener.java
===================================================================
---
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/ServerOpenListener.java 2010-03-26
00:56:45 UTC (rev 5839)
+++
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/remote/ServerOpenListener.java 2010-03-26
18:38:10 UTC (rev 5840)
@@ -112,7 +112,7 @@
// Send server greeting packet...
final ByteBuffer buffer = connection.allocate();
// length placeholder
- buffer.putInt(0);
+ buffer.putShort(RemoteConnectionHandler.LENGTH_PLACEHOLDER);
buffer.put(RemoteProtocol.GREETING);
// version ID
GreetingUtils.writeByte(buffer, RemoteProtocol.GREETING_VERSION,
RemoteProtocol.VERSION);
@@ -129,7 +129,7 @@
GreetingUtils.writeString(buffer, RemoteProtocol.GREETING_ENDPOINT_NAME,
connectionProviderContext.getEndpoint().getName());
// that's it!
buffer.flip();
- buffer.putInt(0, buffer.remaining() - 4);
+ buffer.putShort(0, (short) (buffer.remaining() - 2));
channel.getWriteSetter().set(new
ChannelListener<ConnectedStreamChannel<InetSocketAddress>>() {
public void handleEvent(final ConnectedStreamChannel<InetSocketAddress>
channel) {
for (;;) {