Skip to main content

How to restart NetworkManager ?

7 replies [Last post]
shaikh_sharique
Offline
Joined: 2010-06-17
Points: 0

i am trying to restart network manager by using
if (manager.isStarted())
{
manager.stopNetwork();
}
and then again calling

manager.startNetwork()

but it always give error message
"Only a single instance of the World Peer Group may be instantiated at a single time."

I think as stopNetwork() is a void method it do not wait for managet to stop and jump to next line which is startNetwork();

so is there any way I can hold ther start of Network manager before it completely stop?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
keesp
Offline
Joined: 2007-05-22
Points: 0

I'm not sure if there's a standard JXTA solutin, but you could try the following:

if (manager.isStarted())
{
manager.stopNetwork();
}
while( !manager.isStarted() ){
try{
Thread.sleep( 100 );
}
catch( InterruptedException ex ){
...
//break if this takes too long
}
}
manager.startNetwork();

Cheers

Kees

shaikh_sharique
Offline
Joined: 2010-06-17
Points: 0

hi, thanks for reply,
I had already think about this, and I try your code as well, but
when you call manager.isStarted() method after manager.stopNetwork(), then it is giving false value, which is expected, this indicate that Netwarkmanager is stop, but then, when I try to start network again, bingo, it gives same error message
"Only a single instance of the World Peer Group may be instantiated at a single time"

why isstarted method is giving false and then when you try to start network again it give error message, that manager is running?

thanks
sharique

adamman71
Offline
Joined: 2007-01-31
Points: 0

Looks like a bug to me. I have opened an incident: https://jxta-jxse.dev.java.net/issues/show_bug.cgi?id=387

I had not met this bug when I implemented this code (long time ago), but there has been quite some refactoring since. It may be some kind of cascade effect. Can't wait until we have a viable/operational system for automated tests...

As a workaround, I would suggest trying to remove the 'existing' WPG instance from the PG registry after stopping the NM and before (re)starting it, using;

PeerGroup.globalRegistry.unRegisterInstance(PeerGroupID.worldPeerGroupID, pg);

The reference to the WPG object instance (pg) can be obtained from the NPG by calling getParentGroup() or (most) probably from:

PeerGroup.globalRegistry.lookupInstance(PeerGroupID.worldPeerGroupID);

shaikh_sharique
Offline
Joined: 2010-06-17
Points: 0

Hi,
I am still getting same problem, I stop WorldPeerGroup after stopping NetworkManager and before starting NetworkManager, but it is still giving same problem.
Following is my code
if (manager != null) {
if (manager.isStarted()) {
manager.stopNetwork();
PeerGroup pg = PeerGroup.globalRegistry.lookupInstance(PeerGroupID.worldPeerGroupID);
PeerGroup.globalRegistry.unRegisterInstance(PeerGroupID.worldPeerGroupID, pg);

components.getInstance().setManager(new NetworkManager(configmode, peerinfo.getName(), ConfigurationFile.toURI()));
manager = components.getInstance().getManager();
NetworkConfigurator conf = manager.getConfigurator();

conf.setTcpEnabled(true);
conf.setTcpIncoming(true);
conf.setTcpOutgoing(true);

}

manager.startNetwork();

}

after running this code it is giving following error message
World Peer Group could not be instantiated.

net.jxta.exception.PeerGroupException: Failure instantiating local store
at net.jxta.impl.peergroup.StdPeerGroup.initFirst(StdPeerGroup.java:593)
at net.jxta.impl.peergroup.Platform.initFirst(Platform.java:211)
at net.jxta.impl.peergroup.GenericPeerGroup.init(GenericPeerGroup.java:968)
at net.jxta.peergroup.WorldPeerGroupFactory.newWorldPeerGroup(WorldPeerGroupFactory.java:306)
at net.jxta.peergroup.WorldPeerGroupFactory.(WorldPeerGroupFactory.java:178)
at net.jxta.peergroup.NetPeerGroupFactory.(NetPeerGroupFactory.java:203)
at net.jxta.platform.NetworkManager.startNetwork(NetworkManager.java:410)
.
.
.
.
.
.

adamman71
Offline
Joined: 2007-01-31
Points: 0

Hi Sharike,

It seems like the problem is solved on trunk. We are looking forward at releasing nightly/weekly builds/snapshots. Hence, you will be able to verify by this with latest code.

AdamMan71

shaikh_sharique
Offline
Joined: 2010-06-17
Points: 0

thanks Adamman,

from where exactly, I can download night build, and is there any change in logic of restarting NetworkManager, that you have suggested previously ?

thanks again for your help.

adamman71
Offline
Joined: 2007-01-31
Points: 0

We will send an email on the user mail list with information when ready.