Distributed Computing Middleware - Introduction to Project JXTA
Document Sample


Distributed Computing Middleware:
Introduction to Project JXTA
Juniorprofessor Peter Merz
AG Verteilte Algorithmen
FB Informatik
Technische Uni Kaiserslautern
Wintersemester 2008/09
What is JXTA?
The JXTA Project:
Distributed Computing Middleware
An open set of protocols for creating P2P network computing
applications and services
Announced by Sun in April 2001
Open Source Project (www.jxta.org)
Current Version: 2.4
Over 2 million downloads
Over 100 active projects
Term JXTA:
Is short for juxtapose, as side by side
P2P is juxtaposed to client-server or Web-based computing
Introduction to Project JXTA 2
JXTA Goals
Interoperability
software vendors tend to create specific code for their services
Distributed Computing Middleware
e.g. file sharing, instant messaging etc
incompatible systems
duplicate effort
JXTA attempts give peers a common language to talk to each
other
Platform independence
JXTA technology is designed to be independent of:
programming languages e.g. C or Java
system platforms e.g. Microsoft Windows and UNIX
networking platforms (such as TCP/IP or Bluetooth)
future proof e.g. such technologies should be extended to new
platforms e.g. mobile phones etc e.g. using J2ME
Introduction to Project JXTA 3
JXTA Goals and Functionality
Ubiquity
implementable on every device with a digital heartbeat e.g.
Distributed Computing Middleware
PDAs, phones, sensors, consumer electronics appliances,
network routers, desktop computers, data-center servers,
storage systems
avoid specific binding to platforms (Wintel?)
future proof e.g. such technologies should be extended to new
platforms e.g. mobile phones etc e.g. using J2ME
JXTA provides a framework in which peers:
Discover each other
Self-organize into peer groups
Advertise and Discover network services
Communicate with each other
Monitor each other
Introduction to Project JXTA 4
JXTA Architecture
JXTA
Application JXTA Community Applications Sun Applications
Distributed Computing Middleware
Layer
JXTA
Shell
JXTA
Sun Peer
Service JXTA Community Services
JXTA Services Commands
Layer
JXTA Peer Groups Peer Pipes Peer Monitoring
Core
Security
Any Peer on the Web (Desktop, cell phone, PDA, Server)
Introduction to Project JXTA 5
JXTA Architecture (cont’d)
Platform Layer (JXTA Core):
Distributed Computing Middleware
Minimal and essential primitives for P2P networking
Including discovery , transport, firewall handling, creation of
peer groups, and security
Services Layer:
Desirable (but not necessary) services for a P2P environment
Examples are searching, indexing, file sharing, authentication,
PKI services
Applications Layer:
Implementations of integrated applications such as instant
messaging, document and resource sharing, e-mail systems,
multimedia streaming, ...
Introduction to Project JXTA 6
JXTA Components
Most important components:
Distributed Computing Middleware
Peers and peer groups
Pipes for communication
Advertisements for all entities (services, peers, pipes, peer
groups)
Key aspects:
Use of XML documents (advertisements) to describe network
resources
Abstractions of pipes to peers without reliance on a central
naming or addressing authority such as DNS
A uniform addressing scheme by peer IDs
Introduction to Project JXTA 7
JXTA Peers
Peers:
Networked devices that implements one or more JXTA
Distributed Computing Middleware
protocols
Examples are sensors, phones, PDAs, PCs, servers,
supercomputers
Are independent of each other, operate asynchronously
Have a unique Identifier (Peer ID)
Can have more than one network endpoint
Are organized into groups
Peer types:
Minimal edge : send/receive
Full edge : + cache
Rendezvous : + forwarding requests
Relay : + routing cache + firewall support
Introduction to Project JXTA 8
JXTA Peer Groups
Peer Group:
Distributed Computing Middleware
A virtual entity - speak a set of peer group protocols
A collection of cooperating peers providing a common set of
services e.g. file sharing peer group, a CPU sharing peer group
Peer group boundaries define search scope
can be used to create a monitoring environment
can be password protected and implement local security
policies
Special group, called the World Peer Group (the default peer
group a peer joins) that includes all JXTA peers
At least one rendezvous for a group « groups are the scoping
environment for a rendezvous
Introduction to Project JXTA 9
JXTA Peers and Peer Groups
Peer
Peer: A JXTA node.
Peer
Distributed Computing Middleware
Peer Peer
JXTA Group: Peer
A Rendezvous a group is a set
Peer: a meeting of JXTA nodes Peer Peer
who share a
place e.g. gateway
common interest
for JXTA groups
Peer
Peer Peer
Peer Peer Peer Peer
Peer Peer
Introduction to Project JXTA 10
JXTA Pipes
Pipes:
Virtual Communication Channels
Distributed Computing Middleware
Switchable e.g. TCP/IP, HTTP, Bluetooth
NOT point to point
Pipe endpoints « input pipe (the receiving end) and the output
pipe (the sending end)
Asynchronous and unidirectional
Messages flow from the output pipe into the input pipes
Support the transfer of any object, including binary code, data
strings, and Java technology-based objects
Two Types of Pipes:
(End) Point to (End) Point
Propagate - multicast
Introduction to Project JXTA 11
JXTA Pipes (cont’d)
Point-to-point pipe
Distributed Computing Middleware
Peer A Peer B
Propagate pipe
Peer B
Peer A
Peer C
Input Pipe
Peer E
Output Pipe Peer D
Introduction to Project JXTA 12
JXTA Advertisements
Advertisements:
All entities in have are represented as advertisements
Distributed Computing Middleware
Advertisements are XML documents
6 basic types: Peer, Peer group, pipe, service, content, and
endpoint advertisement
Peer Group Advertisement Example:
<?xml version=”1.0”?>
<!DOCTYPE jxta:PGA>
<jxta:PGA>
<GID>urn:jxta:uuid−BCBCDEABDBBBABEABBBABA000000</GID>
<MSID>urn:jxta:uuid−BFEFDEDFBABAFRUDBACE00000001</MSID>
<Name>My Group</Name>
<Desc>This group is to be used for my own testing</Desc>
</jxta:PGA>
Introduction to Project JXTA 13
JXTA Protocols
Core protocols:
Distributed Computing Middleware
Endpoint Routing Protocol - find routes to a destination
Peer Resolver Protocol - send/receive search queries
Rendezvous Protocol - subscribe to a propagation service
Higher level protocols:
Peer Discovery Protocol - find peers, groups, advertisements
Peer Information Protocol - learn peers’ status/properties
Pipe Binding Protocol - bind pipe endpoints
Protocols in JXTA:
All protocols a provided as services in JXTA
Introduction to Project JXTA 14
JXTA Protocol Stack
Peer Discovery Peer Discovery
Via Peer Resolver Protocol
Protocol Protocol
Peer Information Peer Information
Via Peer Resolver Protocol
Distributed Computing Middleware
Protocol Protocol
Pipe Binding Pipe Binding
Via Peer Resolver Protocol
Protocol Protocol
Peer Resolver Via Enpoint Routing Protocol Peer Resolver
Protocol Protocol
Rendezvous Via Enpoint Routing Protocol Rendezvous
Protocol Protocol
Peer Endpoint Via installed Network Transports Peer Endpoint
Protocol Protocol
Network Transport Via Installed Network Transports Network Transport
Introduction to Project JXTA 15
Peer Discovery and Monitoring
Peer Discovery Protocol (PDP):
A peer uses the PDP to discover a JXTA resource
Distributed Computing Middleware
Resources are described by advertisements e.g. can be
services, pipes, peers, peer groups, or any other
advertisements
Peer is here the subject and not necessarily the object
Using this protocol, peers can advertise their own resources,
and discover the resources from other peers
Peer Information Protocol (PIP):
Allows peers to learn about the capabilities and status of other
peers e.g. uptime, traffic load, capabilities, state, etc.
e.g. one can send a ping message to see if a peer is alive
Also query a peer’s properties where each property as a name
and a value string
Useful for implementing monitoring
Introduction to Project JXTA 16
Pipe Binding and the Resolver
Pipe Binding Protocol (PBP):
Distributed Computing Middleware
Allows a peer to establish a virtual communication channel (i.e.
a pipe) between peers
Allows the binding of the two or more ends of the pipe
endpoints forming the connection
A peer binds a pipe advertisement to a pipe endpoint thus
indicating here messages actually go over the pipe
Bind occurs during the open operation, whereas unbind occurs
during the close operation
Peer Resolver Protocol (PRP):
Enables a peer to implement high-level search capabilities
Allows a peer to send and receive generic queries to find or
search for peers, peer groups, pipes, and other information
Introduction to Project JXTA 17
Rendezvous and Endpoint Routing
Rendezvous Protocol (RVP):
Allows a peer to send messages to all the listeners of the
service
Distributed Computing Middleware
RVP defines how a peer can subscribe or be a subscriber to a
propagation service allowing larger communities to form
A rendezvous nodes’ scope is a peer group
E.g. the rendezvous protocol is used by PRP and by PBP in
order to propagate messages
Endpoint Routing Protocol (ERP):
allows a peer to find information about the available routes for
sending a message to destination peer
I.e. pipes are often not directly connected to each other
Allows the implementation of routing algorithms into JXTA
Peers implementing the endpoint routing protocol respond to
queries with available route information giving a list of
gateways along the route
Introduction to Project JXTA 18
JXTA Java API
Important JXTA packages/classes:
net.jxta.peergroup.PeerGroupFactory:
Distributed Computing Middleware
A factory for instantiating the JXTA core peer groups and
application peer peer groups
net.jxta.peergroup.PeerGroup:
Methods for creating peer groups and providing services for
peer groups
net.jxta.discovery.DiscoveryService:
a discovery service for peers, peer groups, advertisements
implementing the peer discovery protocol (PDP)
net.jxta.pipe.PipeService:
a pipe service for managing pipes implementing the pipe
binding protocol (PBP)
net.jxta.membership.MembershipService:
a service for authentication/credential management
Introduction to Project JXTA 19
JXTA Java API (cont’d)
More Important JXTA packages/classes:
Distributed Computing Middleware
net.jxta.access.AccessService:
a service for access control
net.jxta.endpoint.EndpointService:
An interface endpoint routing protocol (ERP) implementation
net.jxta.peer.PeerInfoService:
An interface to the peer information service (PIP)
net.jxta.rendezvous.RendezVousService:
An interface to the Rendezvous Service Protocol (RVP)
net.jxta.resolver.ResolverService:
An interface to the Peer Resolver Protocol (PRP)
implementation
Introduction to Project JXTA 20
JXTA PeerGroup API
Distributed Computing Middleware
Methods of the PeerGroup class:
newGroup(AdvertisementpgAdv):
Instantiate a peer group from its given advertisement
getAccessService(), getDiscoveryService(),
getEndpointService(), getMembershipService(),
getPeerInfoService(), getPipeService(),
getRendezVousService(), getResolverService():
return the services for the peer group if available
Introduction to Project JXTA 21
The DiscoveryService API
DiscoveryService methods:
addDiscoveryListener(): Adds a Listener for receiving
Distributed Computing Middleware
DiscoveryEvents, listener must implement
discoverEvent(DiscoverEvent e)
getRemoteAdvertisements(): Search for advertisements
including peers and peer groups
DiscoverEvent method:
getResponse(): DiscoveryResponseMsg containing a list of
advertisements
DiscoverResponseMsg methods:
getPeerAdvertisement(): returns the responding peer’s
advertisement
getAdvertisements(): returns the response
advertisement objects
Introduction to Project JXTA 22
The PipeService API
PipeService methods:
Distributed Computing Middleware
createInputPipe(PipeAdvertisement,
PipeMsgListener): create an InputPipe from a pipe
Advertisement
createOutputPipe(PipeAdvertisement,
OutputPipeListener) : attempt to create an OutputPipe
using the specified Pipe Advertisement
PipeMsgListener/OutputPipeListener:
Implement pipeMsgEvent(PipeMsgEvent) and
outputPipeEvent(OutputPipeEvent)
PipeMsgEvent.getMessage() receives a message
OutputPipeEvent.outputPipe.send() for sending a
message
Introduction to Project JXTA 23
The PipeService API (cont’d)
Distributed Computing Middleware
Net.jxta.endpoint.Message and MessageElement:
Message.addMessageElement() and
getMessageElement() for adding a message element or
retrieving it
PipeAdvertisement:
Can be generated from file by
AdvertisementFactory.newAdvertisement()
Introduction to Project JXTA 24
The RendezVous API
RendezVousService methods:
Distributed Computing Middleware
addListener(RendezvousListener) : Adds a listener to
rendezvousEvent(RendezvousEvent)
isConnectedToRendezVous(): Peer is connected to a
rendezvous peer for the group
isRendezVous(): tells whether this rendezvous service
currently acts as a rendezvous peer
RendezvousEvent method:
getType(): Event type. Example RDVCONNECT: connected to
rendezvous peer
Introduction to Project JXTA 25
Hello World Example
Steps required for a simple JXTA application:
Distributed Computing Middleware
1. Start the JXTA framework:
calling PeerGroupFactory.newNetPeerGroup()
instantiates the default platform object and returns the default
net peer group
2. Operation:
Now, peer and peer group names as well as IDs can be
obtained from the net peer group object
3. Termination:
the stopApp() method of the peer group object terminates
the group services
Introduction to Project JXTA 26
Hello World Example (cont’d)
Part I:
public class SimpleJxtaApp {
Distributed Computing Middleware
static PeerGroup netPeerGroup = null;
private void startJxta () {
try {
// create and start the default JXTA NetPeerGroup
netPeerGroup = PeerGroupFactory.newNetPeerGroup();
} catch (PeerGroupException e) {
// could not instantiate the group, print the stack and exit
System.out.println( ” fatal error : group creation failure ” );
e.printStackTrace ();
System.exit(1);
}
}
Introduction to Project JXTA 27
Hello World Example (cont’d)
Part II:
public static void main(String args []) {
System.out.println( ” Starting JXTA .... ” );
Distributed Computing Middleware
SimpleJxtaApp myapp = new SimpleJxtaApp();
myapp.startJxta();
System.out.println( ”Hello from JXTA group ” +
netPeerGroup.getPeerGroupName() );
System.out.println( ” Group ID = ” +
netPeerGroup.getPeerGroupID().toString());
System.out.println( ” Peer name = ” +
netPeerGroup.getPeerName());
System.out.println( ” Peer ID = ” +
netPeerGroup.getPeerID().toString());
System.out.println( ”Good Bye ....”);
myapp.netPeerGroup.stopApp();
System.exit(0);
}
Introduction to Project JXTA 28
Discovery Example
Steps required for discovering peers (or peer groups)
Distributed Computing Middleware
application:
1. Start the JXTA framework: calling
PeerGroupFactory.newNetPeerGroup() and obtaining
the discovery service by calling getDiscoveryService()
2. Add a DiscoveryEvent listener with
addDiscoverListener() method of the discovery service
object
3. Start discovery by calling getRemoteAdvertisements() of
the discovery service and wait for DiscoveryEvents
4. On receiving a DiscoveryEvent the responses of the peers can
be processed
Introduction to Project JXTA 29
Discovery Example (cont’d)
Part I:
public class DiscoveryDemo implements Runnable, DiscoveryListener {
static PeerGroup netPeerGroup = null;
Distributed Computing Middleware
private DiscoveryService discovery;
// start the JXTA platform
private void startJxta () {
try {
netPeerGroup = PeerGroupFactory.newNetPeerGroup();
} catch ( PeerGroupException e) {
// could not instantiate the group, print the stack and exit
System.out.println( ” fatal error : group creation failure ” );
e.printStackTrace ();
System.exit(1);
}
// Get the discovery service from our peer group
discovery = netPeerGroup.getDiscoveryService();
}
Introduction to Project JXTA 30
Discovery Example (cont’d)
Part II:
public void run() {
try {
// Add ourselves as a DiscoveryListener for DiscoveryResponses
Distributed Computing Middleware
discovery.addDiscoveryListener(this);
while (true) {
System.out.println( ”Sending a Discovery Message”);
// look for any peer
discovery.getRemoteAdvertisements(
null , DiscoveryService.PEER, null, null, 5);
// wait a bit before sending next discovery message
try {
Thread.sleep(60 ∗ 1000);
} catch(Exception e) {}
} // end while
} catch(Exception e) {
e.printStackTrace ();
}
}
Introduction to Project JXTA 31
Discovery Example (cont’d)
Part III:
public void discoveryEvent(DiscoveryEvent ev) {
Distributed Computing Middleware
DiscoveryResponseMsg res = ev.getResponse();
String name = ”unknown”;
// Get the responding peer’s advertisement
PeerAdvertisement peerAdv = res.getPeerAdvertisement();
// some peers may not respond with their peerAdv
if (peerAdv != null) {
name = peerAdv.getName();
}
System.out.println( ”Got a Discovery Response [” +
res.getResponseCount() + ” elements] from peer: ” +
name);
// printout each discovered peer
Introduction to Project JXTA 32
Discovery Example (cont’d)
Part IV:
// printout each discovered peer
PeerAdvertisement adv = null;
Distributed Computing Middleware
Enumeration enum = res.getAdvertisements();
if (enum != null ) {
while (enum.hasMoreElements()) {
adv = (PeerAdvertisement) enum.nextElement();
System.out.println ( ” Peer name = ” + adv.getName());
}
}
}
static public void main(String args[]) {
DiscoveryDemo myapp = new DiscoveryDemo();
myapp.startJxta();
myapp.run();
}
}
Introduction to Project JXTA 33
PipeListener Example
Steps required for pipe communication (receiving messages):
Distributed Computing Middleware
1. Start the JXTA framework and obtain a pipe service object
2. Create a pipe advertisement object from a xml file using the
AdvertisementFactory
3. Create an input pipe and provide a PipeMsgListener by calling
createInputPipe() of the pipe service object
4. Wait for PipeMsgEvents
5. On receiving a PipeMsgEvent print message data by extracting
contents of the received message with
getMessageElement() of the message object
Introduction to Project JXTA 34
Pipe Example
Steps required for pipe communication (sending messages):
1. Start the JXTA framework and obtain a pipe service object and
Distributed Computing Middleware
a rendezvous service object, provide a RendezVousListener
object to the rendezvous service
2. Create a pipe advertisement object from a xml file using the
AdvertisementFactory
3. Create an output pipe and provide a OutputPipeListener by
calling createOutputPipe() of the pipe service object
4. Wait for a rendevous connection if not yet present by waiting for
a RendezVousEvent
5. Wait for OutputPipeEvents
6. On receiving a OutputPipeEvent send message data by
creating a message with addMessageElement() of the
message object
Introduction to Project JXTA 35
PipeListener and Pipe Example
Distributed Computing Middleware
Note:
The source code for PipeListener and PipeExample is not printed
here. Instead, the source code is provided as additional material
for the lesson.
Introduction to Project JXTA 36
Exercise
Create two JXTA peers and let them join a common group.
Distributed Computing Middleware
Requirements (in order):
Use JXTA 2.5.
Both peers should behave identically (i.e. run the same
code).
In a first step, discover available groups.
If the group kpvaExercise is not available, create it.
Join the kpvaExercise group.
Provide a discovery mechanism to find other peers in the
kpvaExercise group once joined.
Introduction to Project JXTA 37
Hints
Get JXTA 2.5 for J2SE from
http://download.java.net/jxta/jxta-jxse/2.5/jxse-lib-2.5.zip
Use the API documentation available at https://jxta-
Distributed Computing Middleware
docs.dev.java.net/nonav/jxse-javadoc/2.5/jxse/api/index.html
Your first step is to acquire a reference to the net peer group (using
the NetworkManager class new to JXTA 2.5).
Your second step is to query the net peer group for group
advertisements.
If no kpvaExercise group exists, use the AdvertisementFactory class
to create a group advertisement at run-time.
After creation of the group advertisement, don’t forget to publish it
so other peers can see the group.
You will need to join the group even if you have created it.
For simplicity, use NullAuthentication when you set up an
AuthenticationCredential.
Introduction to Project JXTA 38
Running your JXTA programs
On the command line, type:
Distributed Computing Middleware
java -classpath
jxta.jar:bcprov-jdk14.jar:org.mortbay.jetty.jar:
javax.servlet.jar:.:/your/working/directory/ YourProgramName
Same classpath with javac.
You will need to adapt the classpath if the JAR files are not in
your current directory.
For every peer, JXTA will create a subdirectory under the
current directory to store JXTA-specific data (by default, the
directory’s name is .jxta). To reset the current JXTA peer’s
state, remove that directory.
Introduction to Project JXTA 39
Related docs
Get documents about "