PreCache NetInjector Documentation Center : PreCache NetInjector Application Development

Basic Case, Publication — Java

   







Basic Case, Publication code — Java

— the full code sample for publishing


The previous code samples presented the basics of publishing. A publication application initializes channels, proxies, subjects, and attributes for content distribution.

The basic sequence of the publication process in the completed application is:

  1. Create a proxy connection for the channel. ( Proxy Initialization)
  2. Create a notification for the subject; set the value of the predefined attribute. ( Notification)
  3. Publish the notification for the subject over the channel. ( Content publication)

import com.precache.event.*;

import java.io.*;

public class pub1

{

static

      {

            System.loadLibrary("event-j");

      }

      public static void main(String argv[])

      {

//Create a proxy for the channel and client.

            Proxy p;

            Notification n;

            try

            {

                  p = new Proxy(7,3002);

//Create a notification for the subject.

                  n = new Notification(p,"Sample.Intro1");

//Set the value of the predefined attribute.

                  n.setPredefinedAttr(
                        "Message","Hello World");

//Publish the notification for the subject.

                  p.publish(n);

            }

            catch (Exception e)

            {

                  e.printStackTrace();

            }

      }

}

In the next chapter, Basic Case, Subscription— Java, we will construct a simple application for retrieving the published message.