La presentazione è in caricamento. Aspetta per favore

La presentazione è in caricamento. Aspetta per favore

Errata Corrige. DHT Routing (Tapestry) Tabella di routing (base k=4, digit d=4) Consideriamo il nodo x con id (x 1, x 2, x 3, x 4 ): (1+x 1, *, *, *)

Presentazioni simili


Presentazione sul tema: "Errata Corrige. DHT Routing (Tapestry) Tabella di routing (base k=4, digit d=4) Consideriamo il nodo x con id (x 1, x 2, x 3, x 4 ): (1+x 1, *, *, *)"— Transcript della presentazione:

1 Errata Corrige

2 DHT Routing (Tapestry) Tabella di routing (base k=4, digit d=4) Consideriamo il nodo x con id (x 1, x 2, x 3, x 4 ): (1+x 1, *, *, *) (x 1, 1+x 2, *, *) (x 1, x 2,1+x 3, *) (x 1, x 2, x 3, 1+x 4 ) (2+x 1, *, *, *) (x 1, 2+x 2, *, *) (x 1, x 2, 2+x 3, *) (x 1, x 2, x 3, 2+x 4 ) (3+x 1, *, *, *) (x 1, 3+x 2, *, *) (x 1, x 2, 3+x 3, *) (x 1, x 2, x 3, 3+x 4 ) (in totale sono k-1 d nodi -- n=d k -> d=log k n) Es. tabella di routing (1323 base 4) (2, 1, 3, 0) (1, 0, 2, 3) (1, 3, 3, 2) (1, 3, 2, 0) (3, 1, 2, 2) (1, 1, 1, 3) (1, 3, 0, 1) (1, 3, 2, 1) (0, 3, 2, 1) (1, 2, 1, 2) (1, 3, 1, 1) (1, 3, 2, 2)

3 DHT Routing (Tapestry) Tabella di routing (base k=4, digit d=4) Consideriamo il nodo x con id (x 1, x 2, x 3, x 4 ): (1+x 1, *, *, *) (x 1, 1+x 2, *, *) (x 1, x 2,1+x 3, *) (x 1, x 2, x 3, 1+x 4 ) (2+x 1, *, *, *) (x 1, 2+x 2, *, *) (x 1, x 2, 2+x 3, *) (x 1, x 2, x 3, 2+x 4 ) (3+x 1, *, *, *) (x 1, 3+x 2, *, *) (x 1, x 2, 3+x 3, *) (x 1, x 2, x 3, 3+x 4 ) (in totale sono k-1 d nodi -- n=k d -> d=log k n) Es. tabella di routing (1323 base 4) (2, 1, 3, 0) (1, 0, 2, 3) (1, 3, 3, 2) (1, 3, 2, 0) (3, 1, 2, 2) (1, 1, 1, 3) (1, 3, 0, 1) (1, 3, 2, 1) (0, 3, 2, 1) (1, 2, 1, 2) (1, 3, 1, 1) (1, 3, 2, 2)

4 Koorde m.lookup(k,ks,i) 1if k (m, m.successor] return successor 2else if i (m, m.successor] 3 return d.lookup(k,ks<<1, i topbit(ks)) 4 else 5 return m.successor.lookup(k,ks,i) Cerchiamo il predecessore del nodo immaginario? Passiamo al nuovo nodo del grafo di de Bruijn Il passo 3 viene eseguito al massimo b volte Quante volte eseguiamo il passo 5, vale a dire quanto impieghiamo per trovare il predecessore di un nodo immaginario?

5 Koorde m.lookup(k,ks,i) 1if k (m, m.successor] return successor 2else if i [m, m.successor) 3 return d.lookup(k,ks<<1, i topbit(ks)) 4 else 5 return m.successor.lookup(k,ks,i) Cerchiamo il predecessore del nodo immaginario? Passiamo al nuovo nodo del grafo di de Bruijn Il passo 3 viene eseguito al massimo b volte Quante volte eseguiamo il passo 5, vale a dire quanto impieghiamo per trovare il predecessore di un nodo immaginario?

6 Programming with JXTA Hello World Peer discovery

7 JXTA: Hello World Requirement Java SDK (http://java.sun.com)[jdk1.6.0_03] Java SDK (http://java.sun.com)[jdk1.6.0_03]http://java.sun.com JXTA (http://download.jxta.org/index.html) [JXTA 2.5] JXTA (http://download.jxta.org/index.html) [JXTA 2.5]http://download.jxta.org/index.html) jxse-lib-2.5jxse-tutorials-2.5jxse-doc-2.5

8 JXTA: Hello World Compilare usando JXTA javac -classpath.\lib\jxta.jar SimpleJxtaApp.java Lanciare un applicazione java -classpath.\lib\jxta.jar.\lib\bcprov-jdk14.jar;. SimpleJxtaApp

9 JXTA: Hello World import net.jxta.platform.NetworkManager; import java.text.MessageFormat; /** * A example of strating and stopping JXTA */ public class HelloWorld { /** * Main method args none defined */ public static void main(String args[]) { NetworkManager manager = null; try { manager = new NetworkManager(NetworkManager.ConfigMode.EDGE, "HelloWorld"); System.out.println("Starting JXTA"); manager.startNetwork(); System.out.println("JXTA Started"); } catch (Exception e) { e.printStackTrace(); System.exit(-1); } System.out.println("Waiting for a rendezvous connection"); boolean connected = manager.waitForRendezvousConnection(12000); System.out.println(MessageFormat.format("Connected :{0}", connected)); System.out.println("Stopping JXTA"); manager.stopNetwork(); } }

10 JXTA: Configurazione

11

12

13 Demo

14 Programming with JXTA Peer discovery Gli advertisement vengono mantenuti nella cache di JXTA (./.jxta/cm) Gli advertisement vengono mantenuti nella cache di JXTA (./.jxta/cm) In particolare per ogni gruppo sarà presente una sottodirectory In particolare per ogni gruppo sarà presente una sottodirectory./.jxta/cm/jxta-NetGroup./.jxta/cm/jxta-NetGroup./.jxta/cm/group-ID./.jxta/cm/group-ID Le directory contengono tre tipi di file Le directory contengono tre tipi di file *.idx file, indice record-offset.tbl, entry list advertisement.tbl, advertisement

15 Programming with JXTA Peer discovery Per leggere i messaggi dalla cache si usa il metodo getLocalAdvertisement(); Per leggere i messaggi dalla cache si usa il metodo getLocalAdvertisement(); Per scrivere nella cache si usa invece il metodo getRemoteAdvertisement(); (il quale invia un messaggio di discovery e attende la risposta). Per scrivere nella cache si usa invece il metodo getRemoteAdvertisement(); (il quale invia un messaggio di discovery e attende la risposta). Come si ottiene la risposta Come si ottiene la risposta Si può aspettare e successivamente controllare la propria cache (getLocalAdvertisement()) Si può utilizzare un Discovery Listner (utilizzato nella demo).

16 import net.jxta.discovery.DiscoveryEvent; import net.jxta.discovery.DiscoveryListener; import net.jxta.discovery.DiscoveryService; import net.jxta.document.Advertisement; import net.jxta.peergroup.PeerGroup; import net.jxta.platform.NetworkManager; import net.jxta.protocol.DiscoveryResponseMsg; import java.io.File; import java.util.Enumeration; public class DiscoveryClient implements DiscoveryListener { private transient NetworkManager manager; private transient DiscoveryService discovery; //Constructor for the DiscoveryClient public DiscoveryClient() { try { manager = new NetworkManager(NetworkManager.ConfigMode.ADHOC, "DiscoveryClient", new File(new File(".cache"), "DiscoveryClient").toURI()); manager.startNetwork(); } catch (Exception e) { e.printStackTrace(); System.exit(-1); } // Get the NetPeerGroup PeerGroup netPeerGroup = manager.getNetPeerGroup(); // get the discovery service discovery = netPeerGroup.getDiscoveryService(); } Programming with JXTA Per instanziare JXTA Per discovery

17 // main args command line args public static void main(String args[]) { DiscoveryClient disocveryClient = new DiscoveryClient(); disocveryClient.start(); } /** * loop forever attempting to discover advertisements every minute */ public void start() { long waittime = 60 * 1000L; try { // Add ourselves as a DiscoveryListener for DiscoveryResponse events discovery.addDiscoveryListener(this); discovery.getRemoteAdvertisements( null, // no specific peer (propagate) DiscoveryService.ADV // Adv type(DiscoveryService.ADV null, // Attribute = any null, // Value = any 1, // one advertisement response is all we are looking for null); // no query specific listener. we are using a global listener Programming with JXTA

18 while (true) { // wait a bit before sending a discovery message try { System.out.println("Sleeping for :" + waittime); Thread.sleep(waittime); } catch (Exception e) { // ignored } } System.out.println("Sending a Discovery Message"); // look for any peer discovery.getRemoteAdvertisements( // no specific peer (propagate) null, // Adv type DiscoveryService.ADV, // Attribute = name "Name", // Value = the tutorial "Discovery tutorial", // one advertisement response is all we are looking for 1, // no query specific listener. we are using a global listener null); } } catch (Exception e) { e.printStackTrace(); } Programming with JXTA

19 /** * This method is called whenever a discovery response is received, which are * either in response to a query we sent, or a remote publish by another node ev the discovery event */ public void discoveryEvent(DiscoveryEvent ev) { DiscoveryResponseMsg res = ev.getResponse(); // let's get the responding peer's advertisement System.out.println(" [ Got a Discovery Response [" + res.getResponseCount() + " elements] from peer : " + ev.getSource() + " ]"); Advertisement adv; Enumeration en = res.getAdvertisements(); if (en != null) { while (en.hasMoreElements()) { adv = (Advertisement) en.nextElement(); System.out.println(adv); } /** * Stops the platform */ public void stop() { // Stop JXTA manager.stopNetwork(); } Programming with JXTA

20 import net.jxta.discovery.DiscoveryEvent; import net.jxta.discovery.DiscoveryListener; import net.jxta.discovery.DiscoveryService; import net.jxta.document.Advertisement; import net.jxta.document.AdvertisementFactory; import net.jxta.id.IDFactory; import net.jxta.peergroup.PeerGroup; import net.jxta.peergroup.PeerGroupID; import net.jxta.pipe.PipeService; import net.jxta.platform.NetworkManager; import net.jxta.protocol.DiscoveryResponseMsg; import net.jxta.protocol.PipeAdvertisement; import java.io.File; import java.util.Enumeration; public class DiscoveryServer implements DiscoveryListener { private transient NetworkManager manager; private transient DiscoveryService discovery; public DiscoveryServer() { try { manager = new NetworkManager(NetworkManager.ConfigMode.ADHOC, "DiscoveryServer", new File(new File(".cache"), "DiscoveryServer").toURI()); manager.startNetwork(); } catch (Exception e) { e.printStackTrace(); System.exit(-1); } PeerGroup netPeerGroup = manager.getNetPeerGroup(); // get the discovery service discovery = netPeerGroup.getDiscoveryService(); } Programming with JXTA

21 /** * main args command line args */ public static void main(String args[]) { DiscoveryServer disocveryServer = new DiscoveryServer(); disocveryServer.start(); } public void start() { long lifetime = 60 * 2 * 1000L; long expiration = 60 * 2 * 1000L; long waittime = 60 * 3 * 1000L; try { while (true) { PipeAdvertisement pipeAdv = getPipeAdvertisement(); // publish the advertisement with a lifetime of 2 mintutes System.out.println( "Publishing the following advertisement with lifetime :" + lifetime + " expiration :" + expiration); System.out.println(pipeAdv.toString()); discovery.publish(pipeAdv, lifetime, expiration); discovery.remotePublish(pipeAdv, expiration); try { System.out.println("Sleeping for :" + waittime); Thread.sleep(waittime); } catch (Exception e) {// ignored } } catch (Exception e) { e.printStackTrace(); } Programming with JXTA

22 /** * This method is called whenever a discovery response is received, which are * either in response to a query we sent, or a remote publish by another node * ev the discovery event */ public void discoveryEvent(DiscoveryEvent ev) { DiscoveryResponseMsg res = ev.getResponse(); // let's get the responding peer's advertisement System.out.println(" [ Got a Discovery Response [" + res.getResponseCount() + " elements] from peer : " + ev.getSource() + " ]"); Advertisement adv; Enumeration en = res.getAdvertisements(); if (en != null) { while (en.hasMoreElements()) { adv = (Advertisement) en.nextElement(); System.out.println(adv); } Programming with JXTA

23 /** * Creates a pipe advertisement * a Pipe Advertisement */ public static PipeAdvertisement getPipeAdvertisement() { PipeAdvertisement advertisement = (PipeAdvertisement) AdvertisementFactory.newAdvertisement(PipeAdvertisement.getAdvertisementType()); advertisement.setPipeID(IDFactory.newPipeID(PeerGroupID.defaultNetPeerGroupID)); advertisement.setType(PipeService.UnicastType); advertisement.setName("Discovery tutorial"); return advertisement; } /** * Stops the platform */ public void stop() { // Stop JXTA manager.stopNetwork(); } Programming with JXTA

24 Demo Peer Discovery


Scaricare ppt "Errata Corrige. DHT Routing (Tapestry) Tabella di routing (base k=4, digit d=4) Consideriamo il nodo x con id (x 1, x 2, x 3, x 4 ): (1+x 1, *, *, *)"

Presentazioni simili


Annunci Google