El Lun 09 May 2005 18:01, Viktor Szathmary escribi�:
> I'm ok with injecting the service-id from the constructor, but how
> does hivemind help in this? Are you saying I need to copy-paste it,
> as below? That's not very cool :)
>
> <service-point id="MyService" interface="com.example.MyServiceI">
> <invoke-factory>
> <construct class="com.example.MyService">
> <string>com.example.MyService</string>
> </construct>
> </invoke-factory>
> </service-point>
You can do just:
<service-point id="MyService" interface="com.example.MyServiceI">
<invoke-factory>
<construct class="com.example.MyService">
<service-id/>
</construct>
</invoke-factory>
</service-point>
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>
Or better yet, if you're using auto-wiring and your service implementation
class has a setServiceId(String) method, then HiveMind will automatically
invoke it, with the service-id value set on the parameter, during service
initialization, and this is quite cool, isn't it? :-)
> The reason for passing around the proxy instead of the actual instance
> is that these objects get serialized and need to reconnect to the
> appropriate service. This is what the the proxy does automatically,
> but I'm ok with resolving it myself if there's no other way (but
> that's also not quite as cool :)
In the past when I had to serialize services (and there wasn't native support
for this on HiveMind) I just added a writeReplace() method on the services
base class, and on the services base interface so BuilderFactory adds it to
the proxy, this method just returned a POJO containing the service-id (which
was injected with auto-wiring) and with a readResolve() method that, upon
deserialization, returned the real service which it looked up in the
registry.
That was enough to serialize/deserialize a service instance.
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.
Hope this helps...
>
> regards,
> viktor
>
> On 5/9/05, Pablo Lalloni <[EMAIL PROTECTED]> wrote:
> > El Lun 09 May 2005 17:01, Viktor Szathmary escribi�:
> > > hi,
> > >
> > > how can a hivemind-managed object refer to it's "real self"? for
> > > example, if I need to know the service ID, or want to be able to pass
> > > the proxied instance from the service itself to another object...
> >
> > For knowing the service-id just use a constructor parameter or make your
> > service implementation class implement a setServiceId(String id), then
> > hivemind can inject it.
> >
> > For passing around the proxy... your really shouln't be needing to do
> > such a thing... how come? :-)
> >
> > > btw, i have briefly tried beta-1 (instead of alpha-3), and it seems
> > > service serialization broke - it keeps complaining about "instance not
> > > created in this VM".. since i didnt have time to focus on this, i just
> > > rolled back to alpha-3...
> >
> > Maybe you aren't calling registry.setupThread() before using
> > deserialization on a given thread?
> >
> > --
> > Pablo I. Lalloni <[EMAIL PROTECTED]>
> > Tel�fono +54 (11) 4347-3177
> > Proyecto Pampa
> > Direcci�n Inform�tica Tributaria
> > AFIP
> >
> > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > Nudists are people who wear one-button suits.
--
Pablo I. Lalloni <[EMAIL PROTECTED]>
Tel�fono +54 (11) 4347-3177
Proyecto Pampa
Direcci�n Inform�tica Tributaria
AFIP
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To be a kind of moral Unix, he touched the hem of Nature's shift.
-- Shelley
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]