Example usage for java.rmi NotBoundException NotBoundException

List of usage examples for java.rmi NotBoundException NotBoundException

Introduction

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

Prototype

public NotBoundException() 

Source Link

Document

Constructs a NotBoundException with no specified detail message.

Usage

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

public Remote lookup(String name) throws RemoteException, NotBoundException, AccessException {
    Statement stmt = null;//from  w ww.  ja  va2  s.  c  o m
    ResultSet rset = null;
    try {
        checkConnection();
        stmt = _connection.createStatement();
        rset = stmt.executeQuery("select STUB_HEX,CODEBASE from SERVANTS where NAME='" + name + "'");
        if (rset.next()) {

            final String stubHex = rset.getString(1);
            final String codeBaseStr = rset.getString(2);
            final ClassLoader cl = (codeBaseStr != null
                    ? new URLClassLoader(PoolUtils.getURLS(codeBaseStr), DBLayer.class.getClassLoader())
                    : DBLayer.class.getClassLoader());
            System.out.println("codeBaseStr ::" + codeBaseStr);

            final Object[] resultHolder = new Object[1];
            Runnable lookupRunnable = new Runnable() {
                public void run() {
                    try {
                        resultHolder[0] = hexToStub(stubHex, cl);
                    } catch (Exception e) {
                        final boolean wasInterrupted = Thread.interrupted();
                        if (wasInterrupted) {
                            resultHolder[0] = new LookUpInterrupted();
                        } else {
                            resultHolder[0] = e;
                        }
                    }
                }
            };

            Thread lookupThread = InterruptibleRMIThreadFactory.getInstance().newThread(lookupRunnable);
            lookupThread.start();

            long t1 = System.currentTimeMillis();
            while (resultHolder[0] == null) {
                if ((System.currentTimeMillis() - t1) > PoolUtils.LOOKUP_TIMEOUT_MILLISEC) {
                    lookupThread.interrupt();
                    resultHolder[0] = new LookUpTimeout();
                    registerPingFailure(name);
                    break;
                }
                Thread.sleep(10);
            }

            if (resultHolder[0] instanceof Throwable) {
                if (resultHolder[0] instanceof NotBoundException)
                    throw (NotBoundException) resultHolder[0];
                else
                    throw (RemoteException) resultHolder[0];
            }

            return (Remote) resultHolder[0];

        } else {
            throw new NotBoundException();
        }
    } catch (NotBoundException nbe) {
        throw nbe;
    } catch (AccessException ae) {
        throw ae;
    } catch (LookUpTimeout lue) {
        throw lue;
    } catch (LookUpInterrupted lui) {
        throw lui;
    } catch (SQLException sqle) {
        if (isNoConnectionError(sqle) && canReconnect()) {
            return lookup(name);
        } else {
            throw new RemoteException("", (sqle));
        }
    } catch (Exception e) {
        throw new RemoteException("", (e));
    } 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));
            }
    }
}