Skip to content

Commit 3f6c810

Browse files
committed
2 parents f14bba8 + 16b5b89 commit 3f6c810

File tree

11 files changed

+154
-263
lines changed

11 files changed

+154
-263
lines changed

dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/netty4/Http2WireProtocol.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
11
package org.apache.dubbo.remoting.netty4;
22

33
import io.netty.channel.ChannelHandlerContext;
4-
import io.netty.channel.ChannelPipeline;
5-
import io.netty.handler.codec.http2.DefaultHttp2Connection;
6-
import io.netty.handler.codec.http2.Http2Connection;
7-
import io.netty.handler.codec.http2.Http2ConnectionHandler;
8-
import io.netty.handler.codec.http2.Http2FrameListener;
94
import io.netty.handler.codec.http2.Http2FrameLogger;
105

116
import java.util.Set;
127
import java.util.concurrent.ConcurrentHashMap;
138

149
import static io.netty.handler.logging.LogLevel.DEBUG;
10+
import static io.netty.handler.logging.LogLevel.INFO;
1511

1612
public abstract class Http2WireProtocol implements WireProtocol {
1713
public static final Http2FrameLogger CLIENT_LOGGER = new Http2FrameLogger(DEBUG, "H2_CLIENT");
18-
public static final Http2FrameLogger SERVER_LOGGER = new Http2FrameLogger(DEBUG, "H2_SERVER");
14+
public static final Http2FrameLogger SERVER_LOGGER = new Http2FrameLogger(INFO, "H2_SERVER");
1915
private static final Set<Http2SessionHandler> handlers = ConcurrentHashMap.newKeySet();
2016
private final ProtocolDetector detector = new Http2ProtocolDetector();
2117

dubbo-rpc/dubbo-rpc-triple/pom.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@
3535
<artifactId>dubbo-rpc-api</artifactId>
3636
<version>${project.parent.version}</version>
3737
</dependency>
38-
<dependency>
39-
<groupId>io.grpc</groupId>
40-
<artifactId>grpc-stub</artifactId>
41-
</dependency>
4238
<dependency>
4339
<groupId>com.google.protobuf</groupId>
4440
<artifactId>protobuf-java</artifactId>

dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/GrpcElf.java

Lines changed: 0 additions & 148 deletions
This file was deleted.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package org.apache.dubbo.rpc.protocol.tri;
2+
3+
/**
4+
* See https://github.com/grpc/grpc/blob/master/doc/statuscodes.md
5+
*/
6+
enum GrpcStatus {
7+
OK(0),
8+
NOT_FOUND(5),
9+
UNIMPLEMENTED(12),
10+
INTERNAL(13);
11+
12+
final int code;
13+
14+
GrpcStatus(int code){
15+
this.code=code;
16+
}
17+
}

dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/Http2Request.java

Lines changed: 40 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2,84 +2,75 @@
22

33
import io.netty.buffer.ByteBuf;
44
import io.netty.buffer.ByteBufAllocator;
5+
import io.netty.buffer.CompositeByteBuf;
56
import io.netty.handler.codec.http2.Http2Connection;
67
import io.netty.handler.codec.http2.Http2Headers;
78
import io.netty.handler.codec.http2.Http2Stream;
89

910
public class Http2Request {
10-
private int streamId;
11-
private ByteBuf commulation;
11+
private final int streamId;
12+
private final String path;
1213
private volatile Http2Headers headers;
14+
private CompositeByteBuf pending;
1315
private Http2Stream http2Stream;
1416
private Http2Connection.PropertyKey streamKey;
15-
private String marshaller;
16-
private ByteBufAllocator allocator;
17-
private byte[] content;
17+
private int bytesToRead;
18+
private final ByteBufAllocator alloc;
1819

19-
public Http2Request(int streamId, Http2Stream http2Stream
20-
, Http2Headers headers
21-
//, AbstractHttp2CodecHandler http2CodecHandler
22-
, Http2Connection.PropertyKey streamKey, String marshaller, ByteBufAllocator allocator) {
20+
public Http2Request(int streamId, String path, Http2Stream http2Stream, Http2Headers headers,
21+
Http2Connection.PropertyKey streamKey, ByteBufAllocator allocator) {
2322
this.streamId = streamId;
23+
this.path = path;
2424
this.http2Stream = http2Stream;
2525
this.headers = headers;
26-
//this.http2CodecHandler = http2CodecHandler;
26+
this.alloc=allocator;
2727
this.streamKey = streamKey;
28-
this.marshaller = marshaller;
29-
this.allocator = allocator;
30-
this.commulation = allocator.buffer();
28+
this.pending = allocator.compositeBuffer();
3129
}
3230

3331
public Http2Headers getHeaders() {
3432
return headers;
3533
}
3634

3735
public ByteBuf getData() {
38-
return commulation;
36+
return pending;
3937
}
4038

4139
public int getStreamId() {
4240
return streamId;
4341
}
4442

45-
public byte[] content() {
46-
if (content != null) {
47-
return content;
48-
}
49-
this.content = new byte[commulation.readableBytes()];
50-
commulation.readBytes(content);
51-
commulation.release();
52-
return content;
43+
public void appendData(ByteBuf data) {
44+
pending.addComponent(true, data);
5345
}
5446

55-
public void cumulate(ByteBuf byteBuf) {
56-
commulation = cumulate(allocator, commulation, byteBuf);
57-
}
47+
public ByteBuf getAvailableTrunk(){
5848

59-
public ByteBuf cumulate(ByteBufAllocator alloc, ByteBuf cumulation, ByteBuf in) {
60-
final ByteBuf buffer;
61-
if (cumulation.writerIndex() > cumulation.maxCapacity() - in.readableBytes()
62-
|| cumulation.refCnt() > 1 || cumulation.isReadOnly()) {
63-
// Expand cumulation (by replace it) when either there is not more room in the buffer
64-
// or if the refCnt is greater then 1 which may happen when the user use slice().retain() or
65-
// duplicate().retain() or if its read-only.
66-
//
67-
// See:
68-
// - https://github.com/netty/netty/issues/2327
69-
// - https://github.com/netty/netty/issues/1764
70-
buffer = expandCumulation(alloc, cumulation, in.readableBytes());
71-
} else {
72-
buffer = cumulation;
73-
}
74-
buffer.writeBytes(in);
75-
return buffer;
76-
}
49+
int type = pending.readUnsignedByte();
50+
// if ((type & RESERVED_MASK) != 0) {
51+
// throw Status.INTERNAL.withDescription(
52+
// "gRPC frame header malformed: reserved bits not zero")
53+
// .asRuntimeException();
54+
// }
55+
// compressedFlag = (type & COMPRESSED_FLAG_MASK) != 0;
7756

78-
private ByteBuf expandCumulation(ByteBufAllocator alloc, ByteBuf cumulation, int readable) {
79-
ByteBuf oldCumulation = cumulation;
80-
cumulation = alloc.buffer(oldCumulation.readableBytes() + readable);
81-
cumulation.writeBytes(oldCumulation);
82-
oldCumulation.release();
83-
return cumulation;
57+
// Update the required length to include the length of the frame.
58+
this.bytesToRead = pending.readInt();
59+
/* if (requiredLength < 0 || requiredLength > maxInboundMessageSize) {
60+
throw Status.RESOURCE_EXHAUSTED.withDescription(
61+
String.format("gRPC message exceeds maximum size %d: %d",
62+
maxInboundMessageSize, requiredLength))
63+
.asRuntimeException();
64+
}*/
65+
return tryRead();
66+
67+
}
68+
private ByteBuf tryRead(){
69+
if(bytesToRead>0&&pending.readableBytes()>=bytesToRead){
70+
final ByteBuf ready = alloc.buffer();
71+
pending.readBytes(ready,bytesToRead);
72+
return ready;
73+
}
74+
return null;
8475
}
8576
}

dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/Marshaller.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
11
package org.apache.dubbo.rpc.protocol.tri;
22

3-
import java.io.ByteArrayInputStream;
4-
import java.io.IOException;
5-
import java.io.InputStream;
6-
73
import com.google.protobuf.InvalidProtocolBufferException;
84
import com.google.protobuf.MessageLite;
95
import com.google.protobuf.Parser;
106
import io.netty.buffer.ByteBuf;
117
import io.netty.buffer.ByteBufAllocator;
128
import io.netty.buffer.ByteBufInputStream;
139

10+
import java.io.ByteArrayInputStream;
11+
import java.io.IOException;
12+
import java.io.InputStream;
13+
1414
public class Marshaller {
1515

1616
public static Marshaller marshaller = new Marshaller();
1717

1818
public Object unmarshaller(Class<?> requestClass, ByteBuf in) {
19-
in.readByte();
20-
final int len = in.readInt();
21-
System.out.println(len);
2219
final Parser<?> parser = ProtoUtil.getParser(requestClass);
2320
Object result = null;
2421
try {
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package org.apache.dubbo.rpc.protocol.tri;
2+
3+
public interface TripleConstant {
4+
String STATUS_KEY = "grpc-status";
5+
String MESSAGE_KEY = "grpc-message";
6+
String CONTENT_TYPE_KEY = "content-type";
7+
String CONTENT_PROTO = "application/grpc+proto";
8+
9+
String APPLICATION_GRPC = "application/grpc";
10+
11+
}

0 commit comments

Comments
 (0)