Changeset 840

Show
Ignore:
Timestamp:
09/09/06 22:09:39 (2 years ago)
Author:
alban
Message:

[Bug 138] add support for tracker.none and listenaddress

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/source/org/kolaka/freecast/manager/gui/BrowseHomepageAction.java

    r405 r840  
    2525 
    2626import java.awt.event.ActionEvent; 
    27 import java.net.InetSocketAddress; 
    2827import java.net.URL; 
    2928 
     
    4443        private static final long serialVersionUID = 1014721912985395264L; 
    4544 
    46         private final InetSocketAddress publicHttpServer; 
     45        private final URL listenPage; 
     46  private final boolean localListenPage; 
    4747 
    4848        public BrowseHomepageAction(Resources resources, 
    49                         InetSocketAddress publicHttpServer) throws ResourcesException { 
     49                        URL listenPage, boolean localListenPage) throws ResourcesException { 
    5050                super("Browse network homepage"); 
    51                 this.publicHttpServer = publicHttpServer; 
     51                this.listenPage = listenPage; 
     52    this.localListenPage = localListenPage; 
    5253                loadIcons(resources, "visit.browse"); 
    5354        } 
    5455 
    5556        public void actionPerformed(ActionEvent event) { 
     57    URL url = listenPage; 
    5658                try { 
    57                         URL url = new URL("http", "localhost", publicHttpServer.getPort(), 
    58                                         "/"); 
     59      if (localListenPage) { 
     60        url = new URL(listenPage.getPath(), "localhost", listenPage.getPort(), listenPage.getPath()); 
     61      } 
     62           
    5963                        LogFactory.getLog(getClass()).debug("browse " + url); 
    6064                        Desktop.browse(url); 
    6165                } catch (Exception e) { 
    6266                        LogFactory.getLog(getClass()).error( 
    63                                         "can't start a browser to visit " + publicHttpServer, e); 
     67                                        "can't start a browser to visit " + url, e); 
    6468                } 
    6569        } 
  • trunk/source/org/kolaka/freecast/manager/gui/EmailHomepageAction.java

    r691 r840  
    2626import java.awt.event.ActionEvent; 
    2727import java.io.IOException; 
    28 import java.net.InetSocketAddress; 
    29 import java.net.MalformedURLException; 
    3028import java.net.URL; 
    3129 
     
    4745        private static final long serialVersionUID = -6845487445187546115L; 
    4846 
    49         private final InetSocketAddress publicHttpServer
     47        private final URL listenPage
    5048 
    5149        public EmailHomepageAction(Resources resources, 
    52                         InetSocketAddress publicHttpServer) throws ResourcesException { 
     50                        URL listenPage) throws ResourcesException { 
    5351                super("Email network homepage"); 
    54                 this.publicHttpServer = publicHttpServer
     52                this.listenPage = listenPage
    5553                loadIcons(resources, "visit.email"); 
    5654        } 
     
    6159                } catch (Exception e) { 
    6260                        LogFactory.getLog(getClass()).error( 
    63                                         "can't email to visit " + publicHttpServer, e); 
     61                                        "can't email to visit " + listenPage, e); 
    6462                } 
    6563        } 
    6664         
    6765        private void sendMail() throws IOException, DesktopException { 
    68                 URL url = new URL("http", publicHttpServer.getHostName(), publicHttpServer.getPort(), "/")
     66                URL url = listenPage
    6967                LogFactory.getLog(getClass()).debug("email " + url); 
    7068 
  • trunk/source/org/kolaka/freecast/manager/gui/Main.java

    r405 r840  
    2626import java.net.InetAddress; 
    2727import java.net.InetSocketAddress; 
     28import java.net.URL; 
    2829 
    2930import org.apache.commons.configuration.Configuration; 
     31import org.apache.commons.configuration.DataConfiguration; 
    3032import org.apache.commons.logging.LogFactory; 
    3133import org.kolaka.freecast.NodeConfigurator; 
     
    4244import org.kolaka.freecast.tracker.HttpTracker; 
    4345import org.kolaka.freecast.tracker.HttpTrackerConfigurator; 
     46import org.kolaka.freecast.tracker.NoConfiguredTrackerException; 
    4447 
    4548/** 
     
    6568                super.postInit(configuration); 
    6669 
    67                 HttpTracker tracker = new HttpTracker(); 
    68                 new HttpTrackerConfigurator().configure(tracker, configuration 
    69                                 .subset("tracker")); 
    70                 this.tracker = tracker; 
     70                try { 
     71      HttpTracker tracker = new HttpTracker(); 
     72      new HttpTrackerConfigurator().configure(tracker, configuration 
     73                .subset("tracker")); 
     74      this.tracker = tracker; 
     75    } catch (NoConfiguredTrackerException e) { 
     76      LogFactory.getLog(getClass()).info("no tracker configured"); 
     77      LogFactory.getLog(getClass()).debug("local track won't start"); 
     78    } 
     79     
    7180 
    7281                ConfigurableNode node = new DefaultNode(); 
     
    7685                this.node = node; 
    7786 
    78                 String listenAddressPort = configuration 
    79                                 .getString("httpserver.listenaddress.port"); 
    80                 InetSocketAddressSpecification listenAddressSpecification = new InetSocketAddressSpecificationParser() 
    81                                 .parse("0.0.0.0", listenAddressPort); 
    82                 InetSocketAddress listenAddress = SpecificationServerSocketBinder 
    83                                 .select(listenAddressSpecification); 
     87    boolean localListenPage = tracker != null; 
     88    URL listenPage; 
     89                if (localListenPage) {  
     90                String listenAddressPort = configuration 
     91                                .getString("httpserver.listenaddress.port"); 
     92                InetSocketAddressSpecification listenAddressSpecification = new InetSocketAddressSpecificationParser() 
     93                                .parse("0.0.0.0", listenAddressPort); 
     94                InetSocketAddress listenAddress = SpecificationServerSocketBinder 
     95                                .select(listenAddressSpecification); 
     96   
     97                this.httpServer = new HttpServer(listenAddress); 
     98                InetAddress publicAddress = PublicAddressResolver.getDefaultInstance() 
     99                                .getPublicAddress(); 
     100                httpServer.setServerName(publicAddress); 
    84101 
    85                 this.httpServer = new HttpServer(listenAddress); 
    86                 InetAddress publicAddress = PublicAddressResolver.getDefaultInstance() 
    87                                 .getPublicAddress(); 
    88                 httpServer.setServerName(publicAddress); 
     102      InetSocketAddress publicHttpServer = new InetSocketAddress( 
     103          publicAddress, listenAddress.getPort()); 
     104      listenPage = new URL("http", publicHttpServer.getHostName(), publicHttpServer.getPort(), "/"); 
     105    } else { 
     106      LogFactory.getLog(getClass()).debug("no tracker configured, local http server won't start"); 
     107      LogFactory.getLog(getClass()).debug("configured listen page will be used"); 
     108      listenPage = new DataConfiguration(configuration).getURL("listenpage"); 
     109       
     110      if (listenPage == null) { 
     111        throw new IllegalArgumentException("No configured listen page"); 
     112      } 
     113    } 
     114 
     115    LogFactory.getLog(getClass()).info("listener welcome page: " + listenPage); 
    89116 
    90117                ConfigurableResources resources = new ConfigurableResources( 
    91118                                configuration.subset("gui")); 
    92119                resources.setResourceLocator(getResourceLocator()); 
    93  
    94                 InetSocketAddress publicHttpServer = new InetSocketAddress( 
    95                                 publicAddress, listenAddress.getPort()); 
    96  
    97                 frame = new MainFrame(resources, tracker, node, publicHttpServer); 
     120     
     121                frame = new MainFrame(resources, tracker, node, listenPage); 
    98122                frame.setQuitAction(createQuitAction(resources)); 
    99123                frame.init(); 
     
    112136                frame.setVisible(true); 
    113137 
    114                 httpServer.start(); 
     138    if (httpServer != null) { 
     139      httpServer.start(); 
     140    } 
    115141 
    116                 LogFactory.getLog(Main.class).info( 
    117                                 "start a HttpTracker on port " + tracker.getListenAddress()); 
    118                 tracker.start(); 
     142    if (tracker != null) { 
     143                LogFactory.getLog(Main.class).info( 
     144                                "start a HttpTracker on port " + tracker.getListenAddress()); 
     145                tracker.start(); 
     146    } 
    119147 
    120148                node.init(); 
  • trunk/source/org/kolaka/freecast/manager/gui/MainFrame.java

    r830 r840  
    2828import java.awt.GridBagLayout; 
    2929import java.awt.Insets; 
    30 import java.net.InetSocketAddress
     30import java.net.URL
    3131import java.util.Arrays; 
    3232import java.util.List; 
     
    8080 
    8181        public MainFrame(Resources resources, TrackerService tracker, ConfigurableNode node, 
    82                         InetSocketAddress publicHttpServer) throws ResourcesException { 
     82                        URL listenPage) throws ResourcesException { 
    8383                super(resources); 
    8484 
     
    8686                this.node = node; 
    8787 
    88                 visitAction = new AsyncAction(new BrowseHomepageAction(resources, publicHttpServer)); 
     88    boolean localListenPage = tracker != null; 
     89                visitAction = new AsyncAction(new BrowseHomepageAction(resources, listenPage, localListenPage)); 
    8990                emailHomepageAction = new AsyncAction(new EmailHomepageAction(resources, 
    90                                 publicHttpServer)); 
     91                                listenPage)); 
    9192                setupAction = new SetupAction(((ConfigurableResources) resources).subset("setup"), this, node); 
    9293        } 
     
    101102                constraints.weightx = 1; 
    102103 
    103                 panel.add(new TrackerControlPanel(tracker), constraints); 
     104    if (tracker != null) { 
     105      panel.add(new TrackerControlPanel(tracker), constraints); 
     106    } 
    104107                panel.add(new NodeControlPanel(node), constraints); 
    105108 
  • trunk/source/org/kolaka/freecast/tracker/HttpMultiTrackerConnector.java

    r830 r840  
    3636  private static final long serialVersionUID = 1568160755433034061L; 
    3737  private final DefaultMultiTracker tracker; 
    38  
     38   
    3939  public HttpMultiTrackerConnector() { 
    4040    tracker = new DefaultMultiTracker(new HessianClientInfoProvider()); 
  • trunk/source/org/kolaka/freecast/tracker/HttpTracker.java

    r830 r840  
    6666    LogFactory.getLog(Main.class).trace( 
    6767        "use connector " + connectorClass.getName()); 
     68    if (connectorClass.equals(HttpMultiTrackerConnector.class)) { 
     69      LogFactory.getLog(Main.class).info("multi network support enabled"); 
     70    } 
    6871 
    6972    server = new Server(); 
  • trunk/source/org/kolaka/freecast/tracker/HttpTrackerConfigurator.java

    r830 r840  
    3636public class HttpTrackerConfigurator { 
    3737 
    38         public void configure(HttpTracker tracker, Configuration configuration)
     38        public void configure(HttpTracker tracker, Configuration configuration) throws NoConfiguredTrackerException
    3939    /* 
    4040     * for the moment, the tracker.class changes the Connector implementation  
     
    4545    if (trackerClass.equals("multi")) { 
    4646      connectorClass = HttpMultiTrackerConnector.class; 
     47    } else if (trackerClass.equals("none")) { 
     48      throw new NoConfiguredTrackerException(); 
    4749    } 
    4850    tracker.setConnectorClass(connectorClass); 
  • trunk/source/org/kolaka/freecast/tracker/Main.java

    r830 r840  
    4242        } 
    4343 
    44         protected void postInit(Configuration configuration)
     44        protected void postInit(Configuration configuration) throws Exception
    4545                HttpTracker tracker = new HttpTracker(); 
    4646                new HttpTrackerConfigurator().configure(tracker, configuration