Merge branch 'apache-3.1' into apache-3.2
This commit is contained in:
commit
d7113006ca
|
|
@ -32,7 +32,7 @@ import static java.lang.Math.min;
|
|||
|
||||
public class TelnetDetector implements ProtocolDetector {
|
||||
|
||||
private FrameworkModel frameworkModel;
|
||||
private final FrameworkModel frameworkModel;
|
||||
private final int MaxSize = 2048;
|
||||
private final ChannelBuffer AytPreface = new HeapChannelBuffer(new byte[]{(byte) 0xff, (byte) 0xf6});
|
||||
|
||||
|
|
@ -46,7 +46,7 @@ public class TelnetDetector implements ProtocolDetector {
|
|||
return Result.UNRECOGNIZED;
|
||||
}
|
||||
Result resCommand = commandDetect(in);
|
||||
if (resCommand.equals(Result.RECOGNIZED)){
|
||||
if (resCommand.equals(Result.RECOGNIZED)) {
|
||||
return resCommand;
|
||||
}
|
||||
Result resAyt = telnetAytDetect(in);
|
||||
|
|
@ -62,14 +62,19 @@ public class TelnetDetector implements ProtocolDetector {
|
|||
private Result commandDetect(ChannelBuffer in) {
|
||||
// detect if remote channel send a qos command to server
|
||||
ChannelBuffer back = in.copy();
|
||||
byte[] backBytes = new byte[back.readableBytes()];
|
||||
back.getBytes(back.readerIndex(), backBytes);
|
||||
byte[] backBytes;
|
||||
try {
|
||||
backBytes = new byte[back.readableBytes()];
|
||||
back.getBytes(back.readerIndex(), backBytes);
|
||||
} finally {
|
||||
back.release();
|
||||
}
|
||||
|
||||
String s = new String(backBytes, CharsetUtil.UTF_8);
|
||||
// trim /r/n to let parser work for input
|
||||
s = s.trim();
|
||||
CommandContext commandContext = TelnetCommandDecoder.decode(s);
|
||||
if(frameworkModel.getExtensionLoader(BaseCommand.class).hasExtension(commandContext.getCommandName())){
|
||||
if (frameworkModel.getExtensionLoader(BaseCommand.class).hasExtension(commandContext.getCommandName())) {
|
||||
return Result.RECOGNIZED;
|
||||
}
|
||||
return Result.UNRECOGNIZED;
|
||||
|
|
@ -79,10 +84,10 @@ public class TelnetDetector implements ProtocolDetector {
|
|||
// detect if remote channel send a telnet ayt command to server
|
||||
int prefaceLen = AytPreface.readableBytes();
|
||||
int bytesRead = min(in.readableBytes(), prefaceLen);
|
||||
if(bytesRead == 0 || !ChannelBuffers.prefixEquals(in, AytPreface, bytesRead)) {
|
||||
if (bytesRead == 0 || !ChannelBuffers.prefixEquals(in, AytPreface, bytesRead)) {
|
||||
return Result.UNRECOGNIZED;
|
||||
}
|
||||
if(bytesRead == prefaceLen) {
|
||||
if (bytesRead == prefaceLen) {
|
||||
// we need to consume preface because it's not a qos command
|
||||
// consume and remember to mark, pu server handler reset reader index
|
||||
in.readBytes(AytPreface.readableBytes());
|
||||
|
|
|
|||
|
|
@ -948,4 +948,12 @@ public interface ChannelBuffer extends Comparable<ChannelBuffer> {
|
|||
* array
|
||||
*/
|
||||
int arrayOffset();
|
||||
|
||||
/**
|
||||
* If this buffer is backed by an NIO direct buffer,
|
||||
* in some scenarios it may be necessary to manually release.
|
||||
*/
|
||||
default void release() {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -200,4 +200,9 @@ public class DynamicChannelBuffer extends AbstractChannelBuffer {
|
|||
public int arrayOffset() {
|
||||
return buffer.arrayOffset();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void release() {
|
||||
buffer.release();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ import org.apache.dubbo.remoting.buffer.ChannelBufferFactory;
|
|||
import org.apache.dubbo.remoting.buffer.ChannelBuffers;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.util.ReferenceCountUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
|
@ -448,4 +449,9 @@ public class NettyBackedChannelBuffer implements ChannelBuffer {
|
|||
public int compareTo(ChannelBuffer o) {
|
||||
return ChannelBuffers.compare(this, o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void release() {
|
||||
ReferenceCountUtil.safeRelease(buffer);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -388,11 +388,12 @@ public class ReflectionPackableMethod implements PackableMethod {
|
|||
for (String type : argumentsType) {
|
||||
builder.addArgTypes(type);
|
||||
}
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
for (int i = 0; i < arguments.length; i++) {
|
||||
Object argument = arguments[i];
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
multipleSerialization.serialize(url, serialize, actualRequestTypes[i], argument, bos);
|
||||
builder.addArgs(bos.toByteArray());
|
||||
bos.reset();
|
||||
}
|
||||
return builder.build().toByteArray();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -344,7 +344,7 @@ public class TripleCustomerProtocolWapper {
|
|||
}
|
||||
|
||||
public Builder addArgTypes(String argsType) {
|
||||
Assert.notEmptyString(argsType, "argsType不能为空");
|
||||
Assert.notEmptyString(argsType, "argsType cannot be empty.");
|
||||
argTypes.add(argsType);
|
||||
return this;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue