Created
June 20, 2020 05:16
-
-
Save dmi3coder/8d716f8f9bd8458f229965069e7f668f to your computer and use it in GitHub Desktop.
Example of C language execution 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 net.quarkify.cpp; | |
import io.quarkus.runtime.StartupEvent; | |
import org.graalvm.polyglot.Context; | |
import org.graalvm.polyglot.Source; | |
import org.graalvm.polyglot.Value; | |
import javax.enterprise.event.Observes; | |
import javax.ws.rs.GET; | |
import javax.ws.rs.Path; | |
import javax.ws.rs.Produces; | |
import javax.ws.rs.core.MediaType; | |
import java.io.File; | |
import java.io.IOException; | |
import java.net.URL; | |
@Path("/hello") | |
public class ExampleResource { | |
private Value helloMethod; | |
public void onStart(@Observes StartupEvent se) { | |
new Thread() {{ | |
final URL drawImage = getClass().getClassLoader().getResource("example"); | |
Context polyglot = Context.newBuilder().allowAllAccess(true).build(); | |
Source source = null; | |
try { | |
source = Source.newBuilder("llvm", drawImage).build(); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
helloMethod = polyglot.eval(source); | |
}}.start(); | |
} | |
@GET | |
@Produces(MediaType.TEXT_PLAIN) | |
public String executeHello() throws IOException { | |
helloMethod.execute(); | |
return "See terminal output :)"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment