[ 
https://issues.apache.org/jira/browse/SLING-4026?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14349154#comment-14349154
 ] 

Nicolas commented on SLING-4026:
--------------------------------

We have currently the same problem on our production code when we are 
restarting our server. Sometimes the resource can be adapted, sometimes not. 
What do you propose as a workaround until the problem is fixed?
* A: {code}
@Service
@Component(immediate = true)
public class ExampleComponent {

    @Reference(target = 
"(models.adapter.implementationClass=com.example.ExampleComponent)")
    private AdapterFactory adaptorFactory;

    @Activate
    public void activate(ComponentContext context) {
        Resource resource = ....
        SlingModelExample example = adaptorFactory.getAdapter(resource, 
SlingModelExample.class);
    }

}
{code} 
* B: 
{code}
@Service
@Component(immediate = true)
@Properties({
    @Property(name = "event.topics", value = {
        SlingConstants.TOPIC_ADAPTER_FACTORY_ADDED
    }, propertyPrivate = true),
    @Property(name = EventConstants.EVENT_FILTER, value = 
"(adapters=com.example.ExampleComponent)", propertyPrivate = true)
})
public class ExampleComponent implements EventHandler {

    @Override
    public void handleEvent(final Event event) {
        Resource resource = ....
        SlingModelExample example = resource.adaptTo(SlingModelExample.class);
    }

}
{code} 

> Adapter Factory Race Condition
> ------------------------------
>
>                 Key: SLING-4026
>                 URL: https://issues.apache.org/jira/browse/SLING-4026
>             Project: Sling
>          Issue Type: Bug
>          Components: Extensions
>    Affects Versions: Adapter 2.1.2
>            Reporter: JBodkin
>              Labels: models
>         Attachments: racer.zip
>
>
> During initialization of a bundle, it is possible to encounter a race 
> condition in which the BundleTrackerCustomizer::addingBundle(Bundle bundle, 
> BundleEvent event) is triggered after the bundle has begun initialization of 
> a immediate component.
> {code:java}
> @Component(immediate = true)
> @Service
> public class ExampleImpl {
>     @Activate
>     public void activate(ComponentContext context) {
>         Resource resource = ....
>         // Race condition possible here... Could be executed before the 
> BundleTracker (ModelPackageBundleListener)
>         SlingModelExample example = resource.adaptTo(SlingModelExample);
>     }
> }
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to