spot7.org logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories

Getting a specific implementation from Felix


Your question is confusing since you mix terms for services and bundles. A bundle is an installable unit which contains code. That code can register and consume services. Services are object which, typically, implement some interface which is shared between the bundle providing the service and the bundles consuming the services.

So the first order of business is to make sure the service interface's package is exported by some bundle and imported by all the bundles which plan to participate in providing and consuming the service. This is necessary to ensure type safety. That is, the consuming bundles can safely cast the service object to the expected type of the service.

Once that is done, as you observer, there can be multiple providers of a service. When a provider registers a service, they can specify some metadata about the service in the form of key/value properties. Your example shows this in the Identifier property. When a consumer looks up a service, a filter string can be specified which can specify information to be checked against a service' metadata to select from among multiple provided services.

public class MyServiceConsumer
implements BundleActivator {

@Override
public void start(BundleContext context) throws
Exception {
    System.out.println("Looking for
ImplementationA");

    ServiceReference<MyInterface>[] refs =
   
context.getServiceReferences(MyInterface.class,
"(Identifier=ImplementationA)");
    MyInterface service =
context.getService(refs[0]);
}

}

The above is terrible code; don't actually use it. It does not handle there being no service when the consumer bundle is activated (refs == null), nor does is it prepared for the service to go away. I strongly recommend you use OSGi Declarative Services when writing bundles. It makes service use and dealing with the dynamic super simple.

@Component
public class MyServiceConsumer {
MyInterface service;

@Reference(target="(Identifier=ImplementationA)")
private void bindService(MyInterface s) {
    service = s;
}

@Activate
private activate() {
    // do work
}

@Deactivate
private deactivate() {
    // do work
}

}

This is a component which will only be instantiated when a matching service is present. It will be called at bindService to inject the service instance, the activate will be called to enable to component to do it work. If the injected service goes away, the component will be called at deactivate and then discarded. If later another matching service comes along, a new instance of the component will be activated.

See http://enroute.osgi.org/ for a tutorial on OSGi app dev.


Categories : Java

Related to : Getting a specific implementation from Felix
Finding Paths with Neo4j Cypher Below a Given Length, but Excluding Those with an Nodes with a Specific Property set to a Specific Value
I think this does what I want: MATCH path=(topic: attribute)-[rel:describedBy|influences]-(node: attribute) WHERE id(topic) IN [128204] RETURN DISTINCT extract(r IN rels(path) | r) UNION MATCH path=(topic: attribute)-[rel1: describedBy|influences]-(intermediate: attribute)-[rel2: describedBy|influences]-(node: attribute) WHERE id(topic) IN [128204] AND NOT intermediate.key in ['enrichment', 'clas

Categories : Neo4j
how to tar specific directories with specific names ( date month name )
Using gnu find you can do: find /var/tmp/all-results_dir -type f -newermt '2014-07-01' ! -newermt '2014-08-01' -exec tar -rzf /var/TAR/results_2014_Jul.tar.gz {} + -newermt '2014-07-01' ! -newermt '2014-08-01' will find all files modified in the month of July 2014. tar -rzf will append files in the archive. Script dotar.sh: #!/bin/bash find . -name 'f*' -newermt "2014-$1-01" ! -newerm

Categories : Linux
i want to open a specific file extension on my pc with a specific program
First associate a file type to your extension: assoc .abs=ABSFile Then set up an application to open that file type: ftype ABSFile="C:Path To Your AppYourExeName.exe" %1 %* For more information, see the MS TechNet documentation, or type assoc /? or ftype /? from a command prompt.

Categories : Windows
c# how to get files name into a specific folder which have a specific patter
Try this: foreach (string file in Directory.EnumerateFiles(folderPath, "*CustsExport*.xml")) { } Or your can use regex: Regex reg = new Regex(@".*CustsExport.*.xml",RegexOptions.IgnoreCase); var files = Directory.GetFiles(yourPath, "*.xml") .Where(path => reg.IsMatch(path)) .ToList();

Categories : C#
Implementation PubNub for VB.Net
PubNub VB.Net Quick Start You might consider using PubNub Simple HTTP REST API and here are a few links for using Visual Basic .NET with PubNub. Since we don't have an official VB.NET API you can find really easy to use options. HTTP Streaming over TCP with Telnet Example PubNub HTTP REST API

Categories : Vb.Net
Recently Add
Redirecting the output directory of 'mvn package' or 'mvn compile' command
No suitable constructor found for ProductoExtranjero
java Composite design pattern(Directory &File)
Java JTree's ui refresh after removing node from parent
First REST Spring application
How to cancel Indexing of a Solr document using Update Request Processor
PowerMock - Mock a Singleton with a Private Constructor
Calling a Postgres stored function SQL error
Where to store Morphlines Java custom command class?
Generic repository using map
How can I scroll a ScrolledComposited in Eclipse SWT Design view?
2 Frames/layout in 1 Activity
Writing a switch differently
Next button opens another activity when its reaches the array limit
Is EclipseLink MOXy capable of applying JSR-303 Bean Validation when unmarshalling XML to object?
Why my jdk can't work,and before the java_home, there is a space that is not from me
How to add List of objects in a Map
How to make notepad++ function like regular notepad in cmd?
Cell renderer and the lost focus
how can I implement iterable for LinkedList>
Disable Androids image-crunch in eclipse (run as) builds
java 8 lambda myMap.stream().count() != myMap.size() after merging myMap
Issue with Calendar calculation that spans 2 calendar years
JSF 2.0 Spring bean injection
Java Regex ReplaceAll with grouping
Getting any word and last word using sed
Clicking on link on JEditorPane throws IOException
printing out difference of two arrays
Spring Bean Alias in JavaConfig
Using Factory Method to Create Generics
© Copyright 2017 spot7.org Publishing Limited. All rights reserved.