1

Is there a way to get notified when a method from a Different JVM is called.

Dev Env: JDK8, Windows 10 (later on cloud for deployment).

I have couple of Java applications running, One in App Server and another is standalone batch process.

Whenever a core java class method is called on either of these JVM's e.g. PrintStream.print, I need to get handle to input string and log it somewhere else.

I tried with 1. Java bytecode manipulation libraries e.g. Javassist, to transform byte code using Instrumentation, but it allows to have handle and manipulate User Defined classes / Third party library classes only - not java., sun. etc... (even if we do it somehow, it says - it violates JRE binary licence - Official Javadoc says this process of instrumenting the rt.jar class violates the JRE binary code license - so this may not be the go ahead approach. https://docs.oracle.com/javase/8/docs/technotes/tools/windows/java.html )

  1. Reflections - Can be used when you are on the same JVM, not sure if it works on different JVM.

    Appreciate suggestions.

Naman
  • 27,789
  • 26
  • 218
  • 353
Kedar
  • 11
  • 2
  • 2
    Java agents are capable of retransformation which would allow you to install hooks into target classes even if they are loaded. Have a look into Byte Byddy's AgentBuilder for example. – Rafael Winterhalter Feb 24 '20 at 21:18
  • @RafaelWinterhalter Thank You, I will have a look. If Byte Buddy allows to transform java.* class, does it not violate the JRE binary code license. Is there any other way to get method execution notification, from another JVM, apart from having a java agent. – Kedar Feb 24 '20 at 21:56
  • 1
    When you only want to process what it prints, why don’t you connect the process via a pipe? – Holger Feb 25 '20 at 07:26
  • @Holger Thank You. If we mean tcp/rmi.socket connection, that is not the preferred option by partner applications. Constraint I have is - no code change at partner application, and no opening of ports. Appreciate your help and suggestion. – Kedar Feb 26 '20 at 14:52
  • 1
    I didn’t mean changes to the application. When the application prints to its stdout, you can redirect it to a pipe and read it from your application. – Holger Feb 26 '20 at 15:57
  • Thank you RafaelWinterhalter and @Holger . You inputs have helped towards solution. – Kedar Mar 02 '20 at 15:02

0 Answers0