0

I'm working on the design of an with RAP/RWT, working under Tomcat. I'm learning RAP now, and a couple of questions come to my mind.

My application has a backend that works continuously gathering data from certain sources. On the other hand I want to create a frontend (RWT standalone application, or RAP with workbench functionality, not decided yet) running as a webapp.

  • First question: should I keep the backend as a separate process, and let the frontend RAP application communicate somehow with it? Or can I integrate everything together in the RAP application? Integrating everything together leads to the second question.

  • Second question: how can I detect from within the RAP application, when is the browser window/tab holding my app, closed? I would like to do some resource cleanup when the user closes the graphical interface (i.e. closes the browser). I cannot find anything equivalent to ApplicationWorkbenchWindowAdvisor#preWindowShellClose in RWT standalone applications. Same to dected when the application is started. In general, are there callbacks to follow the webapp lifecycle in RWT standalone applications?

Thanks a lot for your help!

RĂ¼diger Herrmann
  • 20,512
  • 11
  • 62
  • 79

2 Answers2

1

Regarding your first point: When you use EJBs, please be aware that you can only directly access Java EE contexts from the request thread. This is not a problem when you run in JEE_COMPATIBILITY mode, but in SWT_COMPATIBILITY mode you may need to access your EJBs through RWT.requestThreadExec( Runnable );.

As for your second question, the RAP server is currently not informed on browser closes. This issue is discussed in bug 284273 - Session kill mechanism on browser close. It is not yet implemented because IIRC we couldn't find a reliable method of doing so that works in all browsers.

You could implement your own solution using a) the JSExecutor to put some JavaScript on the client that sends a request on browser close, and b) a PhaseListener that listens to these requests and terminates the session.

Arjan Tijms
  • 37,782
  • 12
  • 108
  • 140
ralfstx
  • 3,893
  • 2
  • 25
  • 41
0

(*) First: decoupling is always the best practice. I use RMI stubs for receive notifications from backend application (another RMI object or EJB beans).

 MyEJBListener stub = UnicastRemoteObject.exportObject(new MyEJBListener(display, page,
                                    manager, handlermanager), 0)
 MyEJBClient client1 = MyEJBLocator.findEJBClient("abc");
 client1.addListener(stub);

In the stub use something like

public void notify(Event event){

  UICallBack.activate("stubthread");
  Display..asyncExec(new Runnable() {
   // update event info
  });
}

(*) Second:the method WorkbenchWindowAdvisor#postWindowClose can help you?, and call somethig method form backend app.

Daniel
  • 23,129
  • 12
  • 109
  • 154