I went with the service-id injection and implementing a
readresolve/writereplace myself, just because i needed the service-id
anyway, and found it more natural to use "this" instead of getSelf() -
so I ended up with a service base class similar to this:

public abstract class AbstractFooService implements FooServiceI, Serializable {

        private String name;

        public String getName() {
                return name;
        }

        public void setName(String name) {
                this.name = name;
        }

        protected Object writeReplace() {
                return new ServiceRef(getName());
        }

        private static class ServiceRef implements Serializable {
                private final String name;

                public ServiceRef(String name) {
                        this.name = name;
                }

                protected Object readResolve() throws ObjectStreamException {
                        Object service = 
MyRegistry.getInstance().getService(name,
FooServiceI.class);
                        if (service == null) {
                                throw new InvalidObjectException("Unable to 
find in FDRegistry: " + name);
                        }
                        return service;
                }

        }
}

On 5/9/05, James Carman <[EMAIL PROTECTED]> wrote:
> Yes, basically it'd be a service that's dependent upon itself...
> 
> public class MyService implements MyServiceI
> {
>   private MyServiceI self;
> 
>   public void setSelf( MyServiceI self )
>   {
>     this.self = self;
>   }
> 
>   public Foo findObject()
>   {
>     return new Foo( self );
>   }
> }
> 
> -----Original Message-----
> From: Howard Lewis Ship [mailto:[EMAIL PROTECTED]
> Sent: Monday, May 09, 2005 7:00 PM
> To: [email protected]; Viktor Szathmary
> Subject: Re: referencing "self" in a service
> 
> BTW ... you can have HiveMind inject the service proxy into the service
> implementation, just like any other collaborating service.
> 
> On 5/9/05, Viktor Szathmary <[EMAIL PROTECTED]> wrote:
> > On 5/9/05, Pablo Lalloni <[EMAIL PROTECTED]> wrote:
> > >
> > > Or better:
> > >
> > >  <service-point id="MyService" interface="com.example.MyServiceI">
> > >         <invoke-factory>
> > >                 <construct class="com.example.MyService"
> service-id-property="aProperty"/>
> > >         </invoke-factory>
> > >  </service-point>
> > >
> >
> > thanks, injecting the service-id works well for me. (and it is cool :)
> >
> > > Now we have support natively in HiveMind 1.1 for serialization with
> > > a similar approach but you have to call registry.setupThread()
> > > before the functionality can be used on a given thread.
> >
> > seems like it worked fine without setupThread in alpha-2 (but not in
> > beta-1)... but I suspect the reason for this change was this: "Allow
> > for running with multiple Registries. (HLS) Fixes HIVEMIND-83"
> >
> > thanks,
> >  viktor
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
> 
> --
> Howard M. Lewis Ship
> Independent J2EE / Open-Source Java Consultant
> Creator, Jakarta Tapestry
> Creator, Jakarta HiveMind
> 
> Professional Tapestry training, mentoring, support
> and project work.  http://howardlewisship.com
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
>

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

Reply via email to