2015-08-18 15:39 GMT+03:00 Mark Thomas <ma...@apache.org>:
> On 18/08/2015 12:58, Konstantin Kolinko wrote:
>> 2015-08-18 14:44 GMT+03:00  <ma...@apache.org>:
>>> Author: markt
>>> Date: Tue Aug 18 11:44:43 2015
>>> New Revision: 1696404
>>>
>>> URL: http://svn.apache.org/r1696404
>>> Log:
>>> Remove unused code
>>>
>>> Modified:
>>>     
>>> tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/drawboard/DrawMessage.java
>>>
[...]
>>>
>>>
>>> @@ -203,8 +188,7 @@ public final class DrawMessage {
>>>
>>>          return type + "," + (colorR & 0xFF) + "," + (colorG & 0xFF) + ","
>>>                  + (colorB & 0xFF) + "," + (colorA & 0xFF) + "," + thickness
>>> -                + "," + x1 + "," + y1 + "," + x2 + "," + y2 + ","
>>> -                + (lastInChain ? "1" : "0");
>>> +                + "," + x1 + "," + y1 + "," + x2 + "," + y2;
>>>      }
>>>
>>>      public static DrawMessage parseFromString(String str)
>>> @@ -214,7 +198,6 @@ public final class DrawMessage {
>>>          byte[] colors = new byte[4];
>>>          double thickness;
>>>          double[] coords = new double[4];
>>> -        boolean last;
>>>
>>>          try {
>>>              String[] elements = str.split(",");
>>> @@ -238,15 +221,13 @@ public final class DrawMessage {
>>>                              + coords[i]);
>>>              }
>>>
>>> -            last = !"0".equals(elements[10]);
>>> -
>>
>> I think the above condition can have either value. It is not always
>> false.   As such,  I think removing the "last" flag below is wrong.
>>
>> You can remove getter/setter in DrawMessage, but DrawMessage
>> constructor argument (as passed below) is used.
>>
>> The value of that property is used (directly, without calling a
>> getter) in the following fragment above:
>
> It is only ever used to construct the wire representation from a
> DrawMessage and when constructing a DrawMessage from the wire
> representation.
>
> I don't see it being used outside of those two uses so I see no
> requirement to keep it.
>

1. It is used at client side (by javascript code), and that javascript
code has not been updated.

It must be aligned with java.

2. At the same time you are right in your diagnosis and I do not see
that value being used when performing actual drawing in javascript
code. It is when serializing / deserializing, but I do not see any
other use.

\webapps\examples\websocket\drawboard.xhtml

Line 378 is event handling function:
[[[
                    // Handles an incoming Websocket message.
                    var handleOnMessage = function(message) {
]]]

skipping to line 478 there is the branch that processes the DrawMessage
[[[
                                    } else if (type == "1") {
                                        // We received a new DrawMessage.
                                        var maxLastHandledId = -1;
                                        var drawMessages =
msg.substring(1).split("|");
                                        for (var i = 0; i <
drawMessages.length; i++) {
                                            var elements =
drawMessages[i].split(",");
                                            var lastHandledId =
parseInt(elements[0]);
                                               maxLastHandledId =
Math.max(maxLastHandledId,
                                                       lastHandledId);

                                            var path = new Path(
                                                    parseInt(elements[1]),
                                                    [parseInt(elements[2]),
                                                    parseInt(elements[3]),
                                                    parseInt(elements[4]),

parseInt(elements[5]) / 255.0],
                                                    parseFloat(elements[6]),
                                                    parseFloat(elements[7]),
                                                    parseFloat(elements[8]),
                                                    parseFloat(elements[9]),
                                                    parseFloat(elements[10]),
                                                    elements[11] != "0");

                                            // Draw the path onto the
last canvas.
                                            path.draw(canvasServerImageCtx);
                                        }
]]]

The "elements[11] != "0""  line matches the "lastInChain" flag in java code.

The Path class is starting with line 270.
It has "lastInChain" property that is not used by its draw() method,
.but is used when serializing the message (function pushPath(path) -
line 798)

Best regards,
Konstantin Kolinko

>
>
>>>> -                + "," + x1 + "," + y1 + "," + x2 + "," + y2 + ","
>>>> -                + (lastInChain ? "1" : "0");
>>>> +                + "," + x1 + "," + y1 + "," + x2 + "," + y2;
>>
>>
>>>          } catch (RuntimeException ex) {
>>>              throw new ParseException(ex);
>>>          }
>>>
>>>          DrawMessage m = new DrawMessage(type, colors[0], colors[1],
>>>                  colors[2], colors[3], thickness, coords[0], coords[2],
>>> -                coords[1], coords[3], last);
>>> +                coords[1], coords[3]);
>>>
>>>          return m;
>>>      }
>>>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to