1

I implemented a cluster on Payara Server with 3 Nodes (A, B & C) as Standalone Instances. I use HAproxy as load balancer and everything works fine.

I added WebSockets in my project and HAProxy switches automatically from HTTP to tunnel mode when the client request a websocket.

My problem is this : I need to retrieve websocket session regardless of connected node. For example: "I have 3 users connected to application. User 1 and User 2 are connected to the Node A. User 3 is connected to the Node B. An event occurs on the Node C that requires user 1 and 3 to be notified. But I haven't on the Node C User 1 and User 2 sessions."

I tried to use a Hazelcast distributed List to store sessions at the User connection (OnOpen method). But when I called "add" method on the list, this throws a HazelcastSerializationException because Tyrus Session Object isn't Serializable.

How can I resolve my problem?

Thanks

Luca Romeo
  • 13
  • 5
  • 1
    Have you tried writing your own custom serializer methods? http://stackoverflow.com/a/7290812/212224 – Mike Nov 22 '16 at 13:29
  • Yes, I tried but it doesn't work well. I'm trying to use Hazelcast Executor Service but it cause com.hazelcast.nio.serialization.HazelcastSerializationExcept‌​ion: java.lang.ClassNotFoundException: com.MyTask . – Luca Romeo Nov 25 '16 at 10:18

2 Answers2

1

Please have a look at the StreamSerializer if you don't want-to/can't add any serialization logic to your classes.

http://docs.hazelcast.org/docs/3.7/manual/html-single/index.html#custom-serialization

If you can add serialization logic, please have a look at the IdentifiedDataSerializable:

http://docs.hazelcast.org/docs/3.7/manual/html-single/index.html#identifieddataserializable

There are full examples in the reference manual.

You need to make sure that the object can really be serialized. Some objects should just never be serialized.

pveentjer
  • 10,545
  • 3
  • 23
  • 40
  • Thanks for the support, but I have preferred use Hazelcast Topic for share messages on Nodes instead of to serialize Session Object. it is complicated. – Luca Romeo Dec 19 '16 at 14:48
1

I doubt that transferring WebSocket sessions would help you, as you need to notify the users from the node they are connected to.

You probably want to notify nodes A and B from the node C in order to update the users connected to them. To do that, you could use Hazelcast Topic to send a message to all nodes in the cluster and retrieve the message by the node that has the WebSocket session (edited). You need to get the information from node C to the other nodes that have the session, not the other way around. Passing session to another node would be of no use, as the session is applicable only to an open WebSocket connection.

(edited) Before I suggested to use Hazelcast executor service instead of the Topic, but that causes classloader issues.

OndroMih
  • 7,280
  • 1
  • 26
  • 44
  • I tried with Hazelcast executor service. My task implements Runnable & Serializable but when i called executorService.executeOnAllMembers(new MyTask(input)), this throws com.hazelcast.nio.serialization.HazelcastSerializationException: java.lang.ClassNotFoundException: com.MyTask on the other Nodes. Just, FYI I retrieve Hazelcast Instance in this way : Context ctx = new InitialContext(); HazelcastInstance instance = (HazelcastInstance) ctx.lookup("payara/Hazelcast"); – Luca Romeo Nov 25 '16 at 10:11
  • It's true - I didn't realize that the embedded Hazelcast instance cannot access classes declared in deployed applications, because of classpath isolation. Try broadcasting a message using a [Hazelcast Topic](https://hazelcast.com/use-cases/imdg/imdg-messaging/) and place the listener into the application (I updated my reply) – OndroMih Nov 27 '16 at 10:18
  • I used Hazelcast Topic and it seems work fine. Thank you for the support. – Luca Romeo Dec 12 '16 at 10:41