Groovy - Is memory space shared between pages of different users?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Groovy - Is memory space shared between pages of different users?

DeHaynes
My question is about the memory that groovy uses.  If I write groovy code and put it in a web page.  Then two people open that web page at the same time, does the groovy code interact from both instances?

What I am trying to determine is if I put the following code on a page, if there will be issues?

def observation = Utils.getComponent(ObservationManager.class)
observation.removeListener("Renamer")
def listener = new DocumentRenamer(xwiki, xcontext)
observation.addListener(listener)


The line that removes the listener uses a string.  That string matches what is returned by the getName() of the listener class to identify it.  My concern is that if person A opens the web page, it will create a listener called "Renamer".  Then person B opens the page, the above code would remove person A listener before adding its listener.

Another way to say it is, Is there one ObservationManager for all pages on the server or does each page have its own ObservationManager?


Reply | Threaded
Open this post in threaded view
|

Re: Groovy - Is memory space shared between pages of different users?

jerem
Hi,

Independently of how groovy memory is managed, ObservationManager default
component is a singleton, so it's the same object that is accessed
(thread-safe normally) whatever the page execution.
If your listener is identified by "Renamer", it is the "same" listener you
remove / add each time (for person A or B or anyone).

I think ideally your code that unregisters/registers the listener, should
not be executed by anyone, but executed only when needed, ie if you change
the DocumentRenamer listener content. But there's no issue currently,
except that the listener may be removed / added unnecessarily.

Hope this helps,
Jeremie


2014-04-01 15:06 GMT+02:00 DeHaynes <[hidden email]>:

> My question is about the memory that groovy uses.  If I write groovy code
> and
> put it in a web page.  Then two people open that web page at the same time,
> does the groovy code interact from both instances?
>
> What I am trying to determine is if I put the following code on a page, if
> there will be issues?
>
> def observation = Utils.getComponent(ObservationManager.class)
> observation.removeListener("Renamer")
> def listener = new DocumentRenamer(xwiki, xcontext)
> observation.addListener(listener)
>
>
> The line that removes the listener uses a string.  That string matches what
> is returned by the getName() of the listener class to identify it.  My
> concern is that if person A opens the web page, it will create a listener
> called "Renamer".  Then person B opens the page, the above code would
> remove
> person A listener before adding its listener.
>
> Another way to say it is, Is there one ObservationManager for all pages on
> the server or does each page have its own ObservationManager?
>
>
>
>
>
>
> --
> View this message in context:
> http://xwiki.475771.n2.nabble.com/Groovy-Is-memory-space-shared-between-pages-of-different-users-tp7589880.html
> Sent from the XWiki- Dev mailing list archive at Nabble.com.
> _______________________________________________
> devs mailing list
> [hidden email]
> http://lists.xwiki.org/mailman/listinfo/devs
>
_______________________________________________
devs mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/devs
Reply | Threaded
Open this post in threaded view
|

Re: Groovy - Is memory space shared between pages of different users?

DeHaynes
With this method, doesn't that leave the Listener up and running after the user is done with that page?