diff options
Diffstat (limited to 'kamon-autoweave/src/main')
-rw-r--r-- | kamon-autoweave/src/main/scala/kamon/autoweave/Autoweave.scala | 15 | ||||
-rw-r--r-- | kamon-autoweave/src/main/scala/kamon/autoweave/loader/AgentLoader.scala | 45 |
2 files changed, 29 insertions, 31 deletions
diff --git a/kamon-autoweave/src/main/scala/kamon/autoweave/Autoweave.scala b/kamon-autoweave/src/main/scala/kamon/autoweave/Autoweave.scala index 29c4254a..58111b48 100644 --- a/kamon-autoweave/src/main/scala/kamon/autoweave/Autoweave.scala +++ b/kamon-autoweave/src/main/scala/kamon/autoweave/Autoweave.scala @@ -19,14 +19,13 @@ import kamon.Kamon import kamon.autoweave.loader.AgentLoader import org.aspectj.weaver.loadtime.Agent - object Autoweave { - val config = Kamon.config.getConfig("kamon.autowave.options") - val verbose = config.getBoolean("verbose") - val showWeaveInfo = config.getBoolean("showWeaveInfo") + val config = Kamon.config.getConfig("kamon.autowave.options") + val verbose = config.getBoolean("verbose") + val showWeaveInfo = config.getBoolean("showWeaveInfo") - System.setProperty("aj.weaving.verbose", verbose.toString) - System.setProperty("org.aspectj.weaver.showWeaveInfo", showWeaveInfo.toString) + System.setProperty("aj.weaving.verbose", verbose.toString) + System.setProperty("org.aspectj.weaver.showWeaveInfo", showWeaveInfo.toString) - AgentLoader.attachAgentToJVM(classOf[Agent]) - } + AgentLoader.attachAgentToJVM(classOf[Agent]) +} diff --git a/kamon-autoweave/src/main/scala/kamon/autoweave/loader/AgentLoader.scala b/kamon-autoweave/src/main/scala/kamon/autoweave/loader/AgentLoader.scala index d4efdb85..0ad7fdf7 100644 --- a/kamon-autoweave/src/main/scala/kamon/autoweave/loader/AgentLoader.scala +++ b/kamon-autoweave/src/main/scala/kamon/autoweave/loader/AgentLoader.scala @@ -15,18 +15,18 @@ package kamon.autoweave.loader -import java.io.{File, FileOutputStream, InputStream} +import java.io.{ File, FileOutputStream, InputStream } import java.lang.management.ManagementFactory import java.util import java.util.jar.Attributes.Name -import java.util.jar.{JarEntry, JarOutputStream, Manifest} +import java.util.jar.{ JarEntry, JarOutputStream, Manifest } import com.sun.tools.attach.spi.AttachProvider -import com.sun.tools.attach.{VirtualMachine, VirtualMachineDescriptor} +import com.sun.tools.attach.{ VirtualMachine, VirtualMachineDescriptor } import sun.tools.attach._ import scala.util.control.NoStackTrace -import scala.util.{Failure, Success, Try} +import scala.util.{ Failure, Success, Try } object AgentLoader { @@ -113,25 +113,25 @@ object AgentLoader { private def unqualify(clazz: Class[_]): String = clazz.getName.replace('.', '/') + ".class" /** - * Gets the current HotSpotVirtualMachine implementation otherwise a failure. - * - * @return - * Returns the HotSpotVirtualMachine implementation of the running JVM. - */ - private def findVirtualMachineImplementation(): Try[Class[_ <: HotSpotVirtualMachine]] = System.getProperty("os.name") match { - case os if os.startsWith("Windows") => Success(classOf[WindowsVirtualMachine]) - case os if os.startsWith("Mac OS X") => Success(classOf[BsdVirtualMachine]) - case os if os.startsWith("Solaris") => Success(classOf[SolarisVirtualMachine]) - case os if os.startsWith("Linux") || os.startsWith("LINUX") => Success(classOf[LinuxVirtualMachine]) - case other => Failure(new RuntimeException(s"Cannot use Attach API on unknown OS: $other") with NoStackTrace) + * Gets the current HotSpotVirtualMachine implementation otherwise a failure. + * + * @return + * Returns the HotSpotVirtualMachine implementation of the running JVM. + */ + private def findVirtualMachineImplementation(): Try[Class[_ <: HotSpotVirtualMachine]] = System.getProperty("os.name") match { + case os if os.startsWith("Windows") ⇒ Success(classOf[WindowsVirtualMachine]) + case os if os.startsWith("Mac OS X") ⇒ Success(classOf[BsdVirtualMachine]) + case os if os.startsWith("Solaris") ⇒ Success(classOf[SolarisVirtualMachine]) + case os if os.startsWith("Linux") || os.startsWith("LINUX") ⇒ Success(classOf[LinuxVirtualMachine]) + case other ⇒ Failure(new RuntimeException(s"Cannot use Attach API on unknown OS: $other") with NoStackTrace) } /** - * Attach to the running JVM. - * - * @return - * Returns the attached VirtualMachine - */ + * Attach to the running JVM. + * + * @return + * Returns the attached VirtualMachine + */ private def attachToRunningJVM(): VirtualMachine = { val AttachProvider = new AttachProvider() { override def name(): String = null @@ -141,15 +141,14 @@ object AgentLoader { } findVirtualMachineImplementation() match { - case Success(vmClass) => + case Success(vmClass) ⇒ val pid = getPidFromRuntimeMBean // This is only done with Reflection to avoid the JVM pre-loading all the XyzVirtualMachine classes. val vmConstructor = vmClass.getConstructor(classOf[AttachProvider], classOf[String]) val newVM = vmConstructor.newInstance(AttachProvider, pid) newVM.asInstanceOf[VirtualMachine] - case Failure(reason) => throw reason + case Failure(reason) ⇒ throw reason } } } - |