Beispiel #1
1
  public static void main(String[] args) throws Exception {
    System.setSecurityManager(new SecurityManager());

    // Create an uninitialized class loader
    try {
      new ClassLoader(null) {
        @Override
        protected void finalize() {
          loader = this;
        }
      };
    } catch (SecurityException exc) {
      // Expected
    }
    System.gc();
    System.runFinalization();

    // if 'loader' isn't null, need to ensure that it can't be used as
    // parent
    if (loader != null) {
      try {
        // Create a class loader with 'loader' being the parent
        URLClassLoader child = URLClassLoader.newInstance(new URL[0], loader);
        throw new RuntimeException("Test Failed!");
      } catch (SecurityException se) {
        System.out.println("Test Passed: Exception thrown");
      }
    } else {
      System.out.println("Test Passed: Loader is null");
    }
  }
  /**
   * Sends a leave message to the multicast group and leaves it. The <CODE>DiscoveryResponder</CODE>
   * leaves its multicast group. This method has no effect if the <CODE>DiscoveryResponder</CODE> is
   * <CODE>OFFLINE</CODE> or <CODE>STOPPING</CODE> or <CODE>STARTING</CODE>.
   */
  public void stop() {
    if (state == ONLINE) {
      changeState(STOPPING);
      // ------------------------
      // Stop corresponding thread
      // ------------------------

      responder.stopRequested = true;

      synchronized (responder.interrupted) {
        if (!responder.interrupted.booleanValue()) {
          responderThread.interrupt();
        }
      }

      // Fix for cases when the interrupt does not work (Windows NT)
      try {
        MulticastSocket ms = new MulticastSocket(multicastPort);

        // NPCTE fix for bugId 4499338, esc 0, 04 Sept 2001
        if (usrInet != null) {
          ms.setInterface(usrInet);

          if (logger.finerOn()) {
            logger.finer("stop ", "use the interface " + usrInet);
          }
        }
        // end of NPCTE fix for bugId 4499338

        InetAddress group = InetAddress.getByName(multicastGroup);
        ms.joinGroup(group);
        ms.send(new DatagramPacket(new byte[1], 1, group, multicastPort));
        ms.leaveGroup(group);
      } catch (Exception e) {
        if (logger.finerOn()) {
          logger.finer(
              "stop ",
              "Unexpected exception occurred trying to send empty message " + e.getMessage());
        }
      }

      // ------------------------
      // free 'remained' allocated resource
      // ------------------------
      responder = null;
      System.runFinalization();

      // ----------------
      // Update state
      // ----------------
      // changeState(OFFLINE) ;
    } else {
      if (logger.finerOn()) {
        logger.finer("stop ", "Responder is not ONLINE");
      }
    }
  }