Hello Abdelgadir,

First of all, you're using a version of the dependency manager that has been 
extended by Peter Neubauer (and his team), and I still need to merge those 
changes with the current implementation in Felix, but that does not matter 
much with respect to your comments.

On Tuesday 04 April 2006 16:03, Abdelgadir Ibrahim wrote:

> I have a question regarding this dependency manager. please see my comments
> in the code snipet below:
>
> /** the remove(...) method in class DependentServiceControllerImpl */
>
> public DependentServiceController remove( Dependency dependency )
>     {
>         synchronized ( m_dependencies )
>         {
>             m_dependencies.remove( dependency );
>         }
>         logDependencyRemoved( dependency );
>
>         if ( getState() == ServiceMonitor.TRACKING_OPTIONAL )
>         {
>             // if we're tracking optional dependencies, then any
>             // dependency that is removed can be stopped without
>             // causing state changes
>
>             // (my comments). as I understand:
>             // if we are tracking an optional dependency this means that
>             // 1. all required depndencies are already satisfied (since we
>             //    consider optional ones only after we satisfy the required

Correct.

> ?!) // 2. this service is already instantiated and registered //    i.e.
> active.

Yes.

>             // 3. the removed dependency could be either optional or
> required, //    if optional we just remove it with no side effects. if it
> is //    required and we remove it, then we will need to deactivate this
>             //    service
>             // (Question) why didn't we check for required and deactivate,
> is //  this a bug ?!

Good question. The remove(dependency) method that we're talking about here can 
be invoked by you if you want to remove a dependency from a service. This 
means you're no longer associating the dependency with this service: in other 
words, you no longer care for this dependency.

For example, say we have a service S with two required dependencies R1 and R2, 
and an optional dependency O1. Let's assume all dependencies are actually 
available in the framework, so the service state is "tracking optional". You 
now invoke remove(R1) because you no longer care for this dependency. So S 
now has one required dependency R2 and one optional dependency O1.

This invocation in itself can never cause the service state to change from 
"tracking optional" to "waiting for required". R1, R2 and O1 are still 
available, we just don't care about R1 anymore.

You're probably confused with the method that is invoked when a dependency 
becomes unavailable. When this occurs, the dependencyUnavailable(dependency) 
method is invoked. This method actually performs the check you suggest:

    public void dependencyUnavailable(Dependency dependency) {
        if (dependency.isRequired()) {
            if (m_state == TRACKING_OPTIONAL) {
                if (!allRequiredDependenciesAvailable()) {
                    deactivateService();
                }
            }
        }
        else {
            // optional dependency
        }
        if (m_state == TRACKING_OPTIONAL) {
            updateInstance(dependency);
        }
    }


>
>             dependency.stop( this );
>             // (my comments) shouldn't we check that all required
> dependencies // are available and deactivate the service if not so ?!. }
>
>         else if ( getState() == ServiceMonitor.WAITING_FOR_REQUIRED )
>         {
>             // if we're waiting for required dependencies, then
>             // we only need to stop tracking the dependency if it
>             // too is required; this might trigger a state change
>
>             // (my comments). as I understand:
>             // if we are waiting for a required dependency, that means
>             // 1. this service is not active (not started)
>             //    because some of its required depndencies are not yet

Yes.

> satisfied // 2. the removed dependency can be either required or optional.
> //    if it is optional we dont need to do any thing other than just //   
> remove it. if it is required we similarly dont need to do //    anything
> other than just remove it since we are already //    inactive (see 1.
> above)
>             //(Question) why did we check for required availavility and
> activate,
>             //is this a bug ?!

Similar to my explanation above.

>             dependency.stop( this );
>             if ( allRequiredDependenciesAvailable() )//(my comments) is
> this //needed here? {
>                 activateService();
>             }

But! Contrary to my comments in the code I actually do not check if the 
dependency is required, so that is an issue, because if it is an optional 
dependency and we're still waiting for the required dependencies, then this 
optional dependency will not have been started yet. That means we should not 
stop it.

The rest of the code is correct again, because after we remove a dependency 
when we're still waiting for the required dependencies, removing such a 
dependency might actually trigger a state change to tracking optional.

An example, service S has dependencies R1 and R2 and O1 again. Let's assume R1 
is unavailable, R2 and O1 are available. So S is still waiting for required 
dependencies (since R1 is unavailable).

If we now invoke remove(R1) then S no longer cares for R1 and suddenly all its 
required dependencies (namely R2) are available and it can start tracking 
optional dependencies.

I hope this clarifies things a bit!

Greetings, Marcel

Reply via email to