FileDocCategorySizeDatePackage
BasicFactory_Impl.javaAPI DocExample2423Thu Nov 08 00:23:06 GMT 2001com.ora.rmibook.chapter17.basic.factory

BasicFactory_Impl

public abstract class BasicFactory_Impl extends UnicastRemoteObject implements BasicFactory

Fields Summary
private HashMap
_namesToServers
private HashMap
_serversToSupport
private Integer
_one
Constructors Summary
public BasicFactory_Impl()

    
        
        _namesToServers = createServers();
        _serversToSupport = new HashMap();
    
Methods Summary
protected abstract java.util.HashMapcreateServers()

public voiddoneWithAccount(java.lang.String accountName)

        Remote server = (Account) _namesToServers.get(accountName);

        if (null == server) {
            return;
        }
        Integer support = (Integer) _serversToSupport.get(server);

        if (null == support) {
            System.out.println("Attempt to unexport non-supported account");
            return;
        }
        int newSupportValue = support.intValue() - 1;

        if (newSupportValue > 0) {
            _serversToSupport.put(server, new Integer(newSupportValue));
            return;
        }
        try {
            UnicastRemoteObject.unexportObject(server, true);
            _serversToSupport.remove(server);
            System.out.println("Server " + accountName + " successfully unexported.");
        } catch (Exception e) {
            System.out.println(e);
        }
    
public java.rmi.RemotegetAccount(java.lang.String accountName)

        Remote server = (Remote) _namesToServers.get(accountName);

        if (null == server) {
            return null;
        }
        Integer support = (Integer) _serversToSupport.get(server);

        if (null == support) {
            try {
                RemoteStub stub = (RemoteStub) UnicastRemoteObject.exportObject(server);

                System.out.println("Server " + accountName + " successfully exported.");
                support = _one;
            } catch (Exception e) {
                System.out.println(e);
                return null;
            }
        } else {
            support = new Integer(support.intValue() + 1);
        }
        _serversToSupport.put(server, support);
        return server;