FileDocCategorySizeDatePackage
PropertyBasedMonitoringSocket_RMIServerSocketFactory.javaAPI DocExample1524Thu Nov 08 00:23:24 GMT 2001com.ora.rmibook.chapter18.sockets

PropertyBasedMonitoringSocket_RMIServerSocketFactory.java

package com.ora.rmibook.chapter18.sockets;


import java.rmi.server.*;
import java.net.*;
import java.io.*;


public class PropertyBasedMonitoringSocket_RMIServerSocketFactory
    implements RMIServerSocketFactory {
    private static final String USE_MONITORING_SOCKETS_PROPERTY = "com.ora.rmibook.useMonitoringSockets";
    private static final String TRUE = "true";

    private int _hashCode = "PropertyBasedMonitoringSocket_RMIServerSocketFactory".hashCode();
    private boolean _isMonitoringOn;

    public PropertyBasedMonitoringSocket_RMIServerSocketFactory() {
        String compressionProperty = System.getProperty(USE_MONITORING_SOCKETS_PROPERTY);

        if ((null != compressionProperty) && (compressionProperty.equalsIgnoreCase(TRUE))) {
            _isMonitoringOn = true;
            _hashCode++;
        } else {
            _isMonitoringOn = false;
        }
        return;
    }

    public ServerSocket createServerSocket(int port) {
        try {
            if (_isMonitoringOn) {
                return new MonitoringServerSocket(port);
            } else {
                return new ServerSocket(port);
            }
        } catch (IOException e) {
        }
        return null;
    }

    public boolean equals(Object object) {
        if (object instanceof PropertyBasedMonitoringSocket_RMIServerSocketFactory) {
            return true;
        }
        return false;
    }

    public int hashCode() {
        return _hashCode;
    }
}