Monitors

A Monitor is a mechanism by which the Server or client side user can tap into events that are happening during RPC. A use is logging, but another concerns Connection Rubstness.

Server Side

On the serverside you implement a interface called ServerMonitor:

    void closeError(Class clazz, String desc, IOException e);

    void classNotFound(Class clazz, ClassNotFoundException e);

    void unexpectedException(Class clazz, String desc, Throwable e);

    void stopServerError(Class clazz, String desc, Exception e);

    void newSession(Session session, int newSize, String connectionDetails);

    void removeSession(Session session, int newSize);

    void staleSession(Session session, int newSize);
        

Pre-made implementations are CommonsLoggingServerMonitor, JavaLoggingServerMonitor, Log4JServerMonitor and NullServerMonitor. It is specified as the first parameter in the applicable Server class.

Client Side

On the server side you implement a interface called ServerMonitor:

    void methodCalled(Class clazz, String methodSignature, 
                      long duration, String annotation);

    boolean methodLogging();

    void serviceSuspended(Class clazz, Request request, int attempt, 
                          int suggestedWaitMillis);

    void serviceAbend(Class clazz, int attempt, IOException cause);

    void invocationFailure(Class clazz, String publishedServiceName, 
                           String objectName, String methodSignature, 
                           InvocationException ie);

    void unexpectedConnectionClosed(Class clazz, String name, 
                                    ConnectionClosedException cce);

    void unexpectedInterruption(Class clazz, String name, 
                                InterruptedException ie);

    void classNotFound(Class clazz, String msg, 
                       ClassNotFoundException cnfe);

    void unexpectedIOException(Class clazz, String msg, 
                               IOException ioe);

    void pingFailure(Class clazz, JRemotingException jre);

        

Pre-made implementations are CommonsLoggingClientMonitor, JavaLoggingClientMonitor, Log4JClientMonitor, SimpleRetryingClientMonitor and NullClientMonitor. It is specified as the first parameter in the applicable Transport class.

Connection Robustness

The Client Monitor has a mechanism to participate in the robustness of the connection. Connections are dropped and this provides a way for the user to decide how connections are recovered. By default failing connections will be reported by way of InvocationException (a derivative of RuntimeException) immediately. By chaining the client monitor of your choice to another called SimpleRetryingClientMonitor you'll be able to control the attempt to reconnect/retry.

serviceResolver = new ServiceResolver(new SocketTransport(
                          new ConsoleClientMonitor(new SimpleRetryingClientMonitor(100)), 
                                                    new SocketDetails("localhost", 10333)));

In the above case we specified 100 retries, and the policy for SimpleRetryingClientMonitor is to retry progressively but with an increasing delay between retries (2 to the power of the retry # multiplied by 500 millies). Override method calculateDelayMillis(attempt) if you want to change that.