Singletons in RAP [message #58430] |
Wed, 07 November 2007 18:03 |
Eclipse User |
|
|
|
Originally posted by: andy.freenet.de
Hi,
I have an Application which uses a Singleton "ServiceLocator".
This class extends "SessionSingletonBase", I read this is the
right way to handle Singletons in a RAP Environment.
Well, it seems that is isnŽt.
When I try to access the Singleton-Instance I get the Exception
java.lang.IllegalStateException: No context available outside of the
request service lifecycle.
Ok, I think the error is, that no session-context is available at the time
when I call it.
But how is this problem to be solved?
Best regards!
Andy
|
|
|
Re: Singletons in RAP [message #58456 is a reply to message #58430] |
Wed, 07 November 2007 18:20 |
Eclipse User |
|
|
|
Originally posted by: jkrause.innoopract.com
It depends a little bit on what you are doing. If you are running a job
and accessing the singleton inside the job you might be able to define
the singleton (final) outside of the run method. That way the instance
is available in the job, and you avoid the "No context" exception.
Only if your problem can not be solved this way you may want to have a
look at UICallBack.runNonUIThreadWithFakeContext:
/**
* Sometimes a background thread needs to access values that are stored
* in the session object that started the thread. In particular these
* values may be stored in session singletons. Accessing these singletons
* directly from the background thread would fail. This method fakes the
* missing request context and allows the runnable code to access those
* singletons.
*
* @param display The display that is bound to the session that
contains the
* data to which the current thread should get access.
* @param runnable The runnable that contains the critical code that
* needs to have access to a request context.
*
* @see SessionSingletonBase
* @see ContextProvider
*/
Jochen
Andy wrote:
> Hi,
>
> I have an Application which uses a Singleton "ServiceLocator".
> This class extends "SessionSingletonBase", I read this is the right way
> to handle Singletons in a RAP Environment.
>
> Well, it seems that is isnŽt.
> When I try to access the Singleton-Instance I get the Exception
> java.lang.IllegalStateException: No context available outside of the
> request service lifecycle.
>
> Ok, I think the error is, that no session-context is available at the
> time when I call it.
> But how is this problem to be solved?
>
> Best regards!
>
> Andy
>
|
|
|
Re: Singletons in RAP [message #58562 is a reply to message #58456] |
Thu, 08 November 2007 11:53 |
Eclipse User |
|
|
|
Originally posted by: andy.freenet.de
Hi Andy,
you were right, this was exactly the reason.
Access to a SessionSingletonBase inside of a Job (or any Background-Thread
running on the Server I suppose) gives a IllegalStateException.
But what exactly is the reason for this?
I dont get the Point at the moment, perhaps you could describe shortly or
point me to the right direction?
Thank you
Andy
|
|
|
Re: Singletons in RAP [message #58706 is a reply to message #58562] |
Thu, 08 November 2007 14:35 |
Eclipse User |
|
|
|
Originally posted by: fappel.innoopract.com
Hi Andy,
just a little excerpt of a discussion regarding the usage of session
singletons and background threads that may brings a little more light at
this:
[...]To describe it in modelling terms, the relationship from background
thread to UI (session) in RCP is an 1 to 1 relationship as in RAP it is an 1
to n. Handling this difference can not be done under the hood of RAP, since
the backround job cannot access implicitly the one and only UI-session as in
RCP (e.g. by calling Display#getDefault()). [...]
Ciao
Frank
"Andy" <andy@freenet.de> schrieb im Newsbeitrag
news:cb110d78474d19f18bd6c20ab96a114a$1@www.eclipse.org...
> Hi Andy,
> you were right, this was exactly the reason.
> Access to a SessionSingletonBase inside of a Job (or any Background-Thread
> running on the Server I suppose) gives a IllegalStateException.
> But what exactly is the reason for this?
> I dont get the Point at the moment, perhaps you could describe shortly or
> point me to the right direction?
>
> Thank you
>
> Andy
>
|
|
|
Powered by
FUDForum. Page generated in 0.03868 seconds