question about jsonpayload construction

0 views
Skip to first unread message

kara.rawson

unread,
Sep 1, 2009, 10:44:16 AM9/1/09
to StreamHub Comet Server Community
okay so after getting streamhub up and running, and figured out i have
a question about how the JSONpayload works

here is some code which publishes a payload to my comet server

Payload payload = new JsonPayload("HelloComet");
payload.addField("data", requestData);

CometServlet.pushServer.publish("HelloComet", payload);


why do you need to declare the topic twice? Shouldn't the publish
method be smart enough to derive the topic from what the JSONPayload
constructs. JSONPayload only has one constructor, so the topic has to
be specified. JSONPayload also does not provide any method to allow
you to access the topic member of the JSONPayload class. something
like getTopic would work. it would be much mroe elegant to have it
like:


Payload payload = new JsonPayload("HelloComet");
payload.addField("data", requestData);

CometServlet.pushServer.publish(payload);

just some thoughts

kara

StreamHub Team

unread,
Sep 1, 2009, 4:06:14 PM9/1/09
to StreamHub Comet Server Community
Hi Kara,

Good question!

You are right - it does not seem the most elegant way to do things -
the topic is duplicated and violates the DRY principle amongst other
things.

However, it is there for a good reason - when a JSON payload is
created it gets transformed internally ready to be sent over the wire
- so that when the server comes to publishing the payload it can
immediately send it without having to waste precious CPU cycles
extracting the topic from the payload or transforming the payload in
to its on-the-wire form. It is a very minor optimization but it has
been profiled against the alternative you suggested and came out on
top. When you are sending tens of thousands of messages a second this
seemingly over-the-top optimization increases the throughput.

A little undocumented trick for you, the topic in a JSON payload is
internally stored as a field with the key "topic" so you can't do
payload.getTopic() but you can do payload.getFields().get("topic"). ;)

Kara Rawson

unread,
Sep 1, 2009, 9:53:36 PM9/1/09
to streamhub-comet-...@googlegroups.com
Thanx, thats awesome, i figured it was architected with that in mind, i just wanted to double confirm, so i didn't have to do my own profiling with that comet goodness ^_^.

you should definately just copy over this info into the javadoc for this class, im sure many other will find it useful. I dont know if you have checked out netbeans new and improved profiling system, but it rocks since 6.7. It has alot of debug profiling charts and graphs and such which i haven't really seen in other IDE's before. That might be helpful for you as i have found it very useful in profiling the performance of our app using streamhub. Of course streamhub performed excellant. =)

happy coding.

k
Reply all
Reply to author
Forward
0 new messages