How to choose the Service Scope in grails project

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

How to choose the Service Scope in grails project

Ting-Rung Dai
Dear sir,

I have seen the service scope description in grails User Guide,
But I still confused how to make the choice for which scope that suitable for our project,
In our  project(multi user concurrent operation application), we using the Flex as  user interface then through Web Services to access grails services object (that be exposed as web services through XFire plugin), in such architecture for service scope decision, please give us some suggestion !
Reply | Threaded
Open this post in threaded view
|

Re: How to choose the Service Scope in grails project

Jeff Scott Brown
On Thu, Jul 30, 2009 at 5:25 AM, devonfgu<[hidden email]> wrote:

>
> Dear sir,
>
> I have seen the service scope description in grails User Guide,
> But I still confused how to make the choice for which scope that suitable
> for our project,
> In our  project(multi user concurrent operation application), we using the
> Flex as  user interface then through Web Services to access grails services
> object (that be exposed as web services through XFire plugin), in such
> architecture for service scope decision, please give us some suggestion !

It really depends on details of your app.  Maybe most important is,
does your service have state?  If your services are stateless then
they can almost certainly be shared by multiple concurrent requests
and should probably be singletons.  If they do have state, you need to
figure out when (if ever) it is ok to have that state shared across
users of the service.  Depending on those details you might want the
service to be scoped to prototype, request or session.



jb

--
Jeff Brown
SpringSource
http://www.springsource.com/

Autism Strikes 1 in 166
Find The Cause ~ Find The Cure
http://www.autismspeaks.org/

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: How to choose the Service Scope in grails project

Ting-Rung Dai
In reply to this post by Ting-Rung Dai
Dear jeff,

Thanks your help,

I am confused what is state , could you help to more explain the term of "state",
example what is a state variable ?

I wonder whether if in my service class have declare a instance variable, then the instance variable's data value will cross setting on multi concurrent user session , then will caused my application logic mistake?

Reply | Threaded
Open this post in threaded view
|

Re: How to choose the Service Scope in grails project

Jeff Scott Brown
On Thu, Jul 30, 2009 at 7:17 AM, devonfgu<[hidden email]> wrote:

>
> Dear jeff,
>
> Thanks your help,
>
> I am confused what is state , could you help to more explain the term of
> "state",
> example what is a state variable ?
>
> I wonder whether if in my service class have declare a instance variable,
> then the instance variable's data value will cross setting on multi
> concurrent user session , then will caused my application logic mistake?
>
>

If your service has an instance variable (that is state) and you don't
want that state to be shared by multiple concurrent users of the
service, then you don't want that service to be a singleton.  If a
service is a singleton then every user of that service is sharing the
same copy of the service.  If a service is request scoped then a new
instance is created for every http request.  If a service is sessions
scoped then the service will be kept around and reused for the entire
user session (each user session has their own copy).  I hope that is
making sense and is helpful.

I would like to help but I fear that if this doesn't make sense then
more Grails details may confuse things further.  In that case, you may
need to back up and sort out fundamental details about OO, shared
state etc.  Understanding those fundamentals are important if you are
going to build OO software (Grails or otherwise).

I hope this is helpful and hasn't confused things more.



jb

--
Jeff Brown
SpringSource
http://www.springsource.com/

Autism Strikes 1 in 166
Find The Cause ~ Find The Cure
http://www.autismspeaks.org/

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

RE: How to choose the Service Scope in grails project

grailsme
In reply to this post by Ting-Rung Dai
Inside the Controller declare your service

Class yourController {
 def yourService

        def yourThing {
       
yourUseableVariable=yourService.yourFunction(yourTransportableVariable1,
yourTransportableVariable2)
        }
}

Inside your service declare your Service and function
(the file will named yourServiceService.groovy
Class yourService {
        def yourFunction(Variable1, variable2) // variable 1 and 2 will
contain the values of the two yourTransportableVariables
        {
                her do something extremely valuable and nice
        youveGotaNewVariable = ...... // outcome of your function
        return youveGotaNewVariable
        }
}

When your controller is triggered to yourThing, the service will be started
and yourUseableVariable will contain the value of youveGotaNewVariable

(at least this is how I do it. )
All stupidity reserved by Grailsme

-----Original Message-----
From: devonfgu [mailto:[hidden email]]
Sent: donderdag 30 juli 2009 14:17
To: [hidden email]
Subject: Re: [grails-user] How to choose the Service Scope in grails project


Dear jeff,

Thanks your help,

I am confused what is state , could you help to more explain the term of
"state",
example what is a state variable ?

I wonder whether if in my service class have declare a instance variable,
then the instance variable's data value will cross setting on multi
concurrent user session , then will caused my application logic mistake?


--
View this message in context:
http://www.nabble.com/How-to-choose-the-Service-Scope-in-grails-project-tp24
735778p24737332.html
Sent from the grails - user mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email






---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email