Skip to content

Instantly share code, notes, and snippets.

View nickman's full-sized avatar

Nicholas Whitehead nickman

View GitHub Profile
/**
* Creates a new JMS Message proxy
* @param message The JMS message
* @param connection The session used to create the browser
* @param destination The destination the browser is browsing
* @throws JMSException
*/
public ClosuredJMSMessage(Message message, Session session, Destination destination) throws JMSException {
this.message = message;
this.destination = destination;
@nickman
nickman / install.sh
Created May 20, 2011 13:16
Graphite Server Install Script for Ubuntu
#!/bin/bash
#######################################
# Graphite Install
# Run with sudo for best results
#
#######################################
if [[ "$(/usr/bin/whoami)" != "root" ]]; then
echo "This script must be run as root or using sudo.Script aborted."
exit 1
import com.onexchange.org.*;
import groovy.xml.MarkupBuilder;
writer = new StringWriter()
fixml = new MarkupBuilder(writer);
reqIdCounter = 0;
transactionType = 3;
adjType = 2;
actn = 1;
bizDt = "2011-04-28";
@nickman
nickman / CodeSnippetForMarkupBuilder.groovy
Created July 6, 2011 13:52
Code Snippet For MarkupBuilder
import groovy.xml.MarkupBuilder;
writer = new StringWriter()
fixml = new MarkupBuilder(writer);
fixml.setDoubleQuotes(true);
driverSql = "select * from .......";
@nickman
nickman / IteratingMemoryPoolCommitedMemory.groovy
Created January 6, 2012 15:40
Gmx Example: Iterating Memory Pool Commited Memory
import org.helios.gmx.*;
gmx = Gmx.remote("service:jmx:rmi://testserver1:8002/jndi/rmi://testserver1:8003/jmxrmi");
gmx.mbeans("java.lang:type=MemoryPool,name=*", {
println "${it.objectName}:\t${it.Usage.committed}";
});
@nickman
nickman / IteratingLocalVMs.groovy
Created January 6, 2012 18:54
Gmx Example: Iterating Local VMs And Printing MBeanServerId
import org.helios.gmx.*;
Gmx.attachInstances(true, {
println it.mbean("JMImplementation:type=MBeanServerDelegate").MBeanServerId;
});
@nickman
nickman / RemoteGetTotalBlockCount.groovy
Created January 6, 2012 21:39
Gmx Example: Remote call to compute sum of all thread's block counts
import org.helios.gmx.*;
def gmx = Gmx.remote("service:jmx:rmi://testserver1:8002/jndi/rmi://testserver1:8003/jmxrmi");
gmx.installRemote();
def remoteMBeanServer = gmx.gmxRemote();
def script =
"import java.lang.management.*; long blockedCount = 0; " +
"ManagementFactory.getThreadMXBean().getThreadInfo(ManagementFactory.getThreadMXBean().getAllThreadIds()).each() { " +
"blockedCount += it.getBlockedCount(); }; " +
"return blockedCount; ";
long totalBc = remoteMBeanServer.invokeScript(script, [] as Object[]);
@nickman
nickman / SimpleRemoteClosure.groovy
Created January 13, 2012 14:58
Simplest Closure Remoting Example
def gmx = Gmx.remote("service:jmx:rmi://testserver1:8002/jndi/rmi://testserver1:8003/jmxrmi");
gmx.exec({
println "Hello Jupiter";
});
@nickman
nickman / GroovyClassByteCodeRetrieval.groovy
Created January 13, 2012 15:20
Example of Getting ByteCode From A Compiled Groovy Class
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();
@nickman
nickman / SimpleBCR.groovy
Created January 13, 2012 19:55
Simple Working Exampe of BCR
import org.helios.gmx.classloading.*;
foo = {message -> println message};
bytes = ByteCodeRepository.getInstance().getByteCode(foo.getClass());
println "Class:${foo.getClass().getName()} ByteCode:${bytes.length} bytes";