Singleton Creator

View: New views
9 Messages — Rating Filter:   Alert me  

Singleton Creator

by Ahmed Hashim :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,
In one of my messages in the users mail list, I asked about how to create a singleton class in DWR. Joe kindly refered to this page http://getahead.org/dwr/server/dwrxml/creators/scripted
It was a good solution but I didn't like to use any extra jar from apache.
I found an easy way in spring for declaring singleton beans

<bean id="singleton" class="example.LegacySingleton" factory-method="getInstance" />

Today, I went through DWR trying to implement the same thing to be used in my project

First I got the DWR source and added a new Creator for singleton

in the dwr.xml I added this declaration
<creator id="singleton" class=" org.directwebremoting.create.SingletonCreator" />

The class implementation is attached.

After that I made a simple singleton class "UserService" attached

The definition in the dwr.xml will be easy and clear

<create creator="singleton" javascript="userServiceSingleton">
          <param name="class" value="org.egjug.dwr.UserService" />
          <param name="factoryMethod" value="getInstance" />
      </create>

The complete project is attached.

I will add this simple howto to my blog later on.

--
Ahmed Hashim | EGJUG Leader | http://egjug.org | http://egjug.org/hashimblog/ |SCJP, SCWCD |hashim@egjug.org | +20103836920



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@...
For additional commands, e-mail: dev-help@...

SingletonCreator.java (3K) Download Attachment
UserService.java (878 bytes) Download Attachment
DWRSingleton.war (493K) Download Attachment

Parent Message unknown Re: [dwr-user] Singleton Creator

by Joe Walker-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.

Ahmed is right - this is about how to instantiate a singleton which requires use of a factory method.
Thanks - Ahmed.

Can we add this to DWR? Since this is a change that doesn't touch the core of DWR in any way I'm happy to add it at any time and mark it experimental.
I'm going to be chasing people for CLAs. These state that you have the right to contribute to DWR. See http://getahead.org/dwr/development/contributor for more details. Is that OK?

Joe.


On 4/10/07, Jose Noheda <jose.noheda@...> wrote:
Beans in Spring are singleton by default unless you define them declaring other scope. You don't need the factory-method. This would do it:

<bean id="singleton" class="example.LegacySingleton " />

You can use the Spring creator (in DWR) then and your beans would be singletons.

On 4/10/07, Ahmed Hashim <eng.hashim@...> wrote:
Hi,
In one of my messages in the users mail list, I asked about how to create a singleton class in DWR. Joe kindly refered to this page http://getahead.org/dwr/server/dwrxml/creators/scripted
It was a good solution but I didn't like to use any extra jar from apache.
I found an easy way in spring for declaring singleton beans

<bean id="singleton" class="example.LegacySingleton " factory-method="getInstance" />

Today, I went through DWR trying to implement the same thing to be used in my project

First I got the DWR source and added a new Creator for singleton

in the dwr.xml I added this declaration
<creator id="singleton" class=" org.directwebremoting.create.SingletonCreator" />

The class implementation is attached.

After that I made a simple singleton class "UserService" attached

The definition in the dwr.xml will be easy and clear

<create creator="singleton" javascript="userServiceSingleton">
          <param name="class" value="org.egjug.dwr.UserService" />
          <param name="factoryMethod" value="getInstance" />
      </create>

The complete project is attached.

I will add this simple howto to my blog later on.



--
Ahmed Hashim | EGJUG Leader | http://egjug.org | http://egjug.org/hashimblog/ |SCJP, SCWCD |hashim@egjug.org | +20103836920

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...




Re: Re: [dwr-user] Singleton Creator

by Ahmed Hashim :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.
Sure, Will be happy to add it to DWR.

Regards,

On 4/10/07, Joe Walker <joe@...> wrote:

Ahmed is right - this is about how to instantiate a singleton which requires use of a factory method.
Thanks - Ahmed.

Can we add this to DWR? Since this is a change that doesn't touch the core of DWR in any way I'm happy to add it at any time and mark it experimental.
I'm going to be chasing people for CLAs. These state that you have the right to contribute to DWR. See http://getahead.org/dwr/development/contributor for more details. Is that OK?

Joe.



On 4/10/07, Jose Noheda <jose.noheda@...> wrote:
Beans in Spring are singleton by default unless you define them declaring other scope. You don't need the factory-method. This would do it:

<bean id="singleton" class="example.LegacySingleton " />

You can use the Spring creator (in DWR) then and your beans would be singletons.

On 4/10/07, Ahmed Hashim <eng.hashim@...> wrote:
Hi,
In one of my messages in the users mail list, I asked about how to create a singleton class in DWR. Joe kindly refered to this page http://getahead.org/dwr/server/dwrxml/creators/scripted
It was a good solution but I didn't like to use any extra jar from apache.
I found an easy way in spring for declaring singleton beans

<bean id="singleton" class="example.LegacySingleton " factory-method="getInstance" />

Today, I went through DWR trying to implement the same thing to be used in my project

First I got the DWR source and added a new Creator for singleton

in the dwr.xml I added this declaration
<creator id="singleton" class=" org.directwebremoting.create.SingletonCreator" />

The class implementation is attached.

After that I made a simple singleton class "UserService" attached

The definition in the dwr.xml will be easy and clear

<create creator="singleton" javascript="userServiceSingleton">
          <param name="class" value="org.egjug.dwr.UserService" />
          <param name="factoryMethod" value="getInstance" />
      </create>

The complete project is attached.

I will add this simple howto to my blog later on.



--
Ahmed Hashim | EGJUG Leader | http://egjug.org | http://egjug.org/hashimblog/ |SCJP, SCWCD |hashim@egjug.org | +20103836920

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...






--
Ahmed Hashim | EGJUG Leader | http://egjug.org | http://egjug.org/hashimblog/ |SCJP, SCWCD |hashim@ egjug.org | +20103836920

Re: [dwr-user] Singleton Creator

by mehdiNux :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

 hi,
   I found your method very interesting but you did not mention how to add the tag "creator". For the readers: it takes place between tag "init".
   I also have a question it is  possible that  DWR share the same instance with a bean?.
   For example I create an instance of a class with DWR and I want to access it by a bean declared on another page jsp.
thx.

MehdiNux

Re: [dwr-user] Singleton Creator

by David Marginian-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Yes, creators can specify a scope attirbute.

See the DWR docs:
http://getahead.org/dwr/server/dwrxml/creators

mehdiNux wrote:

>  hi,
>    I found your method very interesting but you did not mention how to add
> the tag "creator". For the readers: it takes place between tag "init".
>    I also have a question it is  possible that  DWR share the same instance
> with a bean?.
>    For example I create an instance of a class with DWR and I want to access
> it by a bean declared on another page jsp.
> thx.
>
> MehdiNux
>  


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@...
For additional commands, e-mail: dev-help@...


Re: [dwr-user] Singleton Creator

by mehdiNux :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

yes I know but the scope share session juste with other call of DWRfunction ca .
when I declare a bean as <jsp:useBean id="MyBean" scope="session " class="Myclass"> it creates another instance of Myclass even if I put a scope application.
in other words when I declare an instance regardless of the scope with DWR , it ll be visible just in the DWR


David Marginian-2 wrote:
Yes, creators can specify a scope attirbute.

See the DWR docs:
http://getahead.org/dwr/server/dwrxml/creators

mehdiNux wrote:
>  hi,
>    I found your method very interesting but you did not mention how to add
> the tag "creator". For the readers: it takes place between tag "init".
>    I also have a question it is  possible that  DWR share the same instance
> with a bean?.
>    For example I create an instance of a class with DWR and I want to access
> it by a bean declared on another page jsp.
> thx.
>
> MehdiNux
>  


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@dwr.dev.java.net
For additional commands, e-mail: dev-help@dwr.dev.java.net

Re: [dwr-user] Singleton Creator

by David Marginian-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Ok, I misunderstood your first response.

You would like your jsp:useBean tag to locate the DWR created instance
in the session (and not create a new instance).  Is that correct?  Sure
this could be done.  DWR does keep the session scoped bean in the
session.  The problem you are having is that the key that DWR uses is
not "MyBean".  I think (I am not sure) that DWR keys the bean based on
the javascript attribute on the create element specified in your
configuration.

So try something like:
jsp:useBean id="whatever your javascript attribute is on your creator"

If that doesn't give you what you are looking for than I am wrong and
you can debug the session to find the correct key to use.

mehdiNux wrote:

> yes I know but the scope share session juste with other call of DWRfunction
> ca .
> when I declare a bean as <jsp:useBean id="MyBean" scope="session "
> class="Myclass"> it creates another instance of Myclass even if I put a
> scope application.
> in other words when I declare an instance regardless of the scope with DWR ,
> it ll be visible just in the DWR
>
>
>
> David Marginian-2 wrote:
>  
>> Yes, creators can specify a scope attirbute.
>>
>> See the DWR docs:
>> http://getahead.org/dwr/server/dwrxml/creators
>>
>> mehdiNux wrote:
>>    
>>>  hi,
>>>    I found your method very interesting but you did not mention how to
>>> add
>>> the tag "creator". For the readers: it takes place between tag "init".
>>>    I also have a question it is  possible that  DWR share the same
>>> instance
>>> with a bean?.
>>>    For example I create an instance of a class with DWR and I want to
>>> access
>>> it by a bean declared on another page jsp.
>>> thx.
>>>
>>> MehdiNux
>>>  
>>>      
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@...
>> For additional commands, e-mail: dev-help@...
>>
>>
>>
>>    
>
>  


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@...
For additional commands, e-mail: dev-help@...


Re: [dwr-user] Singleton Creator

by mehdiNux :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

thank you very much  David Marginian-2 ,it works very well it's what I needed . I did not know that the id is so important lol.
sorry for my bad English lol.
thx
MehdiNux
David Marginian-2 wrote:
Ok, I misunderstood your first response.

You would like your jsp:useBean tag to locate the DWR created instance
in the session (and not create a new instance).  Is that correct?  Sure
this could be done.  DWR does keep the session scoped bean in the
session.  The problem you are having is that the key that DWR uses is
not "MyBean".  I think (I am not sure) that DWR keys the bean based on
the javascript attribute on the create element specified in your
configuration.

So try something like:
jsp:useBean id="whatever your javascript attribute is on your creator"

If that doesn't give you what you are looking for than I am wrong and
you can debug the session to find the correct key to use.

mehdiNux wrote:
> yes I know but the scope share session juste with other call of DWRfunction
> ca .
> when I declare a bean as <jsp:useBean id="MyBean" scope="session "
> class="Myclass"> it creates another instance of Myclass even if I put a
> scope application.
> in other words when I declare an instance regardless of the scope with DWR ,
> it ll be visible just in the DWR
>
>
>
> David Marginian-2 wrote:
>  
>> Yes, creators can specify a scope attirbute.
>>
>> See the DWR docs:
>> http://getahead.org/dwr/server/dwrxml/creators
>>
>> mehdiNux wrote:
>>    
>>>  hi,
>>>    I found your method very interesting but you did not mention how to
>>> add
>>> the tag "creator". For the readers: it takes place between tag "init".
>>>    I also have a question it is  possible that  DWR share the same
>>> instance
>>> with a bean?.
>>>    For example I create an instance of a class with DWR and I want to
>>> access
>>> it by a bean declared on another page jsp.
>>> thx.
>>>
>>> MehdiNux
>>>  
>>>      
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@dwr.dev.java.net
>> For additional commands, e-mail: dev-help@dwr.dev.java.net
>>
>>
>>
>>    
>
>  


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@dwr.dev.java.net
For additional commands, e-mail: dev-help@dwr.dev.java.net

Re: [dwr-user] Singleton Creator

by David Marginian-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

No problem glad it is working for you.

mehdiNux wrote:

> thank you very much  David Marginian-2 ,it works very well it's what I needed
> :jumping:. I did not know that the id is so important lol.
> sorry for my bad English lol:-D.
> thx
> MehdiNux
>
> David Marginian-2 wrote:
>  
>> Ok, I misunderstood your first response.
>>
>> You would like your jsp:useBean tag to locate the DWR created instance
>> in the session (and not create a new instance).  Is that correct?  Sure
>> this could be done.  DWR does keep the session scoped bean in the
>> session.  The problem you are having is that the key that DWR uses is
>> not "MyBean".  I think (I am not sure) that DWR keys the bean based on
>> the javascript attribute on the create element specified in your
>> configuration.
>>
>> So try something like:
>> jsp:useBean id="whatever your javascript attribute is on your creator"
>>
>> If that doesn't give you what you are looking for than I am wrong and
>> you can debug the session to find the correct key to use.
>>
>> mehdiNux wrote:
>>    
>>> yes I know but the scope share session juste with other call of
>>> DWRfunction
>>> ca .
>>> when I declare a bean as <jsp:useBean id="MyBean" scope="session "
>>> class="Myclass"> it creates another instance of Myclass even if I put a
>>> scope application.
>>> in other words when I declare an instance regardless of the scope with
>>> DWR ,
>>> it ll be visible just in the DWR
>>>
>>>
>>>
>>> David Marginian-2 wrote:
>>>  
>>>      
>>>> Yes, creators can specify a scope attirbute.
>>>>
>>>> See the DWR docs:
>>>> http://getahead.org/dwr/server/dwrxml/creators
>>>>
>>>> mehdiNux wrote:
>>>>    
>>>>        
>>>>>  hi,
>>>>>    I found your method very interesting but you did not mention how to
>>>>> add
>>>>> the tag "creator". For the readers: it takes place between tag "init".
>>>>>    I also have a question it is  possible that  DWR share the same
>>>>> instance
>>>>> with a bean?.
>>>>>    For example I create an instance of a class with DWR and I want to
>>>>> access
>>>>> it by a bean declared on another page jsp.
>>>>> thx.
>>>>>
>>>>> MehdiNux
>>>>>  
>>>>>      
>>>>>          
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: dev-unsubscribe@...
>>>> For additional commands, e-mail: dev-help@...
>>>>
>>>>
>>>>
>>>>    
>>>>        
>>>  
>>>      
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@...
>> For additional commands, e-mail: dev-help@...
>>
>>
>>
>>    
>
>  


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@...
For additional commands, e-mail: dev-help@...