Skip to content

Instantly share code, notes, and snippets.

@dmi3coder
Created April 22, 2020 16:12
Show Gist options
  • Save dmi3coder/70021457955ec216907428cabf016943 to your computer and use it in GitHub Desktop.
Save dmi3coder/70021457955ec216907428cabf016943 to your computer and use it in GitHub Desktop.
Simple example of how to call R code from Quarkus
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