Bug 323903 - RAP: Use correct display for background jobs
Summary: RAP: Use correct display for background jobs
Status: RESOLVED FIXED
Alias: None
Product: MAT
Classification: Tools
Component: GUI (show other bugs)
Version: 1.1   Edit
Hardware: All Linux
: P3 normal (vote)
Target Milestone: 1.14.0   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 262603
  Show dependency tree
 
Reported: 2010-08-29 05:51 EDT by Benjamin Muskalla CLA
Modified: 2023-02-20 02:33 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Benjamin Muskalla CLA 2010-08-29 05:51:28 EDT
Running MAT on RAP means running in a multi-user environment. As MAT is heavily using background jobs, we need to clearify to which session the job belongs when it needs to update the UI. Running a Job in a server environment means that possibly every session could have started this job. When updating the UI trough a sync/asyncExec, the display of the user session is needed. The default pattern is to use PlatformUI.getWorkbench().getDisplay but this will not work on RAP in many sitations as RAP cannot decide which display of which session to use. Fixing this is pretty easy as most of the jobs have a reference to a widget lying around and we can just ask the widget for the display. No semantics to SWT are changed that way but this will fix the multi-user case.

If there are no objections. I'd provide a patch for this.
Comment 1 Andrew Johnson CLA 2010-08-29 15:26:09 EDT
I would welcome a patch for this. The uses of PlatformUI.getWorkbench().getDisplay() are quite extensive, so a patch will save a lot of time working out how to fix each one. Do any other uses of PlatformUI.getWorkbench().getDisplay() other than for asyncExec or syncExec need to be fixed? Does the use in InspectorView.clearInput need to be fixed?

What happens with RAP if a use isn't fixed?
Comment 2 Andrew Johnson CLA 2010-09-08 07:20:31 EDT
Using a widget to get the display is straightforward.

Inside a Job.doRun method is it safe to call getSite().getShell().getDisplay() as will the Job be run on a UI thread?

From the doc:

Shell org.eclipse.ui.IWorkbenchSite.getShell()

Returns the shell for this workbench site. Not intended to be called from outside the UI thread. Clients should call IWorkbench.getDisplay() to gain access to the display rather than calling getShell().getDisplay(). 

For compatibility, this method will not throw an exception if called from outside the UI thread, but the returned Shell may be wrong. 

Should we extract the display outside of the Job?


Extracting a display inside a standard MAT query seems to be hard (e.g. CopyActions), as the snapshot seems to be the only object available. Do we need a new argument type to get the display or some other UI component?
Comment 3 Andrew Johnson CLA 2010-09-09 05:33:03 EDT
The symptoms of not fixing this are exceptions such as:

java.lang.IllegalStateException: No context available outside of the request service lifecycle.
	at org.eclipse.rwt.internal.service.ContextProvider.getContext(ContextProvider.java:107)
	at org.eclipse.rwt.internal.service.ContextProvider.getStateInfo(ContextProvider.java:160)
	at org.eclipse.rwt.SessionSingletonBase.getInstance(SessionSingletonBase.java:84)
	at org.eclipse.ui.internal.Workbench.getInstance(Workbench.java:378)
	at org.eclipse.ui.PlatformUI.getWorkbench(PlatformUI.java:94)
Comment 4 Andrew Johnson CLA 2010-09-09 07:59:05 EDT
(In reply to comment #2)
> Using a widget to get the display is straightforward.
> 
> Inside a Job.doRun method is it safe to call getSite().getShell().getDisplay()
> as will the Job be run on a UI thread?
> 
> From the doc:
> 
> Shell org.eclipse.ui.IWorkbenchSite.getShell()
> 
> Returns the shell for this workbench site. Not intended to be called from
> outside the UI thread. Clients should call IWorkbench.getDisplay() to gain
> access to the display rather than calling getShell().getDisplay(). 
> 
> For compatibility, this method will not throw an exception if called from
> outside the UI thread, but the returned Shell may be wrong. 
> 
Is 
editor.getSite().getWorkbenchWindow().getWorkbench().getDisplay();
preferable to
editor.getSite().getShell().getDisplay();
?
Comment 5 Andrew Johnson CLA 2010-09-09 11:50:53 EDT
I'll make some initial changes to fix this, using widget.getDisplay() and editor.getSite().getWorkbenchWindow().getWorkbench().getDisplay();

In HistogramPane, using viewer.getControl().getDisplay() seems slightly risky as the viewer control is disposed and recreated, which might mean calling getDisplay on a disposed control, so using top seems safer.
Comment 6 Andrew Johnson CLA 2010-09-09 13:02:27 EDT
editor.getSite().getWorkbenchWindow().getWorkbench().getDisplay();

fails on a non-UI thread with

java.lang.IllegalStateException: No context available outside of the request service lifecycle.
	at org.eclipse.rwt.internal.service.ContextProvider.getContext(ContextProvider.java:107)
	at org.eclipse.rwt.internal.service.ContextProvider.getStateInfo(ContextProvider.java:160)
	at org.eclipse.rwt.SessionSingletonBase.getInstance(SessionSingletonBase.java:84)
	at org.eclipse.ui.internal.Workbench.getInstance(Workbench.java:378)
	at org.eclipse.ui.PlatformUI.getWorkbench(PlatformUI.java:94)
	at org.eclipse.ui.internal.WorkbenchWindow.getWorkbench(WorkbenchWindow.java:1584)
	at org.eclipse.mat.ui.QueryExecution.displayResult(QueryExecution.java:134)
	at org.eclipse.mat.ui.QueryExecution$ExecutionJob.run(QueryExecution.java:178)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)

I'll revert to editor.getSite().getShell().getDisplay();
but should it work? Should getWorkbenchWindow cache its workbench?
Comment 7 Eclipse Genie CLA 2023-01-30 01:59:43 EST
New Gerrit change created: https://git.eclipse.org/r/c/mat/org.eclipse.mat/+/199628
Comment 9 Andrew Johnson CLA 2023-02-20 02:33:35 EST
Should now be all done.