Firstly I hope you are enjoying building your first Wicket web app.

Is this application scope object immutable? What is the data structure?

IMHO, if it's immutable then it's OK to use composition within your
WebApplication by adding this object as a field within WebApplication.
I would just make it final so it never gets incorrectly pointed to a
different object once initialized.

However if this has mutable shared data, then do not use the
WebApplication's intrinsic lock as you will jeopardize its throughput
to process requests. For example:

public class FooBarApplication extends WebApplication {

private MyAppScopeObject appScopeObject;

public synchronized MyAppScopeObject getAppScopeObject(){
     return appScopeObject;
}

public synchronized void setAppScopeObject(MyAppScopeObject appScopeObject) {
    this.appScopeObject = appScopeObject;
}

}

Instead, use your application-scope object's intrinsic lock or use a
suitable mutex in the Java 5/6 API.

Best,
James.

On Mon, Aug 25, 2008 at 12:04 PM, Marvan Spagnolo <[EMAIL PROTECTED]> wrote:
> Hi all, I'm new to Wicket and developing my first Wicket website.
> I have some temporary objects created inside a users' session but needed by
> a parallel process which uses them
> outside the user session and I would like to avoid temporarily persisting
> them into a database.
>
> I'm looking at using application scope objects but I'm not sure how to do it
> best
> in Wicket.
>
> I guess I should override the get() method of WebApplication
> mimicking the pattern used for custom Session objects.
>
> public class WicketApplication extends MyWebApplication
> {
>  private Object applicationScopeObject;
>
> public WicketApplication() {
> setApplicationScopeObject( <init value> );
> }
>  @Override
> public static WicketApplication get() {
> return (WicketApplication) WebApplication.get();
> }
>  public Object getApplicationScopeObject(){
> return this.applicationScopeObject;
> }
>  public void setApplicationScopeObject( Object applicationScopeObject ){
> this.applicationScopeObject = applicationScopeObject;
> }
>  [...]
> }
>
> public class PageInsideUserSession
> {
> public PageInsideUserSession(){
>  [...]
> // object has already been initialized
> WicketApplication.get().setApplicationScopeObject( object );
> }
> }
>
> public class PageOutsideUserSession
> {
> public PageOutsideUserSession(){
> Object object = WicketApplication.get().getApplicationScopeObject();
> [...]
> }
> }
>
> In my case synchronizing the access to the application scope object should
> not be needed.
>
> Is this approach correct (and efficient) or is there a better solution ?
> Should I maybe use a separate parent class (parent of WicketApplication and
> child of WebApplication) for
> overriding the get() method (in case the override interferes with something
> else in the framework) ?
>
> Cheers,
>
> Marvan
>
> --
> Reza Marvan Spagnolo
> SW Engineer - Freelancer
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to