1 46 47 package org.mr.indexing; 48 49 import java.net.SocketAddress ; 50 import java.util.Set ; 51 52 import org.apache.commons.logging.Log; 53 import org.apache.commons.logging.LogFactory; 54 import org.mr.MantaAgent; 55 import org.mr.core.configuration.ConfigManager; 56 import org.mr.core.net.MWBTransportImpl; 57 import org.mr.core.net.NetworkManager; 58 import org.mr.core.net.TransportImpl; 59 import org.mr.kernel.world.WorldModeler; 60 61 71 public class WBManager { 72 private String mwbPassword; 73 private TransportImpl mwbImpl; 74 private WBHandler wbHandler; 75 private Log log; 76 77 public WBManager() { 78 this.log = LogFactory.getLog("WBLink"); 79 if (this.log.isInfoEnabled()) { 80 this.log.info("WBLink starting"); 81 } 82 83 MantaAgent agent = MantaAgent.getInstance(); 84 ConfigManager config = 85 agent.getSingletonRepository().getConfigManager(); 86 87 if (!config.getBooleanProperty("wblink.enabled", false)) { 88 if (this.log.isInfoEnabled()) { 89 this.log.info("WBLink is disabled"); 90 } 91 return; 92 } 93 if (this.log.isInfoEnabled()) { 94 this.log.info("WBLink starting"); 95 } 96 97 this.mwbPassword = config.getStringProperty("wblink.password"); 98 int mwbLeaseSecs = config.getIntProperty("wblink.lease", 20); 99 100 111 WorldModeler world = agent.getSingletonRepository().getWorldModeler(); 113 String domainName = world.getDefaultDomainName(); 114 Set irsTransports = world.getAgentTransportInfo(domainName, "mwb"); 115 if (irsTransports == null || irsTransports.isEmpty()) { 116 if (this.log.isWarnEnabled()) { 117 this.log.warn("No transport information for the MantaRay WB " + 118 "found in the world map. In order to " + 119 "communicate with the MWB a peer with the " + 120 "name 'mwb' and with a transport type of " + 121 "'MWB' must be present in the world map. " + 122 "Role advertisement and message routing using " + 123 "the WB WILL NOT BE AVAILABLE."); 124 } 125 return; 126 } 127 if (this.mwbPassword == null) { 128 if (this.log.isWarnEnabled()) { 129 this.log.warn("No password to use with the WB found in the " + 130 "configuration. Role advertisement and " + 131 "message routing using the WB WILL NOT BE " + 132 "AVAILABLE."); 133 } 134 return; 135 } 136 137 WBAdvertiser advertiser = new WBAdvertiser(mwbLeaseSecs); 139 agent.getSingletonRepository().getServiceActorControlCenter().setWBSender(advertiser); 140 NetworkManager network = 141 MantaAgent.getInstance().getSingletonRepository().getNetworkManager(); 142 network.addAgentStateListener("mwb", advertiser); 143 144 if (config.getBooleanProperty("wblink.exclusive", false)) { 145 agent.getSingletonRepository().getServiceActorControlCenter().setDefaultSender(null); 146 } 147 148 this.wbHandler = new WBHandler(); 150 } 152 public synchronized TransportImpl getIRSTransportImpl(SocketAddress local, 153 SocketAddress remote) 154 { 155 try { 156 if ((mwbImpl == null || mwbImpl.isDown()) && mwbPassword != null) { 157 mwbImpl = new MWBTransportImpl(local, remote, mwbPassword); 158 } 159 } catch (Exception e) { 160 System.err.println("MWBTransportImpl init returned an error"); 161 e.printStackTrace(); 162 } 163 164 return mwbImpl; 165 } 166 167 public WBHandler getWbHandler() { 168 return this.wbHandler; 169 } 170 } | Popular Tags |