Re: [jgroups-users] v3->v4 move, problem with castMessage
Questions/problems related to using JGroups <[email protected]> Mon, 30 Oct 2017 11:05:14 +0100
| Newsgroups | gmane.comp.java.javagroups.general |
|---|---|
| Message-ID | <mailman.20962.1509357933.12861.javagroups-users@lists.sourceforge.net> |
Hi Bobby,
On 26/10/17 20:13, Questions/problems related to using JGroups wrote:
> Hi again,
>
> Am having various problems with our v3->v4 change. Trying to focus on
> them one at a time, I wanted to ask about the castMessage change. We
> were doing this before to send a message out to every node, collect
> responses, etc:
>
> RspList<MyOb> rspList = md.castMessage(null,
> new Message(null, myString), ro);
>
> ...where myString is actually a constant starting with "n" and MyOb is a
> Serializable object with some primitive data in it and one Address
> object (*).
I don't see a myObj instance getting passed to the call?
> Now trying in v4.0.7 with this:
>
> RspList<MyOb> rspList = md.castMessage(null,
> Util.stringToBytes(myString),
> 0, myString.length(), ro);
That won't work; myString.length() doesn't return the size of the
generated byte[] array, better do this:
byte[] buf=Util.stringToBytes(myString);
RspList<MyOb> rspList = md.castMessage(null, buf, 0, buf.length, ro);
> ...but my Rsp (only 1 node so far) comes back with an exception instead
> of MyOb:
> "java.lang.IllegalArgumentException: type 110 is invalid" (110 is the
> first byte in the array).
Perhaps caused by the incorrect length argument above?
> I see that my handle() method is being called at the receiving end, and
> the exception happens when I call Message#getObject() -- that code
> hasn't changed from 3.x:
>
> @Override
> public Object handle(Message msg) throws Exception {
> final Object payload = msg.getObject();
> }
You pass in a byte[] array generated by Util.stringToBytes(), so you
*cannot* use Message.getObject() to retrieve it, but have to use the
equivalent to de-serialize the byte[] array: Util.bytesToString().
> The getObject eventually calls Util#objectFromByteBuffer, and that
> method is treating the first byte of the message as the type of the
> message, and it falls apart there.
Right. So either use Util.objectToByteBuffer() and
Util.objectFromByteBuffer() to marshall / unmarshall the payload, or
stringToBytes() / bytesToString(), but don't mix and match!
> Is there some other way I should be handling this?
>
> (*) Related: am getting a lot of FindBugs warnings now because we have a
> couple Serializable objects we pass around that include Address objects,
> and that isn't marked Externalizable any more. Any advice there would
> also be appreciated.
I removed Serializable / Externalizable from Address, so they cannot be
serialized with Java serialization (which is a bad idea anyway!). Use
Util.writeAddress()/readAddress() instead
> Thanks,
> Bobby
>
>
>
> ------------------------------------------------------------------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
>
>
>
> _______________________________________________
> javagroups-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/javagroups-users
>
--
Bela Ban | http://www.jgroups.org
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
javagroups-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/javagroups-users