Start of Content Area

This graphic is explained in the accompanying text Server State Change Listener Locate the document in its SAP Library structure

The JCO.ServerStateChangedListenerinterface enables you to monitor the server connection.

This graphic is explained in the accompanying text

public class MyServerStateChangedListener

{

  /**

   *  Simply prints server state changes

   */

  public void serverStateChangeOccurred(JCO.Server server, int old_state, int new_state)

  {

    System.out.print("Server " + server.getProgID() + " changed state from [");

    if ((old_state & JCO.STATE_STOPPED    ) != 0) System.out.print(" STOPPED ");

    if ((old_state & JCO.STATE_STARTED    ) != 0) System.out.print(" STARTED ");

    if ((old_state & JCO.STATE_LISTENING  ) != 0) System.out.print(" LISTENING ");

    if ((old_state & JCO.STATE_TRANSACTION) != 0) System.out.print(" TRANSACTION ");

    if ((old_state & JCO.STATE_BUSY       ) != 0) System.out.print(" BUSY ");

 

    System.out.print("] to [");

    if ((new_state & JCO.STATE_STOPPED    ) != 0) System.out.print(" STOPPED ");

    if ((new_state & JCO.STATE_STARTED    ) != 0) System.out.print(" STARTED ");

    if ((new_state & JCO.STATE_LISTENING  ) != 0) System.out.print(" LISTENING ");

    if ((new_state & JCO.STATE_TRANSACTION) != 0) System.out.print(" TRANSACTION ");

    if ((new_state & JCO.STATE_BUSY       ) != 0) System.out.print(" BUSY ");

    System.out.println("]");

  }

}

Register the Listener class with the API JCO.addServerStateChangedListener():

This graphic is explained in the accompanying text

 public class ThirdExample extends FirstExample {

    public static void main(String[] args) {

        MyExceptionAndErrorListener el = new MyExceptionAndErrorListener();

        JCO.addServerErrorListener(el);

        JCO.addServerExceptionListener(el);

        MyServerStateChangedListener sl = new MyServerStateChangedListener();

        JCO.addServerStateChangedListener(sl);

        FirstExample.startServers() ;

    }

}

 

 

 

 

 

End of Content Area