Switching between shared/unique Java Code with Comet

16 views
Skip to first unread message

John Andrews

unread,
Feb 8, 2017, 8:13:50 AM2/8/17
to Lift
So I've been using Java/Scala/Lift to manage and run some Java code, using AJAX and JSON Rest to pass data into the java program from the browser and back respectively.

Currently I have a Scala class which contains a value with the java class that gets created when a user starts the Lift session by logging in. The AJAX and Rest are handled such that someone can click run on the browser, all other users will get info that an update has run, and then will access the data via Rest per-user.

This works because the Scala class containing the value has an extended object, and other Scala classes to handle control of Ajax/Rest/Updates can simply call functions or data as needed.

However while this works fine if the Java program is singular giving people access to it in a shared way - I'm struggling to find an easy way that someone could switch (even if it's just commenting out a line of code) such that each person gets their own copy without having a completely different setup.

Despite having the Scala code, and the code to accept Ajax commands be CometActor's by having the other classes access the 'Manager.scala' object extended from the class means that even though each person starts with a unique manager, the second it's accessed by another class it becomes shared. (I've tested this by using render, and UUID's)

Is there an easier or better way to manage this so one could easily switch from being able to update/receive data from some shared Java code, but also be able to have it be unique - or do I need to setup two completely different backend setups and tell the developer which to use?

Thanks for your hopeful insight and help!

Antonio Salazar Cardozo

unread,
Feb 8, 2017, 9:03:01 AM2/8/17
to Lift
I'm having a little bit of trouble following exactly how things are structured in your
application. Could you maybe share some simplified versions of the classes/code
involved, or perhaps if it's possible post an example project?
Thanks,
Antonio

John Andrews

unread,
Feb 9, 2017, 6:40:38 AM2/9/17
to Lift
Okay so I actually worked around this by simply making it so that the CometClass was not extended by an Object and the information from Java class/etc is unique. There is one wrinkle though.

Previously I had a RestHelper object that would refer to the CometClass object and use it to get the data from the Java class variable; however since that's not possible the question is what's the best way such that the CometClass is still a CometActor, but I can get it's data. I've looked into some of the example with SessionVar/NamedCometActorSnippet - but that causes issues in terms of what I need to do for the CometClass which by changing it causes it to break/not compile.

Thoughts?

Antonio Salazar Cardozo

unread,
Feb 9, 2017, 12:33:10 PM2/9/17
to Lift
I still feel like I don't fully grasp what you're trying to do and how it isn't
working… However, if you're trying to communicate with a comet after
it's created, the easiest way to handle that is to give it a name that you
can then use with LiftSession's sendCometActorMessage method. e.g.:

<div data-lift="MyComet?name=somename"></div>

S.session.map(_.sendCometActorMessage("MyComet", Full("somename"), TheMessage(...))

Thanks,
Antonio
Reply all
Reply to author
Forward
0 new messages