On Sun, 2004-03-07 at 20:06, Stephen McConnell wrote:
> Scott Brickner wrote:
> 
> > I think that'll probably work. It feels a little ugly, but hey - right
> > now I need a working server, not a pretty one.
> 
> :-)
> 
> The elegant solution is for a component to declare itself part of a 
> family, and the startup sequence if invoked only after all family 
> members are initialized.  There was something along these lines in 
> Merlin 1.0 but it never escalated.

Well, I was thinking of something along these lines...

/**
 * @avalon.component name='directoryDispatcher' lifestyle='singleton'
 * @avalon.service type='Coordinator'
 */
public class CoordinatorImpl implements Coordinator, Configurable {
    private Set requirements = new HashSet();
    private Object lock = new Object();
    private boolean ready;
    private long timeout;

    public void configure( Configuration configuration) throws
ConfigurationException {
        timeout = configuration.getChild(
"time-limit").getValueAsLong();
        Configuration[] requires = configuration.getChildren(
"require");
        for ( int i = 0; i < requires.length; i++) {
            requirements.add( requires[ i].getAttribute( "name"));
        }
    }

    public void coordinate( String name) {
        if ( ready) return;
        synchronized ( lock) {
            if ( !requirements.remove( name)) throw new
IllegalStateException( "already taken: " + name);
            if ( requirements.isEmpty()) {
                ready = true;
                lock.notifyAll();
                return;
            }
            while ( !ready) {
                try {
                    lock.wait( timeout);
                } catch ( InterruptedException e) {
                }
            }
        }
    }
}



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

Reply via email to