The Hypercast API 1.
Overview
The HyperCast software provides an Application Programming Interface (API) for building applications that use overlay sockets. The overlay socket API hides most of the characteristics of the underlying overlay network. As a consequence, the API is fairly independent of the type and the configuration of the overlay network. The overlay socket API is specific to the Java programming language. The API of the overlay socket is message-based, and is not very different from, Java UDP sockets. However, since the data transport between neighbors in the overlay networks can be done via TCP, the reliability of overlay sockets can be better than that of UDP sockets. (Better reliability semantics are achieved with the the HyperCast message store.) Due to the similarity to UDP sockets, transcoding network applications from Java UDP sockets to the overlay sockets of HyperCast is generally straightforward. This chapter provides an overview of the API of overlay sockets.
Figure 1 . Relationship of application program with the APIs of the HyperCast. As illustrated in Figure 1, applications interact with three HyperCast objects: an overlay manager, a configuration object, and an overlay socket. The overlay manager reads the configuration file. Dependent on the value of the attributes in the configuration file, the overlay manager may contact an overlay server to determine if a group exists or to download attributes of an overlay network. The overlay manager creates a configuration object that contains configuration information from the configuration file (and possibly from the overlay server). The application uses the configuration object to create a new overlay socket. The application interacts with the overlay manager and the configuration object only during the process of creating an overlay socket. Once an overlay socket is created, the application interacts generally only with the overlay socket API. 2. HelloWorld ExampleHere we present the Java code of a simple application, called HelloWorld, that uses the overlay socket of HyperCast. The HelloWorld application creates an overlay socket that joins an overlay network. After joining the overlay, the applications multicasts the string Hello World in a message to the overlay network. All applications that receive the message display the content of the message on the screen. The main steps of the application are:
A skeleton of the program is shown in Table 1. In Lines 1–3, an overlay manager is created. It reads the configuration file hypercast.prop. The file contains information on the overlay ID, the address of the overlay server (if it exists), the type of overlay to be used (e.g., hypercube, Delaunay triangulations), whether messages are transmitted over UDP or TCP, etc. In Lines 4–9, the program tests if the overlay network exists and generates a configuration object. The configuration object contains all information necessary to create an overlay socket. In Line 5, the overlay ID is read from the configuration file. If no overlay ID is provided in the file, or if the overlay ID is provided, but the overlay network does not exist, the overlay manager creates a new overlay network (Line 7), possibly also a new overlay ID. The configuration object is created by createOverlay if a new overlay network is created, and by getOverlaySocketConfig if the overlay network already exists. The overlay socket is created by the configuration object (Lines 10–11). In Lines 12–13, the socket joins the overlay network. Note that there is no notification when the process of joining an overlay network is complete. The reason that the API does not provide such a notification is that a node may not be able to decide locally if the process of joining the overlay network has been completed. In the example program, the program waits for a few seconds, to give the overlay socket enough time to join the overlay network. In Lines 16–17 the node creates a message to be transmitted and then multicasts the message to all overlay sockets in the overlay network. The methods createMessage and sendToAll are structured similarly to the constructor and send method of the Java Multicast socket class. The sendToAll transmits the message to all neighbors of the overlay socket in the overlay network that are child nodes in a spanning tree with the sender as the root. If the socket issues the sendToAll before it is fully integrated in the overlay networks, then the transmission does not reach all nodes in the overlay network. Lines 20–31 describe an infinite loop where the overlay socket receives an overlay message (Line 23), extracts the payload (Line 25), converts the payload to a string (Line 27), and prints the string to the screen (Line 30). We note that the receive method is blocking. Lines 32–33 show how a socket leaves an overlay. Due the infinite loop, these lines are never executed in the example program. The following remarks emphasize aspects of the HyperCast overlay socket API. Remarks: · As already indicated, the API of the overlay socket bears similarity of the Java Multicast socket. This similarity is intentional. · The program in Table 1 is not specific to the overlay topology, the transport protocol (UDP or TCP) used to transfer overlay messages, if there is an overlay server, etc. This information is contained in the configuration file. · The service provided by the overlay socket above is a connectionless best-effort datagram service. If TCP is used for data transport between neighbors in the overlay network, then the reliability of transmission is high. However, there is no guarantee that all members of the overlay network receive the message. (Improved reliability semantics are achieved with the functions provided by the HyperCast message store.) · Instead of the synchronous receive operation in the example, the HyperCast overlay can also provide an asynchronous receive operation via upcalls. To use the upcall option, an object must be passed as a parameter when creating the overlay socket. This object must be from a class that implements the I_CallBack interface. All classes that implement the I_CallBack interface have a method called MessageArrived. This method is invoked when a message has been received by the overlay socket. In Table 2, we show a version of the HelloWorld program, which uses callbacks. A complete program is shown in a separate file.
Table 1 . Skeleton of the Hello World application.
Table 2 . Skeleton of the Hello World application (with Callback).
3. Overlay ManagerThe overlay manager of the HyperCast software provides an interface for the management of overlay networks and their attributes. The application programmer uses the overlay manager to determine and set the properties of sockets that connect to the overlay network, to determine if an overlay network already exists, and to create a new overlay network. The use of the methods of the OverlayManager API is summarized below. Details can be obtained from the Javadoc documentation. OverlayManager om = OverlayManager (hypercast.prop) OverlaySocketConfig oc = om.createOverlay
(overlayname) Boolean test = om.doesOverlayExist (overlayname) String prop = om.getDefaultProperty
(propertyname) OverlaySocketConfig conf =
om.getOverlaySocketConfig Properties
prop = overrideDefaults(java.util.Properties defaults,java.lang.String overrides) void
4. Configuration objectThe configuration object OverlaySocketConfig stores the configuration for an overlay socket, and maintains the error and log files. The configuration object creates the overlay socket. The object is usually created by the overlay managemer via the OverlayManager.createOverlay(String overlayID) method, as follows: OverlaySocketConfig co= om.createOverlay(overlayID) Note that the configuration object has a
statistics (I_Stats) interface. Therefore, the configuration object can be
queried by monitoring and control components of HyperCast.
Note: java.net.MulticastSocket
createJavaMulticastSocket 5 Overlay socketThe API of an overlay socket offers applications the ability to: · Join and leave existing overlay networks; · Send data to all or a subset of the members of the overlay network; · Receive data from the overlay. In HyperCast 2.0, four different types of overlay sockets are supported. The type of socket that is created depends on the values of attributes “Node” and “Socket_Adapter” in the configuration file. The types of sockets are: 1. OL_Socket_CO_HC: This overlay socket runs the hypercube overlay protocol. The overlay protocol uses UDP multicast and UDP unicast. Transmission of application messages between members of the overlay network is done with TCP. 2. OL_Socket_CL_HC: The same as (1), but application messages are transmitted with UDP. 3. OL_Socket_CO_DT: This overlay socket runs the DT overlay protocol. The overlay protocol uses UDP unicast. The protocol requires to run an application that acts as the DT server.[2] Transmission of application messages between members of the overlay network is done with TCP. 4. OL_Socket_CO_DT: The same as (1), but application messages are transmitted with UDP. Note: To program with the released jar files, a package needs to be imported to your program: import edu.virginia.cs.mng.hypercast.*; While each type of overlay socket can provide its own application programming interface, all socket types support the API of the I_OverlaySocket class. Therefore, as long as application programs restrict themselves to the methods of I_OverlaySocket, application programs can use different overlay sockets. The following table lists all the API methods provided by the I_OverlaySocket. The calls to the API can be grouped into the following categories. (a) Overlay Participation
(b) Sending and Receiving Messages
Send
message to the parent in the spanning tree with respect to the root with
logical address
(c) Information
[1] In the same sense that a multicast address should uniquely identify a multicast group in the scope in which it is used. [2] We refer to the User Manual for details.
|