1 Reply Latest reply on Jan 6, 2003 8:39 AM by Greg Wilkins

    Jetty addListener/removeListener exception

    Fred Newbie

      I have an MBean that dynamically adds and removes SocketListeners from Jetty HttpServer that comes with JBoss 3.0.3 from the JBoss_3_0_3 cvs tag.

      It looks like there is a problem in main/org/mortbay/http/SocketListener.java:

      public void setHttpServer(HttpServer server)
      {
      Code.assertTrue(_server==null || _server==server,
      "Cannot share listeners");
      _server=server;
      }

      Should be

      public void setHttpServer(HttpServer server)
      {
      Code.assertTrue(server==null || _server==null || _server==server,
      "Cannot share listeners _server:"+_server+" server:"+server);
      _server=server;
      }

      because in main/org/mortbay/http/HttpServer.java addListener sets to a non-null value, then removeListener sets to null, therefore do addListener and then removeListener would always cause the assert to fail, generating an exception.

      public HttpListener addListener(HttpListener listener)
      throws IllegalArgumentException
      {
      listener.setHttpServer(this); //<<<--sets to non-null
      _listeners.add(listener);
      addComponent(listener);
      return listener;
      }

      public void removeListener(HttpListener listener)
      {
      [clip]
      _listeners.remove(l);
      removeComponent(listener);
      if (listener.isStarted())
      try{listener.stop();}catch(InterruptedException e){Code.warning(e);}
      listener.setHttpServer(null); //<<<--sets back to null
      [clip]
      }

      The same issue can be found in AJP13Listener.java.

      Is it correct to update the asserts or should another API be used to add and remove listeners?

      Cheers,
      Fred