@Override
 public void serviceRemoved(ServiceEvent serviceEvent) {
   String name = serviceEvent.getName();
   synchronized (this) {
     removeBoardswithSameName(name);
   }
 }
Exemplo n.º 2
0
 @Override
 public void serviceAdded(ServiceEvent event) {
   Log.d(TAG, "serviceAdded:" + event);
   ZeroServiceInfo zsi = new ZeroServiceInfo(null, event);
   String name = event.getName();
   if (mName.equals(name)) {
     mZsinfo = zsi;
     if (null != mServiceListener) {
       mServiceListener.onServiceRegistered(zsi);
     }
   } else {
     ServiceInfo sinfo = event.getInfo();
     if (null != sinfo) {
       InetAddress[] addrs = sinfo.getInetAddresses();
       if (null != addrs && addrs.length > 0) {
         for (InetAddress addr : addrs) {
           Log.d(TAG, "the addr is:" + addr.getHostName());
         }
         if (null != mDiscoverListener) {
           mDiscoverListener.onServiceFound(zsi);
         }
       }
     }
   }
 }
Exemplo n.º 3
0
  // @Test // not working by 22/09/2013
  public void testRegisterDevice() {

    try {
      JmDNS jmdns =
          JmDNS.create(
              InetAddress.getByName(
                  PropertiesLoader.getInstance()
                      .getProperties()
                      .getProperty("iotsys.gateway.authNsAddr6", "fe80::acbc:b659:71db:5cb7%20")));
      jmdns.addServiceListener(
          "_obix._coap."
              + PropertiesLoader.getInstance()
                  .getProperties()
                  .getProperty("iotsys.gateway.authDomain", "local."),
          new ServiceListener() {

            @Override
            public void serviceAdded(ServiceEvent event) {}

            @Override
            public void serviceRemoved(ServiceEvent event) {}

            @Override
            public void serviceResolved(ServiceEvent event) {
              resolvedEvents.add(event);
            }
          });
      lock.await(20000, TimeUnit.MILLISECONDS);
      ArrayList<String> eventNames = new ArrayList<String>();
      for (ServiceEvent e : resolvedEvents) {
        eventNames.add(e.getName());
      }
      // test all elements in testDeviceNames are returned in eventNames
      for (String qName : testDeviceNames) {
        // if eventNames not contain qName -> fail
        String fk = qName.split("\\.")[0].toLowerCase();
        if (!eventNames.contains(fk)) fail();
      }

    } catch (UnknownHostException e1) {
      // TODO Auto-generated catch block
      e1.printStackTrace();
    } catch (IOException e1) {
      // TODO Auto-generated catch block
      e1.printStackTrace();
    } catch (InterruptedException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
Exemplo n.º 4
0
 @Override
 public void serviceRemoved(ServiceEvent event) {
   Log.d(TAG, "serviceRemoved:" + event);
   ZeroServiceInfo zsi = new ZeroServiceInfo(null, event);
   String name = event.getName();
   if (mName.equals(name)) {
     if (null != mServiceListener) {
       mServiceListener.onServiceUnregistered(zsi);
     }
   } else {
     if (null != mDiscoverListener) {
       mDiscoverListener.onServiceLost(zsi);
     }
   }
 }
  @Override
  public void serviceAdded(ServiceEvent serviceEvent) {
    String type = serviceEvent.getType();
    String name = serviceEvent.getName();

    try (JmDNS dns = serviceEvent.getDNS()) {
      dns.requestServiceInfo(type, name);
      ServiceInfo serviceInfo = dns.getServiceInfo(type, name);
      if (serviceInfo != null) {
        dns.requestServiceInfo(type, name);
      }
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
  @Override
  public void serviceResolved(ServiceEvent serviceEvent) {
    ServiceInfo info = serviceEvent.getInfo();
    for (InetAddress inetAddress : info.getInet4Addresses()) {
      bonour newItem = new bonour();
      newItem.address = inetAddress.getHostAddress();
      newItem.name = serviceEvent.getName();
      if (info.hasData()) {
        newItem.board = info.getPropertyString("board"); // $NON-NLS-1$
        newItem.distroversion = info.getPropertyString("distro_version"); // $NON-NLS-1$
        newItem.name = info.getServer();
      }
      while (newItem.name.endsWith(".")) { // $NON-NLS-1$
        newItem.name = newItem.name.substring(0, newItem.name.length() - 1);
      }
      newItem.port = Integer.toString(info.getPort());

      synchronized (this) {
        removeBoardswithSameAdress(newItem);
        this.myComPorts.add(newItem);
      }
    }
  }
Exemplo n.º 7
0
 @Override
 public void serviceAdded(ServiceEvent event) {
   Log.i(TAG, "Service added: " + event.getType() + "\n Info: " + event.getInfo());
   // Для вызова serviceResolved(...)
   event.getDNS().requestServiceInfo(event.getType(), event.getName(), 100);
 }
 public void serviceRemoved(ServiceEvent event) {
   removeService(event.getDNS(), event.getType(), event.getName());
 }
 public void serviceAdded(ServiceEvent event) {
   addService(event.getDNS(), event.getType(), event.getName());
 }
Exemplo n.º 10
0
 @Override
 public void serviceResolved(ServiceEvent event) {
   System.out.println(
       "Service resolved: " + event.getName() + "." + event.getType() + "\n" + event.getInfo());
 }
Exemplo n.º 11
0
 @Override
 public void serviceAdded(ServiceEvent event) {
   System.out.println("Service added   : " + event.getName() + "." + event.getType());
 }