Hi,

iPOJO does not synchronized those methods to avoid potential deadlocks. So
all callbacks are called without any lock. So, the component must use
'synchronized'.

Regards,

Clement


On 07.06.11 10:53, "Gay David (Annecy)" <[email protected]> wrote:

>Hi all,
>
>Have a question about iPojo. I made a simple component like that :
>
>@Component( name="My.Manager" )
>@Instantiate
>public class MyManagerImpl {
>
>         private boolean                     register;
>         private Set<ServiceReference>       myservices;
>
>    public MyManagerImpl() {
>        register = false;
>        apis = new HashSet<ServiceReference>();
>        adapters = new HashMap<Long,ComponentInstance>();
>    }
>
>    @Validate
>    private void validate() {
>        for( ServiceReference ref : myservices ) {
>            install( ref );
>        }
>        register = true;
>    }
>
>    @Invalidate
>    private void invalidate() {
>        for( ServiceReference ref : myservices ) {
>            uninstall( ref );
>        }
>        register = false;
>    }
>
>    @Bind( id="services", aggregate=true, optional=true )
>         private void bindMyService( MyService srv, ServiceReference ref
>) {
>        myservices.add( ref );
>        if( register ) {
>            install( ref );
>        }
>    }
>
>    @Unbind( id="services" )
>    private void unbindMyService( MyService srv, ServiceReference ref ) {
>        if( myservices.remove(ref) && register ) {
>            uninstall( ref );
>        }
>    }
>
>    @Modified( id="services" )
>    private void modifiedMyService( MyService srv, ServiceReference ref )
>{
>        if( register ) {
>            uninstall( ref );
>            install( ref );
>        }
>    }
>
>         private void install( ServiceReference ref ) {
>                   // bla bla ...
>         }
>
>         private void uninstall( ServiceReference ref ) {
>                   // bla bla ...
>         }
>}
>
>At runtime, sometimes I have an exception :
>
>2011-06-06 16:21:37,222 GMT+0200 - [Thread-3] ERROR (test.?:?) - [ERROR]
>My.Manager : [My.Manager-0] The callback method validate has thrown an
>exception : null
>java.util.ConcurrentModificationException
>                at
>java.util.HashMap$HashIterator.nextEntry(HashMap.java:793)
>                at java.util.HashMap$KeyIterator.next(HashMap.java:828)
>                at test.MyManagerImpl.__validate(RestManagerImpl.java:78)
>                at test.MyManagerImpl.validate(RestManagerImpl.java)
>                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
>Method)
>                at
>sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:
>39)
>                at
>sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorIm
>pl.java:25)
>                at java.lang.reflect.Method.invoke(Method.java:597)
>                at
>org.apache.felix.ipojo.util.Callback.call(Callback.java:235)
>                at
>org.apache.felix.ipojo.util.Callback.call(Callback.java:191)
>
>For what I understand, it means that the iteration over the collection in
>the validate() method is modified by another thread.
>Is it possible that bind/unbind/validate/unvalidate callback method could
>be call concurrently ?
>
>I don't find it clearly in the ipojo doc, but I understand that iPojo
>take care of that.
>I'm wrong ? Do I have to synchronize myself ?
>
>BTW : I'm currently using iPojo 1.6.4
>
>Regards
>David
>
>


Reply via email to