Return-Path: Delivered-To: apmail-commons-user-archive@www.apache.org Received: (qmail 16670 invoked from network); 18 Feb 2011 17:59:47 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 18 Feb 2011 17:59:47 -0000 Received: (qmail 5251 invoked by uid 500); 18 Feb 2011 17:59:45 -0000 Delivered-To: apmail-commons-user-archive@commons.apache.org Received: (qmail 4925 invoked by uid 500); 18 Feb 2011 17:59:42 -0000 Mailing-List: contact user-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Commons Users List" Delivered-To: mailing list user@commons.apache.org Delivered-To: moderator for user@commons.apache.org Received: (qmail 85898 invoked by uid 99); 18 Feb 2011 17:41:49 -0000 X-ASF-Spam-Status: No, hits=-0.0 required=5.0 tests=RCVD_IN_DNSWL_LOW,SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (athena.apache.org: local policy) MIME-Version: 1.0 Date: Fri, 18 Feb 2011 18:40:57 +0100 Message-ID: Subject: [daemon] From: Matthias Altmann To: user@commons.apache.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Hi @all, I'm trying to run a daemon for JXTA, a Java Framework for P2P networks. Here I used the Java Implementation with the following code integrating JSVC: package privatenet; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.net.URISyntaxException; import java.util.Properties; import net.jxta.discovery.DiscoveryService; import net.jxta.document.MimeMediaType; import net.jxta.document.StructuredDocumentFactory; import net.jxta.document.XMLElement; import net.jxta.exception.PeerGroupException; import net.jxta.id.IDFactory; import net.jxta.peergroup.NetPeerGroupFactory; import net.jxta.peergroup.PeerGroup; import net.jxta.peergroup.PeerGroupID; import net.jxta.platform.ModuleSpecID; import net.jxta.platform.NetworkConfigurator; import net.jxta.protocol.ConfigParams; import net.jxta.protocol.ModuleImplAdvertisement; import net.jxta.protocol.PeerGroupAdvertisement; import net.jxta.rendezvous.RendezvousEvent; import net.jxta.rendezvous.RendezVousService; import net.jxta.rendezvous.RendezvousListener; import org.apache.log4j.Logger; import org.apache.log4j.PropertyConfigurator; import org.apache.commons.daemon.Daemon; import org.apache.commons.daemon.DaemonContext; public class Rendezvous implements RendezvousListener,Daemon { RendezVousService netpgRendezvous; RendezVousService apppgRendezvous; private static Logger logger; private String jxtaHome; private PeerGroup netPeerGroup; private PeerGroup newGroup; private DiscoveryService discovery; private NetworkConfigurator configurator; // our chosen peer ID private String peerID =3D "urn:jxta:uuid-79B6A084D3264DF8B641867D926C48D9F8BA10F44BA74475ABE2BB568892= B0DC03"; // parameters that define our private JXTA NetPeerGroup String NetPeerGroupID=3D"urn:jxta:uuid-8B33E028B054497B8BF9A446A224B1FF0= 2"; String NetPeerGroupName=3D"My NetPG"; String NetPeerGroupDesc=3D"A Private Net Peer Group"; // ---------------------------------------------------------------------= ------------ public void initRdv() { jxtaHome =3D System.getProperty("JXTA_HOME"); if( null =3D=3D jxtaHome ) { logger.info("JXTA_HOME null. Exiting."); System.out.println("JXTA_HOME null. Exiting."); System.exit(1); } logger =3D initLogger(); clearCache(new File(jxtaHome,"cm")); logger.info("Private " + this.getClass().getName() + " Starting"); } // ---------------------------------------------------------------------= ----------- /** * Load everything that is basically needed to start the Rendezvous. * Open configuration files, init the logger, create the ServerSockets, the Threads, etc ... * * @see org.apache.commons.daemon.Daemon#init(org.apache.commons.daemon.= DaemonContext) */ public void init(DaemonContext dc) throws Exception { // initialize the RDV this.initRdv(); // configure JXTA this.configurator =3D this.configureJXTA(); } public void start() throws Exception { try { startJXTA(); createPeerGroup(); waitForQuit(); } catch (PeerGroupException e) { e.printStackTrace(); logger.warn("Exiting."); System.exit(0); } catch (Exception e) { logger.warn("Unable to start JXTA platform. Exiting."); e.printStackTrace(); System.exit(0); } } /** * Stop the Rendezvous/Relay. * * @see org.apache.commons.daemon.Daemon#stop() */ public void stop() throws Exception { logger.info("Stop Rdv ..."); // stop JXTA this.stopJXTA(); } /** * Destroy any object created in init(). * * @see org.apache.commons.daemon.Daemon#destroy() */ public void destroy() { logger.info("Destroy Rdv ..."); // only reset the logger logger =3D null; } // ---------------------------------------------------------------------= -------------------- private void startJXTA() throws PeerGroupException, Exception { logger.info("Starting JXTA platform"); NetPeerGroupFactory factory; try { factory =3D new NetPeerGroupFactory( (ConfigParams)configurator.getPlatformConfig(), new File(jxtaHome).toURI(), IDFactory.fromURI(new URI(NetPeerGroupID)), NetPeerGroupName, (XMLElement) StructuredDocumentFactory.newStructuredDocument(MimeMediaType.XMLUTF8, "desc", NetPeerGroupName) ); } catch(URISyntaxException e) { throw new Exception(e.getMessage()); } netPeerGroup =3D factory.getInterface(); // The rendezvous service for NetPeerGroup netpgRendezvous =3D netPeerGroup.getRendezVousService(); netpgRendezvous.addListener(this); netpgRendezvous.startRendezVous(); // The NetPeerGroup discovery service discovery =3D netPeerGroup.getDiscoveryService(); logger.info("Platform started"); } private void stopJXTA() throws PeerGroupException, Exception { logger.info("Stopping JXTA platform"); /**< Stop the Rendezvous Service **/ netpgRendezvous.stopRendezVous(); logger.info("Platform stopped"); } // ---------------------------------------------------------------------= -------------------- private void createPeerGroup() throws Exception, PeerGroupException { // The new-application subgroup parameters. String name =3D "My App Group"; String desc =3D "My App Group Description"; String gid =3D "urn:jxta:uuid-79B6A084D3264DF8B641867D926C48D902"; String specID =3D "urn:jxta:uuid-309B33F10EDF48738183E3777A7C3DE9C5BFE5794E974DD99AC7D409F568= 6F3306"; StringBuilder sb =3D new StringBuilder("=3DCreating group: "); sb.append(name).append(", "); sb.append(desc).append(", "); sb.append(gid).append(", "); sb.append(specID); logger.info(sb.toString()); ModuleImplAdvertisement implAdv =3D netPeerGroup.getAllPurposePeerGroupImplAdvertisement(); ModuleSpecID modSpecID =3D (ModuleSpecID )IDFactory.fromURI(new URI(specID)); implAdv.setModuleSpecID(modSpecID); // Publish the Peer Group implementation advertisement. discovery.publish(implAdv); discovery.remotePublish(null, implAdv); // Create the new group using the group ID, advertisement, name, and description PeerGroupID groupID =3D (PeerGroupID )IDFactory.fromURI(new URI(gid))= ; newGroup =3D netPeerGroup.newGroup(groupID,implAdv,name,desc); // Start the rendezvous for our applcation subgroup. apppgRendezvous =3D newGroup.getRendezVousService(); apppgRendezvous.addListener(this); apppgRendezvous.startRendezVous(); // Publish the group remotely. newGroup() handles the local publishi= ng. PeerGroupAdvertisement groupAdv =3D newGroup.getPeerGroupAdvertisemen= t(); discovery.remotePublish(null, groupAdv); logger.info("Private Application newGroup =3D " + name + " created and published"); } // ---------------------------------------------------------------------= -------------------- private NetworkConfigurator configureJXTA() { logger.info("Configuring platform"); logger.info("RDV_HOME =3D " + jxtaHome); configurator =3D new NetworkConfigurator(); configurator.setHome(new File(jxtaHome)); configurator.setPeerId(peerID); configurator.setName("My Peer Name"); configurator.setPrincipal("ofno"); configurator.setPassword("consequence"); configurator.setDescription("Private Rendezvous"); configurator.setUseMulticast(false); URI seedingURI; seedingURI =3D new File("seeds.txt").toURI(); configurator.addRdvSeedingURI(seedingURI); configurator.addRelaySeedingURI(seedingURI); configurator.setMode(NetworkConfigurator.RDV_SERVER + NetworkConfigurator.RELAY_SERVER); configurator.setUseOnlyRelaySeeds(true); configurator.setUseOnlyRendezvousSeeds(true); configurator.setTcpEnabled(true); configurator.setTcpIncoming(true); configurator.setTcpOutgoing(true); try { configurator.save(); } catch(IOException e) { e.printStackTrace(); System.exit(1); } logger.info("Platform configured and saved"); return configurator; } // ---------------------------------------------------------------------= -------------------- public void rendezvousEvent(RendezvousEvent event) { String eventDescription; int eventType; eventType =3D event.getType(); switch( eventType ) { case RendezvousEvent.RDVCONNECT: eventDescription =3D "RDVCONNECT"; break; case RendezvousEvent.RDVRECONNECT: eventDescription =3D "RDVRECONNECT"; break; case RendezvousEvent.RDVDISCONNECT: eventDescription =3D "RDVDISCONNECT"; break; case RendezvousEvent.RDVFAILED: eventDescription =3D "RDVFAILED"; break; case RendezvousEvent.CLIENTCONNECT: eventDescription =3D "CLIENTCONNECT"; break; case RendezvousEvent.CLIENTRECONNECT: eventDescription =3D "CLIENTRECONNECT"; break; case RendezvousEvent.CLIENTDISCONNECT: eventDescription =3D "CLIENTDISCONNECT"; break; case RendezvousEvent.CLIENTFAILED: eventDescription =3D "CLIENTFAILED"; break; case RendezvousEvent.BECAMERDV: eventDescription =3D "BECAMERDV"; break; case RendezvousEvent.BECAMEEDGE: eventDescription =3D "BECAMEEDGE"; break; default: eventDescription =3D "UNKNOWN RENDEZVOUS EVENT"; } logger.info("RendezvousEvent: event =3D " + eventDescription + " from peer =3D " + event.getPeer= ()); } // ---------------------------------------------------------------------= -------------------- private Logger initLogger() { // See http://logging.apache.org/log4j/docs/manual.html // Allows for deepest control over Log4J config. System.setProperty("log4j.defaultInitOverride", "true"); Logger logger=3Dnull; try { ClassLoader cl =3D this.getClass().getClassLoader(); InputStream is =3D cl.getResourceAsStream("privatenet/log4j.proper= ties"); Properties p =3D new Properties(); p.load(is); is.close(); org.apache.log4j.PropertyConfigurator.configure(p); logger =3D Logger.getLogger(this.getClass()); } catch (Exception e) { e.printStackTrace(); } finally { return logger; } } // ---------------------------------------------------------------------= -------------------- private static void clearCache(final File rootDir) { try { if (rootDir.exists()) { File[] list =3D rootDir.listFiles(); for (File aList : list) { if (aList.isDirectory()) { clearCache(aList); } else { aList.delete(); } } } rootDir.delete(); System.out.println("Cache component " + rootDir.toString() + " cleared."); } catch (Throwable t) { logger.info("Unable to clear " + rootDir.toString(), t); } } // ---------------------------------------------------------------------= -------------------- synchronized public void waitForQuit() { try { wait(); } catch (InterruptedException e) { e.printStackTrace(); } } } Then I packaged this code into jar which I delivered to Jsvc with: jsvc -verbose -debug -Djava.io.tmpdir=3D/var/tmp -outfile /usr/jxta/out.log -errfile /usr/jxta/error.log -pidfile /var/run/rdv.pid -cp /usr/share/java/commons-daemon.jar:/usr/jxta/rdv.jar:/usr/jxta/lib/bcprov-j= dk14.jar:/usr/jxta/lib/javax.servlet.jar:/usr/jxta/lib/jdom.jar:/usr/jxta/l= ib/jxta.jar:/usr/jxta/lib/jxtaext.jar:/usr/jxta/lib/log4j-1.2.16.jar:/usr/j= xta/lib/org.mortbay.jetty.jar:/usr/jxta/lib/swixml.jar:/usr/jxta/lib/saxpat= h.jar:/usr/jxta/lib/jaxen-core.jar:/usr/jxta/lib/jaxen-jdom.jar:/usr/jxta/l= ib/args4j-2.0.7.jar privatenet.Rendezvous error.log gives me an Nullpointer Exception showing: Using default JVM in /usr/lib/jvm/java-6-sun-1.6.0.22/jre/lib/i386/client/libjvm.so Attemtping to load library /usr/lib/jvm/java-6-sun-1.6.0.22/jre/lib/i386/client/libjvm.so JVM library /usr/lib/jvm/java-6-sun-1.6.0.22/jre/lib/i386/client/libjvm.so loaded JVM library entry point found (0x010393A0) +-- DUMPING JAVA VM CREATION ARGUMENTS ----------------- | Version: 0x010004 | Ignore Unrecognized Arguments: True | Extra options: 4 | "-verbose" (0x00000000) | "-Djava.io.tmpdir=3D/var/tmp" (0x00000000) | "-Djava.class.path=3D/usr/share/java/commons-daemon.jar:/usr/jxta/rdv.j= ar:/usr/jxta/lib/bcprov-jdk14.jar:/usr/jxta/lib/javax.servlet.jar:/usr/jxta= /lib/jdom.jar:/usr/jxta/lib/jxta.jar:/usr/jxta/lib/jxtaext.jar:/usr/jxta/li= b/log4j-1.2.16.jar:/usr/jxta/lib/org.mortbay.jetty.jar:/usr/jxta/lib/swixml= .jar:/usr/jxta/lib/saxpath.jar:/usr/jxta/lib/jaxen-core.jar:/usr/jxta/lib/j= axen-jdom.jar:/usr/jxta/lib/args4j-2.0.7.jar" (0x00000000) +------------------------------------------------------- Java VM created successfully Class org/apache/commons/daemon/support/DaemonLoader found Native methods registered java_init done Daemon loading... java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessor= Impl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethod= AccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.apache.commons.daemon.support.DaemonLoader.load(DaemonLoader= .java:156) Caused by: java.lang.NullPointerException at privatenet.Rendezvous.initRdv(Unknown Source) at privatenet.Rendezvous.init(Unknown Source) ... 5 more Cannot load daemon java_load failed Service exit with a return value of 3 Do you have any idea, where the problem is? Help would be really appreciated --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@commons.apache.org For additional commands, e-mail: user-help@commons.apache.org