Standard APIs to Third-Party Services


Peer-to-peer architecture is designed to be a network of peers that can discover other peers having common interests, exchange messages with them, and share resources. This interconnection of peers requires a basic mechanism for messaging. For example, consider the JXTA project, which is a set of open, generalized P2P protocols defined as XML messages that establish a layer on top of the Internet and non-IP network protocols. The JXTA set of protocols allows peers ranging from cell phones and wireless PDAs to PCs and servers to interact through messaging, independent of their network location and topology. The JXTA project has defined a layered architecture for this purpose. We will now discuss the logical requirements of any P2P architecture and list the set of APIs that Java offers for these requirements.

Two Basic Requirements of Any P2P Architecture

Any P2P system will require a mechanism to accomplish the following tasks:

  • Peers should be able to send and receive messages to and from each other.

  • Every peer should be able to process messages being exchanged. This includes the capability to author messages that a peer wants to send to other peers, and the capability to understand messages coming from other peers.

As an example, consider the following scenario. A peer wants to ask other peers if anyone knows the address of a discussion group on P2P issues. He will need to author a search query (message) and send it to the peers that he thinks are relevant and might answer his search query. Recipients of this search query will need to process the incoming message to understand what is required. Some of the peers who receive this search query might want to forward this message to other relevant peers.

This scenario clearly asks for the capability to perform the two previously defined tasks each peer should be able to send and receive messages and process the messages coming in from other peers. These two requirements are very basic in nature, and any network that behaves in a P2P manner will address them.

How Java Handles Basic P2P Requirements

Sun has provided the Java Messaging Service (JMS), an API meant to cater for general messaging requirements. The JMS API defines a common set of interfaces and associated semantics that allow Java applications to communicate with other messaging implementations. JMS is a part of the J2EE specification, so all major J2EE-compliant application servers include JMS features. Independent JMS implementations are also available.

JMS provides a basic messaging framework in which you can create messaging sessions based on topics of your interest. The API does all the low-level tasks, such as

  • Creating and maintaining topics for messages to be exchanged

  • Maintaining a database of users and the interest of each user in different topics

  • Network-related tasks such as the creation of listeners

You can build your messaging logic on top of JMS. Later in this chapter, we will describe the JMS architecture in detail. We will also build a sample messaging application based on JMS.

Processing of Messages

XML has become the de facto standard for almost all exchanges of structured information over the Internet. Naturally, XML is the favorite candidate to be used as the format of P2P messages. JXTA has defined several XML formats to provide various services. For example, the search service in JXTA defines XML structures (Document Type Definitions, or DTDs) to specify and respond to search requests.

All JXTA applications will need to process (author and understand) XML messages. Java has comprehensive support for XML processing. There are two Java-based APIs for XML processing:

  • Java API for XML Processing (JAXP)

  • Java API for XML Binding (JAXB)

JAXP and JAXB provide different approaches to address the same problem XML processing. JAXP has implemented the four popular XML-related W3C specifications:

  • Simple API for XML (SAX)

  • Document Object Model (DOM)

  • Extensible Stylesheet Language for Transformation (XSLT)

  • XPath

SAX, DOM, and XSLT are ways to expose an XML file for processing. XPath helps in reaching specific parts of an XML document. We'll discuss details of JAXP later in this chapter and provide sample implementations of small projects related to SAX, DOM, XSLT and XPath.

JAXB is a recent addition to Java's capability of XML processing. In fact, JAXB specification is still under development, and only an early access release is yet available. JAXB enables the quick and easy generation of Java classes capable of processing any particular XML structure (DTDs).

JAXB can compile your DTD into one or more Java classes. Currently, only DTDs are supported, although support for XML schemas is anticipated in the coming versions. When Java classes are available for XML processing, your Java applications can use these classes. We will do a small JAXB project later in this chapter.

The Concept of XML Messaging

The Java API for XML Messaging (JAXM) combines the XML processing and messaging features in one API. It offers both a messaging framework similar to that of JMS, and a SOAP authoring mechanism. Therefore, the basic purpose of having JAXM is to provide for Java-based SOAP messaging. There are a number of ways we can accomplish SOAP messaging in Java. The last section of this chapter is focused on this topic.



JavaT P2P Unleashed
JavaT P2P Unleashed
ISBN: N/A
EAN: N/A
Year: 2002
Pages: 209

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net