Back to home page

OSCL-LXR

 
 

    


0001 #
0002 # Licensed to the Apache Software Foundation (ASF) under one or more
0003 # contributor license agreements.  See the NOTICE file distributed with
0004 # this work for additional information regarding copyright ownership.
0005 # The ASF licenses this file to You under the Apache License, Version 2.0
0006 # (the "License"); you may not use this file except in compliance with
0007 # the License.  You may obtain a copy of the License at
0008 #
0009 #    http://www.apache.org/licenses/LICENSE-2.0
0010 #
0011 # Unless required by applicable law or agreed to in writing, software
0012 # distributed under the License is distributed on an "AS IS" BASIS,
0013 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0014 # See the License for the specific language governing permissions and
0015 # limitations under the License.
0016 #
0017 
0018 # Methods to directly access the JVM running the SparkR backend.
0019 
0020 #' Call Java Methods
0021 #'
0022 #' Call a Java method in the JVM running the Spark driver. The return
0023 #' values are automatically converted to R objects for simple objects. Other
0024 #' values are returned as "jobj" which are references to objects on JVM.
0025 #'
0026 #' @details
0027 #' This is a low level function to access the JVM directly and should only be used
0028 #' for advanced use cases. The arguments and return values that are primitive R
0029 #' types (like integer, numeric, character, lists) are automatically translated to/from
0030 #' Java types (like Integer, Double, String, Array). A full list can be found in
0031 #' serialize.R and deserialize.R in the Apache Spark code base.
0032 #'
0033 #' @param x object to invoke the method on. Should be a "jobj" created by newJObject.
0034 #' @param methodName method name to call.
0035 #' @param ... parameters to pass to the Java method.
0036 #' @return the return value of the Java method. Either returned as a R object
0037 #'  if it can be deserialized or returned as a "jobj". See details section for more.
0038 #' @seealso \link{sparkR.callJStatic}, \link{sparkR.newJObject}
0039 #' @rdname sparkR.callJMethod
0040 #' @examples
0041 #' \dontrun{
0042 #' sparkR.session() # Need to have a Spark JVM running before calling newJObject
0043 #' # Create a Java ArrayList and populate it
0044 #' jarray <- sparkR.newJObject("java.util.ArrayList")
0045 #' sparkR.callJMethod(jarray, "add", 42L)
0046 #' sparkR.callJMethod(jarray, "get", 0L) # Will print 42
0047 #' }
0048 #' @note sparkR.callJMethod since 2.0.1
0049 sparkR.callJMethod <- function(x, methodName, ...) {
0050   callJMethod(x, methodName, ...)
0051 }
0052 
0053 #' Call Static Java Methods
0054 #'
0055 #' Call a static method in the JVM running the Spark driver. The return
0056 #' value is automatically converted to R objects for simple objects. Other
0057 #' values are returned as "jobj" which are references to objects on JVM.
0058 #'
0059 #' @details
0060 #' This is a low level function to access the JVM directly and should only be used
0061 #' for advanced use cases. The arguments and return values that are primitive R
0062 #' types (like integer, numeric, character, lists) are automatically translated to/from
0063 #' Java types (like Integer, Double, String, Array). A full list can be found in
0064 #' serialize.R and deserialize.R in the Apache Spark code base.
0065 #'
0066 #' @param x fully qualified Java class name that contains the static method to invoke.
0067 #' @param methodName name of static method to invoke.
0068 #' @param ... parameters to pass to the Java method.
0069 #' @return the return value of the Java method. Either returned as a R object
0070 #'  if it can be deserialized or returned as a "jobj". See details section for more.
0071 #' @seealso \link{sparkR.callJMethod}, \link{sparkR.newJObject}
0072 #' @rdname sparkR.callJStatic
0073 #' @examples
0074 #' \dontrun{
0075 #' sparkR.session() # Need to have a Spark JVM running before calling callJStatic
0076 #' sparkR.callJStatic("java.lang.System", "currentTimeMillis")
0077 #' sparkR.callJStatic("java.lang.System", "getProperty", "java.home")
0078 #' }
0079 #' @note sparkR.callJStatic since 2.0.1
0080 sparkR.callJStatic <- function(x, methodName, ...) {
0081   callJStatic(x, methodName, ...)
0082 }
0083 
0084 #' Create Java Objects
0085 #'
0086 #' Create a new Java object in the JVM running the Spark driver. The return
0087 #' value is automatically converted to an R object for simple objects. Other
0088 #' values are returned as a "jobj" which is a reference to an object on JVM.
0089 #'
0090 #' @details
0091 #' This is a low level function to access the JVM directly and should only be used
0092 #' for advanced use cases. The arguments and return values that are primitive R
0093 #' types (like integer, numeric, character, lists) are automatically translated to/from
0094 #' Java types (like Integer, Double, String, Array). A full list can be found in
0095 #' serialize.R and deserialize.R in the Apache Spark code base.
0096 #'
0097 #' @param x fully qualified Java class name.
0098 #' @param ... arguments to be passed to the constructor.
0099 #' @return the object created. Either returned as a R object
0100 #'   if it can be deserialized or returned as a "jobj". See details section for more.
0101 #' @seealso \link{sparkR.callJMethod}, \link{sparkR.callJStatic}
0102 #' @rdname sparkR.newJObject
0103 #' @examples
0104 #' \dontrun{
0105 #' sparkR.session() # Need to have a Spark JVM running before calling newJObject
0106 #' # Create a Java ArrayList and populate it
0107 #' jarray <- sparkR.newJObject("java.util.ArrayList")
0108 #' sparkR.callJMethod(jarray, "add", 42L)
0109 #' sparkR.callJMethod(jarray, "get", 0L) # Will print 42
0110 #' }
0111 #' @note sparkR.newJObject since 2.0.1
0112 sparkR.newJObject <- function(x, ...) {
0113   newJObject(x, ...)
0114 }