Presentation is loading. Please wait.

Presentation is loading. Please wait.

9-1 JXTA Discovery www.jxta.org. 9-1 Learning Objectives This module will help you... – Understand how JXTA advertisements are published, cached, and.

Similar presentations


Presentation on theme: "9-1 JXTA Discovery www.jxta.org. 9-1 Learning Objectives This module will help you... – Understand how JXTA advertisements are published, cached, and."— Presentation transcript:

1 9-1 JXTA Discovery www.jxta.org

2 9-1 Learning Objectives This module will help you... – Understand how JXTA advertisements are published, cached, and expired – Understand the JXTA discovery mechanism – Gain familiarity with the JXTA Discovery Service API

3 9-1 Advertisements XML documents – Provide platform-independent representation of objects that can be exchanged between different platforms (e.g., Java and C) Common operations – Create – Publish – Discover/search

4 9-1 Publishing Advertisements Cache Manager Discovery Service Index Store Expiration Store Expiration Persistence – Locally – Remotely – Out of band Horizon – Where to publish – When not to publish

5 9-1 Advertisement Caching Advertisements may be cached by peers – Protocols don't specify how peers cache info – Standard JXTA API bindings automatically perform caching Each advertisement published with a time-to-live – Relative expiration date – When expired, advertisements are removed – Advertisements can be re-published

6 9-1 Publish versus RemotePublish Publish() – Stores advertisement in persistent local cache – Exposes advertisements within peergroup – Can specify lifetime and expiration for others (DEFAULT_LIFETIME and DEFAULT_EXPIRATION) RemotePublish() – Publishes advertisement within local subnet and to connected rendezvous peers within the context of the group – Advertisements held in other peers' cache for specified duration (DEFAULT_EXPIRATION)

7 9-1 Rendezvous Peers Each peer group has a set of rendezvous peers – Rendezvous peers cache indices to edge peer advertisements – Discovery queries routed between rendezvous peers Any peer may become a rendezvous peer Peers can be pre-configured to know certain rendezvous peers or can discover them dynamically

8 9-1 Discovery Service Asynchronous mechanism for discovering advertisements (peers, peer groups, pipes, services) Implements Peer Discovery Protocol (PDP) Can retrieve advertisements in local cache Can send Discovery Query Message – To a specific peer – Propagated to JXTA network

9 9-1 Peergroup Services Services are accessible through the peergroup object: Java discService = peerGroup.getDiscoveryService(); C Jxta_PG_get_discovery_service(group, &discovery); PeerGroup Services Membership Pipe Discovery Rendezvous Resolver Endpoint PeerInfo

10 9-1 Asynchronous Discovery Model Peer propagates discovery request within a peergroup Responses are received asynchronously – Can query local cache (advertisements are stored asynchronously as they arrive) – Can use event-based notification (implement discovery listener) No guarantees when/if a response will be received

11 9-1 Guidelines Discovery – Limit discovery within NetPeerGroup to boot- strapping operation (i.e. Finding group, etc.) – Scope discovery of other resources within a smaller peergroup Publishing Advertisements – Should search for advertisements before creating – may already be published – Don't introduce inconsistencies (e.g., advertisements are uniquely identified by an ID, and some thought should be given when discovering by name)

12 9-1 Discovery Service – Java API void publish(Advertisement advertisement, int type) – Publish an advertisement with default lifetime and expiration for others. void publish(Advertisement adv, int type, long lifetime, long lifetimeForOthers) – Publish an advertisement that will expire after a certain time. void remotePublish(Advertisement advertisement, int type) – Remote publish an advertisement: will attempt to remote publish adv on all configured transports.. void remotePublish(Advertisement adv, int type, long lifetime) – Remote publish an advertisement: will attempt to remote publish adv on all configured transports. The Advertisement will carry a a expiration of lifetime. Publish Advertisements

13 9-1 Enumeration getLocalAdvertisements(int type, String attribute String value) – Retrieve stored peer, group, and general JXTA advertisements. void getRemoteAdvertisements(String peerid, int type,String attribute, String value, int threshold, net.jxta.discovery.DiscoveryListener listener) – Discovery JXTA peer, group, and general JXTA advertisements. void addDiscoveryListener(DiscoveryListener listener) – Add a discovery listener, to be notified on discovery events.. boolean removeDiscoveryListener(DiscoveryListener listener) – Remove a discovery listener. void flushAdvertisements(String id, int type) – Flush stored advertisements. Discovery Service – Java API Discover and Flush Advertisements

14 9-1 Discovery Example – Java public class DiscoveryDemo implements DiscoveryListener { static PeerGroup netPeerGroup = null; private DiscoveryService discovery; PeerAdvertisement peerAdv; static public void main(String args[]) { DiscoveryDemo myapp = new DiscoveryDemo(); myapp.startJxta(); myapp.run(); } // method to start the JXTA platform private void startJxta() { try { netPeerGroup =PeerGroupFactory.newNetPeerGroup(); } catch ( PeerGroupException e) {... } // Get the discovery service from our peer group discovery = netPeerGroup.getDiscoveryService(); }

15 9-1 Discovery Example – Java (continued) P ublic void discoveryEvent(DiscoveryEvent ev) { DiscoveryResponseMsg res = ev.getResponse(); String name = “unknown”; // Get the responding peer's advertisement // get the peer advertisement PeerAdvertisement peerAdv = res.getPeerAdvertisement(); if (peerAdv != null) { name = peerAdv.getName(); } System.out.println(" [ Got a Discovery Response ["+ res.getResponseCount()+ " elements] from peer : " + name +" ]"); // get the discovered Advertisements.... Enumeration responses = res.getAdvertisements(); }

16 9-1 Discovery Example – Java (continued) public void run() { try { discovery.addDiscoveryListener(this); while (true) { System.out.println("Sending a Peer Discovery Message"); discovery.getRemoteAdvertisements(null, DiscoveryService.PEER, null, null, 5, null); try { Thread.sleep(10 * 1000); }.. }.. }

17 9-1 Discovery Service – C API Jxta_status discovery_service_publish(Jxta_discovery_service *service, Jxta_advertisement *adv, short type, long lifetime, long lifetimeForOthers) Publish an advertisement that will expire after a certain time. Jxta_status discovery_service_remote_publish(Jxta_discovery_service *service, Jxta_id *peerid, Jxta_advertisement *adv, short type, long expirationtime) Remote publish an advertisement: will attempt to remote publish adv on all configured transports with the specified expiration. Jxta_status discovery_service_flush_advertisements(Jxta_discovery_service *service, char *id, short type) Flush stored advertisement Publish and Flush Advertisements

18 9-1 Discovery Service – C API Jxta_status discovery_service_get_local_advertisements (Jxta_discovery_service *service, short type, const char *attribute, const char *value, Jxta_vector **advertisements) – Retrieve stored peer, group and general JXTA advertisements. Jxta_status discovery_service_get_remote_advertisements (Jxta_discovery_service *service, Jxta_id *peerid, short type, const char *attribute, const char *value, int threshold, Jxta_discovery_listener *listener) – Discover peer, group, and general JXTA advertisements. Discover and Retrieve Advertisements

19 9-1 Discovery Service – C API Jxta_status discovery_service_add_discovery_listener (Jxta_discovery_service *service, Jxta_discovery_listener *listener) – Register a discovery listener, to be notified on discovery events. Jxta_status discovery_service_remove_discovery_listener (Jxta_discovery_service *service, Jxta_discovery_listener *listener) – Remove a discovery listener. Discovery Listeners

20 9-1 Discovery Example – C Jxta_PG_get_discovery_service(group, &discovery); discovery_service_get_local_advertisements(discovery, DISC_GROUP, (char *)jstring_get_string(attr), (char *)jstring_get_string(value), & res_vec); if (res_vec != NULL ) { int i; printf("restored %d group advertisement(s) \n",jxta_vector_size(res_vec)); for (i=0; i < jxta_vector_size(res_vec); i++ ){ Jxta_PGA * pgadv; Jstring * xml; jxta_vector_get_object_at (res_vec, (Jxta_object**)&pgadv, i); jxta_PGA_getxml( pgadv, &xml ); printf( (char *)jstring_get_string(xml) ); JXTA_OBJECT_RELEASE(pgadv); JXTA_OBJECT_RELEASE(xml); } JXTA_OBJECT_RELEASE(res_vec); }

21 9-1 End – JXTA Discovery www.jxta.org


Download ppt "9-1 JXTA Discovery www.jxta.org. 9-1 Learning Objectives This module will help you... – Understand how JXTA advertisements are published, cached, and."

Similar presentations


Ads by Google