AR System Java API

com.bmc.arsys.api
Class AlertReceiver

java.lang.Object
  extended by com.bmc.arsys.api.AlertReceiver

public class AlertReceiver
extends Object

Helper class to facilitate programming AR System Alert client programs. To create an AR System Alert client program, simply instantiate object of this type and pass in your own handler (an instance of a class that implements AlertReceiverCallbackHandler interface); then call AlertReceiver.beginReceive method. There after, as alerts are sent by AR Server to logged in user in your client program - your callback handler's onAlertRecieved will be called. To stop further receiving alerts, simply call AlertReceiver.endReceive method.

Sample Test program

    ...
    public void onAlertRecieved(AlertMessageInfo alertMsg) {
     //implement callback logic
     ...
     }
     ...
    public void method check    {
     AlertReceiver receiver = null;
     ...
     try {
           receiver = new AlertReceiver(callback, portnum);
           receiver.beginReceive(serverContext);
          } catch (ARException e) {
          //do logging etc
          } finally  {
          //when done close the receiver    
          receiver.close();
         } 
       }
    ...
    


Constructor Summary
AlertReceiver(AlertCallbackHandler callbackHandler)
          Constructs an AlertReceiver.
AlertReceiver(AlertCallbackHandler callbackHandler, int port)
          Constructs an AlertReceiver.
 
Method Summary
 boolean beginReceive(ARServerUser context)
          Begin receiving alert messages for the user from a particular ARServer specified by the context.
 void close()
          Close the server socket and stop the thread started to listen on the server socket.
 void stopReceive(ARServerUser context)
          Stop receiving alert messages for the user from a particular ARServer specified by the context.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AlertReceiver

public AlertReceiver(AlertCallbackHandler callbackHandler)
              throws IOException
Constructs an AlertReceiver.

Parameters:
callbackHandler -
Throws:
IOException

AlertReceiver

public AlertReceiver(AlertCallbackHandler callbackHandler,
                     int port)
              throws IOException
Constructs an AlertReceiver. It will create a server socket, bound to the specified port. A port of 0 creates a socket on any free port.

Parameters:
callbackHandler - handler that will be invoked upon receiving alerts
port - the port number, or 0 to use any free port.
Throws:
IOException - if an I/O error occurs when opening the socket
Method Detail

beginReceive

public boolean beginReceive(ARServerUser context)
                     throws ARException
Begin receiving alert messages for the user from a particular ARServer specified by the context. This will start a separate thread to listen on the server socket to receive alerts. We do not start a new thread if we want to receive alerts from two servers.

Parameters:
context - specifies the user and AR Server to start receiving alerts
Throws:
ARException - if invalid login

stopReceive

public void stopReceive(ARServerUser context)
                 throws ARException
Stop receiving alert messages for the user from a particular ARServer specified by the context.

Parameters:
context - specifies the user and AR Server to stop receiving alerts
Throws:
ARException - if invalid login

close

public void close()
           throws IOException
Close the server socket and stop the thread started to listen on the server socket.

Throws:
IOException - if an I/O error occurs when closing the socket.

AR System Java API

© Copyright 2006, 2007 BMC Software, Inc.