Overview of the Main API Classes and Interfaces

12-8 Developing Web Applications, Servlets, and JSPs for Oracle WebLogic Server

12.3.2 Programming Using the Server-Side Pub-Sub APIs

The pub-sub server itself might sometimes need to get messages from a channel so as to monitor information or intercept incoming data before it gets published to subscribed clients. The server might also want to publish messages to a channel directly to, for example, make an announcement to all subscribed clients or provide additional services. The pub-sub server might also need to perform maintenance on the channels, such as create new ones or destroy existing ones. WebLogic Server provides a pub-sub API in the com.bea.httppubsub package to perform all of these tasks. Pub-sub programmers use the API in servlets or POJOs plain old Java objects of the Web application that contains the pub-sub application. Programming with the API is optional and needed only if the pub-sub server must perform tasks additional to the standard publish and subscribe on the client side.

12.3.2.1 Overview of the Main API Classes and Interfaces

The following list describes the main interfaces and classes of the pub-sub server API: ■ com.bea.httppubsub.PubSubServer—This is the most important interface of the pub-sub server API. It represents an instance of the pub-sub server that is associated with the current Web application; you use the context path of the current servlet to get the associated pub-sub server. Using this interface, programmers can manage channels, configure the pub-sub server, and create local clients that are used to publish to and subscribe to channels. ■ com.bea.httppubsub.LocalClient—After a programmer has instanciated an instance of the current pub-sub server using the PubSubServer interface, the programmer must then create a LocalClient, which is the client representative on the server side. This client is always connected to the pub-sub server. Using this client, programmers can publish and subscribe to channels. Remote clients, such as browser-based clients, are represented with the com.bea.httppubsub.Client interface. ■ com.bea.httppubsub.ClientManager—Interface for creating a new LocalClient. ■ com.bea.httppubsub.Channel—Interface that represents a channel and all its subchannels. With this interface, programmers can get the list of clients currently subscribed to a channel and its subchannels, publish messages to a channel, get a list of all subchannels, subscribe or unsubscribe to a channel, and destroy a channel. ■ com.bea.httppubsub.MessageFilter—Interface for creating message filters that intercept the messages that a client publishes to a channel. See Section 12.3.3, Configuring and Programming Message Filter Chains for details. ■ com.bea.httppubsub.DeliveredMessageListener—Interface that programmers use to create an object that listens to a channel and is notified every time a client remote or local publishes a message to the channel. ■ com.bea.httppubsub.BayeuxMessage—Interface that represents the messages that are exchanged between the pub-sub server and a Bayeux client. There are additional supporting classes, interfaces, enums, and exceptions in the com.bea.httppubsub package; see the HTTP Pub-Sub API Javadoc for the complete documentation. The following sections describe how to perform the most common server-side tasks using the pub-sub API, such as publishing messages to and subscribing to a channel. The sample snippets are taken from the Java source files of the pub-sub server sample Using the HTTP Publish-Subscribe Server 12-9 on the distribution kit: WL_ HOME samplesserverexamplessrcexampleswebapppubsubstocksr cstockWar, where WL_HOME refers to the main WebLogic Server installation directory, such as oraclehomewlserver_10.3.

12.3.2.2 Getting a Pub-Sub Server Instance and Creating a Local Client