📄 configurator.java
字号:
LOG.info( "Reconfig requested - no PeerAdvertisement" );
advertisement = (PeerAdvertisement)
AdvertisementFactory.newAdvertisement(
PeerAdvertisement.getAdvertisementType());
advertisement.setName("");
advertisement.setDescription("");
advertisement.setPeerID(
IDFactory.newPeerID(PeerGroupID.worldPeerGroupID));
// Do not set a GID here; we have no authority to do so and it is
// fortunately disregarded anyway.
// advertisement.setPeerGroupID(PeerGroupID.worldPeerGroupID);
}
/*
* create the default Service Params for protos.
*/
StructuredDocument http = (StructuredTextDocument)
advertisement.getServiceParam(PeerGroup.httpProtoClassID);
StructuredDocument tcp = (StructuredTextDocument)
advertisement.getServiceParam(PeerGroup.tcpProtoClassID);
HTTPAdv httpAdv = null;
boolean httpDisabled = false;
TCPAdv tcpAdv = null;
boolean tcpDisabled = false;
if (http != null) {
try {
httpDisabled = http.getChildren("isOff").hasMoreElements();
Element param = null;
Enumeration httpChilds = http.getChildren(
TransportAdvertisement.getAdvertisementType());
// get the TransportAdv from either TransportAdv or HttpAdv
if( httpChilds.hasMoreElements() ) {
param = (Element) httpChilds.nextElement();
} else {
httpChilds = http.getChildren(
HTTPAdv.getAdvertisementType());
if( httpChilds.hasMoreElements() ) {
param = (Element) httpChilds.nextElement();
}
}
httpAdv = (HTTPAdv)
AdvertisementFactory.newAdvertisement((TextElement) param);
boolean found = false;
try {
String interfaceAddress = httpAdv.getInterfaceAddress();
if ( interfaceAddress != null
&& !interfaceAddress.equals("")) {
String hostAddr =
InetAddress.getLocalHost().getHostAddress();
InetAddress[] all = InetAddress.getAllByName(hostAddr);
int i = all.length;
while (i-- > 0) {
if (all[i].getHostAddress().equals(interfaceAddress)) {
found = true;
break;
// OK, it is in-there
}
}
}
} catch (Throwable t2) {
// Could not verify ? Something's fishy. Let's check further
// if a reconfig is in order.
}
if (! found) {
String cfMode = httpAdv.getConfigMode();
if (cfMode == null || ! cfMode.equals("manual")) {
reconf = true;
if( LOG.isEnabledFor(Priority.INFO) )
LOG.info( "Reconfig requested - http set to manual config" );
}
}
} catch (Exception advTrouble) {
if( LOG.isEnabledFor(Priority.WARN) )
LOG.warn( "Reconfig requested - http advertisement corrupted", advTrouble );
httpAdv = null;
}
}
if (httpAdv == null) {
reconf = true;
if( LOG.isEnabledFor(Priority.INFO) )
LOG.info( "Reconfig requested - http advertisement missing" );
httpAdv = new HTTPAdv( );
httpAdv.setProtocol( "http" );
httpAdv.setPort( "9700" );
httpAdv.setRouterEnabled(true);
httpAdv.setProxyEnabled(false);
httpAdv.setServerEnabled(false);
}
if (tcp != null) {
try {
tcpDisabled = tcp.getChildren("isOff").hasMoreElements();
Element param = null;
Enumeration tcpChilds = tcp.getChildren(
TransportAdvertisement.getAdvertisementType());
// get the TransportAdv from either TransportAdv or TcpAdv
if( tcpChilds.hasMoreElements() ) {
param = (Element) tcpChilds.nextElement();
} else {
tcpChilds = tcp.getChildren(
TCPAdv.getAdvertisementType());
if( tcpChilds.hasMoreElements() ) {
param = (Element) tcpChilds.nextElement();
}
}
tcpAdv = (TCPAdv)
AdvertisementFactory.newAdvertisement((TextElement) param);
boolean found = false;
try {
String interfaceAddress = tcpAdv.getInterfaceAddress();
if ( interfaceAddress != null
&& !interfaceAddress.equals("")) {
String hostAddr =
InetAddress.getLocalHost().getHostAddress();
InetAddress[] all = InetAddress.getAllByName(hostAddr);
int i = all.length;
while (i-- > 0) {
if (all[i].getHostAddress().equals(interfaceAddress)) {
found = true;
break;
// OK, it is in-there
}
}
}
} catch (Throwable t2) {
// Could not verify ? Something's fishy. Let's check further
// if a reconfig is in order.
}
if (! found) {
String cfMode = tcpAdv.getConfigMode();
if (cfMode == null || ! cfMode.equals("manual")) {
reconf = true;
if( LOG.isEnabledFor(Priority.INFO) )
LOG.info( "Reconfig requested - tcp set to manual config" );
}
}
} catch (Exception advTrouble) {
if( LOG.isEnabledFor(Priority.WARN) )
LOG.warn( "Reconfig requested - http advertisement corrupted", advTrouble );
tcpAdv = null;
}
}
if (tcpAdv == null) {
reconf = true;
if( LOG.isEnabledFor(Priority.INFO) )
LOG.info( "Reconfig requested - tcp advertisement missing" );
String port = "9701";
// get the port from a property
String tcpPort = System.getProperty("jxta.tcp.port");
if (tcpPort != null)
port = tcpPort;
tcpAdv = new TCPAdv();
tcpAdv.setProtocol( "TCP" );
tcpAdv.setPort( port );
tcpAdv.setMulticastAddr( "224.0.1.85" );
tcpAdv.setMulticastPort( "1234" );
tcpAdv.setMulticastSize( "16384" );
tcpAdv.setServer( "" );
tcpAdv.setInterfaceAddress( "" );
}
String hn = "";
try {
hn = InetAddress.getLocalHost().getHostName();
} catch (Exception e) {
hn = "";
}
if (httpAdv.getServer() == null) {
httpAdv.setServer(hn + ":9700");
httpAdv.setServerEnabled(false);
}
String winProxy = System.getProperty("jxta.proxy");
if (winProxy != null) {
String proxyServer = parseHttpProxyServer(winProxy);
if (proxyServer != null) {
httpAdv.setProxyEnabled(true);
httpAdv.setProxy(proxyServer.substring(proxyServer.indexOf("=")+1));
}
} else if (httpAdv.getProxy() == null) {
httpAdv.setProxy("myProxy.myDomain:8080");
httpAdv.setProxyEnabled(false);
}
if (httpAdv.getRouters() == null) {
Vector r = new Vector();
httpAdv.setRouters(r);
// Do not set routerEnabled. If the adv is brand new, then
// it was set to true already (as a default). Otherwise it is
// what it is. HTTPAdv already set it properly; we're just
// making ConfigDialog's life simpler by providing an empty
// vector instead of null.
}
// See if TLS will reconfigure
if (TlsConfig.willConfigureTls()) {
reconf = true;
if( LOG.isEnabledFor(Priority.INFO) )
LOG.info( "Reconfig requested - TLS wanted config" );
}
// If we did not modify anything of importance or see anything wrong,
// leave the adv alone.
if (reconf == false) return false;
// Create new param docs that contain the updated advs
http = StructuredDocumentFactory.newStructuredDocument(
new MimeMediaType("text", "xml"), "Parm");
StructuredDocumentUtils.copyElements(
http,
http,
(StructuredDocument) httpAdv.getDocument(new MimeMediaType("text", "xml")));
if (httpDisabled) {
http.appendChild(http.createElement("isOff"));
}
advertisement.putServiceParam(PeerGroup.httpProtoClassID, http);
tcp = StructuredDocumentFactory.newStructuredDocument(
new MimeMediaType("text", "xml"), "Parm");
StructuredDocumentUtils.copyElements(
tcp,
tcp,
(StructuredDocument) tcpAdv.getDocument(new MimeMediaType("text", "xml")));
if (tcpDisabled) {
tcp.appendChild(tcp.createElement("isOff"));
}
advertisement.putServiceParam(PeerGroup.tcpProtoClassID, tcp);
} catch(Exception serious) {
if (LOG.isEnabledFor(Priority.ERROR))
LOG.error("Trouble while fixing advertisement. Hope for the best.", serious);
}
return true;
}
/**
* Adjust the log4j priority based on the user's configuration file.
* If the configuration is not set or the value is "user default",
* then don't change it.
*
* @since 1.0
*/
private void adjustLog4JPriority() {
if (advertisement == null || advertisement.getDebugLevel() == null) {
return;
}
String requestedLevel = advertisement.getDebugLevel();
if ("user default".equals(requestedLevel)) {
if (LOG.isEnabledFor(Priority.DEBUG)) LOG.debug("user default requested");
return;
}
if (LOG.isEnabledFor(Priority.DEBUG)) LOG.debug("Setting priority to [" + requestedLevel +
"] based on the user's configuration");
Category jxtaCategory = Category.getInstance("net.jxta");
jxtaCategory.setPriority(Priority.toPriority(requestedLevel));
}
/**
*Description of the Class
*/
class PosRandom extends Random {
/**
*Description of the Method
*
* @return Description of the Returned Value
* @since 1.0
*/
public int nextPos() {
return next(31);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -