1 Reply Latest reply on Aug 24, 2010 8:17 AM by timfox

    Builder API for the ServerLocator

    jmesnil

      I'm currently fixing the tests in the HA branch.


      It's a minor thing but I think we could really improve the developer experience configuring HornetQ by using a builder API for the server locator.
      I don't like the current implementation where you can configure the server locator until the first created session factory. I'd prefer the server locator to be configurable but immutable. Once you get a ref on it, it is never changing.
      Using a builder API would be cleaner. Instead of

       

       

      ServerLocator locator = HornetQClient.createServerLocatorWithHA(transportConfigs);
      locator.setBlockOnAcknowledge(true);
      locator.setConsumerWindowSize(1234);
      ClientSessionFactory csf = locator.createSessionFactory();
      locator.setBlockOnAcknowledge(false); // => throws an exception 
      

       

      We would have

       

      ServerLocator locator = HornetQClient.createServerLocator(transportConfigs).ha(true).blockOnAcknowledge(true).consumerWindowSize(1234).build();
      ClientSessionFactory csf = locator.createSessionFactory(); 


      There is no setter methods on the ServerLocator, it is immutable but we can still create a configurable server locator. We just need to introduce a ServerLocatorBuilder class.


      HornetQClient.createServerLocator() returns a ServerLocatorBuilder with a ServerLocatorImpl instance. The builder class has methods that can be chained. e.g

       

      public ServerLocatorBuilder blockOnAcknowledge(boolean ack)
      {
         this.locator.setBlockOnAcknowledge(ack);
         return this;
      }
      

       

      Nothing ground breaking, simple obvious builder API.
      We've bigger things to do but it'd make for a cleaner and safer API to expose to HornetQ users. wdyt?