geronimo-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Fei Fei" <micro.soft....@hotmail.com>
Subject [talking]Is those code have quality?
Date Mon, 05 Feb 2007 17:34:04 GMT

     Firstly,I am sorry,This is talking about project openejb.but this mail 
list is used to project geronimo.But,I really hope everyone can give me some 
advice.Thanks.

     I review code at org.apache.openejb.server.activemq.BrokerServer,I 
don't know this class want to do anything,but I think some code is no 
auality,like this:

    public void init(Properties properties) throws Exception {
        String port = properties.getProperty("port", "1527");
        String bind = properties.getProperty("bind");
        String disabled = properties.getProperty("disabled");
        this.port = Integer.parseInt(port);
        this.disabled = Boolean.parseBoolean(disabled);
        @0
        host = InetAddress.getByName(bind);

        @1
        if (this.disabled) {
            return;
        }
        URI uri = new URI("tcp", null, bind, this.port, null, null, null);

        broker = new BrokerService();
        broker.setPersistent(false);
        broker.addConnector(uri);
    }

    public void start() throws ServiceException {
        @2
        if (disabled) return;
        try {
            broker.start();
        } catch (Exception e) {
            throw new ServiceException(e);
        }
    }

    due to @1 and @2,I think if the field of disabled is false,this class(or 
call service,it implements ServerService) will not working,so ,the prob 
is,you specify the field type is boolean(then sometimes it will value of 
false),but the @0 is working every time,this 
invocation(InetAddress.getByName(..)) will use a great many system 
resources,following invocation code(the char 'l:' means 'line:'):

   l:956  public static InetAddress getByName(String host)
		throws UnknownHostException {
		return InetAddress.getAllByName(host)[0];
   l:959  }

   l:1000  public static InetAddress[] getAllByName(String host)
		throws UnknownHostException {

		......

		return getAllByName0(host);
   l:1061  }

   l:1095  private static InetAddress[] getAllByName0 (String host)
		throws UnknownHostException
		{
		return getAllByName0(host, true);
   l:1099  }

   l:1104  static InetAddress[] getAllByName0 (String host, boolean check)
		throws UnknownHostException  {
		.....
		/* Make a copy of the InetAddress array */
		objcopy = ((InetAddress [])obj).clone();
		return (InetAddress [])objcopy;
   l:1139  }

   so,you see,I deem you review code to here,to a certainty found some 
prob.yes ,it will work fine,but this project is from Apache,isn't all best 
developer working with apache project?(I nill write more.very tired now.I am 
going to bed..)

   I think just change to:
    public void init(Properties properties) throws Exception {
        String disabled = properties.getProperty("disabled");
        this.disabled = Boolean.parseBoolean(disabled);
        @1
        if (this.disabled) {
            return;
        }

        String port = properties.getProperty("port", "1527");
        this.port = Integer.parseInt(port);
        String bind = properties.getProperty("bind");
        @0
        host = InetAddress.getByName(bind);
        URI uri = new URI("tcp", null, bind, this.port, null, null, null);

        broker = new BrokerService();
        broker.setPersistent(false);
        broker.addConnector(uri);
    }

	if you see this message,give me some idea please,thanks.

- A Fei -

_________________________________________________________________
>From predictions to trailers, check out the MSN Entertainment Guide to the 
Academy Awards® 
http://movies.msn.com/movies/oscars2007/?icid=ncoscartagline1


Mime
View raw message