Example usage for java.rmi RemoteException RemoteException

List of usage examples for java.rmi RemoteException RemoteException

Introduction

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

Prototype

public RemoteException(String s, Throwable cause) 

Source Link

Document

Constructs a RemoteException with the specified detail message and cause.

Usage

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

public void applyDBScript(InputStream scriptInputStream)
        throws RemoteException, NotBoundException, AccessException {
    Statement stmt = null;/*  w  w  w.  j  a v a  2 s . c o  m*/
    ResultSet rset = null;
    try {
        checkConnection();
        stmt = _connection.createStatement();

        BufferedReader br = new BufferedReader(new InputStreamReader(scriptInputStream));
        String line = null;
        StringBuffer sbuffer = new StringBuffer();
        try {
            while ((line = br.readLine()) != null) {
                sbuffer.append(line.trim());
                sbuffer.append(" ");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        StringTokenizer st = new StringTokenizer(replaceCode(sbuffer.toString()), ";");
        while (st.hasMoreElements()) {
            String statmentStr = ((String) st.nextElement()).trim();
            if (statmentStr.equals(""))
                continue;

            System.out.println("<" + statmentStr + ">");

            try {
                if (statmentStr.trim().equalsIgnoreCase("commit")) {
                    _connection.commit();
                } else {
                    stmt.execute(statmentStr);
                }
                System.out.println("OK");
            } catch (SQLException sqle) {
                if (statmentStr.toUpperCase().startsWith("DROP")) {
                    System.out.println("NOK / " + statmentStr + " Failed ");
                } else {
                    sqle.printStackTrace();
                }
            }

        }
    } catch (SQLException sqle) {

        if (isNoConnectionError(sqle) && canReconnect()) {
            applyDBScript(scriptInputStream);
        } else {
            throw new RemoteException("", (sqle));
        }

    } finally {
        if (stmt != null)
            try {
                stmt.close();
            } catch (Exception e) {
                throw new RemoteException("", (e));
            }
        if (rset != null)
            try {
                stmt.close();
            } catch (Exception e) {
                throw new RemoteException("", (e));
            }
    }
}

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

public void setJobID(String servantName, String jobID) throws RemoteException {
    Statement stmt = null;//from  w  w  w.  ja  va  2 s.c om
    try {
        checkConnection();
        stmt = _connection.createStatement();
        stmt.execute("update SERVANTS SET JOB_ID='" + jobID + "' WHERE NAME='" + servantName + "'");
        _connection.commit();
    } catch (SQLException sqle) {
        if (isNoConnectionError(sqle) && canReconnect()) {
            setJobID(servantName, jobID);
        } else {
            throw new RemoteException("", (sqle));
        }
    } finally {
        if (stmt != null)
            try {
                stmt.close();
            } catch (Exception e) {
                throw new RemoteException("", (e));
            }
    }
}

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

public void setNotified(String servantName, boolean notified) throws RemoteException {
    Statement stmt = null;/*from w  w  w.  ja va  2  s. c  o  m*/
    try {
        checkConnection();
        stmt = _connection.createStatement();
        stmt.execute(
                "update SERVANTS SET NOTIFIED=" + (notified ? "1" : "0") + " WHERE NAME='" + servantName + "'");
        _connection.commit();
    } catch (SQLException sqle) {
        if (isNoConnectionError(sqle) && canReconnect()) {
            setNotified(servantName, notified);
        } else {
            throw new RemoteException("", (sqle));
        }
    } finally {
        if (stmt != null)
            try {
                stmt.close();
            } catch (Exception e) {
                throw new RemoteException("", (e));
            }
    }
}

From source file:org.kchine.rpf.MainServer.java

public static void main(String[] args) throws Exception {

    PoolUtils.initLog4J();/*  www .  j  a  v a  2  s . co m*/
    PoolUtils.ensurePublicIPIsUsedForRMI();
    PoolUtils.noGui();

    try {

        if (System.getSecurityManager() == null) {
            System.setSecurityManager(new YesSecurityManager());
        }

        boolean isNodeProvided = System.getProperty("node") != null && !System.getProperty("node").equals("");
        if (isNodeProvided) {
            NodeDataDB nodeData = null;
            try {
                rmiRegistry = ServerDefaults.getRmiRegistry();
                nodeData = ((DBLayerInterface) rmiRegistry)
                        .getNodeData("NODE_NAME='" + System.getProperty("node") + "'").elementAt(0);
            } catch (Exception e) {
                log.info("Couldn't retrieve Node Info for node <" + System.getProperty("node") + ">");
                e.printStackTrace();
                return;
            }
            System.setProperty("autoname", "true");
            _servantPoolPrefix = nodeData.getPoolPrefix();

            System.out.println("nodedata:" + nodeData);
        }

        if (System.getProperty("autoname") != null && System.getProperty("autoname").equalsIgnoreCase("true")) {
            log.info("Instantiating " + _mainServantClassName + " with autonaming, prefix "
                    + _servantPoolPrefix);
            servantName = null;
        } else {
            // no autonaming, check the name here
            if (System.getProperty("name") != null && !System.getProperty("name").equals("")) {
                servantName = System.getProperty("name");
            }
            log.info("Instantiating " + _mainServantClassName + " with name " + servantName + " , prefix "
                    + _servantPoolPrefix);
        }

        if (rmiRegistry == null)
            rmiRegistry = ServerDefaults.getRmiRegistry();

        System.out.println("### code base:" + System.getProperty("java.rmi.server.codebase"));

        ClassLoader cl = new URLClassLoader(PoolUtils.getURLS(System.getProperty("java.rmi.server.codebase")),
                MainServer.class.getClassLoader());
        Thread.currentThread().setContextClassLoader(cl);
        System.out.println(Arrays.toString(PoolUtils.getURLS(System.getProperty("java.rmi.server.codebase"))));

        mainServantClass = cl.loadClass(_mainServantClassName);

        boolean isPrivateServant = !isNodeProvided && ((System.getProperty("private") != null
                && System.getProperty("private").equalsIgnoreCase("true")));

        String servantCreationListenerStub = System.getProperty("listener.stub");
        if (servantCreationListenerStub != null && !servantCreationListenerStub.equals("")) {
            servantCreationListener = (ServantCreationListener) PoolUtils
                    .hexToObject(servantCreationListenerStub);
        }

        if (!isPrivateServant) {
            mservant = (ManagedServant) mainServantClass
                    .getConstructor(new Class[] { String.class, String.class, Registry.class })
                    .newInstance(new Object[] { servantName, _servantPoolPrefix, rmiRegistry });

        } else {

            mservant = (ManagedServant) mainServantClass
                    .getConstructor(new Class[] { String.class, String.class, Registry.class })
                    .newInstance(new Object[] { null, "PRIVATE_", rmiRegistry });

        }

        //System.out.println("clone:"+mservant.cloneServer());
        if (servantCreationListener != null) {
            PoolUtils.callBack(servantCreationListener, mservant, null);
        }

        String sname = mservant.getServantName();
        log.info("sname :::" + sname);
        if (rmiRegistry instanceof DBLayerInterface) {
            if (System.getProperty("node") != null && !System.getProperty("node").equalsIgnoreCase("")) {
                ((DBLayerInterface) rmiRegistry).updateServantNodeName(sname, System.getProperty("node"));
            } else {
                Vector<NodeDataDB> nodes = ((DBLayerInterface) rmiRegistry).getNodeData("");
                for (int i = 0; i < nodes.size(); ++i) {
                    String nodeName = nodes.elementAt(i).getNodeName();
                    String nodeIp = nodes.elementAt(i).getHostIp();
                    String nodePrefix = nodes.elementAt(i).getPoolPrefix();
                    if (sname.startsWith(nodePrefix) && nodeIp.equals(PoolUtils.getHostIp())) {
                        ((DBLayerInterface) rmiRegistry).updateServantNodeName(sname, nodeName);
                        break;
                    }
                }
            }

            HashMap<String, Object> attributes = new HashMap<String, Object>();
            Enumeration<Object> sysPropKeys = (Enumeration<Object>) System.getProperties().keys();
            while (sysPropKeys.hasMoreElements()) {
                String key = (String) sysPropKeys.nextElement();
                if (key.startsWith("attr.")) {
                    attributes.put(key, System.getProperty(key));
                }
            }

            ((DBLayerInterface) rmiRegistry).updateServantAttributes(sname, attributes);
        }
        //log.info("*************************$$$$$$$$$$$$");
        log.info("Servant " + sname + " instantiated successfully.");

    } catch (InvocationTargetException ite) {
        if (servantCreationListener != null) {
            PoolUtils.callBack(servantCreationListener, null,
                    new RemoteException("", ite.getTargetException()));
        }
        throw new Exception(PoolUtils.getStackTraceAsString(ite.getTargetException()));

    } catch (Exception e) {

        log.info("----------------------");
        log.info(PoolUtils.getStackTraceAsString(e));
        e.printStackTrace();
        log.error(e);

        if (servantCreationListener != null) {
            PoolUtils.callBack(servantCreationListener, null, new RemoteException("", e));
        }

        System.exit(1);
    }
}

From source file:org.kchine.rpf.ManagedServantAbstract.java

public String export(Properties namingRegistryProperties, String prefixOrName, boolean autoName)
        throws RemoteException {
    try {//from   w ww  .  ja  v a 2  s.  c o m
        Registry registry = ServerDefaults.getRegistry(namingRegistryProperties);
        if (autoName) {
            String newname = null;
            while (true) {
                newname = makeName(prefixOrName, registry);
                try {
                    registry.bind(newname, java.rmi.server.RemoteObject.toStub(this));
                    break;
                } catch (AlreadyBoundException e) {
                }
            }
            return newname;
        } else {
            registry.rebind(prefixOrName, java.rmi.server.RemoteObject.toStub(this));
            return prefixOrName;
        }
    } catch (Exception e) {
        throw new RemoteException("", e);
    }
}

From source file:org.mule.module.fws.api.PortProvider.java

public T getPort(String action) throws RemoteException {
    try {/*from  ww  w . j a  va 2  s  .  co m*/
        T port = newPort();
        setHeaders(getTimestamp(), action, (Stub) port);
        return port;
    } catch (Exception e) {
        throw new RemoteException("A Service exception occured while trying to create the port", e);
    }
}

From source file:org.mule.module.jira.api.DefaultAxisPortProvider.java

public JiraSoapService getService() throws RemoteException {
    JiraSoapServiceServiceLocator serviceLocator = new JiraSoapServiceServiceLocator();
    serviceLocator.setJirasoapserviceV2EndpointAddress(address);
    try {//from  w w w.  jav  a 2 s.  c o  m
        return serviceLocator.getJirasoapserviceV2();
    } catch (ServiceException e) {
        throw new RemoteException("A Service exception occured while trying to create the service", e);
    }
}

From source file:org.mule.module.magento.api.DefaultAxisPortProvider.java

public Mage_Api_Model_Server_V2_HandlerPortType getPort() throws RemoteException {
    MagentoServiceLocator serviceLocator = new MagentoServiceLocator();
    serviceLocator.setMage_Api_Model_Server_V2_HandlerPortEndpointAddress(address);
    try {/*from  w ww  .  j a  va2 s  . c  o m*/
        return serviceLocator.getMage_Api_Model_Server_V2_HandlerPort();
    } catch (ServiceException e) {
        throw new RemoteException("A Service exception occured while trying to create the port", e);
    }
}

From source file:org.nimbustools.messaging.gt4_0_elastic.v2008_05_05.rm.defaults.DefaultRequestSI.java

public RequestSpotInstancesResponseType requestSpotInstances(RequestSpotInstancesType req, Caller caller,
        Manager manager) throws RemoteException {

    final SpotRequestInfo result;
    try {//  ww w  . ja  v a 2s. c o m
        SpotCreateRequest creq = this.translateReqSpotInstances(req, caller);
        AddCustomizations.addAll((_CreateRequest) creq, this.repr, this.mdServer);
        result = manager.requestSpotInstances(creq, caller);

    } catch (Exception e) {
        throw new RemoteException(e.getMessage(), e);
    }

    try {
        SpotInstanceRequestSetItemType sirsit = this.describeSI.translateSpotInfo(result);

        SpotInstanceRequestSetType sirs = new SpotInstanceRequestSetType();
        sirs.setItem(new SpotInstanceRequestSetItemType[] { sirsit });

        RequestSpotInstancesResponseType response = new RequestSpotInstancesResponseType();
        response.setSpotInstanceRequestSet(sirs);

        return response;
    } catch (Exception e) {
        final String err = "Problem translating valid request spot instances "
                + "result into elastic protocol.  Backout required. " + " Error: " + e.getMessage();
        logger.error(err, e);
        this.cancelSI.backOutRequestSpotInstances(result, caller, manager);
        // gets caught by Throwable hook:
        throw new RuntimeException(err, e);
    }
}

From source file:org.nimbustools.messaging.gt4_0_elastic.v2008_05_05.rm.defaults.DefaultRequestSI.java

/**
 * Translate request spot instances // ww  w  .  j  a  va 2s.  c  om
 * into something the Manager understands.
 * 
 * @param req given SI request
 * @param caller caller object
 * @return valid create request for manager
 * @throws RemoteException unexpected error
 * @throws CannotTranslateException invalid request or configuration
 */
public SpotCreateRequest translateReqSpotInstances(RequestSpotInstancesType req, Caller caller)
        throws RemoteException, CannotTranslateException {

    final String ownerID;
    try {
        ownerID = this.container.getOwnerID(caller);
    } catch (CannotTranslateException e) {
        throw new RemoteException(e.getMessage(), e);
    }

    LaunchSpecificationRequestType launchSpec = req.getLaunchSpecification();

    final String imageID = launchSpec.getImageId();
    if (imageID == null) {
        throw new RemoteException("Request is missing image ID");
    }

    // currently ignored: groupSet, placement, kernel, ramdiskid,
    // blockDeviceMapping

    final _CustomizationRequest cust;
    final String keyname = launchSpec.getKeyName();
    if (keyname != null && this.sshKeys != null) {
        cust = this.repr._newCustomizationRequest();
        final SSHKey key = this.sshKeys.findKey(ownerID, keyname);
        if (key == null) {
            throw new RemoteException("There is no key '" + keyname + "' registered for you to use");
        }
        cust.setContent(key.getPubKeyValue());
        cust.setPathOnVM("/root/.ssh/authorized_keys");
    } else {
        cust = null;
    }

    final CustomizationRequest[] custRequests;
    if (cust != null) {
        custRequests = new CustomizationRequest[1];
        custRequests[0] = cust;
    } else {
        custRequests = null;
    }

    final String raType = launchSpec.getInstanceType();
    final ResourceAllocation ra = this.RAs.getMatchingRA(raType, req.getInstanceCount().intValue(),
            req.getInstanceCount().intValue(), true);
    final NIC[] nics = this.getNICs(ra.getPublicNetwork(), ra.getPrivateNetwork());

    final RequiredVMM reqVMM = this.RAs.getRequiredVMM();

    String userData = null;
    final UserDataType t_userData = launchSpec.getUserData();
    if (t_userData != null) {
        final String base64Encoded = t_userData.getData();
        if (base64Encoded != null) {
            if (!Base64.isBase64(base64Encoded)) {
                throw new RemoteException("userdata does not appear to " + "be base64 encoded?");
            }
            final byte[] bytes = Base64.decode(base64Encoded.getBytes());
            userData = new String(bytes);
        }
    }

    final VMFile[] files = this.repository.constructFileRequest(imageID, ra, caller);

    final Double spotPrice;
    try {
        spotPrice = new Double(req.getSpotPrice());
    } catch (NumberFormatException e) {
        throw new RemoteException("Error in spot price conversion.");
    }

    boolean persistent = DefaultDescribeSI.PERSISTENT.equalsIgnoreCase(req.getType());

    final _SpotCreateRequest screq = this.repr._newSpotCreateRequest();

    screq.setContext(null);
    screq.setCoScheduleDone(false);
    screq.setCoScheduleID(null);
    screq.setCoScheduleMember(false);
    screq.setCustomizationRequests(custRequests);
    screq.setInitialStateRequest(State.STATE_Running);
    screq.setName(imageID);
    screq.setRequestedKernel(null); // todo
    screq.setRequestedNics(nics);
    screq.setRequestedRA(ra);
    screq.setRequestedSchedule(null); // ask for default
    screq.setRequiredVMM(reqVMM);
    screq.setShutdownType(CreateRequest.SHUTDOWN_TYPE_TRASH);
    screq.setVMFiles(files);
    screq.setMdUserData(userData);
    screq.setSshKeyName(keyname);

    screq.setPersistent(persistent);
    screq.setSpotPrice(spotPrice);

    return screq;
}