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
| public class MyStringServerFactory implements ChannelPipelineFactory { | |
| public ChannelPipeline getPipeline() throws Exception { | |
| ChannelPipeline p = Channels.pipeline(); | |
| // Decoders | |
| p.addLast("frameDecoder", new DelimiterBasedFrameDecoder(Delimiters.lineDelimiter())); | |
| p.ddLast("stringDecoder", new StringDecoder(CharsetUtil.UTF_8)); | |
| // Encoder | |
| p.addLast("stringEncoder", new StringEncoder(CharsetUtil.UTF_8)); | |
| return p; | |
| } |
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
| <table border='1'><tr><th>Direction</th><th>Sharable</th><th>Exclusive</th></tr><tr><td>Upstream</td><td valign='top'> | |
| <ul> | |
| <li>org.jboss.netty.handler.timeout.ReadTimeoutHandler</li> | |
| <li>org.jboss.netty.handler.codec.base64.Base64Decoder</li> | |
| <li>org.jboss.netty.handler.timeout.IdleStateHandler</li> | |
| <li>org.jboss.netty.handler.codec.protobuf.ProtobufDecoder</li> | |
| <li>org.jboss.netty.handler.codec.string.StringDecoder</li> | |
| </ul></td><td valign='top'> | |
| <ul> | |
| <li>org.jboss.netty.handler.timeout.IdleStateAwareChannelUpstreamHandler</li> |
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
| Executor bossPool = Executors.newCachedThreadPool(); | |
| Executor workerPool = Executors.newCachedThreadPool(); | |
| ChannelFactory channelFactory = new NioClientSocketChannelFactory(boosPool, workerPool); | |
| ChannelPipelineFactory pipelineFactory = new ChannelPipelineFactory() { | |
| public ChannelPipeline getPipeline() throws Exception { | |
| return Channels.pipeline( | |
| new ObjectEncoder() | |
| } | |
| }; | |
| Bootstrap boostrap = new ClientBootstrap(channelFactory); |
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 org.helios.jmx; | |
| import java.io.ObjectInputStream; | |
| import java.lang.management.ManagementFactory; | |
| import java.util.Set; | |
| import javax.management.Attribute; | |
| import javax.management.AttributeList; | |
| import javax.management.AttributeNotFoundException; | |
| import javax.management.InstanceAlreadyExistsException; |
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
| import org.helios.gmx.classloading.*; | |
| import org.codehaus.groovy.control.* | |
| def instrumentation = ByteCodeRepository.getInstance().agentInstrumentation.getInstrumentation(); | |
| class ByteCodeNet implements java.lang.instrument.ClassFileTransformer { | |
| public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined, java.security.ProtectionDomain protectionDomain, byte[] classfileBuffer) { | |
| if(ByteCodeRepository.getInstance().isGeneratedClosure(classfileBuffer)) { | |
| println "Generated Closure: $className"; | |
| } |
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
| import org.codehaus.groovy.control.* | |
| import org.codehaus.groovy.ast.ClassHelper; | |
| import org.helios.gmx.classloading.*; | |
| // Acquire the instrumentation instance | |
| def instrumentation = ByteCodeRepository.getInstance().agentInstrumentation.getInstrumentation(); | |
| // Define a closre | |
| foo = {message -> println message}; | |
| // Define a simple class file transformer | |
| class ByteCodeNet implements java.lang.instrument.ClassFileTransformer { | |
| def clazzName; |
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
| /** | |
| * {@inheritDoc} | |
| * @see java.lang.instrument.ClassFileTransformer#transform(java.lang.ClassLoader, java.lang.String, java.lang.Class, java.security.ProtectionDomain, byte[]) | |
| */ | |
| @Override | |
| public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException { | |
| byte[] bytecode = classfileBuffer; | |
| if(classBeingRedefined==null) { | |
| if(loader instanceof GroovyClassLoader && isGeneratedClosure(bytecode)) { |
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
| import org.helios.gmx.classloading.*; | |
| foo = {message -> println message}; | |
| bytes = ByteCodeRepository.getInstance().getByteCode(foo.getClass()); | |
| println "Class:${foo.getClass().getName()} ByteCode:${bytes.length} bytes"; |
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
| import org.codehaus.groovy.control.* | |
| // Compile a closure producing class | |
| cu = new CompilationUnit(); | |
| cu.addSource("ClosureFactory.groovy", "public class ClosureFactory { public Closure getClosure() { return {message -> println message} }; }"); | |
| cu.compile(); | |
| // Get the closure, the closure class bytes and invoke the closure. | |
| clazz = Class.forName("ClosureFactory"); | |
| clozure = clazz.newInstance().getClosure(); | |
| clozureClass = clozure.getClass(); |