/** {@inheritDoc} */ @Override public void run() { while (true) { try { Thread.currentThread().setName( Locale.getString(JanusJXTAGroup.class, "DISCOVER_THREAD_NAME", //$NON-NLS-1$ getPeerGroup().getPeerName())); } catch(AssertionError e) { throw e; } catch(Throwable _) { // } // TODO make all this configurations try { PipeUtil.discoverAdvertisements(getPeerGroup(), null, this); Thread.sleep(1000); } catch (AssertionError ae) { throw ae; } catch (InterruptedException e) { // } } }
/** Broadcast the given message. * * @param message describes the message and its context. * @throws IOException */ public void broadcastMessage(Message message) throws IOException { // very hard implementation, will modified to use propagate List<PipeAdvertisement> list = PipeUtil.getAdvertisements(getPeerGroup(), null); for (PipeAdvertisement pipeAdvertisement : list) { // make sure it is not us if (!this.networkHandler.getKernelAddress().toString().equals(pipeAdvertisement.getName())) { sendMessage(message, true, pipeAdvertisement); } } }
private PipeAdvertisement findCandidateKernel() { List<PipeAdvertisement> list = PipeUtil.getAdvertisements(getPeerGroup(), null); while (!list.isEmpty()) { int idx = RandomNumber.nextInt(list.size()); PipeAdvertisement a = list.get(idx); if (this.networkHandler.getKernelAddress().toString().equals(a.getName())) { list.remove(idx); } else { return a; } } return null; }
/** {@inheritDoc} */ @Override public void run() { try { Thread.currentThread().setName( Locale.getString(JanusJXTAGroup.class, "SERVER_THREADS_NAME", //$NON-NLS-1$ getPeerGroup().getPeerName())); } catch(AssertionError e) { throw e; } catch(Throwable _) { // } try { if (this.serverPipe == null) { this.serverPipe = new JxtaServerPipe( getPeerGroup(), PipeUtil.getAdvertisement( getPeerGroup(), getPeerGroup().getPeerName(), PipeService.UnicastType, null)); // lock forever this.serverPipe.setPipeTimeout(0); } while (true) { JxtaBiDiPipe bidiPipe = this.serverPipe.accept(); if (bidiPipe != null) { IncommingConnectionHandler handler = new IncommingConnectionHandler(); handler.attachBiDiPipe(bidiPipe); } } } catch (AssertionError ae) { throw ae; } catch (IOException e) { Logger.getLogger(getClass().getName()).severe(Throwables.toString(e)); } }
/** * Join the group. * * @throws Exception */ public void join() throws Exception { synchronized (this.joined) { if (!this.joined) { PipeAdvertisement pipeAdvertisment = PipeUtil.getAdvertisement(getPeerGroup(), getPeerGroup().getPeerName(), PipeService.UnicastType, null); DiscoveryService ds = getPeerGroup().getDiscoveryService(); ds.publish(pipeAdvertisment); ds.remotePublish(pipeAdvertisment); ExecutorService executors = this.networkHandler.getJXTAExecutorService(); executors.submit(new Server()); executors.submit(new PipeDiscover()); getPeerGroup().getRendezVousService().setAutoStart(true, 12000); this.joined = true; } } }