Multiple Interface Implementations - AEM/CQ - OSGi
<p>There is an service interface <code>HelloService</code>, this is implemented by 2 Service implementations</p>

<p><strong>HelloService Interface</strong></p>

<pre><code>public interface HelloService {
    public String getRepositoryName();
}
</code></pre>

<p><strong>HelloServiceImpl1 implementation</strong></p>

<pre><code>@Service
@Component(metatype = false)
public class HelloServiceImpl1 implements HelloService {

    @Reference
    private SlingRepository repository;

    public String getRepositoryName() {
        return repository.getDescriptor(Repository.REP_NAME_DESC);
    }
}
</code></pre>

<p><strong>HelloServiceimpl2 implementation</strong></p>

<pre><code>@Service
@Component(metatype = false)
public class HelloServiceImpl2 implements HelloService {

    public String getRepositoryName() {
        return "Response from HelloServiceImpl2";
    }
}
</code></pre>

<p>Now to use the service we use </p>

<pre><code>@Reference
HelloService helloService;
</code></pre>

<p>Inside required method, call is made as</p>

<pre><code>helloService.getRepositoryName();
</code></pre>

<p>I am getting response always from <code>HelloServiceImpl1</code>. Checked another example in AEM APIs, <code>SlingRepository</code> is extended by <code>AbstractSlingRepository</code> and <code>AbstractSlingRepository2</code>, how is the implementation picked internally, as while consuming we specify only <code>@Reference SlingRepository repository;</code></p>

<p>How is this handled in AEM OSGi? </p>

<hr>

<p><strong>Update based on response</strong></p>

<p>Checked on the syntax for this, following are observations</p>

<p><em>For using service ranking</em>, use following with Service Implementation</p>

<pre><code>@Properties({
    @Property(name = Constants.SERVICE_RANKING, intValue = 100)
})
</code></pre>

<p>For this no change in consumption, higher service ranking implementation is picked up, control is with provider</p>

<pre><code>@Reference
HelloService helloService;
</code></pre>

<p><em>For using target filter</em>, use following annotation to specify property</p>

<pre><code>@Properties({
   @Property(name="type", value="Custom")
})
</code></pre>

<p>While consuming based on filter, specify target, control is with consumer</p>

<pre><code> @Reference (target="(type=Custom)")
 HelloService helloService;
</code></pre>

<p>If both service ranking and filter are used, filter is taking precedence.</p>