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

Pierre De Rop commented on FELIX-4847:
--------------------------------------

And what about using some java constructs instead of a temporal service 
dependency for your use case ?
Indeed, you could use a CountDownLatch that could be used to wait for the 
Foobar service (synchronously).
something like:

{code}
public class FoobarIT {
    final CountDownLatch latch = new CountDownLatch(1);
        
    @Rule
    public TestRule testRule = new DependencyManagerTestRule() { protected 
Object getWrapped() { return FoobarIT.this; }};

    @Inject
    private BundleContext bundleContext;

    private Foobar foobar;

    @ServiceDependency(name = Foobar.PID)
    void bind(Foobar foobar) {
        this.foobar = foobar;
        latch.countDown();
    }

    @ServiceDependency
    private ConfigurationAdmin configurationAdmin;

    @ResourceDependency(filter = "(" + ResourceHandler.PATH + "=/META-INF/"
        + Foobar.PID + ".cfg)")
    private URL url;

    @Init
    Map<String, ?> init() throws IOException
    {
        Bundle bundle = this.bundleContext.getBundle();
        String location = bundle.getLocation();
        Configuration configuration = 
this.configurationAdmin.getConfiguration(Foobar.PID, location);
        Properties properties = new Properties();
        try (InputStream inputStream = this.url.openStream();)
        {
            properties.load(inputStream);
        }
        configuration.update((Dictionary) properties);
        return Collections.singletonMap(Foobar.PID + ".required", 
Boolean.FALSE);
    }


    @Test
    public void test() {
        latch.await(10000, TimeUnit.MILLISECONDS);
        this.foobar.blockUntilConfigured();
    }
}
{code}

making sense ?


> Allow TemporalServiceDependency to be optional
> ----------------------------------------------
>
>                 Key: FELIX-4847
>                 URL: https://issues.apache.org/jira/browse/FELIX-4847
>             Project: Felix
>          Issue Type: Wish
>          Components: Dependency Manager
>    Affects Versions: dependencymanager-3.2.0
>            Reporter: Tuomas Kiviaho
>         Attachments: TemporalServiceDependencyImpl.java, 
> dm.test.with.bndtools.tgz, dm.test.with.maven.tgz
>
>
> I wanted to use temporal service to wait for CM update thread to finish what 
> it's doing (because the spec doesn't have a non-parallel version). 
> Everything worked fine until JUnit test rule said that the component isn't 
> ready yet. I was merely checking that every required dependency was also 
> available and to my surprise the temporal service was marked unavailable 
> until the CM had completed what it was doing.
> 1) Shouldn't temporal service be always available externally via available 
> property and keep track on the actual state only internally? This approach 
> might not be backwards compatible.
> 2) Could temporal service be allowed to be marked as optional. This would 
> suit my use case, but it feels like a 'golden hammer' approach because it 
> alters component's state machine behavior a bit which in turn can be harmful 
> for other use cases. 
> As a workaround I'd have to differentiate the dependencies somehow from each 
> other, but I see that the 4.x has removed the dedicated interface that I was 
> thinking of relying upon to. 



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

Reply via email to