RelProxy: A Hot Class Reloader and Scripting for Java and Groovy
Join the DZone community and get the full member experience.
Join For FreeWhat is RelProxy?
RelProxy has three principal features:
1) A class reloader in runtime from source code in Groovy or Java. Similar to JRebel but not so sophisticated... and cheaper.
2) A scripting environment for Java as a scripting language, including "shell scripts" coded in pure Java.
3) JSR-223 Java Scripting API support for "the scripting language named Java."
RelProxy was born to provide automatic class reload to ItsNat, a Java based web framework, for code in Groovy, it became a general purpose tool including Java support.
1) A class reloader in runtime from source code in Groovy or Java.
This is when RelProxy makes its job through a utility named GProxy. With GProxy, we create a java.lang.reflect.Proxy and pass this proxy instead of the original Groovy object. When a method is called to java.lang.reflect.Proxy, the method call is intercepted by GProxy an through Groovy engine RelProxy checks whether some class has changed, when changed the source code of the class of the original object or other dependent class, the original object is re-created based on the new class, the same dependent classes.
FalseDB db = new FalseDB(); ItsNatServletRequestListener listener = JProxy.create(new example.javaex.JProxyExampleLoadListener(db), ItsNatServletRequestListener.class); docTemplate.addItsNatServletRequestListener(listener);
#!/usr/bin/env jproxysh String msg = args[0] + args[1]; System.out.println(msg); System.out.println("example_java_shell 1 "); example.javashellex.JProxyShellExample.exec();
#!/usr/bin/env jproxysh import example.javashellex.JProxyShellExample; public class example_java_shell_complete_class { public static void main(String[] args) { String msg = args[0] + args[1]; System.out.println(msg); System.out.println("example_java_shell_complete_class 1 "); JProxyShellExample.exec(); } }
jproxysh example_normal_class.java "HELLO " "WORLD!"
jproxysh -c 'System.out.print("This code snippet says: ");' \ 'System.out.println("Hello World!!");'
jproxysh -c 'public class _jproxyMainClass_ { ' \ ' public static void main(String[] args) { ' \ ' System.out.print("This code snippet says: ");' \ ' System.out.println("Hello World!!");' \ ' }' \ '}'
jproxysh
JProxyScriptEngineFactory factory = JProxyScriptEngineFactory.create(jpConfig); ScriptEngineManager manager = new ScriptEngineManager(); manager.registerEngineName("Java", factory); manager.getBindings().put("msg","HELLO GLOBAL WORLD!"); ScriptEngine engine = manager.getEngineByName("Java"); Bindings bindings = engine.createBindings(); bindings.put("msg","HELLO SCOPE WORLD!"); StringBuilder code = new StringBuilder(); code.append( " javax.script.Bindings bindings = context.getBindings(javax.script.ScriptContext.ENGINE_SCOPE); \n"); code.append( " String msg = (String)bindings.get(\"msg\"); \n"); code.append( " System.out.println(msg); \n"); code.append( " bindings = context.getBindings(javax.script.ScriptContext.GLOBAL_SCOPE); \n"); code.append( " msg = (String)bindings.get(\"msg\"); \n"); code.append( " System.out.println(msg); \n"); code.append( " example.javashellex.JProxyShellExample.exec(engine); \n"); code.append( " return \"SUCCESS\";"); String result = (String)engine.eval( code.toString() , bindings); System.out.println("RETURNED: " + result);
Opinions expressed by DZone contributors are their own.
Trending
-
Competing Consumers With Spring Boot and Hazelcast
-
Microservices With Apache Camel and Quarkus (Part 2)
-
Writing a Vector Database in a Week in Rust
-
Step Into Serverless Computing
Comments