1 10 package org.mmbase.clustering.multicast; 11 12 import java.util.Map ; 13 14 import org.mmbase.clustering.ClusterManager; 15 import org.mmbase.util.logging.Logger; 16 import org.mmbase.util.logging.Logging; 17 import org.mmbase.util.xml.UtilReader; 18 19 20 31 public class Multicast extends ClusterManager { 32 33 private static final Logger log = Logging.getLoggerInstance(Multicast.class); 34 35 public static final String CONFIG_FILE = "multicast.xml"; 36 37 40 private String multicastHost = "ALL-SYSTEMS.MCAST.NET"; 41 42 47 private int multicastPort = 4243; 48 49 50 private int multicastTTL = 1; 51 52 53 private int dpsize = 64 * 1024; 54 55 56 private ChangesSender mcs; 57 58 private ChangesReceiver mcr; 59 60 63 private final UtilReader reader = new UtilReader(CONFIG_FILE, 64 new Runnable () { 65 public void run() { 66 synchronized(Multicast.this) { 67 stopCommunicationThreads(); 68 readConfiguration(reader.getProperties()); 69 startCommunicationThreads(); 70 } 71 } 72 }); 73 74 76 77 public Multicast(){ 78 readConfiguration(reader.getProperties()); 79 start(); 80 } 81 82 85 protected synchronized void readConfiguration(Map configuration) { 86 super.readConfiguration(configuration); 87 88 String tmp = (String ) configuration.get("multicastport"); 89 if (tmp != null && !tmp.equals("")) { 90 try { 91 multicastPort = Integer.parseInt(tmp); 92 } catch (Exception e) {} 93 } 94 95 tmp = (String ) configuration.get("multicasthost"); 96 if (tmp != null && !tmp.equals("")) { 97 multicastHost = tmp; 98 } 99 100 tmp = (String ) configuration.get("multicastTTL"); 101 if (tmp != null && !tmp.equals("")) { 102 try { 103 multicastTTL = Integer.parseInt(tmp); 104 } catch (Exception e) {} 105 } 106 107 tmp = (String ) configuration.get("dpsize"); 108 if (tmp != null && !tmp.equals("")) { 109 try { 110 dpsize = Integer.parseInt(tmp); 111 } catch (Exception e) {} 112 } 113 114 log.info("multicast host: " + multicastHost + 115 ", port: " + multicastPort + 116 ", TTL: " + multicastTTL + 117 ", datapacketsize: " + dpsize); 118 119 } 120 121 protected synchronized void startCommunicationThreads() { 122 try { 123 mcs = new ChangesSender(multicastHost, multicastPort, multicastTTL, nodesToSend, send); 124 } catch (java.net.UnknownHostException e) { 125 log.error(e); 126 } 127 try { 128 mcr = new ChangesReceiver(multicastHost, multicastPort, dpsize, nodesToSpawn); 129 } catch (java.net.UnknownHostException e) { 130 log.error(e); 131 } 132 } 133 134 protected synchronized void stopCommunicationThreads() { 135 if (mcs != null) { 136 mcs.stop(); 137 log.service("Stopped communication sender " + mcs); 138 mcs = null; 139 } 140 if (mcr != null) { 141 mcr.stop(); 142 log.service("Stopped communication receiver " + mcr); 143 mcr = null; 144 } 145 } 146 147 } 148 | Popular Tags |