Skip to main content

Starting many peers with availableProcessors()

1 reply [Last post]
adrianoska
Offline
Joined: 2012-03-15
Points: 0

Hi there,

I'm a beginner in JXTA. I'm trying starting peers with availableProcessors(), but one error is shown: Only a single instance of the World Peer Group may be instantiated at a single time.

If someone can help me, I'll grateful.

I'm trying to do something as:

<div>public class Starter{</div><div>    int numProc;</div><div>    int tcpPort;</div><div>    final String nome = &quot;WORKER-&quot;;</div><div>    </div><div>    public Starter(){</div><div>        Runtime runtime = Runtime.getRuntime();</div><div>        numProc = runtime.availableProcessors();</div><div>        tcpPort = 9702;</div><div>    }</div><div>    </div><div>    public void start(){</div><div>        for(int i=0;i&lt;numProc;i++){</div><div>            Worker w = new Worker(nome+tcpPort, tcpPort);</div><div>            new Thread(w).start();</div><div>            tcpPort++;</div><div>            //try{Thread.sleep(2000);}catch(Exception e){}</div><div>        }</div><div>    }</div><div>    </div><div>    </div><div>    public static void main(String a[]){</div><div>        Starter starter = new Starter();</div><div>        starter.start();</div><div>    }</div><div>}</div><div><br /><br />and the method that starting JXTA in class Worker is:</div><div><br /><br /><div>private void startJxta(){</div><div>        try {</div><div>            excluirArquivosDiretorio(new File(new File(&quot;.&quot;+nome), nome));</div><div>            </div><div>            FileReader reader = new FileReader(&quot;Rendezvous_Relay.dat&quot;);</div><div>            BufferedReader leitor = new BufferedReader(reader);</div><div> </div><div>            String tcp = leitor.readLine();</div><div>            String http = leitor.readLine();</div><div> </div><div>            reader.close();</div><div>            leitor.close();</div><div>            </div><div>            manager = new NetworkManager(</div><div>                NetworkManager.ConfigMode.EDGE, nome, </div><div>                new File(new File(&quot;.&quot;+nome), nome).toURI());</div><div>            NetworkConfigurator networkConfigurator = </div><div>                    manager.getConfigurator();</div><div>            networkConfigurator.setTcpEnabled(true);</div><div>            networkConfigurator.setHttpEnabled(true);</div><div>            networkConfigurator.setTcpPort(tcpPort);</div><div>            networkConfigurator.setHttpPort(8080);</div><div>            networkConfigurator.setUseMulticast(false);</div><div>            networkConfigurator.addSeedRelay(new URI(tcp));</div><div>            networkConfigurator.addSeedRendezvous(new URI(tcp));</div><div>            //networkConfigurator.addSeedRelay(new URI(http));</div><div>            //networkConfigurator.addSeedRendezvous(new URI(http));</div><div>            manager.startNetwork();</div><div>        </div><div>            //Get the NetPeerGroup</div><div>            PeerGroup netPeerGroup = manager.getNetPeerGroup();</div><div>            // get the discovery service</div><div>            discovery = netPeerGroup.getDiscoveryService();</div><div>            pipeService = netPeerGroup.getPipeService();</div><div>            discovery.addDiscoveryListener(this);</div><div>            pipeID = IDFactory.newPipeID(PeerGroupID.worldPeerGroupID, nome.getBytes());</div><div>            </div><div>            if (manager.waitForRendezvousConnection(60000)) {</div><div>                jta.append(&quot;\n\nConectou com o Peer Rendezvous\n\n&quot;);</div><div>            } else {</div><div>                jta.append(&quot;\n\nN&atilde;o conectou com o Peer Rendezvous\n\n&quot;);</div><div>            }</div><div>        } catch (Exception e) {</div><div>            e.printStackTrace();</div><div>            jta.append(e.getMessage());</div><div>            System.exit(-1);</div><div>        }</div></div>

Would thus not need to start each peer separately.
I want show each peer into a JTextArea.

Thanks a lot.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
headgrowe
Offline
Joined: 2012-03-18
Points: 0

if you are running this workers on 1 machine you should change " excluirArquivosDiretorio(new File(new File("."+nome), nome));" each time...the name must be unique!