|
From: Alexander S. <as...@us...> - 2008-11-27 18:33:47
|
Update of /cvsroot/jxtaim/jxtaim/src/vsis/im/util/config In directory fdv4jf1.ch3.sourceforge.com:/tmp/cvs-serv6730/src/vsis/im/util/config Modified Files: ConfigurationService.java JxtaConfigurator.java JxtaConfiguratorImpl.java Log Message: 2008-11-27 Alexander Sack <as...@jw...> Port configuration code to jxta 2.5 and do some randome cleanups * src/vsis/im/util/config/ConfigurationService.java, src/vsis/im/util/config/JxtaConfigurator.java, src/vsis/im/util/config/JxtaConfiguratorImpl.java - refactor all Platform configuration code and make it use NetworkManager and NetworkConfigurator introduced by JXTA 2.5 instead of the old Configurator * src/vsis/im/communication/JxtaConnection.java - (nm): NEW field: private NetworkManager nm - (goOnline): goOnline takes care now to setup NetworkManager and configure it using the new ConfigurationService mechanisms; catch and forward rethrow new exceptions * src/vsis/im/util/XMLResource.java - (load): improve logging - (<class>) fix indentation of field definition * src/vsis/im/Main.java: - [cleanup] drop not used com.sun import * src/conf/DefaultConfiguration.xml: - fix default relay and rendevouz auto-uri's used to gather initial seeds. Index: JxtaConfiguratorImpl.java =================================================================== RCS file: /cvsroot/jxtaim/jxtaim/src/vsis/im/util/config/JxtaConfiguratorImpl.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** JxtaConfiguratorImpl.java 16 Mar 2006 19:11:41 -0000 1.7 --- JxtaConfiguratorImpl.java 27 Nov 2008 18:33:37 -0000 1.8 *************** *** 39,43 **** import org.w3c.dom.Element; ! import net.jxta.ext.config.*; import vsis.im.util.FS; --- 39,44 ---- import org.w3c.dom.Element; ! import net.jxta.platform.NetworkConfigurator; ! import net.jxta.platform.NetworkManager; import vsis.im.util.FS; *************** *** 73,78 **** configureLogLevels(); configurePeerAdvertisement(); - configureHTTP(); - configureTCP(); configureRelay(); configureRendezVous(); --- 74,77 ---- *************** *** 111,115 **** * configure http */ ! private void configureHTTP() { int port = -1; --- 110,114 ---- * configure http */ ! protected void configureNetworkConfiguratorHttp(NetworkConfigurator nc) { int port = -1; *************** *** 131,154 **** // is alternative reasonable? ! String uri = "http://" + ip + ":" + port; System.err.println("adding http transport with address from uri: '" ! + uri + "'"); - HttpTransport transport = new HttpTransport(); - - Address address = new Address(); - try { - address.setAddress(new URI(uri)); - } catch (java.net.URISyntaxException e) { - log.error(e); - return; - } if (!this.resources.getBoolean(ConfigConst.HTTP_IS_SERVER)) { ! address.setPortRange(1); } ! ! transport.addAddress(address); if (this.resources.getBoolean(ConfigConst.HTTP_USE_PROXY)) { ProxyAddress proxyAddress = new ProxyAddress(); --- 130,149 ---- // is alternative reasonable? ! String pub_address = null; // XXX: implement this config ! System.err.println("adding http transport with address from uri: '" ! + ip + ":" + port +"'"); + nc.setHttpEnabled(true); if (!this.resources.getBoolean(ConfigConst.HTTP_IS_SERVER)) { ! nc.setHttpPort (port); ! nc.setHttpIncoming(true); ! nc.setHttpPublicAddress(ip+":"+port, true); // XXX: needs its own config } ! nc.setHttpInterfaceAddress(ip); ! nc.setHttpOutgoing(true); + /* XXX: not sure what to do here if (this.resources.getBoolean(ConfigConst.HTTP_USE_PROXY)) { ProxyAddress proxyAddress = new ProxyAddress(); *************** *** 160,167 **** return; } ! transport.setProxyAddress(proxyAddress); ! } ! addTransport(transport); ! } --- 155,160 ---- return; } ! // XXX: fix me!! implement http proxy support? ! }*/ } *************** *** 169,179 **** * Configure TCP */ ! private void configureTCP() { ! TcpTransport transport = new TcpTransport(); ! TcpTransportAddress address = new TcpTransportAddress(); int port = -1; - System.out.println("configureTCP()"); - try { port = Integer.parseInt(System.getProperty("jxta.tcp.port")); --- 162,168 ---- * Configure TCP */ ! protected void configureNetworkConfiguratorTcp(NetworkConfigurator nc) { int port = -1; try { port = Integer.parseInt(System.getProperty("jxta.tcp.port")); *************** *** 191,201 **** String s = this.resources.getString(ConfigConst.TCP_MULTICAST_ADDRESS); if (s != null) { ! MulticastAddress mca = new MulticastAddress(); - mca.setMulticast(true); int mPort = -1; - try { mPort = this.resources.getInt(ConfigConst.TCP_MULTICAST_PORT); --- 180,190 ---- String s = this.resources.getString(ConfigConst.TCP_MULTICAST_ADDRESS); + // XXX: make a MULTICAST_ENABLED config entry ... e.g. no s could also mean default address if (s != null) { ! nc.setUseMulticast(true); ! nc.setMulticastAddress(s); int mPort = -1; try { mPort = this.resources.getInt(ConfigConst.TCP_MULTICAST_PORT); *************** *** 203,221 **** } ! if (mPort != -1) { ! try { ! mca.setAddress(new URI("udp://" + s + ":" + mPort)); ! } catch (java.net.URISyntaxException e) { ! log.error(e); ! return; ! } ! } else { ! try { ! mca.setAddress(new URI("udp://" + s)); ! } catch (java.net.URISyntaxException e) { ! log.error(e); ! return; ! } ! } int mSize = -1; --- 192,197 ---- } ! if (mPort != -1) ! nc.setMulticastPort(mPort); int mSize = -1; *************** *** 227,269 **** if (mSize > -1) { ! mca.setSize(mSize); } - - address.addMulticastAddress(mca); } s = this.resources.getString(ConfigConst.TCP_IPADDRESS_SOURCE); ! if (ConfigConst.ANY_ALL.equalsIgnoreCase(s)) { ! try { ! String uri = "tcp://" + DEFAULT_IP_ADDRESS + ":" + port; - - System.err.println("Setting TCP: " + uri); ! address.setAddress(new URI(uri)); ! address.setPortRange(1); ! ! } catch (java.net.URISyntaxException e) { ! log.error(e); ! return; ! } ! } else { ! try { ! String uri = "tcp://" ! + this.resources.getString(ConfigConst.TCP_IPADDRESS) ! + ":" + port; ! System.out.println("Setting TCP: " + uri); ! address.setAddress(new URI(uri)); ! } catch (java.net.URISyntaxException e) { ! log.error(e); ! return; ! } ! address.setPortRange(port); } - transport.addAddress(address); - addTransport(transport); } --- 203,236 ---- if (mSize > -1) { ! nc.setMulticastSize(mSize); } } s = this.resources.getString(ConfigConst.TCP_IPADDRESS_SOURCE); ! nc.setTcpEnabled(true); ! nc.setTcpOutgoing(true); ! nc.setTcpIncoming(true); ! ! if (port == -1) { ! nc.setTcpIncoming(false); ! nc.setTcpInterfaceAddress(null); ! } else if (ConfigConst.ANY_ALL.equalsIgnoreCase(s)) { ! String uri = "tcp://" + DEFAULT_IP_ADDRESS + ":" + port; ! System.err.println("Setting TCP: " + uri); ! ! nc.setTcpInterfaceAddress(DEFAULT_IP_ADDRESS); ! nc.setTcpPort(port); } else { ! String uri = "tcp://" ! + this.resources.getString(ConfigConst.TCP_IPADDRESS) ! + ":" + port; ! System.out.println("Setting TCP: " + uri); ! nc.setTcpInterfaceAddress(s); ! nc.setTcpPort(port); } } *************** *** 327,336 **** r.add("tcp://" + rdvString); } else { ! try { ! r.add(new URI(rdvString)); ! } catch (URISyntaxException e) { ! // TODO Auto-generated catch block ! e.printStackTrace(); ! } } } --- 294,298 ---- r.add("tcp://" + rdvString); } else { ! r.add(rdvString); } } *************** *** 359,362 **** --- 321,325 ---- String autoUri = this.resources.getString(ConfigConst.RENDEZVOUS_AUTO_URI); setAutoUri(autoUri); + log.info("set autouri rendevous: " + autoUri); } Index: ConfigurationService.java =================================================================== RCS file: /cvsroot/jxtaim/jxtaim/src/vsis/im/util/config/ConfigurationService.java,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** ConfigurationService.java 20 Mar 2006 18:07:21 -0000 1.14 --- ConfigurationService.java 27 Nov 2008 18:33:37 -0000 1.15 *************** *** 40,46 **** import net.jxta.document.MimeMediaType; import net.jxta.document.StructuredDocument; - import net.jxta.ext.config.AbstractConfigurator; - import net.jxta.ext.config.Configurator; - import net.jxta.impl.protocol.PlatformConfig; import org.apache.log4j.Logger; --- 40,43 ---- *************** *** 65,70 **** */ public class ConfigurationService implements ServiceProvider { - private static Configurator configurator = null; - public static final String SERVICE_NAME = "ConfiguratorService"; --- 62,65 ---- *************** *** 88,92 **** */ public void init() { - AbstractConfigurator.register(JxtaimConfigurator.class); } --- 83,86 ---- *************** *** 108,126 **** jimConfig.configure(); ! // XXX: THIS I REALLY DIRTY since configurator *must* be static ! // this thing actually constrains the class to be one instance ! // per classloader hierarchy only. So please take care for that ! configurator = jimConfig.newConfigurator(); ! ! // configurator.setHome(FS.getHome()); ! System.out.println("post configurator!"); ! // System.err.println("JXTA HOME: "+configurator.getHome()); ! configurator.save(); ! ! // jimConfig.save(".jxta/PlatformConfig"); initFontStore(); - log.info("Jxta-PlatformConfig-File created!"); } catch (Exception e) { log.error("Error while creating the PlatformConfig-File", e); --- 102,109 ---- jimConfig.configure(); ! System.out.println("juxim configurations parsed!"); initFontStore(); } catch (Exception e) { log.error("Error while creating the PlatformConfig-File", e); *************** *** 128,183 **** } ! public static class JxtaimConfigurator extends AbstractConfigurator { ! ! public JxtaimConfigurator() ! throws net.jxta.exception.ConfiguratorException { ! super(configurator); ! } ! ! public PlatformConfig createPlatformConfig(Configurator pc) ! throws net.jxta.exception.ConfiguratorException { ! Configurator c = (Configurator) pc; ! ! // if(!configured(c.getHome())) { ! // System.err.println("JXTA HOME: "+c.getHome()); ! // createConfig(c.getHome(), jimConfig.getPeerName()); ! // } ! // else { ! // System.err.println("YYYYYYYYYYYYYYYYYYYYY CALLLLLLLLLLED"); ! // } ! ! jimConfig.configureConfigurator(c); ! ! // try { ! // pc.getPlatformConfig().save(); ! ! // } catch (ConfiguratorException ce) { ! // ce.printStackTrace(); ! // } ! ! PlatformConfig cc = pc.getPlatformConfig(); ! ! Document doc = cc.getDocument(MimeMediaType.XMLUTF8); ! ! try { ! System.out.println("JXTAHOME=" + pc.getJXTAHome()); ! new File(pc.getJXTAHome()).mkdir(); ! log.info("writing platform config to '" + pc.getJXTAHome() ! + "/PlatformConfig" + "'"); ! File file = new File(c.getHome() + "/PlatformConfig"); ! if (!file.exists()) { ! file.createNewFile(); ! } ! FileOutputStream out = new FileOutputStream(file); ! doc.sendToStream(out); ! out.close(); ! log.info("platform config created: "+file.getAbsolutePath()); ! } catch (Exception e) { ! throw new net.jxta.exception.ConfiguratorException( ! "Error writing PlatformConfig", e); ! } ! ! return cc; ! } } --- 111,116 ---- } ! public JxtaConfigurator getJxtaConfigurator() { ! return jimConfig; } *************** *** 196,218 **** } - private static void createConfig(File home, String name) { - try { - InputStream is = getResourceInputStream("PlatformConfig.master"); - home.mkdirs(); - PlatformConfig platformConfig = (PlatformConfig) AdvertisementFactory - .newAdvertisement(MimeMediaType.XMLUTF8, is); - is.close(); - platformConfig.setName(name); - File newConfig = new File(home, "PlatformConfig"); - OutputStream op = new FileOutputStream(newConfig); - StructuredDocument doc = (StructuredDocument) platformConfig - .getDocument(MimeMediaType.XMLUTF8); - doc.sendToStream(op); - op.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - protected void initFontStore() { --- 129,132 ---- *************** *** 366,369 **** --- 280,288 ---- } + + public String getPeername() { + return jimConfig.getPeerName(); + } + public FontStore getFontStore() { return fontStore; Index: JxtaConfigurator.java =================================================================== RCS file: /cvsroot/jxtaim/jxtaim/src/vsis/im/util/config/JxtaConfigurator.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** JxtaConfigurator.java 16 Mar 2006 19:11:41 -0000 1.9 --- JxtaConfigurator.java 27 Nov 2008 18:33:37 -0000 1.10 *************** *** 45,50 **** import net.jxta.document.MimeMediaType; import net.jxta.exception.ConfiguratorException; ! import net.jxta.ext.config.*; ! import net.jxta.impl.protocol.PlatformConfig; import net.jxta.protocol.PeerAdvertisement; --- 45,51 ---- import net.jxta.document.MimeMediaType; import net.jxta.exception.ConfiguratorException; ! ! import net.jxta.platform.NetworkConfigurator; ! import net.jxta.platform.NetworkManager; import net.jxta.protocol.PeerAdvertisement; *************** *** 62,66 **** * @author Alexander Sack <as...@jw...> */ ! public class JxtaConfigurator { public final static int DEFAULT_HTTP_PORT = 9700; --- 63,67 ---- * @author Alexander Sack <as...@jw...> */ ! public abstract class JxtaConfigurator { public final static int DEFAULT_HTTP_PORT = 9700; *************** *** 168,179 **** return peerName; } - - public void addTransport(Transport transport) { - transports.add(transport); - } - - public List getTransports() { - return transports; - } public void setAutoRdvAddress(String adressUri) { --- 169,172 ---- *************** *** 270,353 **** private String autoRelayUri; ! public void configureConfigurator(Configurator c) throws net.jxta.exception.ConfiguratorException { - System.out.println("setting home: "); - System.out.println("setting home: " + FS.getHome().getPath()); - // TODO: this breaks the system ... we need to find another way? - // Configurator.setHome(FS.getHome()); - c.setName(getPeerName()); ! System.err.println("configuring: setting peername: " + getPeerName()); ! //c.addTransports(getTransports()); ! c.setTransports(getTransports()); ! ! System.err ! .println("configuring: adding transports: " + c.getTransports()); ! Iterator i = c.getTransports().iterator(); ! ! while(i.hasNext()) { ! ! Transport t = (Transport) i.next(); ! Iterator j = t.getAddresses().iterator(); ! ! while(j.hasNext()) ! { ! Address adr = (Address) j.next(); ! System.err.println("Address portrange = "+adr.getPortRange()); ! System.err.println("Address uri = "+adr.getAddress()); ! } ! ! } ! c.setRendezVousBootstrapAddress(null); ! c.setRelaysBootstrapAddress(null); ! //c.setRelaysDiscovery(false); ! if (rdvs != null) ! c.setRendezVous(rdvs); ! // c.addRendezVous(rdvs); ! c.setRendezVous(isRdv); ! try { ! if(this.autoRdvAddress != null) { ! c.setRendezVousBootstrapAddress(this.autoRdvAddress); ! System.out.println("auto rdv address set: "+this.autoRdvAddress); ! } ! } catch (ConfiguratorException e) { ! e.printStackTrace(); } System.err.println("configuring: setting rdvs: " + rdvs); if(relays != null) ! c.setRelays(relays); if(autoRelay) { ! try { ! c.setRelaysBootstrapAddress(new URI(autoRelayUri)); ! } catch (ConfiguratorException e) { ! // TODO Auto-generated catch block ! e.printStackTrace(); ! } catch (URISyntaxException e) { ! // TODO Auto-generated catch block ! e.printStackTrace(); ! } } if(autoRdv) { ! try { ! c.setRendezVousBootstrapAddress(new URI(autoUri)); ! } catch (ConfiguratorException e) { ! // TODO Auto-generated catch block ! e.printStackTrace(); ! } catch (URISyntaxException e) { ! // TODO Auto-generated catch block ! e.printStackTrace(); ! } ! } else { ! c.setRendezVousBootstrapAddress(null); } ! System.err.println("configuring: setting relays: " + relays); } --- 263,300 ---- private String autoRelayUri; ! public void configureRdvRelay(NetworkConfigurator nc) throws net.jxta.exception.ConfiguratorException { ! nc.clearRelaySeedingURIs(); ! nc.setUseOnlyRelaySeeds(true); ! nc.clearRendezvousSeedingURIs(); ! nc.setUseOnlyRendezvousSeeds(true); ! System.err.println ("adding Rdv Seeds: "+rdvs); if (rdvs != null) ! nc.setRendezvousSeeds((java.util.Set<java.lang.String>) rdvs); ! // nc.setRendezVous(isRdv); XXX: not sure what to do here ! if(this.autoRdvAddress != null) { ! nc.addRdvSeedingURI(this.autoRdvAddress); ! System.err.println("auto rdv address set: "+this.autoRdvAddress); } System.err.println("configuring: setting rdvs: " + rdvs); if(relays != null) ! nc.setRelaySeedURIs(relays); if(autoRelay) { ! nc.addRelaySeedingURI(autoRelayUri); ! log.info ("configured seeding uri (relay) "+ autoRelayUri); } if(autoRdv) { ! nc.addRdvSeedingURI(autoUri); ! log.info ("configured seeding uri (rdv) "+ autoUri); } ! log.info("configuring: setting relays: " + relays); } *************** *** 391,395 **** this.autoRelay = autoRelay; } - public void setAutoRelayUri(String autoRelayUri) { --- 338,341 ---- *************** *** 397,440 **** } ! public Configurator newConfigurator() { ! ! Configurator configurator = null; ! try { ! PlatformConfig config = (PlatformConfig) ! AdvertisementFactory.newAdvertisement(MimeMediaType.XMLUTF8, new FileInputStream(FS.getHome().getPath() + "/" + "PlatformConfig")); ! configurator = new Configurator(config); ! } catch (FileNotFoundException e1) { ! log.debug("no PlatformConfig found. Generating new", e1); ! } catch (IOException e1) { ! log.error(e1); ! } ! ! if(configurator == null) ! { if(!isRdv) { System.err.println("EDGE Profile configurator."); ! configurator = new net.jxta.ext.config.Configurator(FS.getHome().toURI(), Profile.EDGE); } else { System.err.println("RDV Profile configurator."); ! configurator = new net.jxta.ext.config.Configurator(FS.getHome().toURI(), Profile.RENDEZVOUS); ! } ! } else { ! System.err.println("using old configurator from PlatformConfig"); ! } ! ! configurator.setSecurity(this.principal, this.credential); ! ! try { ! configureConfigurator(configurator); ! ! System.out.println("PlatformConfig = " +configurator.getPlatformConfig()); ! } catch (ConfiguratorException e) { ! e.printStackTrace(); ! log.error(e); ! UIUtils.displayErrorNoChance("Configuration Error in base system."); } - return configurator; } --- 343,369 ---- } + protected abstract void configureNetworkConfiguratorHttp(NetworkConfigurator nc); + protected abstract void configureNetworkConfiguratorTcp(NetworkConfigurator nc); ! public void configureNetworkManager(NetworkManager nm) ! throws java.io.IOException, net.jxta.exception.ConfiguratorException { ! NetworkConfigurator nc = nm.getConfigurator(); if(!isRdv) { System.err.println("EDGE Profile configurator."); ! nc.setMode(NetworkConfigurator.EDGE_NODE); } else { System.err.println("RDV Profile configurator."); ! nc.setMode(NetworkConfigurator.RDV_NODE); } + + nc.setPrincipal(this.principal); + nc.setPassword(this.credential); + + configureNetworkConfiguratorHttp(nc); + configureNetworkConfiguratorTcp(nc); + + configureRdvRelay(nm.getConfigurator()); + // transports } |