9-1 JXTA Discovery . 9-1 Learning Objectives This module will help you... – Understand how JXTA...
-
Upload
erick-wood -
Category
Documents
-
view
215 -
download
0
Transcript of 9-1 JXTA Discovery . 9-1 Learning Objectives This module will help you... – Understand how JXTA...
![Page 1: 9-1 JXTA Discovery . 9-1 Learning Objectives This module will help you... – Understand how JXTA advertisements are published, cached, and.](https://reader036.fdocuments.net/reader036/viewer/2022070400/56649f125503460f94c24f1b/html5/thumbnails/1.jpg)
9-1
JXTA DiscoveryJXTA Discovery
www.jxta.orgwww.jxta.org
![Page 2: 9-1 JXTA Discovery . 9-1 Learning Objectives This module will help you... – Understand how JXTA advertisements are published, cached, and.](https://reader036.fdocuments.net/reader036/viewer/2022070400/56649f125503460f94c24f1b/html5/thumbnails/2.jpg)
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
![Page 3: 9-1 JXTA Discovery . 9-1 Learning Objectives This module will help you... – Understand how JXTA advertisements are published, cached, and.](https://reader036.fdocuments.net/reader036/viewer/2022070400/56649f125503460f94c24f1b/html5/thumbnails/3.jpg)
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
![Page 4: 9-1 JXTA Discovery . 9-1 Learning Objectives This module will help you... – Understand how JXTA advertisements are published, cached, and.](https://reader036.fdocuments.net/reader036/viewer/2022070400/56649f125503460f94c24f1b/html5/thumbnails/4.jpg)
9-1
Publishing Advertisements
CacheManager
Discovery Service
IndexIndex
StoreExpirationStoreExpiration
• Persistence– Locally– Remotely– Out of band
• Horizon– Where to publish– When not to
publish
![Page 5: 9-1 JXTA Discovery . 9-1 Learning Objectives This module will help you... – Understand how JXTA advertisements are published, cached, and.](https://reader036.fdocuments.net/reader036/viewer/2022070400/56649f125503460f94c24f1b/html5/thumbnails/5.jpg)
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
![Page 6: 9-1 JXTA Discovery . 9-1 Learning Objectives This module will help you... – Understand how JXTA advertisements are published, cached, and.](https://reader036.fdocuments.net/reader036/viewer/2022070400/56649f125503460f94c24f1b/html5/thumbnails/6.jpg)
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)
![Page 7: 9-1 JXTA Discovery . 9-1 Learning Objectives This module will help you... – Understand how JXTA advertisements are published, cached, and.](https://reader036.fdocuments.net/reader036/viewer/2022070400/56649f125503460f94c24f1b/html5/thumbnails/7.jpg)
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
![Page 8: 9-1 JXTA Discovery . 9-1 Learning Objectives This module will help you... – Understand how JXTA advertisements are published, cached, and.](https://reader036.fdocuments.net/reader036/viewer/2022070400/56649f125503460f94c24f1b/html5/thumbnails/8.jpg)
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
![Page 9: 9-1 JXTA Discovery . 9-1 Learning Objectives This module will help you... – Understand how JXTA advertisements are published, cached, and.](https://reader036.fdocuments.net/reader036/viewer/2022070400/56649f125503460f94c24f1b/html5/thumbnails/9.jpg)
9-1
Peergroup Services
Services are accessible through the peergroup object:
JavadiscService = peerGroup.getDiscoveryService();
CJxta_PG_get_discovery_service(group, &discovery);
PeerGroup Services
MembershipMembership
PipePipe
DiscoveryDiscovery
RendezvousRendezvous
ResolverResolver
EndpointEndpoint
PeerInfoPeerInfo
![Page 10: 9-1 JXTA Discovery . 9-1 Learning Objectives This module will help you... – Understand how JXTA advertisements are published, cached, and.](https://reader036.fdocuments.net/reader036/viewer/2022070400/56649f125503460f94c24f1b/html5/thumbnails/10.jpg)
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
![Page 11: 9-1 JXTA Discovery . 9-1 Learning Objectives This module will help you... – Understand how JXTA advertisements are published, cached, and.](https://reader036.fdocuments.net/reader036/viewer/2022070400/56649f125503460f94c24f1b/html5/thumbnails/11.jpg)
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)
![Page 12: 9-1 JXTA Discovery . 9-1 Learning Objectives This module will help you... – Understand how JXTA advertisements are published, cached, and.](https://reader036.fdocuments.net/reader036/viewer/2022070400/56649f125503460f94c24f1b/html5/thumbnails/12.jpg)
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
![Page 13: 9-1 JXTA Discovery . 9-1 Learning Objectives This module will help you... – Understand how JXTA advertisements are published, cached, and.](https://reader036.fdocuments.net/reader036/viewer/2022070400/56649f125503460f94c24f1b/html5/thumbnails/13.jpg)
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 APIDiscover and Flush Advertisements
![Page 14: 9-1 JXTA Discovery . 9-1 Learning Objectives This module will help you... – Understand how JXTA advertisements are published, cached, and.](https://reader036.fdocuments.net/reader036/viewer/2022070400/56649f125503460f94c24f1b/html5/thumbnails/14.jpg)
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(); }
![Page 15: 9-1 JXTA Discovery . 9-1 Learning Objectives This module will help you... – Understand how JXTA advertisements are published, cached, and.](https://reader036.fdocuments.net/reader036/viewer/2022070400/56649f125503460f94c24f1b/html5/thumbnails/15.jpg)
9-1
Discovery Example – Java (continued)Public 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();
}
![Page 16: 9-1 JXTA Discovery . 9-1 Learning Objectives This module will help you... – Understand how JXTA advertisements are published, cached, and.](https://reader036.fdocuments.net/reader036/viewer/2022070400/56649f125503460f94c24f1b/html5/thumbnails/16.jpg)
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); } .. } .. }
![Page 17: 9-1 JXTA Discovery . 9-1 Learning Objectives This module will help you... – Understand how JXTA advertisements are published, cached, and.](https://reader036.fdocuments.net/reader036/viewer/2022070400/56649f125503460f94c24f1b/html5/thumbnails/17.jpg)
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
![Page 18: 9-1 JXTA Discovery . 9-1 Learning Objectives This module will help you... – Understand how JXTA advertisements are published, cached, and.](https://reader036.fdocuments.net/reader036/viewer/2022070400/56649f125503460f94c24f1b/html5/thumbnails/18.jpg)
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
![Page 19: 9-1 JXTA Discovery . 9-1 Learning Objectives This module will help you... – Understand how JXTA advertisements are published, cached, and.](https://reader036.fdocuments.net/reader036/viewer/2022070400/56649f125503460f94c24f1b/html5/thumbnails/19.jpg)
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
![Page 20: 9-1 JXTA Discovery . 9-1 Learning Objectives This module will help you... – Understand how JXTA advertisements are published, cached, and.](https://reader036.fdocuments.net/reader036/viewer/2022070400/56649f125503460f94c24f1b/html5/thumbnails/20.jpg)
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);
}
![Page 21: 9-1 JXTA Discovery . 9-1 Learning Objectives This module will help you... – Understand how JXTA advertisements are published, cached, and.](https://reader036.fdocuments.net/reader036/viewer/2022070400/56649f125503460f94c24f1b/html5/thumbnails/21.jpg)
9-1
End – JXTA DiscoveryEnd – JXTA Discovery
www.jxta.orgwww.jxta.org