Created
April 22, 2020 16:12
-
-
Save dmi3coder/70021457955ec216907428cabf016943 to your computer and use it in GitHub Desktop.
Simple example of how to call R code from Quarkus
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package tech.donau.quarkify; | |
import org.graalvm.polyglot.*; | |
import javax.ws.rs.*; | |
import javax.ws.rs.core.MediaType; | |
import java.io.IOException; | |
import java.net.URL; | |
@Path("/cooling") | |
public class CpuCoolingResource { | |
public static Context context = Context.newBuilder().allowIO(true).allowAllAccess(true).build(); | |
@GET | |
@Produces(MediaType.TEXT_PLAIN) | |
public String hello() throws IOException { | |
final URL cpuCoolingR = getClass().getClassLoader().getResource("cpu_cooling.R"); | |
System.out.println(cpuCoolingR); | |
Value needs_cooling = context.eval(Source.newBuilder("R", cpuCoolingR).build()); | |
return needs_cooling.asDouble() > 0.8 ? "Enable cooling" : "No need to enable cooling"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment