Example usage for java.rmi AlreadyBoundException AlreadyBoundException

List of usage examples for java.rmi AlreadyBoundException AlreadyBoundException

Introduction

In this page you can find the example usage for java.rmi AlreadyBoundException AlreadyBoundException.

Prototype

public AlreadyBoundException() 

Source Link

Document

Constructs an AlreadyBoundException with no specified detail message.

Usage

From source file:org.kchine.rpf.db.DBLayer.java

public void bind(String name, Remote obj, HashMap<String, Object> options)
        throws RemoteException, AlreadyBoundException, AccessException {

    Statement stmt = null;// ww  w .j  av a  2  s .  co m
    ResultSet rset = null;
    try {
        checkConnection();
        stmt = _connection.createStatement();
        lock(stmt);
        rset = stmt.executeQuery("select count(*) from SERVANTS where NAME='" + name + "'");
        rset.next();
        if (rset.getInt(1) > 0) {
            throw new AlreadyBoundException();
        }
    } catch (AlreadyBoundException abe) {
        try {
            if (stmt != null) {
                unlock(stmt);
                _connection.commit();
            }
        } catch (Exception e) {
            throw new RemoteException("", e);
        }
        throw abe;
    } catch (SQLException sqle) {
        if (isNoConnectionError(sqle) && canReconnect()) {
            bind(name, obj);
        } else {
            throw new RemoteException("", sqle);
        }
    } finally {
        if (rset != null)
            try {
                stmt.close();
            } catch (Exception e) {
                throw new RemoteException("", e);
            }
        if (stmt != null)
            try {
                stmt.close();
            } catch (Exception e) {
                throw new RemoteException("", e);
            }
    }

    stmt = null;
    String stub_hex = stubToHex(obj);
    try {
        stmt = _connection.createStatement();
        stmt.execute(
                "Insert into SERVANTS (NAME,STUB_HEX,IN_USE,PING_FAILURES,REGISTER_TIME,PROCESS_ID,HOST_NAME,HOST_IP,OS,CODEBASE,JOB_ID,JOB_NAME,NOTIFY_EMAIL,NOTIFIED) "
                        + "values ('" + name + "','" + stub_hex + "',0,0," + sysdateFunctionName() + ",'"
                        + options.get("process.id") + "','" + options.get("host.name") + "','"
                        + options.get("host.ip") + "','" + options.get("os.name") + "',"
                        + (options.get("java.rmi.server.codebase") == null ? "NULL"
                                : "'" + options.get("java.rmi.server.codebase") + "',")
                        + (options.get("job.id") == null ? "NULL" : "'" + options.get("job.id") + "'") + ","
                        + (options.get("job.name") == null ? "NULL" : "'" + options.get("job.name") + "'") + ","
                        + (options.get("notify.email") == null ? "NULL"
                                : "'" + options.get("notify.email") + "'")
                        + ",0)");
    } catch (SQLException sqle) {
        sqle.printStackTrace();
        if (isConstraintViolationError(sqle))
            throw new AlreadyBoundException();
        else
            throw new RemoteException("", (sqle));
    } finally {
        try {
            if (stmt != null) {
                unlock(stmt);
                _connection.commit();
            }
        } catch (Exception e) {
            throw new RemoteException("", (e));
        }
        if (stmt != null)
            try {
                stmt.close();
            } catch (Exception e) {
                throw new RemoteException("", (e));
            }
    }
}