Documentation

Trace:

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
jvx:communication:push_publish [2019/03/14 13:05]
admin
jvx:communication:push_publish [2020/07/08 17:48] (current)
cduncan articles
Line 1: Line 1:
 ~~NOTRANS~~ ~~NOTRANS~~
-~~Title: Publish/​Push ​messages~~+~~Title: Publish/​Push ​Messages~~
  
 A standard JVx application requests data from the server side via [[jvx:​communication:​connections|Connection]]. This concept doesn'​t support sending messages from the server to the client side.  A standard JVx application requests data from the server side via [[jvx:​communication:​connections|Connection]]. This concept doesn'​t support sending messages from the server to the client side. 
  
-In JVx we have a keep alive mechanism and this usually checksevery 30 secondsif the connection to the server-side is still valid. This alive check can be used to send properties to the clientusing [[jvx:​communication:​client_server_properties|connection properties]]. It's also known as server-side polling mechanism. But this mechanism isn't the best approach for sending any kind of information to the client-side.+In JVxwe have a keep alive mechanism and this usually checks every 30 seconds if the connection to the server-side is still valid. This alive check can be used to send properties to the client using [[jvx:​communication:​client_server_properties|connection properties]]. It's also known as server side polling mechanism. But this mechanism isn't the best approach for sending any kind of information to the client side.
  
-To solve this problem, we introduced the Callback Broker on server-side. This broker is available for any session via [[jvx:​server:​lco:​sessioncontext|SessionContext]]. It makes it possible to send any objects ​to the client-side. The client-side is able to listen to so called call-back calls. A call-back ​call is not the same as an [[jvx:​communication:​async_callback|async call]]. The difference is that an async call will be triggered from the client-side and starts a new Thread ​on server-sidefor the execution. A call-back ​call is triggered from the server-side and sends information to the client-side.+To solve this problem, we introduced the Callback Broker on server side. This broker is available for any session via [[jvx:​server:​lco:​sessioncontext|SessionContext]]. It makes it possible to send any object ​to the client-side. The client-side is able to listen to so called call-back calls and, e.g., change the UI or trigger data updates. 
 +  
 +callback ​call is not the same as an [[jvx:​communication:​async_callback|async call]]. The difference is that an async call will be triggered from the client side and starts a new thread ​on server side for the execution. A callback ​call is triggered from the server side and sends information to the client side.
  
-If you publish a message, it's not guaranteed that the message will be pushed immediately to the client-side. This is technology dependent, e.g. it will work immediately with [[vaadin:​home|Vaadin UI]] because websockets are supported. If the technology doesn'​t support push, the pull mechanism via alive check will be used. So it's guaranteed that the client-side receives the message as soon as possible.+If you publish a message, it's not guaranteed that the message will be pushed immediately to the client side. This is technology-dependent, e.g.it will work immediately with [[vaadin:​home|Vaadin UI]] because websockets are supported. If the technology doesn'​t support push, the pull mechanism via alive check will be used. So it's guaranteed that the client side receives the message as soon as possible.
  
 If you want to use the publish mechanism, simply register a listener on your connection: If you want to use the publish mechanism, simply register a listener on your connection:
Line 33: Line 35:
 SessionContext.getCurrentInstance().getCallBackBroker().publish("​COUNT_ADD",​ Integer.valueOf(1));​ SessionContext.getCurrentInstance().getCallBackBroker().publish("​COUNT_ADD",​ Integer.valueOf(1));​
 </​code>​ </​code>​
-on the server-side. But be careful if you run in a Thread, ​because the broker won't be available outside the server execution thread. So, use a cached instance of the broker, e.g.:+on the server side.  
 + 
 +**But be careful** if you run in a thread ​because the broker won't be available outside the server execution thread. So, use a cached instance of the broker, e.g.:
  
 <code java> <code java>
Line 39: Line 43:
  
 Thread th = new Thread(new Runnable() Thread th = new Thread(new Runnable()
-{ +{    ​
-    private int i = pStart; +
-    +
     public void run()     public void run()
     {     {
Line 74: Line 76:
 } }
 </​code>​ </​code>​
-If you don't use a specific mode, the CurrentSession mode will be used as default setting.+If you don't use a specific mode, the CurrentSession mode will be used as default setting, like in the above example.
This website uses cookies for visitor traffic analysis. By using the website, you agree with storing the cookies on your computer.More information