Skip to main content

Several JXTA peers within one VM

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

Hello,

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(WorldPeerGroupFactory.java:258)<br />
	at net.jxta.peergroup.WorldPeerGroupFactory.(WorldPeerGroupFactory.java:140)<br />
	at net.jxta.peergroup.NetPeerGroupFactory.(NetPeerGroupFactory.java:122)<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.
yclian
Offline
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?

Thanks,
Yuen-Chi Lian

thenetworker
Offline
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.

pepsi_
Offline
Joined: 2007-08-15
Points: 0

Thanks for answering.

It is because of [url=http://en.wikipedia.org/wiki/OSGi]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.

@thenetworker:
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) ...

bondolo
Offline
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 : https://jxta-benchmarking.dev.java.net/ for examples.