On Wednesday 24 December 2003 07:33, Marco Tedone wrote:
> ----- Original Message -----
> From: "Niclas Hedhman" <[EMAIL PROTECTED]>
> > Furthermore, I think that "ohh, the service I need is now available,
> > let's use it." is intrinsic to the LifeCycle of all (but the most simple)
> > components.
>
> Could you make an example?

Almost all systems are based on some form of lookup of service, whether it be 
Avalon ServiceManager, JNDI, JDBC connects, whatever.

So the code would be;

  SomeService s = (SomeService) provider.lookup( whatever );
  s.useService();

which makes a lot of assumptions about what is available. This is the most 
important lesson from learning Jini.

In truly distributed and robust environments, a client doesn't do lookups at 
all. It registers itself as "interested" in a service and then gets 
notifications of when this service is available. So the above could look 
like;


provider.addInterestListener( whatever, this );
  :
  :
if( m_Available )
{
   m_Service.useService();
}
else
{
   // some necessary backup...
}

public void serviceAvailable( InterestEvent event )
{
    if( whatever.equals( event.getLookupRole() )
    {
        m_Service = event.getService();
        m_Available = true;
    }
}

public void serviceUnavailable( InterestEvent event )
{
    if( whatever.equals( event.getLookupRole() )
    {
        m_Service = null;
        m_Available = false;
    }
}


There is of course a lot more to it, and better names can be used, and 100 
other implementation details.

Most programmers would call the above an overkill for most applications, since 
they "know" the execution will be local. That may not be true later.
But please do come over to [EMAIL PROTECTED] with these kind of discussion. It 
belongs more there, than in the [EMAIL PROTECTED]

Cheers
Niclas

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

Reply via email to