title: When to use ServiceTracker vs ServiceReference
body: <p>I am just starting with OSGi programming and have come across two ways to listener for services being activated.</p>
  
  <p>The first way, from an EclipseRCP book, uses ServiceReference:</p>
  
  <pre><code>String filter="(objectclass="+IModelCreator.class.getName()+")";
  context.addServiceListener(this, filter);
  modelCreators = Collections.synchronizedMap(
      new HashMap&lt;ModelID, List&lt;IModelCreator&gt;&gt;());
  ServiceReference references[] = context.getServiceReferences(null, filter);
  if(references==null) return;
  for(int i=0;i&lt;references.length;++i) {
      this.serviceChanged(new ServiceEvent(ServiceEvent.REGISTERED,
          references[i]));
  }
  </code></pre>
  
  <p>The second, from internet examples, uses ServiceTracker:</p>
  
  <pre><code>ServiceTracker logReaderTracker = new ServiceTracker(context,
                  org.osgi.service.log.LogReaderService.class.getName(), null);
  logReaderTracker.open();
  Object[] readers = logReaderTracker.getServices();
  if (readers != null) {
          for (int i = 0; i &lt; readers.length; i++) {
          LogReaderService lrs = (LogReaderService) readers[i];
          m_readers.add(lrs);
          lrs.addLogListener(m_logger);
      }
  }
  logReaderTracker.close();
  </code></pre>
  
  <p>Which one of these is the correct and/or best way of holding a register of all the services that implement a given Interface? Is there another way of accomplishing this? Why does there seem to be two ways of doing the same thing?</p>