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) 

Source Link

Document

Constructs a RemoteException with the specified detail message.

Usage

From source file:org.kchine.r.server.impl.DefaultAssignInterfaceImpl.java

public long assign(final long rObjectId, final String slotsPath, final RObject robj) throws RemoteException {
    log.info("Assigning.. to obj id " + rObjectId + " " + slotsPath + "   --> " + robj);
    final long[] result = new long[1];
    final Exception[] exceptionHolder = new Exception[1];
    DirectJNI.getInstance().runR(new org.kchine.r.server.ExecutionUnit() {
        public void run(Rengine e) {
            try {
                String rootvar = DirectJNI.getInstance().newTemporaryVariableName();
                String argvar = DirectJNI.getInstance().newTemporaryVariableName();
                e.rniAssign(rootvar, rObjectId, 0);

                if (!(robj instanceof ReferenceInterface)) {
                    e.rniAssign(argvar, DirectJNI.getInstance().putObject(robj), 0);
                } else {
                    String argvar2 = DirectJNI.getInstance().newTemporaryVariableName();
                    e.rniAssign(argvar2, ((org.kchine.r.server.ReferenceInterface) robj).getRObjectId(), 0);
                    e.rniEval(e.rniParse(argvar + "<-" + argvar2
                            + ((org.kchine.r.server.ReferenceInterface) robj).getSlotsPath(), 1), 0);
                    e.rniEval(e.rniParse("rm(" + argvar2 + ")", 1), 0);
                }/*from www . j  a  v a  2s  .  c o m*/

                e.rniEval(e.rniParse(rootvar + slotsPath + "<-" + argvar, 1), 0);
                result[0] = e.rniEval(e.rniParse(rootvar, 1), 0);
                e.rniEval(e.rniParse("rm(" + rootvar + "," + argvar + ")", 1), 0);
            } catch (Exception ex) {
                exceptionHolder[0] = ex;
            }
        }
    });

    if (exceptionHolder[0] != null)
        throw new RemoteException(Utils.getStackTraceAsString(exceptionHolder[0]));
    return result[0];
}

From source file:org.kchine.r.server.impl.DefaultAssignInterfaceImpl.java

public RObject getObjectFromReference(final RObject refObj) throws RemoteException {

    if (DirectJNI.getInstance().runRInProgress()) {
        try {//w  w w .  j  a va2 s.  com
            return DirectJNI.getInstance().getObjectFromReference((ReferenceInterface) refObj);
        } catch (Exception e) {
            throw new RemoteException(Utils.getStackTraceAsString(e));
        }
    } else {
        final RObject[] robjHolder = new RObject[1];
        final Exception[] exceptionHolder = new Exception[1];
        DirectJNI.getInstance().runR(new org.kchine.r.server.ExecutionUnit() {
            public void run(Rengine e) {
                try {

                    robjHolder[0] = DirectJNI.getInstance().getObjectFromReference((ReferenceInterface) refObj);

                } catch (Exception ex) {
                    exceptionHolder[0] = ex;
                }
            }
        });
        if (exceptionHolder[0] != null)
            throw new RemoteException(Utils.getStackTraceAsString(exceptionHolder[0]));
        return robjHolder[0];
    }

}

From source file:org.kchine.r.server.impl.DefaultAssignInterfaceImpl.java

public RList getAttributes(final long rObjectId, final String slotsPath) throws RemoteException {
    final RList[] result = new RList[1];
    final Exception[] exceptionHolder = new Exception[1];
    DirectJNI.getInstance().runR(new org.kchine.r.server.ExecutionUnit() {
        public void run(Rengine e) {
            try {
                String rootvar = DirectJNI.getInstance().newTemporaryVariableName();
                e.rniAssign(rootvar, rObjectId, 0);
                result[0] = ((RList) DirectJNI.getInstance()
                        .getObjectFrom("attributes(" + rootvar + slotsPath + ")", false));
                e.rniEval(e.rniParse("rm(" + rootvar + ")", 1), 0);
            } catch (Exception ex) {
                exceptionHolder[0] = ex;
            }/*from  ww  w .j  a  v a  2s  .co m*/
        }
    });

    if (exceptionHolder[0] != null)
        throw new RemoteException(Utils.getStackTraceAsString(exceptionHolder[0]));
    return result[0];

}

From source file:org.kchine.r.server.impl.DefaultAssignInterfaceImpl.java

public long setAttributes(final long rObjectId, final String slotsPath, final RList attrs)
        throws RemoteException {
    final long[] result = new long[1];
    final Exception[] exceptionHolder = new Exception[1];
    DirectJNI.getInstance().runR(new org.kchine.r.server.ExecutionUnit() {
        public void run(Rengine e) {
            try {
                String rootvar = DirectJNI.getInstance().newTemporaryVariableName();
                String argvar = DirectJNI.getInstance().newTemporaryVariableName();
                e.rniAssign(rootvar, rObjectId, 0);
                if (attrs != null) {
                    e.rniAssign(argvar, DirectJNI.getInstance().putObject(attrs), 0);
                } else {
                    e.rniEval(e.rniParse(argvar + "<-NULL", 1), 0);
                }//from w  ww.  j a v  a  2s  . c  o  m
                e.rniEval(e.rniParse("attributes(" + rootvar + slotsPath + ")<-" + argvar, 1), 0);
                result[0] = e.rniEval(e.rniParse(rootvar, 1), 0);
                e.rniEval(e.rniParse("rm(" + rootvar + "," + argvar + ")", 1), 0);

            } catch (Exception ex) {
                exceptionHolder[0] = ex;
            }
        }
    });
    if (exceptionHolder[0] != null)
        throw new RemoteException(Utils.getStackTraceAsString(exceptionHolder[0]));
    return result[0];
}

From source file:org.kchine.r.server.impl.DefaultAssignInterfaceImpl.java

public int[] getIndexNA(final long rObjectId, final String slotsPath) throws RemoteException {
    final int[][] result = new int[1][];
    final Exception[] exceptionHolder = new Exception[1];
    DirectJNI.getInstance().runR(new org.kchine.r.server.ExecutionUnit() {
        public void run(Rengine e) {
            try {
                String rootvar = DirectJNI.getInstance().newTemporaryVariableName();
                e.rniAssign(rootvar, rObjectId, 0);
                int[] isNaIdx = e.rniGetIntArray(e.rniEval(e.rniParse(
                        "(0:(length(" + rootvar + slotsPath + ")-1))[is.na(" + rootvar + slotsPath + ")]", 1),
                        0));//w w  w .  ja  v a2 s  . com
                result[0] = isNaIdx.length == 0 ? null : isNaIdx;
                e.rniEval(e.rniParse("rm(" + rootvar + ")", 1), 0);

            } catch (Exception ex) {
                exceptionHolder[0] = ex;
            }
        }
    });

    if (exceptionHolder[0] != null)
        throw new RemoteException(Utils.getStackTraceAsString(exceptionHolder[0]));
    return result[0];
}

From source file:org.kchine.r.server.impl.DefaultAssignInterfaceImpl.java

public long setIndexNA(final long rObjectId, final String slotsPath, final int[] indexNA)
        throws RemoteException {
    final long[] result = new long[1];
    final Exception[] exceptionHolder = new Exception[1];
    DirectJNI.getInstance().runR(new org.kchine.r.server.ExecutionUnit() {
        public void run(Rengine e) {
            try {
                String rootvar = DirectJNI.getInstance().newTemporaryVariableName();
                String argvar = DirectJNI.getInstance().newTemporaryVariableName();
                e.rniAssign(rootvar, rObjectId, 0);

                if (indexNA != null) {
                    int length = e.rniGetIntArray(
                            e.rniEval(e.rniParse("length(" + rootvar + slotsPath + ")", 1), 0))[0];
                    boolean[] naBooleans = new boolean[length];
                    for (int i = 0; i < indexNA.length; ++i)
                        naBooleans[indexNA[i]] = true;
                    String naBooleansVar = DirectJNI.getInstance().newTemporaryVariableName();
                    e.rniAssign(naBooleansVar, e.rniPutBoolArray(naBooleans), 0);
                    e.rniEval(e.rniParse("is.na(" + rootvar + slotsPath + ")<-" + naBooleansVar, 1), 0);
                    e.rniEval(e.rniParse("rm(" + naBooleansVar + ")", 1), 0);
                }/*from   ww w. j  a v  a  2 s.  co m*/

                result[0] = e.rniEval(e.rniParse(rootvar, 1), 0);
                e.rniEval(e.rniParse("rm(" + rootvar + "," + argvar + ")", 1), 0);

            } catch (Exception ex) {
                exceptionHolder[0] = ex;
            }
        }
    });
    if (exceptionHolder[0] != null)
        throw new RemoteException(Utils.getStackTraceAsString(exceptionHolder[0]));
    return result[0];
}

From source file:org.kchine.r.server.impl.DefaultAssignInterfaceImpl.java

public String[] getNames(final long rObjectId, final String slotsPath) throws RemoteException {
    final String[][] result = new String[1][];
    final Exception[] exceptionHolder = new Exception[1];
    DirectJNI.getInstance().runR(new org.kchine.r.server.ExecutionUnit() {
        public void run(Rengine e) {
            try {
                String rootvar = DirectJNI.getInstance().newTemporaryVariableName();
                e.rniAssign(rootvar, rObjectId, 0);
                String[] names = null;
                long namesId = e.rniEval(e.rniParse("names(" + rootvar + slotsPath + ")", 1), 0);
                if (namesId != 0 && e.rniExpType(namesId) == STRSXP) {
                    names = e.rniGetStringArray(namesId);
                }//from ww w  . j  a v  a 2s  . co m
                result[0] = names;
                e.rniEval(e.rniParse("rm(" + rootvar + ")", 1), 0);

            } catch (Exception ex) {
                exceptionHolder[0] = ex;
            }
        }
    });
    if (exceptionHolder[0] != null)
        throw new RemoteException(Utils.getStackTraceAsString(exceptionHolder[0]));
    return result[0];
}

From source file:org.kchine.r.server.impl.DefaultAssignInterfaceImpl.java

public long setNames(final long rObjectId, final String slotsPath, final String[] names)
        throws RemoteException {
    final long[] result = new long[1];
    final Exception[] exceptionHolder = new Exception[1];

    System.out.println("before set name ->" + rObjectId);

    DirectJNI.getInstance().runR(new org.kchine.r.server.ExecutionUnit() {
        public void run(Rengine e) {
            try {
                String rootvar = DirectJNI.getInstance().newTemporaryVariableName();
                String argvar = DirectJNI.getInstance().newTemporaryVariableName();
                e.rniAssign(rootvar, rObjectId, 0);

                if (names != null) {
                    e.rniAssign(argvar, e.rniPutStringArray(names), 0);
                } else {
                    e.rniEval(e.rniParse(argvar + "<-NULL", 1), 0);
                }/*www.  j  a  va2  s. c  om*/

                e.rniEval(e.rniParse("names(" + rootvar + slotsPath + ")<-" + argvar, 1), 0);
                result[0] = e.rniEval(e.rniParse(rootvar, 1), 0);
                e.rniEval(e.rniParse("rm(" + rootvar + "," + argvar + ")", 1), 0);

            } catch (Exception ex) {
                exceptionHolder[0] = ex;
            }
        }
    });
    if (exceptionHolder[0] != null)
        throw new RemoteException(Utils.getStackTraceAsString(exceptionHolder[0]));

    // System.out.println("after set name ->" + result[0]);
    return result[0];

}

From source file:org.kchine.r.server.impl.DefaultAssignInterfaceImpl.java

public String[] getValueStringArray(final long rObjectId, final String slotsPath) throws RemoteException {
    final String[][] result = new String[1][];
    final Exception[] exceptionHolder = new Exception[1];
    DirectJNI.getInstance().runR(new org.kchine.r.server.ExecutionUnit() {
        public void run(Rengine e) {
            try {
                String rootvar = DirectJNI.getInstance().newTemporaryVariableName();
                e.rniAssign(rootvar, rObjectId, 0);

                if (e.rniGetBoolArrayI(
                        e.rniEval(e.rniParse("is.null(" + rootvar + slotsPath + ")", 1), 0))[0] == 1) {
                    result[0] = null;/* w  ww  .  j ava  2s .  c o m*/
                    return;
                }

                e.rniAssign(rootvar, rObjectId, 0);
                result[0] = e.rniGetStringArray(e.rniEval(e.rniParse(rootvar + slotsPath, 1), 0));
                e.rniEval(e.rniParse("rm(" + rootvar + ")", 1), 0);

            } catch (Exception ex) {
                exceptionHolder[0] = ex;
            }
        }
    });
    if (exceptionHolder[0] != null)
        throw new RemoteException(Utils.getStackTraceAsString(exceptionHolder[0]));
    return result[0];
}

From source file:org.kchine.r.server.impl.DefaultAssignInterfaceImpl.java

public long setValueStringArray(final long rObjectId, final String slotsPath, final String[] value)
        throws RemoteException {
    final long[] result = new long[1];
    final Exception[] exceptionHolder = new Exception[1];
    DirectJNI.getInstance().runR(new org.kchine.r.server.ExecutionUnit() {
        public void run(Rengine e) {
            try {
                String rootvar = DirectJNI.getInstance().newTemporaryVariableName();
                e.rniAssign(rootvar, rObjectId, 0);
                String argvar = DirectJNI.getInstance().newTemporaryVariableName();

                if (value != null) {
                    e.rniAssign(argvar, e.rniPutStringArray(value), 0);
                } else {
                    e.rniEval(e.rniParse(argvar + "<-NULL", 1), 0);
                }/*from   w  ww. ja  va2s. c  om*/

                e.rniEval(e.rniParse(rootvar + slotsPath + "<-" + argvar, 1), 0);

                result[0] = e.rniEval(e.rniParse(rootvar, 1), 0);
                e.rniEval(e.rniParse("rm(" + rootvar + "," + argvar + ")", 1), 0);

            } catch (Exception ex) {
                exceptionHolder[0] = ex;
            }
        }
    });
    if (exceptionHolder[0] != null)
        throw new RemoteException(Utils.getStackTraceAsString(exceptionHolder[0]));
    return result[0];

}