public void removedService(ServiceReference reference, Object service) {
      ServiceRegistration registration = (ServiceRegistration) service;

      registration.unregister();
      context.ungetService(reference);

      logger.debug("service was unregistered");

      try {
        ((TCPServer) subscriber).suspend();
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
    public Object addingService(ServiceReference reference) {

      Object serviceObj = context.getService(reference);

      if (serviceObj instanceof RemotePublisherIF) {
        rpublisher = (RemotePublisherIF) serviceObj;
        logger.debug(
            "New RemotePublisherService found: "
                + reference.getProperty(PublisherIF.PUBLISHER_NAME));
      }

      if (serviceObj instanceof PublisherIF) {
        lpublisher = (PublisherIF) serviceObj;
        logger.debug(
            "New LocalPublisherService found:" + reference.getProperty(PublisherIF.PUBLISHER_NAME));
      }

      if (serviceObj instanceof DBManagerIF) {
        dbManager = (DBManagerIF) serviceObj;
        logger.debug(
            "New DBManagerService found: "
                + reference.getProperty(DBManagerIF.DB_TYPE)
                + ":"
                + reference.getProperty(DBManagerIF.DB_NAME));
      }

      // if the TCP Subscriber is just started, the object is initialized but if it has been
      // already up and running but the publisher has gone done and come back or a new publisher
      // has been detected, it only resubscribes with the publisher, preventing the connected
      // services
      // from being disconnected. Also, in case of a new publisher joining in, the clients already
      // subscribed
      // with other subscribers under certain topics, automatically get resubscribed with the new
      // publisher
      // without the change being noticed by the subscribed clients

      if (dbManager != null && rpublisher != null && lpublisher != null) {
        if (subscriber == null) {
          subscriber = new TCPServer(lpublisher, rpublisher, dbManager);
          // The Subscriber service registers the TCP server
          Properties props = new Properties();
          props.put(SubscriberIF.SUBSCRIBER_NAME, TCPServer.NAME);
          ServiceRegistration registration =
              context.registerService(SubscriberIF.class.getName(), subscriber, props);

          ((TCPServer) subscriber).start();

          return registration;
        } else {

          logger.debug("Resubscription");

          // TODO nimak - The server may not be suspended at this point. It doesn't cause any
          // problem right now,
          //				but might be something to check for proper behavior later on. Basically resuming the
          //				thread is not needed if the thread has not been suspended already
          ((TCPServer) subscriber).resume();
          try {
            ((TCPServer) subscriber).reSubscribe(rpublisher);
          } catch (Exception e) {
            e.printStackTrace();
          }
        }
      }
      return null;
    }
 public void stop(BundleContext context) throws Exception {
   ((TCPServer) subscriber).interrupt();
   ((TCPServer) subscriber).close();
   tracker.close();
 }