Home > Articles

This chapter is from the book

This chapter is from the book

Peer Endpoint Protocol

Peer endpoint routing is not really a public API. Endpoint routing is used to enable pipes or simplistic messaging, such as that found in the peer info, peer resolver, and pipe binding protocols.

The EndpointService class provides a front-end API and environment to all endpoint protocols. Applications can use the Endpoint API directly to control or examine the topology of the JXTA network. The Endpoint API would normally be used to help implement a new endpoint protocol.

We will only touch on a few aspects of this protocol. The more interesting functionality to most JXTA developers is how routes are formed.

Use in Applications

In Chapter 2, we talked about the many reasons for routing in JXTA. You do not need to worry about using the actual protocol in your application. For example, the pipe binding protocol uses the Peer endpoint protocol to build routes. As a result, there is no need to supply the pipe with a route, just the other endpoint.

There are reasons for using the protocol directly if you are writing your own implementation of a pipe or other method of P2P communication. Knowing the protocol is also very important for understanding how routes are built.

Accessing the Service

To access the endpoint service, you get the service from your peer group as in the following line:

EndpointService getEndpointService();

The EndpointService interface (shown in Figure 3.23) contains multiple and very useful methods:

  • addEndpointProtocol—This method allows us to add a new type of communication protocol.

  • addFilterListener—Used to add a listener to filter endpoint messages.

  • addListener—Used to listen for messages to a specific endpoint address.

  • demux—Used to de-multiplex a message. Given an incoming message this method calls the appropriate listener by the destination returned by the getDestAddress() method of the message.

  • getEndpointProtocolByName—This is a convenience method used to fetch an endpoint protocol.

  • getEndpointProtocol—Returns an enumeration of endpoint protocols.

  • getGroup—Returns the group of which this service is a member.

  • GetMessenger—Creates an EndpointMessenger given an EndpointAddress. The messenger is used to send messages to the specific address defined by the EndpointAddress.

  • newEndpointAddress—Creates a new endpoint at a specific URI.

  • newMessage—Creates a message to be used to send a message to an endpoint.

  • ping—Used to determine if a peer exists.

  • propagate—Used to continue sending the message to other peers.

  • removeEndpointProtocol—Uses to remove a protocol that is no longer valid.

  • removeEndpointListener—Used to remove the endpoint listener.

  • removeEndpointFilterListener—Used to remove the endpoint filter listener.

Figure 3.23 UML of EndpointService interface.

Filter Listener

The filter is a fun and useful part of the endpoint API. What the system allows you to do is snoop on any of the messages in the system. You simply specify an XML tag name, the listener, and a Boolean that specifies whether you are interested in oncoming or outgoing messages.

The following is the method from the EndpointService interface:

void addFilterListener(String elementName, EndpointFilterListener listener
            , boolean incoming) throws IllegalArgumentException;

There is also an equivalent remove method:

void removeFilterListener( String address
                  , EndpointFilterListener listener
                  , Boolean incoming);

The listener is easy to use, as you can see by the UML diagram in Figure 3.24. The method gives you the message, the source address, and the destination address. Of course, the purpose of the listener is to filter messages. Consequently, the return value is a message. Normally, you would either modify the message or return a null if the message is to be blocked.

Figure 3.24 UML of EndpointFilterListener interface.

EndpointRouterMessage

One of the more interesting messages to listen for with the EndpointFilterListener is the EndpointRouterMessage. The message is used to build a path between gateway peers to connect endpoints. By looking for these messages, you can determine the route.

Figure 3.25 UML of EndpointRouterMessage interface.

The messages that are passed between peers are the EndpointRouterQuery, EndpointRouterAnswer, and the EndpointRoute messages. Note that the EndpointRouter class is the source of these messages.

The query is used to request a route, and the answer is a response that contains a route to the destination peer. Note that there is no guarantee that there is a route to the peer, and you may not get the answer message.

The DTD specification for the EndpointRouterQuery message is as follows:

<!ELEMENT EndpointRouterQuery  (Credential,
                 Dest,
                 Cached)>
<!ELEMENT Credential  #PCDATA>
<!ELEMENT Dest     #PCDATA>
<!ELEMENT Cached    #PCDATA>

The DTD specification for the EndpointRouterAnswer message is as follows:

<!ELEMENT EndpointRouterAnswer (Credential,
                 Dest,
                 RoutingPeer,
                 RouterPeerAdv,
                 Gateway)>
<!ELEMENT Credential   #PCDATA>
<!ELEMENT Dest      #PCDATA>
<!ELEMENT RoutingPeer   #PCDATA>
<!ELEMENT RouterPeerAdv  (PeerAdvertisement)>
<!ELEMENT Gateway     #PCDATA>

The DTD specification for the EndpointRoute message is as follows:

<!ELEMENT EndpointRoute  (Src,
              Dest,
              TTL,
              Gateway)>
<!ELEMENT Src    #PCDATA>
<!ELEMENT Dest    #PCDATA>
<!ELEMENT TTL    #PCDATA>
<!ELEMENT Gateway  #PCDATA>

ping

Another useful method is ping. The method, shown next, simply takes an endpoint address and returns a Boolean value of true if the address can be reached:

boolean ping (EndpointAddress addr);

The ping method is not as useful as the ping you are used to in normal networking. This ping does not return any useful information; it only lets you know that can reach the peer. The actual processing may also be much different. For example, the ping method may return true if the peer knows about the peer in some endpoint protocols. In HTTP, you do not ping the client because you really can't do so. Remember that the HTTP client must initiate the connection. If you did this, you have no reasonable guarantee that the client will check the gateway any time soon. So, for the sake of time and effort, you assume you can talk to an HTTP endpoint if you find its gateway.

Given how an HTTP ping works, the quality of the ping method may seem suspect compared to a traditional network ping that always connects to a machine if successful. However, the usefulness of ping is that it is implemented by each of the protocols. This essentially gives you a transmission protocol-independent ability to test for an endpoint. In JXTA, this is the primary goal, so other aspects, such as the actual connection or timing, is less important. Simply put, ping is less a network ping than a test for existence according to the protocol implemented by the endpoint.

Depending on the protocol of the endpoint, you may be able to sniff a returning ping message with the filter listener. You should look at the specific implementation of the protocol to understand what the message looks like.

If you are looking for a traditional ping, you will need to implement it yourself. Your ping will only work with peers in your group with your ping code.

EndpointMessenger

One method of the EndpointService interface that is very useful for applications is getMessenger. The getMessenger method takes an endpoint and returns an object that implements an EndpointMessenger interface. The EndpointMessenger (UML seen in Figure 3.26), has two methods—close and sendMessage. Messages sent via the sendMessage method are processed by an EndpointListener that will be covered in a moment.

Figure 3.26 UML for EndpointMessenger interface.

The EndpointMessenger should seem very familiar to you from the previous discussion of output pipes. The simple fact is that a pipe can use the EndpointMessenger code implemented by the endpoint.

To get an endpoint messenger, you must first create an endpoint address. You do this with the following method in the EndpointService:

EndpointAddress newEndpointAddress (String uri);

The URI in this case is a unique string. The URI consists of a unique identifier that should be distinguishable between groups and services. For example, you could use the peer group ID and a service name like Message Queue. You could further refine the address by concatenating the peer group id, the service name, and a third parameter, such as a sequence number. In this way, you could create multiple addresses on a single endpoint. This is similar to how you would implement a type of pipe and create multiple pipe connections.

To retrieve the messenger, you supply the EndpointAddress object you created with the newEndpointAddress method, as seen by the following method signature from the EndpointService interface:

EndpointMessenger getMessenger (EndpointAddress addr) throws IOException;

Where Is the Router?

You might ask, if this is the endpoint router, where is the router? The router is deep in the bowels of this API and is actually a part of the platform as a module. The getMessenger method eventually results in the execution of methods to obtain a route between peers. The UML for the EndpointRouter is shown in Figure 3.27.

You can access the EndpointRouter by calling the loadModule method on your peer group. The following is an example that creates a router for a peer group:

EndpointRouter router;
router = peerGroup.loadModule( "net.jxta.impl.endpoint.EndpointRouter"
               , Platform.refRouterProtoSpecID 
               , PeerGroup.Both);

Figure 3.27 UML of EndpointRouter class.

Note

Note that there is no need to access the router in your code. The router is access via other classes in the JXTA API.

Endpoint Listener

There is another listener interface you can use. The addListener method in the EndpointService interface adds an incoming message listener to a specifically named address that is usually formed by concatenating the name of the invoking service and a parameter unique to that service across all groups.

The listener is called when you send a message through an EndpointMessenger to an EndpointAddress constructed with matching serviceName and serviceParam.

The address parameter is really the same string used to create the EndpointAddress. Although the parameters are called two different things, uri and address, they are the same thing (expect the parameter names to be one or the other in a future version).

The following is the method signature from the EndpointService interface:

public void addListener( String address
            , EndpointListener listener
            ) throws IllegalArgumentException;

The method may throw an IllegalArgumentException if the address is deemed incorrect by the protocol.

The EndpointListener interface is shown in Figure 3.28.

Figure 3.28 UML of EndpointListener interface and EndpointAddress class used to process endpoint

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020