Skip to content

Commit

Permalink
migrate to protobuf javalite, print connect exception stack (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
FZambia authored May 2, 2021
1 parent 6871e7b commit a4aefb5
Show file tree
Hide file tree
Showing 7 changed files with 7,937 additions and 17,026 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ option java_outer_classname = "Protocol";
Then:

```
protoc --java_out=./ client.proto
protoc --java_out=lite:./ client.proto
mv io/github/centrifugal/centrifuge/internal/protocol/Protocol.java centrifuge/src/main/java/io/github/centrifugal/centrifuge/internal/protocol/Protocol.java
rm -r io/
```
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.1'
classpath 'com.android.tools.build:gradle:4.1.2'
}
}

Expand Down
2 changes: 1 addition & 1 deletion centrifuge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ version = "0.0.5"

dependencies {
implementation 'com.squareup.okhttp3:okhttp:3.10.0'
implementation 'com.google.protobuf:protobuf-java:3.11.4'
implementation 'com.google.protobuf:protobuf-javalite:3.11.4'
implementation 'net.sourceforge.streamsupport:streamsupport-cfuture:1.7.0'
implementation 'com.google.code.gson:gson:2.8.6'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@

public class Client {
private WebSocket ws;
private String url;
private final String url;

Options getOpts() {
return opts;
}

private Options opts;
private final Options opts;
private String token = "";
private String name = "java";
private String version = "";
Expand Down Expand Up @@ -229,7 +229,11 @@ public void onFailure(WebSocket webSocket, Throwable t, Response response) {
}

private void handleConnectionOpen() {
this.sendConnect();
try {
this.sendConnect();
} catch (Exception e) {
e.printStackTrace();
}
}

private void handleConnectionMessage(byte[] bytes) {
Expand Down Expand Up @@ -383,7 +387,7 @@ private void sendSubscribeSynchronized(String channel, boolean recover, StreamPo

Protocol.Command cmd = Protocol.Command.newBuilder()
.setId(this.getNextId())
.setMethod(Protocol.MethodType.SUBSCRIBE)
.setMethod(Protocol.Command.MethodType.SUBSCRIBE)
.setParams(req.toByteString())
.build();

Expand Down Expand Up @@ -461,7 +465,7 @@ private void sendUnsubscribeSynchronized(Subscription sub) {

Protocol.Command cmd = Protocol.Command.newBuilder()
.setId(this.getNextId())
.setMethod(Protocol.MethodType.UNSUBSCRIBE)
.setMethod(Protocol.Command.MethodType.UNSUBSCRIBE)
.setParams(req.toByteString())
.build();

Expand Down Expand Up @@ -591,7 +595,7 @@ private void _sendPing() {

Protocol.Command cmd = Protocol.Command.newBuilder()
.setId(this.getNextId())
.setMethod(Protocol.MethodType.PING)
.setMethod(Protocol.Command.MethodType.PING)
.setParams(req.toByteString())
.build();

Expand Down Expand Up @@ -773,7 +777,7 @@ private void sendConnect() {

Protocol.Command cmd = Protocol.Command.newBuilder()
.setId(this.getNextId())
.setMethod(Protocol.MethodType.CONNECT)
.setMethod(Protocol.Command.MethodType.CONNECT)
.setParams(req.toByteString())
.build();

Expand Down Expand Up @@ -805,7 +809,7 @@ private void handleAsyncReply(Protocol.Reply reply) {
try {
Protocol.Push push = Protocol.Push.parseFrom(reply.getResult());
String channel = push.getChannel();
if (push.getType() == Protocol.PushType.PUBLICATION) {
if (push.getType() == Protocol.Push.PushType.PUBLICATION) {
Protocol.Publication pub = Protocol.Publication.parseFrom(push.getData());
Subscription sub = this.getSub(channel);
if (sub != null) {
Expand All @@ -825,15 +829,15 @@ private void handleAsyncReply(Protocol.Reply reply) {
serverSub.setLastOffset(pub.getOffset());
}
}
} else if (push.getType() == Protocol.PushType.SUB) {
Protocol.Sub sub = Protocol.Sub.parseFrom(push.getData());
} else if (push.getType() == Protocol.Push.PushType.SUBSCRIBE) {
Protocol.Subscribe sub = Protocol.Subscribe.parseFrom(push.getData());
ServerSubscription serverSub = new ServerSubscription(sub.getRecoverable(), sub.getOffset(), sub.getEpoch());
this.serverSubs.put(channel, serverSub);
serverSub.setRecoverable(sub.getRecoverable());
serverSub.setLastEpoch(sub.getEpoch());
this.listener.onSubscribe(this, new ServerSubscribeEvent(channel, false, false));
serverSub.setLastOffset(sub.getOffset());
} else if (push.getType() == Protocol.PushType.JOIN) {
} else if (push.getType() == Protocol.Push.PushType.JOIN) {
Protocol.Join join = Protocol.Join.parseFrom(push.getData());
ClientInfo info = new ClientInfo();
info.setClient(join.getInfo().getClient());
Expand All @@ -851,7 +855,7 @@ private void handleAsyncReply(Protocol.Reply reply) {
this.listener.onJoin(this, new ServerJoinEvent(channel, info));
}
}
} else if (push.getType() == Protocol.PushType.LEAVE) {
} else if (push.getType() == Protocol.Push.PushType.LEAVE) {
Protocol.Leave leave = Protocol.Leave.parseFrom(push.getData());
LeaveEvent event = new LeaveEvent();
ClientInfo info = new ClientInfo();
Expand All @@ -870,8 +874,8 @@ private void handleAsyncReply(Protocol.Reply reply) {
this.listener.onLeave(this, new ServerLeaveEvent(channel, info));
}
}
} else if (push.getType() == Protocol.PushType.UNSUB) {
Protocol.Unsub.parseFrom(push.getData());
} else if (push.getType() == Protocol.Push.PushType.UNSUBSCRIBE) {
Protocol.Unsubscribe.parseFrom(push.getData());
Subscription sub = this.getSub(channel);
if (sub != null) {
sub.unsubscribeNoResubscribe();
Expand All @@ -882,7 +886,7 @@ private void handleAsyncReply(Protocol.Reply reply) {
this.serverSubs.remove(channel);
}
}
} else if (push.getType() == Protocol.PushType.MESSAGE) {
} else if (push.getType() == Protocol.Push.PushType.MESSAGE) {
Protocol.Message msg = Protocol.Message.parseFrom(push.getData());
MessageEvent event = new MessageEvent();
event.setData(msg.getData().toByteArray());
Expand Down Expand Up @@ -911,7 +915,7 @@ private void sendSynchronized(byte[] data, CompletionCallback cb) {

Protocol.Command cmd = Protocol.Command.newBuilder()
.setId(this.getNextId())
.setMethod(Protocol.MethodType.SEND)
.setMethod(Protocol.Command.MethodType.SEND)
.setParams(req.toByteString())
.build();

Expand Down Expand Up @@ -1002,7 +1006,7 @@ private void rpcSynchronized(String method, byte[] data, ReplyCallback<RPCResult

Protocol.Command cmd = Protocol.Command.newBuilder()
.setId(this.getNextId())
.setMethod(Protocol.MethodType.RPC)
.setMethod(Protocol.Command.MethodType.RPC)
.setParams(req.toByteString())
.build();

Expand Down Expand Up @@ -1052,7 +1056,7 @@ private void publishSynchronized(String channel, byte[] data, ReplyCallback<Publ

Protocol.Command cmd = Protocol.Command.newBuilder()
.setId(this.getNextId())
.setMethod(Protocol.MethodType.PUBLISH)
.setMethod(Protocol.Command.MethodType.PUBLISH)
.setParams(req.toByteString())
.build();

Expand Down Expand Up @@ -1087,7 +1091,7 @@ private void historySynchronized(String channel, ReplyCallback<HistoryResult> cb

Protocol.Command cmd = Protocol.Command.newBuilder()
.setId(this.getNextId())
.setMethod(Protocol.MethodType.HISTORY)
.setMethod(Protocol.Command.MethodType.HISTORY)
.setParams(req.toByteString())
.build();

Expand Down Expand Up @@ -1137,7 +1141,7 @@ private void presenceSynchronized(String channel, ReplyCallback<PresenceResult>

Protocol.Command cmd = Protocol.Command.newBuilder()
.setId(this.getNextId())
.setMethod(Protocol.MethodType.PRESENCE)
.setMethod(Protocol.Command.MethodType.PRESENCE)
.setParams(req.toByteString())
.build();

Expand Down Expand Up @@ -1184,7 +1188,7 @@ private void presenceStatsSynchronized(String channel, ReplyCallback<PresenceSta

Protocol.Command cmd = Protocol.Command.newBuilder()
.setId(this.getNextId())
.setMethod(Protocol.MethodType.PRESENCE_STATS)
.setMethod(Protocol.Command.MethodType.PRESENCE_STATS)
.setParams(req.toByteString())
.build();

Expand Down Expand Up @@ -1222,7 +1226,7 @@ private void refreshSynchronized(String token, ReplyCallback<Protocol.RefreshRes

Protocol.Command cmd = Protocol.Command.newBuilder()
.setId(this.getNextId())
.setMethod(Protocol.MethodType.REFRESH)
.setMethod(Protocol.Command.MethodType.REFRESH)
.setParams(req.toByteString())
.build();

Expand Down
Loading

0 comments on commit a4aefb5

Please sign in to comment.