JXTA%20Training%20-%20Discovery - PowerPoint PPT Presentation

About This Presentation
Title:

JXTA%20Training%20-%20Discovery

Description:

www.jxta.org Learning Objectives This module will help you... Understand how JXTA advertisements are published, cached, and expired Understand the JXTA discovery ... – PowerPoint PPT presentation

Number of Views:81
Avg rating:3.0/5.0
Slides: 22
Provided by: carle176
Category:

less

Transcript and Presenter's Notes

Title: JXTA%20Training%20-%20Discovery


1
JXTA Discovery
www.jxta.org
2
(No Transcript)
3
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
Publishing Advertisements
  • Persistence
  • Locally
  • Remotely
  • Out of band
  • Horizon
  • Where to publish
  • When not to publish

Discovery Service
Cache Manager
Index
Store Expiration
5
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
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
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
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
(No Transcript)
10
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
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
Discovery Service Java API
Publish Advertisements
  • 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.

13
Discovery Service Java API
Discover and Flush Advertisements
  • 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.

14
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
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()

16
Discovery Example Java (continued)
public void run() try
discovery.addDiscoveryListener(this)
while (true)
System.out.println("Sending a Peer Discovery
Message") discovery.getRemoteAdve
rtisements(null, DiscoveryService.PEER,
null, null, 5, null) try
Thread.sleep(10 1000)
..
..
17
Discovery Service C API
Publish and Flush Advertisements
  • Jxta_status discovery_service_publish(Jxta_discove
    ry_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

18
Discovery Service C API
Discover and Retrieve Advertisements
  • Jxta_status discovery_service_get_local_advertisem
    ents (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_advertise
    ments (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.

19
Discovery Service C API
Discovery Listeners
  • Jxta_status discovery_service_add_discovery_listen
    er (Jxta_discovery_service service,
    Jxta_discovery_listener listener)
  • Register a discovery listener, to be notified on
    discovery events.
  • Jxta_status discovery_service_remove_discovery_li
    stener (Jxta_discovery_service service,
    Jxta_discovery_listener listener)
  • Remove a discovery listener.

20
Discovery Example C

Jxta_PG_get_discovery_service(group,
discovery) discovery_service_get_local_advert
isements(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 (i0 i lt
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
End JXTA Discovery
www.jxta.org
Write a Comment
User Comments (0)
About PowerShow.com