Skip to main content

Several JXTA peers within one VM

4 replies [Last post]
Joined: 2007-08-15
Points: 0


I just want to ask whether it is possible to run several jxta peers within one java virtual machine. I've tried following thing:

<br />
  System.setProperty("JXTA_HOME", ".jxta/client1");<br />
  NetPeerGroupFactory factory = new NetPeerGroupFactory();<br />
  PeerGroup netPeerGroup = factory.getInterface();</p>
<p>  System.setProperty("JXTA_HOME", ".jxta/client2");<br />
  NetPeerGroupFactory factory2 = new NetPeerGroupFactory();<br />
  PeerGroup netPeerGroup2 = factory2.getInterface();<br />

This piece of code ends up to the following error message:

<br />
  Exception in thread "main" net.jxta.exception.PeerGroupException: Only a single instance of the World Peer Group may be instantiated at a single time.<br />
	at net.jxta.peergroup.WorldPeerGroupFactory.newWorldPeerGroup(<br />
	at net.jxta.peergroup.WorldPeerGroupFactory.(<br />
	at net.jxta.peergroup.NetPeerGroupFactory.(<br />

Has anyone a clue how to solve this problem? I don't want to start another VM for an additional peer.

Thanks in advance

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2007-04-29
Points: 0

I am writing an ESB which allows multiple JXTA endpoints to be set up. I intended to make each endpoint as one JXTA peer, it seems like I have to change my design now.. after knowing this problem.

An endpoint, at the inbound, polls advertisements from a peer group, etc., and at the outbound, publishes advertisements to a peer group.

I discovered this problem when I'm writing a unit test case that sets up one peer to listen and another to publish.

Anything that you can advice on i) the endpoitn design, ii) the unit test case?

Yuen-Chi Lian

Joined: 2003-06-13
Points: 0

JXTA is not designed to run several peers within a single VM.

System.setProperty("JXTA_HOME", ".jxta/client1");
System.setProperty("JXTA_HOME", ".jxta/client2");

will not work for sure.

However, why do you want to run two peers in a single VM? Are you just curious or do you have any business cases to support the need to do so?

Why not to run two peers in two separate VMs? I run 10 without any problems on my little laptop.

Joined: 2007-08-15
Points: 0

Thanks for answering.

It is because of [url=]OSGi[/url] why I want to run several peers within one single VM. I have converted the jxta lib into an osgi bundle. It works fine, but I can only instantiate one single peer at runtime.

I think it doesn't matter if the JXTA_HOME property has changed during runtime, because it's only used when creating a world/net peer group (for saving purposes) ...

Joined: 2003-06-11
Points: 0

The current JXSE implementation does not typically allow more than one Peer to be run within a single java virtual machine. Unfortunately there are a number of class statics and singletons that currently prevent more than a single peer.

There are work arounds though. The restriction of one peer per instance is actually per root class loader, not per JVM. So one technique is to create multiple class loaders containing separate jxta instances. This technique is used by the jxta-benchmarking project which to load each peer into a separate class loader. This technique does work quite well and has been used for jxta unit tests as well for benchmarking. See the source of : for examples.