code: @Override
      public void serviceChanged(ServiceEvent event) {
          if (event.getType() == ServiceEvent.REGISTERED)
          {
          }
          if (event.getType() == ServiceEvent.UNREGISTERING)
          {
              service = null;
          }
      }
docs: Listen for register/unregister events.