My favorites | Sign in
Project Logo
                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package com.extensiblejava.hello.client;

import com.extensiblejava.hello.service.HelloService;

import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import org.osgi.util.tracker.ServiceTracker;

public class HelloConsumer implements BundleActivator {

private ServiceTracker helloWorldTracker;
private HelloService helloService;

public void setService(HelloService helloService) {
this.helloService = helloService;
}

public void removeService() {
this.helloService = null;
}

public void start(BundleContext context) throws Exception {
helloWorldTracker = new ServiceTracker(context, HelloService.class.getName(), null);
helloWorldTracker.open();
HelloService hello = (HelloService) helloWorldTracker.getService();

if (hello == null) {
System.out.println("Hello service unavailable on HelloConsumer start");
} else {
System.out.println(hello.sayHello());
}
}

public void stop(BundleContext context) {
HelloService hello = (HelloService) helloWorldTracker.getService();
if (hello == null) {
System.out.println("Hello service unavailable on HelloConsumer stop");
} else {
System.out.println(hello.sayGoodbye());
}

helloWorldTracker.close();
}

}
Show details Hide details

Change log

r11 by pragkirk on Mar 18, 2008   Diff
Initial checkin.
Go to: 
Project members, sign in to write a code review

Older revisions

All revisions of this file

File info

Size: 1322 bytes, 46 lines

File properties

svn:executable
Hosted by Google Code