Sun Cluster Data Services Developer's Guide for Solaris OS

ProcedureHow to Register and Unregister Callbacks

The registration task involves the following actions:

  1. Create the Java code that implements the preceding logic.

    The following example code shows the implementation of the registerCallbacks method of the CrnpClient class (which is called by the CrnpClient constructor). The calls to createRegistrationString() and readRegistrationReply() are described in more detail later in this chapter.

    regIp and regPort are object members that are set up by the constructor.

    private void registerCallbacks() throws Exception
    { 
            Socket sock = new Socket(regIp, regPort);
            String xmlStr = createRegistrationString();
            PrintStream ps = new 
                    PrintStream(sock.getOutputStream());
            ps.print(xmlStr);
            readRegistrationReply(sock.getInputStream();
            sock.close();
    }
  2. Implement the unregister method.

    This method is called by the shutdown method of CrnpClient. The implementation of createUnregistrationString is described in more detail later in this chapter.

    private void unregister() throws Exception
    {
            Socket sock = new Socket(regIp, regPort);
            String xmlStr = createUnregistrationString();
            PrintStream ps = new PrintStream(sock.getOutputStream());
            ps.print(xmlStr);
            readRegistrationReply(sock.getInputStream());
            sock.close();
    }