Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » On the use of Workspace and WorkManager API
On the use of Workspace and WorkManager API [message #1258331] Thu, 27 February 2014 09:18 Go to next message
El Arbi Aboussoror is currently offline El Arbi AboussororFriend
Messages: 90
Registered: June 2010
Member
Hi,

I was facing some troubles with an eclipse based product, I had the following exception raising at product startup:
	org.eclipse.core.runtime.AssertionFailedException: assertion failed: Operation was not prepared.
	at org.eclipse.core.runtime.Assert.isTrue(Assert.java:110)
	at org.eclipse.core.internal.resources.Workspace.beginOperation(Workspace.java:297)
	at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:1971)
	at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:1957)
	at org.eclipse.jdt.internal.core.JavaModelManager$19.run(JavaModelManager.java:4733)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)


Sometimes it raises from the JavaModelManager.run and sometimes from another job (e.g. AutoBuildJob). The problem was our misuse of the WorkManager checkin/checkout, beginUnprotected/endUnprotected methods. It took me a while to understand that I should rather use workspace.prepareOperation / beginOperation instead of a checkin.
This misuse led to an Assert.isTrue(false) in the org.eclipse.core.internal.resources.Workspace.beginOperation(boolean) method:

	public void beginOperation(boolean createNewTree) throws CoreException {
		WorkManager workManager = getWorkManager();
		workManager.incrementNestedOperations();
		if (!workManager.isBalanced())
			Assert.isTrue(false, "Operation was not prepared.");
		if (workManager.getPreparedOperationDepth() > 1) {
			if (createNewTree && tree.isImmutable())
				newWorkingTree();
			return;
		}
....




The WorkManager documentation says Quote:
" ...This class also tracks operation state for each thread that is involved in an operation. This includes prepared and running operation depth, auto-build strategy and cancel state."


But I still don't understand completely what is the semantics behind the WorkManager fields:
org.eclipse.core.internal.resources.WorkManager.preparedOperations
and org.eclipse.core.internal.resources.WorkManager.nestedOperations ?

And what is the meaning of an unbalanced WorkManger (workManager.isBalanced() == false) ?


Re: On the use of Workspace and WorkManager API [message #1258348 is a reply to message #1258331] Thu, 27 February 2014 09:38 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Comments below.

On 27/02/2014 10:19 AM, El Arbi Aboussoror wrote:
> Hi,
>
> I was facing some troubles with an eclipse based product, I had the
> following exception raising at product startup:
>
> org.eclipse.core.runtime.AssertionFailedException: assertion
> failed: Operation was not prepared.
> at org.eclipse.core.runtime.Assert.isTrue(Assert.java:110)
> at
> org.eclipse.core.internal.resources.Workspace.beginOperation(Workspace.java:297)
> at
> org.eclipse.core.internal.resources.Workspace.run(Workspace.java:1971)
> at
> org.eclipse.core.internal.resources.Workspace.run(Workspace.java:1957)
> at
> org.eclipse.jdt.internal.core.JavaModelManager$19.run(JavaModelManager.java:4733)
> at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)
>
>
> Sometimes it raises from the JavaModelManager.run and sometimes from
> another job (e.g. AutoBuildJob). The problem was our misuse of the
> WorkManager checkin/checkout, beginUnprotected/endUnprotected methods.
Why are you needing to use such internal methods directly? Can't you
use API like WorkspaceJob or WorkspaceModifyOperation instead?
> It took me a while to understand that I should rather use
> workspace.prepareOperation / beginOperation instead of a checkin.
> This misuse led to an Assert.isTrue(false) in the
> org.eclipse.core.internal.resources.Workspace.beginOperation(boolean)
> method:
>
> public void beginOperation(boolean createNewTree) throws
> CoreException {
> WorkManager workManager = getWorkManager();
> workManager.incrementNestedOperations();
> if (!workManager.isBalanced())
> Assert.isTrue(false, "Operation was not prepared.");
> if (workManager.getPreparedOperationDepth() > 1) {
> if (createNewTree && tree.isImmutable())
> newWorkingTree();
> return;
> }
> ...
>
>
>
> The WorkManager documentation says Quote:
>> " ...This class also tracks operation state for each thread that is
>> involved in an operation. This includes prepared and running
>> operation depth, auto-build strategy and cancel state."
>
>
> But I still don't understand completely what is the semantics behind
> the WorkManager fields:
> org.eclipse.core.internal.resources.WorkManager.preparedOperations
> and org.eclipse.core.internal.resources.WorkManager.nestedOperations ?
>
> And what is the meaning of an unbalanced WorkManger
> (workManager.isBalanced() == false) ?
>
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: On the use of Workspace and WorkManager API [message #1258413 is a reply to message #1258348] Thu, 27 February 2014 11:04 Go to previous message
El Arbi Aboussoror is currently offline El Arbi AboussororFriend
Messages: 90
Registered: June 2010
Member
It was a legacy code and we were facing memory leak problems due to the reference to workspace that was hold by the WorkspaceJob.
Previous Topic:Security Preferences
Next Topic:Problem update with proxy server
Goto Forum:
  


Current Time: Wed Apr 24 14:05:10 GMT 2024

Powered by FUDForum. Page generated in 0.04145 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top