Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wrong event setting #3043

Merged
merged 7 commits into from Jan 16, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -99,6 +99,10 @@ public void setEvent(String event) {
mData = event;
}

public void setEvent(boolean mEvent) {
beiwei30 marked this conversation as resolved.
Show resolved Hide resolved
this.mEvent = mEvent;
}

public boolean isBroken() {
return mBroken;
}
Expand Down
Expand Up @@ -43,9 +43,6 @@

/**
* ExchangeCodec.
*
*
*
*/
public class ExchangeCodec extends TelnetCodec {

Expand Down Expand Up @@ -175,25 +172,35 @@ protected Object decodeBody(Channel channel, InputStream is, byte[] header) thro
Request req = new Request(id);
req.setVersion(Version.getProtocolVersion());
req.setTwoWay((flag & FLAG_TWOWAY) != 0);
if ((flag & FLAG_EVENT) != 0) {
req.setEvent(Request.HEARTBEAT_EVENT);
}
Object data = null;
ralf0131 marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we can remove this, since we will decode event data later. In my opinion we should do this:

if ((flag & FLAG_EVENT) != 0) {
    request.setEvent(true);
}

try {
    if (req.isEvent()) {
        data = decodeEventData(channel, in);
    } else {
        data = decodeRequestData(channel, in);
   }

   request.setData(data);
}

I don't think we should distinguish event type any longer

try {
ObjectInput in = CodecSupport.deserialize(channel.getUrl(), is, proto);
Object data;
if (req.isHeartbeat()) {
data = decodeHeartbeatData(channel, in);
} else if (req.isEvent()) {
data = decodeEventData(channel, in);
} else {
data = decodeRequestData(channel, in);
}
req.setData(data);
} catch (Throwable t) {
// bad request
req.setBroken(true);
ralf0131 marked this conversation as resolved.
Show resolved Hide resolved
req.setData(t);
}
if (!req.isBroken()) {
if ((flag & FLAG_EVENT) != 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case if the condition if ((flag & FLAG_EVENT) != 0) does not gets satisfied then, what will be the event value of request object? Is there any default event type?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are currently only two events here, and the value of READONLY_EVENT is empty by default, so when this is an event and the data is empty, this is a READONLY_EVENT.
It has no default event.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the limited knowledege about this part (so @chickenlj @carryxyh @beiwei30 correct me if I am not correct). I think we should either have a default event type if noting is passed in data(more informative way and declaring a default behaviour) or we should reject the request if no default behaviour is spported. It will make the easy to debug and reason about the issue.

If we provide some default behaviour (event type) and which is not communicated, for user it might be confusiong (because it is not documented or communicated to them).

if (data != null && data.equals(Request.READONLY_EVENT)) {
beiwei30 marked this conversation as resolved.
Show resolved Hide resolved
req.setEvent(Request.READONLY_EVENT);
} else {
req.setEvent(Request.HEARTBEAT_EVENT);
}
}
req.setData(data);
} else {
if ((flag & FLAG_EVENT) != 0) {
req.setEvent(true);
}
}
return req;
}
}
Expand Down
Expand Up @@ -126,7 +126,7 @@ public static void sent(Channel channel, Request request) {
* @param channel channel to close
*/
public static void closeChannel(Channel channel) {
for (Map.Entry<Long, Channel> entry: CHANNELS.entrySet()) {
for (Map.Entry<Long, Channel> entry : CHANNELS.entrySet()) {
if (channel.equals(entry.getValue())) {
DefaultFuture future = getFuture(entry.getKey());
if (future != null && !future.isDone()) {
Expand Down Expand Up @@ -255,7 +255,6 @@ private void invokeCallback(ResponseCallback c) {
if (callbackCopy == null) {
throw new NullPointerException("callback cannot be null.");
}
c = null;
Response res = response;
if (res == null) {
throw new IllegalStateException("response cannot be null. url:" + channel.getUrl());
Expand Down
Expand Up @@ -166,25 +166,35 @@ protected Object decodeBody(Channel channel, InputStream is, byte[] header) thro
Request req = new Request(id);
req.setVersion(Version.getProtocolVersion());
req.setTwoWay((flag & FLAG_TWOWAY) != 0);
if ((flag & FLAG_EVENT) != 0) {
req.setEvent(Request.HEARTBEAT_EVENT);
}
Object data = null;
try {
ObjectInput in = CodecSupport.deserialize(channel.getUrl(), is, proto);
Object data;
if (req.isHeartbeat()) {
data = decodeHeartbeatData(channel, in);
} else if (req.isEvent()) {
data = decodeEventData(channel, in);
} else {
data = decodeRequestData(channel, in);
}
req.setData(data);
} catch (Throwable t) {
// bad request
req.setBroken(true);
req.setData(t);
}
if (!req.isBroken()) {
if ((flag & FLAG_EVENT) != 0) {
if (data != null && data.equals(Request.READONLY_EVENT)) {
req.setEvent(Request.READONLY_EVENT);
} else {
req.setEvent(Request.HEARTBEAT_EVENT);
}
}
req.setData(data);
} else {
if ((flag & FLAG_EVENT) != 0) {
req.setEvent(true);
}
}
return req;
}
}
Expand Down
Expand Up @@ -113,11 +113,8 @@ protected Object decodeBody(Channel channel, InputStream is, byte[] header) thro
Request req = new Request(id);
req.setVersion(Version.getProtocolVersion());
req.setTwoWay((flag & FLAG_TWOWAY) != 0);
if ((flag & FLAG_EVENT) != 0) {
req.setEvent(Request.HEARTBEAT_EVENT);
}
Object data = null;
try {
Object data;
ObjectInput in = CodecSupport.deserialize(channel.getUrl(), is, proto);
if (req.isHeartbeat()) {
data = decodeHeartbeatData(channel, in);
Expand All @@ -136,7 +133,6 @@ protected Object decodeBody(Channel channel, InputStream is, byte[] header) thro
}
data = inv;
}
req.setData(data);
} catch (Throwable t) {
if (log.isWarnEnabled()) {
log.warn("Decode request failed: " + t.getMessage(), t);
Expand All @@ -145,6 +141,21 @@ protected Object decodeBody(Channel channel, InputStream is, byte[] header) thro
req.setBroken(true);
req.setData(t);
}
if (!req.isBroken()) {
if ((flag & FLAG_EVENT) != 0) {
if (data != null && data.equals(Request.READONLY_EVENT)) {
req.setEvent(Request.READONLY_EVENT);
} else {
req.setEvent(Request.HEARTBEAT_EVENT);
}
}
req.setData(data);
} else {
if ((flag & FLAG_EVENT) != 0) {
req.setEvent(true);
}
}

return req;
}
}
Expand Down