My favorites | Sign in
Project Logo
                
Changes to /trunk/osgi/HelloWorldSpec/client/src/com/extensiblejava/hello/client/HelloConsumer.java
r0 vs. r12   Edit
  Compare: vs.   Format:
Revision r12
Go to: 
Project members, sign in to write a code review
/trunk/osgi/HelloWorldSpec/client/src/com/extensiblejava/hello/client/HelloConsumer.java /trunk/osgi/HelloWorldSpec/client/src/com/extensiblejava/hello/client/HelloConsumer.java   r12
Properties
 svn:executable
  
Contents
  1 package com.extensiblejava.hello.client;
  2
  3 import com.extensiblejava.hello.service.HelloService;
  4
  5 import org.osgi.framework.BundleActivator;
  6 import org.osgi.framework.BundleContext;
  7 import org.osgi.framework.ServiceReference;
  8 import org.osgi.util.tracker.ServiceTracker;
  9
  10 public class HelloConsumer implements BundleActivator {
  11
  12 private ServiceTracker helloWorldTracker;
  13
  14 public void start(BundleContext context) throws Exception {
  15 helloWorldTracker = new ServiceTracker(context, HelloService.class.getName(), null);
  16 helloWorldTracker.open();
  17 HelloService hello = (HelloService) helloWorldTracker.getService();
  18
  19 if (hello == null) {
  20 System.out.println("Hello service unavailable on HelloConsumer start");
  21 } else {
  22 System.out.println(hello.sayHello());
  23 }
  24 }
  25
  26 public void stop(BundleContext context) {
  27 HelloService hello = (HelloService) helloWorldTracker.getService();
  28 if (hello == null) {
  29 System.out.println("Hello service unavailable on HelloConsumer stop");
  30 } else {
  31 System.out.println(hello.sayGoodbye());
  32 }
  33
  34 helloWorldTracker.close();
  35 }
  36
  37 /*public void setHelloService(HelloService hello) {
  38 this.hello = hello;
  39 }*/
  40
  41 }
Hosted by Google Code