コード例 #1
0
 public synchronized void shutdown() {
   active = false;
   if (advertiseViaMulticastDNS) {
     zeroConf.unadvertise();
   }
   if (handlerThread != null) {
     handlerThread.interrupt();
   }
   if (receiverThread != null) {
     receiverThread.interrupt();
   }
   if (socket != null) {
     socket.close();
   }
 }
コード例 #2
0
  public void activateOptions() {
    InetAddress addr = null;

    try {
      Class c = Class.forName(decoder);
      Object o = c.newInstance();

      if (o instanceof Decoder) {
        this.decoderImpl = (Decoder) o;
      }
    } catch (ClassNotFoundException cnfe) {
      getLogger().warn("Unable to find decoder", cnfe);
    } catch (IllegalAccessException iae) {
      getLogger().warn("Could not construct decoder", iae);
    } catch (InstantiationException ie) {
      getLogger().warn("Could not construct decoder", ie);
    }

    try {
      addr = InetAddress.getByName(address);
    } catch (UnknownHostException uhe) {
      uhe.printStackTrace();
    }

    try {
      active = true;
      socket = new MulticastSocket(port);
      socket.joinGroup(addr);
      receiverThread = new MulticastReceiverThread();
      receiverThread.start();
      handlerThread = new MulticastHandlerThread();
      handlerThread.start();
      if (advertiseViaMulticastDNS) {
        zeroConf = new ZeroConfSupport(ZONE, port, getName());
        zeroConf.advertise();
      }

    } catch (IOException ioe) {
      ioe.printStackTrace();
    }
  }