There are a few ways to deal with discovered services but here is one that uses the OSGi framework.
Please take a look at the modified Activator.start method of the o.e.e.examples.remoteservices.quotes.consumer bundle . Replace the start method with this code and then connect to the
yazafatutu.com server.
The code will extract all services in the framework every 10 seconds and will print a list of all services and a list with remote services.
It extracts the services from the framework with Activator.getContext().getAllServiceReferences(null, null);
the null, null can be replaced by your specific class and filter requirements.
It then extracts the actual service from the service reference (Activator.getContext().getService(serviceReference)) and prints the class name.
The next loop only prints services with the property "service.imported" not equal to null. This indicates that the service is a remote property.
Is it useful to know if the service is a remote service? In one way, yes. You have to adapt your programming style to be "remote aware" and realize that calls can be delayed.
On the other hand, there is no difference in remote and local services from an OSGi point of view. With the discovery in place, services are "just there" to be used.
Best regards,
Wim
public void start(BundleContext bundleContext) throws Exception {
Activator.context = bundleContext;
Runnable runner = new Runnable() {
public void run() {
try {
ServiceReference[] services = Activator.getContext().getAllServiceReferences(null, null);
System.out.println("All Services");
System.out.println("------------");
for (ServiceReference serviceReference : services) {
Object obj = Activator.getContext().getService(serviceReference);
System.out.println(obj.getClass().getSimpleName());
}
services = Activator.getContext().getAllServiceReferences(null, null);
System.out.println();
System.out.println("Remote Services");
System.out.println("------------");
for (ServiceReference serviceReference : services) {
if (serviceReference.getProperty("service.imported") != null) {
Object obj = Activator.getContext().getService(serviceReference);
System.out.println(obj.getClass().getSimpleName());
}
}
} catch (InvalidSyntaxException e) {
e.printStackTrace();
}
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
}
new Thread(this).start();
}
};
new Thread(runner).start();
}
On Tue, Aug 17, 2010 at 11:27 AM, Nicholas Loulloudes
<loulloudes.n@xxxxxxxxxxxx> wrote:
Hi Wim,
The listener in the consumer example you have provided me, as far as i
understand tracks for services changes and based on
the event (i.e Registration) it shows some service details. In my case,
how can i first get a list of all the available services?
Thanks.
Wim Jongman wrote:
Hi,
The service will already be available/published as a local
service. Why not get a list of all services and display that to the
user. You can also filter all remote services by specifying the remote
service property in the filter.
Look at the listener code in [1] to see an approach on
publications.
Best regards,
Wim
On Tue, Aug 17, 2010 at 8:01 AM, Markus
Alexander Kuppe
<ecf-dev_eclipse.org@lemmster.de>
wrote:
On 08/17/2010 07:58 AM, Nicholas Loulloudes wrote:
> Hi Markus,
>
> I am experimenting with the Zookeeper code rom Wim's tutorial, and
one
> of the things i would like to do is to obtain a list of the
services
> provided by a host.
> I tried to use the IDiscoveryLocator interface as suggested in the
> Zoodiscovery wiki, but when calling the getServices() method, an
empty
> array is returned.
>
> Could the discovery part in OSGi assist me in getting a list of the
> published services? If yes, could you direct me on how to achieve
this?
Question is, what is supposed to happen with the list of services once
retrieved. Do you want your distribution provider to create endpoints
and connect to each of to invoke services? Or do you just want to
display the results and e.g. let a user choose a service manually?
--
________________________________________________________
Nicholas Loulloudes
PhD Candidate,
High Performance Computing Systems Laboratory (HPCL)
University of Cyprus,
Nicosia, Cyprus
Tel: +357-22892663
Email: loulloudes.n[at]
cs.ucy.ac.cy
_______________________________________________
ecf-dev mailing list
ecf-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/ecf-dev