so, you’ve found java.lang.instrument.Instrumentation. neat, huh?
now, rather than having to start your agent via the command line, wouldn’t it be neat to do what they suggest in the package javadocs and load an agent dynamically at runtime?
i had a hell of a time finding details on exactly how to do this. install an agent in another vm? sure. current vm? nah.
in randomly following links last night, i came across a blog post from dain, and it mentioned a getPid() routine that OpenJPA uses. this tickled my memory, and i went looking for the class that uses it. i found the InstrumentationFactory from the OpenJPA code. jackpot!
what they do, is use the Attach API that Sun added in Java 6 to dynamically load an agent. They had to do a trick in order to figure out the current PID, but with that, no problem!
i did need to make some tweaks to their code to have it load in my environment. if you’re working in an environment with dynamic class loaders, when the class is loaded as an agent, it will be a new instance and thus not visible to the factory as-is. to get around this, split the factory into two pieces. the agent, and the factory. the factory does not use the agent at all, it always accesses it reflectively. then, after the agent has been loaded, use Class.forName("your.agent.class.name", true, ClassLoader.getSystemClassLoader() ) to get the instance. reflectively load the stored instrumentation and bingo!
June 27th 2008 · Tags: instrumentation, java | 2 Comments »
yesterday was my last day at radar networks. i had been there for 31 months. (incidentally, i’ll be 31 years old in a few months as well).
i’ve learned a lot working there; it was the first venture-funded startup i had worked for. i got to see the team grow from around 5 to the current 20-something. my co-workers and teammates were all immensely skilled in areas different than i, so it was a great experience to witness how they did what they did. we worked like mad to get twine launched. i now leave it in their capable hands to allow it to grow and mature. keep an eye on it, there are a lot of cool ideas that should be surfacing in the next few months.
the completely different thing is going to work for a gaming company, electrotank. i’m not much of a gamer myself (aside from lots of mario kart. comment if you’ve got it on the wii as well so we can play!),
it will be an opportunity to learn about an entirely different industry. what i’ll be doing is of course what i’m good at, helping architect/design/build the back-end systems for maintainability and scaling. their core product is built on apache mina, so this will also allow me to spend more time with the community than i had in the past year.
i wish all my past radar colleagues the best, look forward to meeting all my new teammates, and tackling the fun challenges ahead!
May 31st 2008 · Tags: changes, electrotank, life, radar | 2 Comments »
here are the slides for my presentation at apachecon us 2007 on MINA
November 14th 2007 · Tags: tech | No Comments »