Push event from Server

Hi all,

I’m evaluating the use of vaadin to build an integrated application, where the server part already exists as Java application and the client part should be written using vaadin.
One evaluating point is: How can I push an event from server to the web client?
I created already an event receiver inside vaadin application, but when an event occurs, how the vaadin client can be updated (sample: fill a text box).

Any hints will be appreciated!
Thanks a lot!
Peter

[font=Courier New]

public class WebApplication extends Application implements ValueChangeListener {
	Window mainWindow;

	class EventReceiver implements com.mycompany.Util.UserInterfaceEvent {
		public void EventOccured( String name, String value )
		{
			textField.setValue(value); 
			textField.commit();         // <-- this will not update the user interface
		}
	}

	public void init() {
		com.mycompany.Util.EventNotifier(new EventReceiver());

[/font]

Hi,

Throw in Dontpush Ozonelayer add-on and then your client side (browser) has constantly open connection to the server. Server side updates will then just work.

One thing to note is that when you are modifying the UI from a non-users initiated thread, you should manually synchronize over the application instance. Otherwise you’ll face odd “concurrency” issues at some point.

cheers,
matti

Thank you Matti for the response. Sounds like that DONTPUSH fullfill my needs.
I downloaded
http://code.google.com/p/dontpush/
but I can’t get the sample running.

I’m working with

  • jdk1.6.0_26
  • Eclipse Indigo SR2 1.4.2.20120213-0813
  • Tomcat 6.0.26

Do I need any more, like Maven?

Can you give me some more information, how to get the chat-example running.
Thank you for your help!
Peter


callstack:

javax.servlet.ServletException: Failed to load application class: com.example.chat_example.Chat_exampleApplication
com.vaadin.terminal.gwt.server.ApplicationServlet.init(ApplicationServlet.java:71)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:859)
org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:579)
org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1555)
java.lang.Thread.run(Thread.java:662)

Hi,

Using DontPush itself don’t need Maven, but the example project there is using maven (like most modern java projects do) to handle various dependencies and project setup. If you are using eclipse you should install m2e plugin.

cheers,
matti

Hi Matti,
sorry for asking again.
I deployed the chat-example on my Apache Tomcat/6.0.26.
I can start the application in different browsers 1 and 2.
The text messages will not occur automatically in other browser.
Only after typing a new message in browser 2, the message from browser 1 will be shown in browser 2.
What is missing in my installation?
Below my web.xml.
Thank you for your help!
Regards,
Peter


<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
	<display-name>chat-example</display-name>
	<context-param>
		<description>
		Vaadin production mode</description>
		<param-name>productionMode</param-name>
		<param-value>false</param-value>
	</context-param>
	<servlet>
		<servlet-name>WebSocket Chat Application</servlet-name>
		<servlet-class>com.vaadin.terminal.gwt.server.ApplicationServlet</servlet-class>
		<init-param>
			<description>
			Vaadin application class to start</description>
			<param-name>application</param-name>
			<param-value>org.vaadin.dontpush.chat.WebSocketChatApplication</param-value>
		</init-param>
		<init-param>
			<param-name>widgetset</param-name>
			<param-value>org.vaadin.dontpush.chat.DemoChatWidgetset</param-value>
		</init-param>		
	</servlet>
	<servlet-mapping>
		<servlet-name>WebSocket Chat Application</servlet-name>
		<url-pattern>/*</url-pattern>
	</servlet-mapping>
	<welcome-file-list>
		<welcome-file>index.html</welcome-file>
		<welcome-file>index.htm</welcome-file>
		<welcome-file>index.jsp</welcome-file>
		<welcome-file>default.html</welcome-file>
		<welcome-file>default.htm</welcome-file>
		<welcome-file>default.jsp</welcome-file>
	</welcome-file-list>
</web-app>

Hi,

You should have two servlets like in the example, one for “push channel” and one for static resources and host page:

http://code.google.com/p/dontpush/source/browse/trunk/dontpush-root/demo-ozonelayer/src/main/webapp/WEB-INF/web.xml

I think you should refer to this wiki page if you didn’t check out the actual demo project:
http://code.google.com/p/dontpush/wiki/DontpushOzoneLayerAddOn

cheers,
matti