incubator-kitty-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pids...@apache.org
Subject svn commit: r1131237 - in /incubator/kitty/sandbox/trunk: ./ agent/ agent/src/ agent/src/main/ agent/src/main/java/ agent/src/main/java/org/ agent/src/main/java/org/apache/ agent/src/main/java/org/apache/kitty/ agent/src/main/java/org/apache/kitty/agen...
Date Fri, 03 Jun 2011 20:58:20 GMT
Author: pidster
Date: Fri Jun  3 20:58:18 2011
New Revision: 1131237

URL: http://svn.apache.org/viewvc?rev=1131237&view=rev
Log:
Add stub for prototype agent, groovy1.8 rewrite and associated gradle build

Added:
    incubator/kitty/sandbox/trunk/agent/
    incubator/kitty/sandbox/trunk/agent/build.gradle
    incubator/kitty/sandbox/trunk/agent/src/
    incubator/kitty/sandbox/trunk/agent/src/main/
    incubator/kitty/sandbox/trunk/agent/src/main/java/
    incubator/kitty/sandbox/trunk/agent/src/main/java/org/
    incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/
    incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/
    incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/agent/
    incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/agent/Agent.java   (with props)
    incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/agent/AgentClassLoader.java   (with props)
    incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/agent/AgentCommandExecutor.java   (with props)
    incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/agent/AgentDataCollector.java   (with props)
    incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/agent/AgentParameterParser.java   (with props)
    incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/agent/AgentRuntime.java   (with props)
    incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/agent/AgentScriptEngine.java   (with props)
    incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/agent/impl/
    incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/agent/impl/CommandExecutorImpl.java   (with props)
    incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/agent/impl/DataCollectorImpl.java   (with props)
    incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/agent/impl/RuntimeImpl.java   (with props)
    incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/agent/impl/ScriptEngineImpl.java   (with props)
    incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/loader/
    incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/loader/Loader.java   (with props)
    incubator/kitty/sandbox/trunk/agent/src/main/resources/
    incubator/kitty/sandbox/trunk/agent/src/main/resources/META-INF/
    incubator/kitty/sandbox/trunk/agent/src/main/resources/META-INF/services/
    incubator/kitty/sandbox/trunk/agent/src/main/resources/META-INF/services/org.apache.kitty.agent.AgentRuntime
    incubator/kitty/sandbox/trunk/agent/src/test/
    incubator/kitty/sandbox/trunk/agent/src/test/java/
    incubator/kitty/sandbox/trunk/agent/src/test/java/org/
    incubator/kitty/sandbox/trunk/agent/src/test/java/org/apache/
    incubator/kitty/sandbox/trunk/agent/src/test/java/org/apache/kitty/
    incubator/kitty/sandbox/trunk/agent/src/test/java/org/apache/kitty/agent/
    incubator/kitty/sandbox/trunk/agent/src/test/java/org/apache/kitty/loader/
    incubator/kitty/sandbox/trunk/agent/src/test/resources/
    incubator/kitty/sandbox/trunk/build.gradle   (with props)
    incubator/kitty/sandbox/trunk/groovy1.8/
    incubator/kitty/sandbox/trunk/groovy1.8/build.gradle   (with props)
    incubator/kitty/sandbox/trunk/groovy1.8/src/
    incubator/kitty/sandbox/trunk/groovy1.8/src/main/
    incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/
    incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/
    incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/
    incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/
    incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/Dispatcher.groovy   (with props)
    incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/Exceptions.groovy   (with props)
    incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/Kitty.groovy   (with props)
    incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/KittyShell.groovy   (with props)
    incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/Main.groovy   (with props)
    incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/annotations/
    incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/annotations/Command.groovy   (with props)
    incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/annotations/Connector.groovy   (with props)
    incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/annotations/Library.groovy   (with props)
    incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/commands/
    incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/commands/Common.groovy   (with props)
    incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/commands/Connect.groovy   (with props)
    incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/commands/Tomcat.groovy   (with props)
    incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/util/
    incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/util/ConnectionURLParser.groovy   (with props)
    incubator/kitty/sandbox/trunk/groovy1.8/src/main/java/
    incubator/kitty/sandbox/trunk/groovy1.8/src/main/resources/
    incubator/kitty/sandbox/trunk/groovy1.8/src/main/resources/META-INF/
    incubator/kitty/sandbox/trunk/groovy1.8/src/main/resources/META-INF/services/
    incubator/kitty/sandbox/trunk/groovy1.8/src/test/
    incubator/kitty/sandbox/trunk/groovy1.8/src/test/groovy/
    incubator/kitty/sandbox/trunk/groovy1.8/src/test/java/
    incubator/kitty/sandbox/trunk/groovy1.8/src/test/java/org/
    incubator/kitty/sandbox/trunk/groovy1.8/src/test/java/org/apache/
    incubator/kitty/sandbox/trunk/groovy1.8/src/test/java/org/apache/kitty/
    incubator/kitty/sandbox/trunk/groovy1.8/src/test/java/org/apache/kitty/KittyTest1.java   (with props)
    incubator/kitty/sandbox/trunk/groovy1.8/src/test/resources/
    incubator/kitty/sandbox/trunk/settings.gradle   (with props)
Modified:
    incubator/kitty/sandbox/trunk/   (props changed)

Propchange: incubator/kitty/sandbox/trunk/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Fri Jun  3 20:58:18 2011
@@ -0,0 +1,7 @@
+.settings
+
+.gradle
+
+.classpath
+
+.project

Added: incubator/kitty/sandbox/trunk/agent/build.gradle
URL: http://svn.apache.org/viewvc/incubator/kitty/sandbox/trunk/agent/build.gradle?rev=1131237&view=auto
==============================================================================
--- incubator/kitty/sandbox/trunk/agent/build.gradle (added)
+++ incubator/kitty/sandbox/trunk/agent/build.gradle Fri Jun  3 20:58:18 2011
@@ -0,0 +1,50 @@
+/*
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+*/
+
+title = 'Apache Kitty (Incubating) Agent'
+description = 'This is the Apache Kitty Gradle build script'
+
+version = '0.1-SANDBOX-SNAPSHOT'
+packageName = 'apache-kitty-agent'
+applicationName = 'kitty-agent'
+
+mainClassName = 'org.apache.kitty.loader.Loader'
+agentClassName = 'org.apache.kitty.agent.Agent'
+
+sourceCompatibility = 1.6
+targetCompatibility = 1.6
+
+jar {
+	baseName = "$packageName"
+	manifest {
+		attributes (
+			'Main-Class': "$mainClassName",
+			'Premain-Class': "$agentClassName",
+			'Agent-Class': "$agentClassName",
+			'Implementation-Title': "$title", 
+			'Implementation-Version': "$version",
+			'Can-Redefine-Classes': 'true',
+			'Can-Retransform-Classes': 'true',
+			'Can-Set-Native-Method-Prefix': 'false'
+		)
+	}
+}
+
+distZip {
+	baseName = "$packageName"
+}
+

Added: incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/agent/Agent.java
URL: http://svn.apache.org/viewvc/incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/agent/Agent.java?rev=1131237&view=auto
==============================================================================
--- incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/agent/Agent.java (added)
+++ incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/agent/Agent.java Fri Jun  3 20:58:18 2011
@@ -0,0 +1,97 @@
+/*
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+*/
+
+package org.apache.kitty.agent;
+
+import java.lang.instrument.Instrumentation;
+import java.lang.management.ManagementFactory;
+import java.net.URL;
+import java.util.ServiceLoader;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.management.InstanceAlreadyExistsException;
+import javax.management.MBeanRegistrationException;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+
+/**
+ * @author $Id$
+ *
+ */
+public class Agent {
+	
+	private static final Logger logger = Logger.getLogger(Agent.class.getName());
+
+	private static final String TITLE = Agent.class.getPackage().getImplementationTitle();
+
+	private static final String VERSION = Agent.class.getPackage().getImplementationVersion();
+
+	/**
+	 * 
+	 */
+	public static final int DEFAULT_PORT = -1;
+
+    public static void premain(String agentArgs, Instrumentation inst) {
+        internal(agentArgs, inst);
+    }
+
+    public static void agentmain(String agentArgs, Instrumentation inst) {
+        internal(agentArgs, inst);
+    }
+    
+    public static void internal(String agentArgs, Instrumentation inst) {
+
+    	try {    		
+    		URL[] urls = new URL[0];
+    		ClassLoader tccl = Thread.currentThread().getContextClassLoader();    		
+    		AgentClassLoader cl = new AgentClassLoader(urls, tccl);
+    		
+    		ServiceLoader<AgentRuntime> runtimes = ServiceLoader.load(AgentRuntime.class, cl);
+    		
+    		// does this trick the JVM into reloading the JAR?
+    		runtimes.reload();
+    		
+    		AgentRuntime agent = runtimes.iterator().next();
+    		AgentParameterParser parser = new AgentParameterParser(agentArgs);
+    		agent.setProperties(parser.getProperties());
+
+    		// Loading it into JMX will check whether it's already running
+			MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
+			ObjectName name = new ObjectName("org.apache.kitty:type=Agent");
+			mbs.registerMBean(agent, name);
+			
+			// Enable the agent after loading it into JMX
+			agent.enable();
+
+    		logger.log(Level.INFO, "{0} {1} loaded", new Object[] { TITLE, VERSION });
+			
+		} catch (InstanceAlreadyExistsException e) {
+    		logger.warning("Agent is already loaded!");
+    		throw new RuntimeException(e.getMessage());
+    		
+		} catch (MBeanRegistrationException e) {
+			logger.log(Level.SEVERE, "Unable to load Agent MXBean");
+    		throw new RuntimeException(e.getMessage());
+    		
+		} catch (Exception e) {
+			logger.log(Level.SEVERE, "Exception loading Agent MXBean");
+    		throw new RuntimeException(e.getMessage());
+		}
+    }
+
+}
\ No newline at end of file

Propchange: incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/agent/Agent.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/agent/Agent.java
------------------------------------------------------------------------------
    svn:keywords = Id Author Date Rev

Propchange: incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/agent/Agent.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/agent/AgentClassLoader.java
URL: http://svn.apache.org/viewvc/incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/agent/AgentClassLoader.java?rev=1131237&view=auto
==============================================================================
--- incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/agent/AgentClassLoader.java (added)
+++ incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/agent/AgentClassLoader.java Fri Jun  3 20:58:18 2011
@@ -0,0 +1,33 @@
+/*
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+*/
+
+package org.apache.kitty.agent;
+
+import java.net.URL;
+import java.net.URLClassLoader;
+
+/**
+ * @author $Id$
+ *
+ */
+public class AgentClassLoader extends URLClassLoader {
+
+	public AgentClassLoader(URL[] urls, ClassLoader parent) {
+		super(urls, parent);
+	}
+
+}
\ No newline at end of file

Propchange: incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/agent/AgentClassLoader.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/agent/AgentClassLoader.java
------------------------------------------------------------------------------
    svn:keywords = Id Author Date Rev

Propchange: incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/agent/AgentClassLoader.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/agent/AgentCommandExecutor.java
URL: http://svn.apache.org/viewvc/incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/agent/AgentCommandExecutor.java?rev=1131237&view=auto
==============================================================================
--- incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/agent/AgentCommandExecutor.java (added)
+++ incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/agent/AgentCommandExecutor.java Fri Jun  3 20:58:18 2011
@@ -0,0 +1,14 @@
+package org.apache.kitty.agent;
+
+import javax.management.MXBean;
+
+/**
+ * @author $Id$
+ *
+ */
+@MXBean
+public interface AgentCommandExecutor {
+
+	String execute(String groovy);
+	
+}

Propchange: incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/agent/AgentCommandExecutor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/agent/AgentCommandExecutor.java
------------------------------------------------------------------------------
    svn:keywords = Id Author Date Rev

Propchange: incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/agent/AgentCommandExecutor.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/agent/AgentDataCollector.java
URL: http://svn.apache.org/viewvc/incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/agent/AgentDataCollector.java?rev=1131237&view=auto
==============================================================================
--- incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/agent/AgentDataCollector.java (added)
+++ incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/agent/AgentDataCollector.java Fri Jun  3 20:58:18 2011
@@ -0,0 +1,36 @@
+package org.apache.kitty.agent;
+
+import javax.management.MXBean;
+
+/**
+ * @author $Id$
+ *
+ */
+@MXBean
+public interface AgentDataCollector {
+	
+	public static final String MX_BEAN_NAME = "org.apache.kitty:type=DataCollector";	
+	
+	/**
+	 * @return status
+	 */
+	String getStatus();
+	
+	/**
+	 * @return data
+	 */
+	String getBlackBoxData();
+
+	/**
+	 * @param bean
+	 * @param attribute
+	 */
+	void addMonitor(String bean, String attribute);
+
+	/**
+	 * @param bean
+	 * @param attribute
+	 */
+	void removeMonitor(String bean, String attribute);
+	
+}

Propchange: incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/agent/AgentDataCollector.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/agent/AgentDataCollector.java
------------------------------------------------------------------------------
    svn:keywords = Id Author Date Rev

Propchange: incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/agent/AgentDataCollector.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/agent/AgentParameterParser.java
URL: http://svn.apache.org/viewvc/incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/agent/AgentParameterParser.java?rev=1131237&view=auto
==============================================================================
--- incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/agent/AgentParameterParser.java (added)
+++ incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/agent/AgentParameterParser.java Fri Jun  3 20:58:18 2011
@@ -0,0 +1,40 @@
+package org.apache.kitty.agent;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author $Id$
+ *
+ */
+public class AgentParameterParser {
+
+	private String originalParameters;
+	
+	AgentParameterParser(String originalParameters) {
+		this.originalParameters = originalParameters;		
+	}
+	
+	public Map<String, String> getProperties() {
+		
+		Map<String, String> parameters = new HashMap<String, String>();
+		
+		if (originalParameters != null) {
+			
+			String[] split = originalParameters.split("\\,");
+			
+			for (String param : split) {
+				String[] pair = param.split("\\=");
+				String value = "true";
+				if (pair.length == 2) {
+					value = pair[1];
+				}
+				
+				parameters.put(pair[0], value);
+			}
+		}
+		
+		return parameters;
+	}
+	
+}

Propchange: incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/agent/AgentParameterParser.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/agent/AgentParameterParser.java
------------------------------------------------------------------------------
    svn:keywords = Id Author Date Rev

Propchange: incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/agent/AgentParameterParser.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/agent/AgentRuntime.java
URL: http://svn.apache.org/viewvc/incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/agent/AgentRuntime.java?rev=1131237&view=auto
==============================================================================
--- incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/agent/AgentRuntime.java (added)
+++ incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/agent/AgentRuntime.java Fri Jun  3 20:58:18 2011
@@ -0,0 +1,68 @@
+/*
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+*/
+
+package org.apache.kitty.agent;
+
+import java.util.Map;
+
+import javax.management.MXBean;
+
+/**
+ * @author $Id$
+ *
+ */
+@MXBean
+public interface AgentRuntime {
+	
+	public static final String MX_BEAN_NAME = "org.apache.kitty:type=Agent";
+	
+	/**
+	 * @return enabled
+	 */
+	boolean isEnabled();
+	
+	/**
+	 * Enable statistic logging
+	 */
+    void enable();
+
+    /**
+     * Disable statistic logging
+     */
+    void disable();
+
+    /**
+     * @param type
+     */
+    void enableScriptEngine(String type);
+
+    /**
+     * @param type
+     */
+    void disableScriptEngine(String type);
+    
+    /**
+     * Unload agent
+     */
+    void unload();
+
+    /**
+     * @param properties
+     */
+	void setProperties(Map<String, String> properties);
+
+}
\ No newline at end of file

Propchange: incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/agent/AgentRuntime.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/agent/AgentRuntime.java
------------------------------------------------------------------------------
    svn:keywords = Id Author Date Rev

Propchange: incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/agent/AgentRuntime.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/agent/AgentScriptEngine.java
URL: http://svn.apache.org/viewvc/incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/agent/AgentScriptEngine.java?rev=1131237&view=auto
==============================================================================
--- incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/agent/AgentScriptEngine.java (added)
+++ incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/agent/AgentScriptEngine.java Fri Jun  3 20:58:18 2011
@@ -0,0 +1,36 @@
+/*
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+*/
+
+package org.apache.kitty.agent;
+
+import javax.management.MXBean;
+
+/**
+ * @author $Id$
+ *
+ */
+@MXBean
+public interface AgentScriptEngine {
+	
+	public static final String MX_BEAN_NAME = "org.apache.kitty:type=ScriptEngine";
+
+	/**
+	 * @param script
+	 */
+	void exec(String script);
+	
+}
\ No newline at end of file

Propchange: incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/agent/AgentScriptEngine.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/agent/AgentScriptEngine.java
------------------------------------------------------------------------------
    svn:keywords = Id Author Date Rev

Propchange: incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/agent/AgentScriptEngine.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/agent/impl/CommandExecutorImpl.java
URL: http://svn.apache.org/viewvc/incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/agent/impl/CommandExecutorImpl.java?rev=1131237&view=auto
==============================================================================
--- incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/agent/impl/CommandExecutorImpl.java (added)
+++ incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/agent/impl/CommandExecutorImpl.java Fri Jun  3 20:58:18 2011
@@ -0,0 +1,32 @@
+package org.apache.kitty.agent.impl;
+
+import javax.script.ScriptEngine;
+import javax.script.ScriptEngineManager;
+import javax.script.ScriptException;
+
+import org.apache.kitty.agent.AgentCommandExecutor;
+
+/**
+ * @author $Id$
+ *
+ */
+public class CommandExecutorImpl implements AgentCommandExecutor {
+
+	private ScriptEngineManager manager;
+
+	private ScriptEngine gEngine;
+
+	public CommandExecutorImpl() {
+		this.manager = new ScriptEngineManager();
+		this.gEngine = manager.getEngineByName("groovy");
+	}
+
+	public String execute(String groovy) {
+		try {
+			return (String) gEngine.eval(groovy);
+		} catch (ScriptException e) {
+			return e.getMessage();
+		}
+	}
+		
+}

Propchange: incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/agent/impl/CommandExecutorImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/agent/impl/CommandExecutorImpl.java
------------------------------------------------------------------------------
    svn:keywords = Id Author Date Rev

Propchange: incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/agent/impl/CommandExecutorImpl.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/agent/impl/DataCollectorImpl.java
URL: http://svn.apache.org/viewvc/incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/agent/impl/DataCollectorImpl.java?rev=1131237&view=auto
==============================================================================
--- incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/agent/impl/DataCollectorImpl.java (added)
+++ incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/agent/impl/DataCollectorImpl.java Fri Jun  3 20:58:18 2011
@@ -0,0 +1,124 @@
+package org.apache.kitty.agent.impl;
+
+import java.lang.management.ManagementFactory;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.management.InstanceNotFoundException;
+import javax.management.MBeanServer;
+import javax.management.MalformedObjectNameException;
+import javax.management.Notification;
+import javax.management.NotificationFilter;
+import javax.management.NotificationListener;
+import javax.management.ObjectName;
+
+import org.apache.kitty.agent.AgentDataCollector;
+
+/**
+ * @author $Id$
+ *
+ */
+public class DataCollectorImpl implements AgentDataCollector {
+	
+	private static class MonitorRef {
+		
+		private final String bean;
+		
+		private final String attribute;
+		
+		MonitorRef(String bean, String attribute) {
+			this.bean = bean;
+			this.attribute = attribute;			
+		}
+
+		public String getBean() {
+			return bean;
+		}
+
+		@SuppressWarnings("unused")
+		public String getAttribute() {
+			return attribute;
+		}
+	}
+
+	private String status;
+	
+	private Set<MonitorRef> monitorRefs;
+	
+	public DataCollectorImpl() {
+		this.status = "unknown";
+		this.monitorRefs = new HashSet<MonitorRef>();
+	}
+	
+	/**
+	 * {@inheritDoc}
+	 */
+	@Override
+	public String getStatus() {
+		return status;
+	}
+
+	/**
+	 * {@inheritDoc}
+	 */
+	@Override
+	public void addMonitor(String bean, String attribute) {
+		MonitorRef monitorRef = new MonitorRef(bean, attribute);
+		monitorRefs.add(monitorRef);
+		
+		MBeanServer server = ManagementFactory.getPlatformMBeanServer();
+		
+		try {
+			ObjectName name = new ObjectName(monitorRef.getBean());
+			
+			NotificationListener listener = new NotificationListener() {
+				@Override
+				public void handleNotification(Notification notification, Object obj) {
+					//
+				}
+			};
+			
+			NotificationFilter filter = new NotificationFilter() {
+
+				private static final long serialVersionUID = 1L;
+				
+				@Override
+				public boolean isNotificationEnabled(Notification notification) {
+					return true;
+				}
+			};
+			
+			Object handback = null;
+			
+			server.addNotificationListener(name, listener, filter, handback);
+			
+		} catch (MalformedObjectNameException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		} catch (InstanceNotFoundException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		} catch (NullPointerException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}
+	}
+
+	/**
+	 * {@inheritDoc}
+	 */
+	@Override
+	public void removeMonitor(String bean, String attribute) {
+		MonitorRef monitorRef = new MonitorRef(bean, attribute);
+		monitorRefs.remove(monitorRef);
+	}
+
+	/**
+	 * {@inheritDoc}
+	 */
+	@Override
+	public String getBlackBoxData() {
+		return "{ data: 'some JSON data' }";
+	}
+
+}

Propchange: incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/agent/impl/DataCollectorImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/agent/impl/DataCollectorImpl.java
------------------------------------------------------------------------------
    svn:keywords = Id Author Date Rev

Propchange: incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/agent/impl/DataCollectorImpl.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/agent/impl/RuntimeImpl.java
URL: http://svn.apache.org/viewvc/incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/agent/impl/RuntimeImpl.java?rev=1131237&view=auto
==============================================================================
--- incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/agent/impl/RuntimeImpl.java (added)
+++ incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/agent/impl/RuntimeImpl.java Fri Jun  3 20:58:18 2011
@@ -0,0 +1,174 @@
+package org.apache.kitty.agent.impl;
+
+import java.lang.management.ManagementFactory;
+import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+import javax.script.ScriptEngine;
+import javax.script.ScriptEngineManager;
+
+import org.apache.kitty.agent.AgentDataCollector;
+import org.apache.kitty.agent.AgentRuntime;
+import org.apache.kitty.agent.AgentScriptEngine;
+
+/**
+ * @author $Id$
+ *
+ */
+public class RuntimeImpl implements AgentRuntime {
+	
+	private static final Logger logger = Logger.getLogger(RuntimeImpl.class.getName());
+	
+	private Map<String, String> properties;
+
+	private MBeanServer mbs;
+	
+	private ScriptEngineManager sem;
+	
+	private AgentDataCollector adl;
+
+    public RuntimeImpl() {
+    	super();
+    	this.mbs = ManagementFactory.getPlatformMBeanServer();
+    	this.sem = new ScriptEngineManager();
+    	this.adl = new DataCollectorImpl();
+    	
+    }
+
+	/**
+     * {@inheritDoc}
+     */
+    public boolean isEnabled() {
+		try {
+			ObjectName name = new ObjectName(AgentDataCollector.MX_BEAN_NAME);
+			return mbs.isRegistered(name);			
+		} catch (Exception e) {
+			return false;
+		}
+	}
+
+	/**
+     * {@inheritDoc}
+     */
+    public void enable() {
+
+		try {
+			ObjectName name = new ObjectName(AgentDataCollector.MX_BEAN_NAME);
+			if (!mbs.isRegistered(name)) {
+				mbs.registerMBean(adl, name);
+			}
+			else {
+	    		System.out.println("Kitty Agent Runtime: ALREADY ENABLED");
+			}
+			
+			System.out.println("Kitty Agent Runtime: ENABLED");
+			
+		} catch (Exception e) {
+			logger.log(Level.SEVERE, e.getMessage());
+		}
+		finally {
+			//
+		}
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void disable() {
+
+		try {
+			ObjectName name = new ObjectName(AgentDataCollector.MX_BEAN_NAME);
+			if (mbs.isRegistered(name)) {
+				mbs.unregisterMBean(name);
+			}
+			else {
+	    		System.out.println("Kitty Agent Runtime: ALREADY DISABLED");
+			}
+			
+	       	System.out.println("Kitty Agent Runtime: DISABLED");
+	       	
+		} catch (Exception e) {
+			logger.log(Level.SEVERE, e.getMessage());
+		}
+		finally {
+			//
+		}
+    }
+
+    @Override
+	public void enableScriptEngine(String type) {
+
+		try {
+			ObjectName name = new ObjectName(AgentScriptEngine.MX_BEAN_NAME + ",engine=" + type);
+			if (mbs.isRegistered(name)) {
+		       	System.out.println("Kitty Agent ScriptEngine: " + type  + " ALREADY ENABLED");		       	
+			}
+			else {
+				ScriptEngine engineInternal = sem.getEngineByName(type);
+				AgentScriptEngine engine = new ScriptEngineImpl(engineInternal);
+				mbs.registerMBean(engine, name);
+			}
+
+		} catch (Exception e) {
+			logger.log(Level.SEVERE, e.getMessage());
+		}
+		finally {
+			//
+		}
+	}
+
+	@Override
+	public void disableScriptEngine(String type) {
+
+		try {
+			ObjectName name = new ObjectName(AgentScriptEngine.MX_BEAN_NAME + ",engine=" + type);
+			if (mbs.isRegistered(name)) {
+				mbs.invoke(name, "close", null, null);
+				mbs.unregisterMBean(name);
+		       	System.out.println("Kitty Agent ScriptEngine: " + type  + " DISABLED");		       	
+			}
+			else {
+		       	System.out.println("Kitty Agent ScriptEngine: " + type  + " NOT ENABLED");		       	
+			}
+			
+		} catch (Exception e) {
+			logger.log(Level.SEVERE, e.getMessage());
+		}
+		finally {
+			//
+		}
+		
+	}
+
+	/**
+     * {@inheritDoc}
+     */
+    public void unload() {
+
+    	disable();
+    	
+		try {
+			ObjectName name = new ObjectName(AgentRuntime.MX_BEAN_NAME);
+			mbs.unregisterMBean(name);			
+		} catch (Exception e) {
+			logger.log(Level.SEVERE, e.getMessage());
+		}
+
+    	System.out.println("Kitty Agent Runtime: UNLOADED");
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+	public void setProperties(Map<String, String> properties) {
+		this.properties = properties;
+	}
+
+	public Map<String, String> getProperties() {
+		return properties;
+	}
+	
+}

Propchange: incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/agent/impl/RuntimeImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/agent/impl/RuntimeImpl.java
------------------------------------------------------------------------------
    svn:keywords = Id Author Date Rev

Propchange: incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/agent/impl/RuntimeImpl.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/agent/impl/ScriptEngineImpl.java
URL: http://svn.apache.org/viewvc/incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/agent/impl/ScriptEngineImpl.java?rev=1131237&view=auto
==============================================================================
--- incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/agent/impl/ScriptEngineImpl.java (added)
+++ incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/agent/impl/ScriptEngineImpl.java Fri Jun  3 20:58:18 2011
@@ -0,0 +1,34 @@
+package org.apache.kitty.agent.impl;
+
+import javax.script.ScriptEngine;
+import javax.script.ScriptException;
+
+import org.apache.kitty.agent.AgentScriptEngine;
+
+/**
+ * @author $Id$
+ *
+ */
+public class ScriptEngineImpl implements AgentScriptEngine {
+
+	private final ScriptEngine engineInternal;
+
+	public ScriptEngineImpl(ScriptEngine engineInternal) {
+		this.engineInternal = engineInternal;
+	}
+
+	/**
+	 * {@inheritDoc}
+	 */
+	@Override
+	public void exec(String script) {
+		try {
+			this.engineInternal.eval(script);
+			
+		} catch (ScriptException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}
+	}
+
+}

Propchange: incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/agent/impl/ScriptEngineImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/agent/impl/ScriptEngineImpl.java
------------------------------------------------------------------------------
    svn:keywords = Id Author Date Rev

Propchange: incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/agent/impl/ScriptEngineImpl.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/loader/Loader.java
URL: http://svn.apache.org/viewvc/incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/loader/Loader.java?rev=1131237&view=auto
==============================================================================
--- incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/loader/Loader.java (added)
+++ incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/loader/Loader.java Fri Jun  3 20:58:18 2011
@@ -0,0 +1,156 @@
+package org.apache.kitty.loader;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Properties;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.management.remote.JMXServiceURL;
+
+import com.sun.tools.attach.VirtualMachine;
+import com.sun.tools.attach.VirtualMachineDescriptor;
+
+/**
+ * @author $Id$
+ *
+ */
+public class Loader {
+	
+	private static final Logger logger = Logger.getLogger(Loader.class.getName());
+
+	private static final String SUN_MANAGEMENT_JMXREMOTE = "com.sun.management.jmxremote";
+	
+	private static final String LOCAL_CONNECTOR_ADDRESS = "com.sun.management.jmxremote.localConnectorAddress";
+
+	/**
+	 * @param args
+	 */
+	public static void main(String[] args) {
+		
+		switch (args.length) {
+		case 2 :
+			if ("--load".equalsIgnoreCase(args[0])) {
+				load(args);	
+				break;
+			}
+		case 1 :
+			if ("--list".equalsIgnoreCase(args[0])) {
+				list(args);	
+				break;
+			}
+			else if ("--enable-jmx".equalsIgnoreCase(args[0])) {
+				enableJMX(args);	
+				break;
+			}
+		default :
+			usage();
+			break;
+		}
+	}
+
+	private static void usage() {
+		logger.info("Usage: java -jar apache-kitty-agent-vN.N.jar --list | --load <pid> <jar> | --enable-jmx");
+	}
+
+	private static void list(String[] args) {
+		logger.info("Listing JVM processes...");
+		
+		List<VirtualMachineDescriptor> vmds = VirtualMachine.list();
+		
+		Collections.sort(vmds, new Comparator<VirtualMachineDescriptor>() {
+			public int compare(VirtualMachineDescriptor one,
+					VirtualMachineDescriptor two) {				
+				int id1 = Integer.parseInt(one.id());
+				int id2 = Integer.parseInt(two.id());				
+				return id1 - id2;
+			} 			
+		});
+		
+		for (VirtualMachineDescriptor vmd : vmds) {
+			String displayName = vmd.displayName();
+			if (displayName == null || "".equals(displayName)) {
+				displayName = "<unknown>";
+			}
+
+			System.out.println(String.format(" %6s - %s", vmd.id(), displayName ));
+		}		
+	}
+	
+	private static void enableJMX(String[] args) {
+		logger.log(Level.CONFIG, "Enabling JMX Management Agent in: ", new Object[] { args[0] });
+
+		VirtualMachine vm = null;
+		
+		try {
+			vm = VirtualMachine.attach(args[0]);
+
+			Properties agentProps = vm.getAgentProperties();
+
+			if (!agentProps.containsKey(LOCAL_CONNECTOR_ADDRESS)) {
+				String javaHome = vm.getSystemProperties().getProperty("java.home");
+				String agent = javaHome + File.separator  + "lib" + File.separator + "management-agent.jar";
+				vm.loadAgent(agent, SUN_MANAGEMENT_JMXREMOTE);
+				agentProps = vm.getAgentProperties();
+			}
+
+			String connectorAddress = agentProps.getProperty(LOCAL_CONNECTOR_ADDRESS);
+			JMXServiceURL url = new JMXServiceURL(connectorAddress);
+			logger.log(Level.CONFIG, "Loaded JMX Management Agent into [{0}] {1}", new Object[] {vm.id(), url});
+			
+		} catch (Exception e) {
+			logger.severe(e.getMessage());
+		}
+		finally {
+			if (vm != null) {
+			    try {
+					vm.detach();
+				} catch (IOException e) {
+					e.printStackTrace();
+				}
+			}
+		}
+	}
+	
+	private static void load(String[] args) {
+		logger.log(Level.CONFIG, "Loading Agent in {1} ", new Object[] { args[1] });
+		
+		String pid = args[1];
+		String agentArgs = "";
+
+		VirtualMachine vm = null;
+		
+		try {
+			vm = VirtualMachine.attach(pid);
+
+			String agentJar = System.getProperty("java.class.path").split("\\,")[0];
+			if (!agentJar.startsWith("/")) 
+				agentJar = System.getProperty("user.dir") + File.separator + agentJar;
+			
+			File jar = new File(agentJar);
+			if (!jar.exists()) {
+				logger.log(Level.SEVERE, "Agent JAR {0} not found", new Object[] { jar.getAbsolutePath()});
+			}
+			else {
+				vm.loadAgent(jar.getAbsolutePath(), agentArgs);
+				logger.log(Level.INFO, "Loaded Kitty Agent into {0}", new Object[] { vm.id() });				
+			}
+
+		} catch (Exception e) {
+			logger.severe(e.getMessage());
+		}
+		finally {
+			if (vm != null) {
+			    try {
+					vm.detach();
+				} catch (IOException e) {
+					e.printStackTrace();
+				}				
+			}
+		}
+	}
+
+}

Propchange: incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/loader/Loader.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/loader/Loader.java
------------------------------------------------------------------------------
    svn:keywords = Id Author Date Rev

Propchange: incubator/kitty/sandbox/trunk/agent/src/main/java/org/apache/kitty/loader/Loader.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/kitty/sandbox/trunk/agent/src/main/resources/META-INF/services/org.apache.kitty.agent.AgentRuntime
URL: http://svn.apache.org/viewvc/incubator/kitty/sandbox/trunk/agent/src/main/resources/META-INF/services/org.apache.kitty.agent.AgentRuntime?rev=1131237&view=auto
==============================================================================
--- incubator/kitty/sandbox/trunk/agent/src/main/resources/META-INF/services/org.apache.kitty.agent.AgentRuntime (added)
+++ incubator/kitty/sandbox/trunk/agent/src/main/resources/META-INF/services/org.apache.kitty.agent.AgentRuntime Fri Jun  3 20:58:18 2011
@@ -0,0 +1 @@
+org.apache.kitty.agent.impl.RuntimeImpl
\ No newline at end of file

Added: incubator/kitty/sandbox/trunk/build.gradle
URL: http://svn.apache.org/viewvc/incubator/kitty/sandbox/trunk/build.gradle?rev=1131237&view=auto
==============================================================================
--- incubator/kitty/sandbox/trunk/build.gradle (added)
+++ incubator/kitty/sandbox/trunk/build.gradle Fri Jun  3 20:58:18 2011
@@ -0,0 +1,74 @@
+/*
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+*/
+
+configurations {
+	compile {
+		description = 'compile classpath'
+		transitive = true
+	}
+	runtime {
+		extendsFrom compile
+	}
+}
+
+configurations.compile {
+	description = 'compile classpath'
+}
+
+allprojects {
+	//
+}
+
+subprojects {
+	defaultTasks ['assemble']
+
+	apply plugin: 'eclipse'			// adds support for eclipse project generation
+	apply plugin: 'idea'			// adds support for idea project generation
+	apply plugin: 'java'			// adds support for java
+	apply plugin: 'application'		// adds support for creating application wrappers
+	
+    repositories {
+       mavenCentral()
+    }
+
+    dependencies {
+        testCompile 'junit:junit:4.8.2'
+    }
+
+    jar {
+        manifest.attributes provider: 'gradle'
+    }
+}
+
+project(":agent") {
+
+}
+
+project(":groovy1.8") {
+
+	apply plugin: 'groovy'			// adds support for groovy
+
+	dependencies {
+		groovy 'org.codehaus.groovy:groovy:1.8.0'
+		groovy 'commons-cli:commons-cli:1.2'
+    	groovy 'commons-logging:commons-logging:1.1.1'
+		groovy 'jline:jline:0.9.94'
+		groovy 'org.fusesource.jansi:jansi:1.2.1'
+	}
+
+}
+

Propchange: incubator/kitty/sandbox/trunk/build.gradle
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/kitty/sandbox/trunk/build.gradle
------------------------------------------------------------------------------
    svn:keywords = Id Author Date Rev

Propchange: incubator/kitty/sandbox/trunk/build.gradle
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/kitty/sandbox/trunk/groovy1.8/build.gradle
URL: http://svn.apache.org/viewvc/incubator/kitty/sandbox/trunk/groovy1.8/build.gradle?rev=1131237&view=auto
==============================================================================
--- incubator/kitty/sandbox/trunk/groovy1.8/build.gradle (added)
+++ incubator/kitty/sandbox/trunk/groovy1.8/build.gradle Fri Jun  3 20:58:18 2011
@@ -0,0 +1,45 @@
+/*
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+*/
+
+title = 'Apache Kitty (Incubating) SANDBOX'
+
+description = 'This is the Apache Kitty build script'
+version = '0.1-GR1.8-SANDBOX-SNAPSHOT'
+
+packageName = 'apache-kitty'
+applicationName = 'kitty'
+mainClassName = 'org.apache.kitty.Main'
+
+sourceCompatibility = 1.6
+targetCompatibility = 1.6
+
+defaultTasks = ['assemble']
+
+jar {
+	baseName = "$packageName"
+	manifest {
+		attributes (
+			'Main-Class': "$mainClassName",
+			'Implementation-Title': "$title",
+			'Implementation-Version': "$version"
+		)
+	}
+}
+
+distZip {
+	baseName = "$packageName"
+}

Propchange: incubator/kitty/sandbox/trunk/groovy1.8/build.gradle
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/kitty/sandbox/trunk/groovy1.8/build.gradle
------------------------------------------------------------------------------
    svn:keywords = Id Author Date Rev

Propchange: incubator/kitty/sandbox/trunk/groovy1.8/build.gradle
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/Dispatcher.groovy
URL: http://svn.apache.org/viewvc/incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/Dispatcher.groovy?rev=1131237&view=auto
==============================================================================
--- incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/Dispatcher.groovy (added)
+++ incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/Dispatcher.groovy Fri Jun  3 20:58:18 2011
@@ -0,0 +1,156 @@
+package org.apache.kitty
+
+import java.lang.reflect.Method
+import java.util.Map
+import java.util.regex.Pattern
+import javax.management.ObjectName
+import javax.management.MBeanServerConnection as JmxConnection
+import javax.management.remote.JMXServiceURL as JmxUrl
+
+import groovy.jmx.builder.JmxBuilder
+import groovy.util.Expando
+import org.codehaus.groovy.reflection.CachedMethod
+
+import org.apache.kitty.annotations.Command
+import org.apache.kitty.annotations.Connector
+import org.apache.kitty.annotations.Library
+import org.apache.kitty.commands.Common
+import org.apache.kitty.util.ConnectionURLParser
+
+// This is not elegant right now
+/**
+ * @author $Id$
+ *
+ */
+class Dispatcher {
+
+	static {
+		// adds convenience method 'logout' synonmous with 'disconnect'
+		Dispatcher.metaClass.logout << { args-> disconnect(*args) }
+	}
+	
+	def shell
+	def commands = []
+	def client = null
+	def loginErrorCount = 0
+	
+
+	def connect(final Map map) {
+		
+		if (loginErrorCount >= 3) {
+			this.loginErrorCount = 0
+			shell.display "Maximum of 3 tries"
+			return
+		}
+		
+		try {
+			connectInternal(map)
+		}
+		catch (SecurityException e) {
+			
+			shell.error "Authentication required, please provide credentials: "
+			this.loginErrorCount++
+			this.client = null
+			
+			// try to find existing credentials
+			// re-use username if present
+			def arr = map?.properties?.'jmx.remote.credentials' as String[]
+			def username = (arr?.length >= 1) ? arr[0] : shell.username()
+			
+			// always get a new password
+			def password = shell.password()
+			def creds = ['jmx.remote.credentials': ["$username", "$password"] as String[]]
+			
+			// restart cycle with updated property map
+			this.connect host: map.host, port: map.port, properties: creds
+		}
+	}
+	
+	def connectInternal(final Map map) {
+
+		disconnect()
+		
+		def jmx = new JmxBuilder()
+		this.client = jmx.connectorClient(map.clone())
+		this.client.connect()
+		this.loginErrorCount = 0
+		shell.setPrompt(map.host)
+		
+		// display short information about connection
+		info()
+	}
+
+	def disconnect(Object... arguments) {
+		if (this.client != null) {
+			this.client.close()
+			this.client = null
+			shell?.reset()
+			shell.display "Disconnected..."
+		}
+	}
+
+	def methodMissing(String methodName, arguments) {
+		try {
+			for (Class c : commands) {
+				if (!c.isAnnotationPresent(Library)) continue
+				
+				def lib = c.newInstance(shell: shell)
+				
+				for (CachedMethod cm : lib.metaClass.methods) {
+					// some tests
+					if (!cm.isPublic() || !cm.name.equals(methodName)) continue
+					if (!cm.cachedMethod.isAnnotationPresent(Command)) continue
+					return mapMethod(methodName, cm, lib, arguments)
+				}
+			}
+	
+			shell.error "Command %s not found!", methodName
+		}
+		catch (RuntimeException e) {
+			throw new KittyRuntimeException("$methodName (${ arguments }) ${e.getMessage()}", e)
+		}
+		catch (Exception e) {
+			throw new KittyException("$methodName (${ arguments }) ${e.getMessage()}", e)
+		}
+	}
+	
+	def mapMethod(String methodName, CachedMethod cm, lib, arguments) {
+
+		// name matches & method is public & @Command
+		Command cmd = cm.cachedMethod.getAnnotation(Command)
+		
+		def cachedMethod = { Object... internal->
+	
+			if (cmd.connection()) {
+				if (client != null) {
+					lib.connection = client.getMBeanServerConnection()
+				}
+				else {
+					shell.error "Not connected"
+					return
+				}
+			}
+
+			def ret = lib."$methodName"(*internal)
+			
+			if (cm.cachedMethod.isAnnotationPresent(Connector)) {
+				connect(ret as Map)
+			}
+			else {
+				return ret
+			}
+		}
+		
+		cachedMethod.resolveStrategy = Closure.DELEGATE_FIRST
+		cachedMethod.delegate = this
+		
+		this.metaClass."$methodName" << cachedMethod
+		cachedMethod(*arguments)
+	}
+	
+	def close() {
+		// close stub
+		disconnect()
+	}
+
+}
\ No newline at end of file

Propchange: incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/Dispatcher.groovy
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/Dispatcher.groovy
------------------------------------------------------------------------------
    svn:keywords = Id Author Date Rev

Propchange: incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/Dispatcher.groovy
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/Exceptions.groovy
URL: http://svn.apache.org/viewvc/incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/Exceptions.groovy?rev=1131237&view=auto
==============================================================================
--- incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/Exceptions.groovy (added)
+++ incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/Exceptions.groovy Fri Jun  3 20:58:18 2011
@@ -0,0 +1,22 @@
+package org.apache.kitty
+
+import groovy.transform.InheritConstructors
+
+
+/**
+ * @author $Id$
+ *
+ */
+@InheritConstructors
+class KittyException extends Exception {
+	//
+}
+
+/**
+ * @author $Id$
+ *
+ */
+@InheritConstructors
+class KittyRuntimeException extends RuntimeException {
+	//
+}

Propchange: incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/Exceptions.groovy
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/Exceptions.groovy
------------------------------------------------------------------------------
    svn:keywords = Id Author Date Rev

Propchange: incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/Exceptions.groovy
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/Kitty.groovy
URL: http://svn.apache.org/viewvc/incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/Kitty.groovy?rev=1131237&view=auto
==============================================================================
--- incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/Kitty.groovy (added)
+++ incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/Kitty.groovy Fri Jun  3 20:58:18 2011
@@ -0,0 +1,117 @@
+package org.apache.kitty
+
+import java.util.Scanner
+import java.util.regex.Pattern
+
+import jline.ANSIBuffer
+import jline.ANSIBuffer.ANSICodes
+import jline.CandidateListCompletionHandler
+import jline.ConsoleReader
+import jline.History
+
+import org.apache.kitty.commands.Common
+import org.apache.kitty.commands.Connect
+import org.apache.kitty.commands.Tomcat
+
+/**
+ * @author $Id$
+ *
+ */
+class Kitty {
+
+	public static final String TITLE = KittyShell.class.getPackage().getImplementationTitle()
+
+	public static final String VERSION = KittyShell.class.getPackage().getImplementationVersion()
+
+	private static final String PATTERN = Pattern.compile("\"[^\"]*\"|'[^']*'|[A-Za-z\\S']+")
+
+	private KittyShell kittyShell
+
+	private Dispatcher dispatcher
+	
+	def running = true
+
+	def Kitty() {
+		// TODO configurable commands
+		def commands = [ Connect.class, Common.class, Tomcat.class ]
+		
+		this.kittyShell = new KittyShell()
+		
+		def emc = new ExpandoMetaClass(Dispatcher, false, true)
+		emc.initialize()
+		this.dispatcher = new Dispatcher(shell: kittyShell, commands: commands)
+		this.dispatcher.metaClass = emc
+		
+		this.addShutdownHook { -> this.close() }
+	}
+	
+	def runConsole(String[] initial) {
+		
+		// TODO handle additional initial args
+
+		kittyShell.display "${TITLE:'####### Apache Kitty (TEST MODE)'} ${VERSION:'v0.0'} #######"
+		kittyShell.display " "
+
+		while (running) {
+			try {
+				String line = kittyShell.readInput()
+				if ("".equals(line)) continue
+
+				// split the line, handling quoted strings
+				def phrases = splitQuoted(line)
+				if (["exit", "quit"].contains(phrases[0])) {
+					close()
+				}
+				else {
+					runCommand(phrases)
+				}
+			}
+			catch (KittyRuntimeException e) {
+				kittyShell.error e.getMessage()
+			}
+			catch (KittyException e) {
+				kittyShell.error e.getMessage()
+			}
+			catch (Exception e) {
+				e.printStackTrace()
+				close()
+			}
+		}
+	}
+
+	def runCommand(String[] line) throws KittyRuntimeException {
+		
+		try {
+			// strip first and use the rest as args
+			def command = line[0]
+			def arguments = (line.length > 1) ? line[1..-1] : []
+	
+			// Use spread operator to split args
+			dispatcher."$command"(*arguments)
+		}
+		catch (Exception e) {
+			throw new KittyRuntimeException(e)
+		}
+	}
+	
+	def close() {
+		this.running = false
+		dispatcher?.close()
+		kittyShell?.close()
+	}
+	
+	// There must be a groovier way of doing this		
+	private String[] splitQuoted(String line) {
+		
+		def output = []
+		def scanner = new Scanner(line)
+		def token
+		
+		while ((token = scanner.findInLine(PATTERN)) != null) {
+			output << token.replaceAll("^[\"']", "")
+		}
+		
+		return output as String[]
+	}
+
+}
\ No newline at end of file

Propchange: incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/Kitty.groovy
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/Kitty.groovy
------------------------------------------------------------------------------
    svn:keywords = Id Author Date Rev

Propchange: incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/Kitty.groovy
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/KittyShell.groovy
URL: http://svn.apache.org/viewvc/incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/KittyShell.groovy?rev=1131237&view=auto
==============================================================================
--- incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/KittyShell.groovy (added)
+++ incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/KittyShell.groovy Fri Jun  3 20:58:18 2011
@@ -0,0 +1,127 @@
+package org.apache.kitty
+
+import jline.ANSIBuffer
+import jline.ANSIBuffer.ANSICodes
+import jline.CandidateListCompletionHandler
+import jline.ConsoleReader
+import jline.History
+import jline.SimpleCompletor
+
+import org.fusesource.jansi.AnsiRenderer
+import org.fusesource.jansi.Ansi
+import org.fusesource.jansi.AnsiConsole
+import org.codehaus.groovy.tools.shell.AnsiDetector
+
+/**
+ * @author $Id$
+ *
+ */
+class KittyShell {
+	
+	public static final String HISTORY_FILE = "kitty.history"
+	
+	private static final String PROMPT = "@|cyan %s:|@@|yellow %s|@> "
+	
+	static {
+		// Install the system adapters
+		AnsiConsole.systemInstall()
+
+		// Register jline ansi detector
+		Ansi.setDetector(new AnsiDetector())
+	}
+
+	def int index
+	def ConsoleReader reader
+	def String user
+	
+	def KittyShell() {
+		this.index = 0
+		this.user = "kitty"
+
+		def userHome = System.getProperty("user.home")
+		def historyFile = new File(userHome, HISTORY_FILE)
+		
+		if (!historyFile.exists()) 
+			historyFile.createNewFile()
+		
+		def history = new History(historyFile)
+		
+		this.reader = new ConsoleReader()
+		reader.setBellEnabled false
+		reader.setUseHistory true
+		reader.setHistory history		
+		reader.setCompletionHandler(new CandidateListCompletionHandler())
+
+		// TODO dynamically load completors, based on commands discovered	
+		def commands = [
+			"connect", 
+			"disconnect", 
+			"domains", 
+			"info", 
+			"bean", 
+			"os", 
+			"runtime", 
+			"threads", 
+			"memory"
+		]
+		
+		reader.addCompletor(new SimpleCompletor(commands as String[]))
+		
+		// init prompt
+		this.setPrompt '~'
+	}
+	
+	def error(String msg, Object... args) {
+		this.index++
+		msg = AnsiRenderer.render("@|red ERROR:|@ $msg\n")
+		reader.printString String.format(msg, args)
+	}
+	
+	def display(String msg, Object... args) {
+		this.index++
+		msg = AnsiRenderer.render("$msg")
+		reader.printString String.format("$msg\n", args)
+	}
+
+	void setPrompt(hostname) {
+		def prompt = String.format(PROMPT, user ?: '*', hostname ?: '*')
+		reader.setDefaultPrompt AnsiRenderer.render(prompt)
+	}
+	
+	void reset() {
+		this.user = 'kitty'
+		this.setPrompt '~'
+	}
+	
+	void clear() {
+		reader.clearScreen()
+	}
+
+	String readInput() throws KittyException {
+		try {
+			return reader.readLine().trim()
+		}
+		catch (IOException ioe) {
+			throw new KittyException(ioe)
+		}
+	}
+
+	String username() throws KittyException {
+		reader.setUseHistory false
+		this.user = reader.readLine('Username: ').trim()
+		reader.setUseHistory true
+		return this.user;
+	}	
+
+	String password() throws KittyException {
+		reader.setUseHistory false
+		String password = reader.readLine('Password: ', '*' as Character).trim()
+		reader.setUseHistory true
+		return password
+	}
+	
+	def close() {
+		// close stub
+	}
+
+}
\ No newline at end of file

Propchange: incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/KittyShell.groovy
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/KittyShell.groovy
------------------------------------------------------------------------------
    svn:keywords = Id Author Date Rev

Propchange: incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/KittyShell.groovy
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/Main.groovy
URL: http://svn.apache.org/viewvc/incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/Main.groovy?rev=1131237&view=auto
==============================================================================
--- incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/Main.groovy (added)
+++ incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/Main.groovy Fri Jun  3 20:58:18 2011
@@ -0,0 +1,34 @@
+package org.apache.kitty
+
+/**
+ * @author $Id$
+ * 
+ */
+class Main {
+	
+	def static main(args) {
+
+		def usage = System.getProperty("apache.kitty.usage", "(sh kitty|kitty.bat) [<args>]")
+
+		def cli = new CliBuilder(usage: "$usage")
+		cli.i(longOpt: 'console', 'Launch in an interactive prompt (default)')
+		cli.s(longOpt: 'script', 'Launch inline for scripted access')
+		cli.h(longOpt: 'help', 'Show help')
+
+		def opt = cli.parse(args)
+
+		if (opt?.h) {
+			usage(cli)
+			return
+		}
+		
+		def func = (opt?.s) ? 'runCommand' : 'runConsole'
+		new Kitty()."$func"(opt.args)
+	}
+
+	def static usage(cli) {
+		println "${Main.class.getPackage()}"
+		println cli.usage()
+	}
+	
+}
\ No newline at end of file

Propchange: incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/Main.groovy
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/Main.groovy
------------------------------------------------------------------------------
    svn:keywords = Id Author Date Rev

Propchange: incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/Main.groovy
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/annotations/Command.groovy
URL: http://svn.apache.org/viewvc/incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/annotations/Command.groovy?rev=1131237&view=auto
==============================================================================
--- incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/annotations/Command.groovy (added)
+++ incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/annotations/Command.groovy Fri Jun  3 20:58:18 2011
@@ -0,0 +1,25 @@
+package org.apache.kitty.annotations
+
+import java.lang.annotation.Documented
+import java.lang.annotation.ElementType
+import java.lang.annotation.Inherited
+import java.lang.annotation.Retention
+import java.lang.annotation.RetentionPolicy
+import java.lang.annotation.Target
+
+/**
+ * @author $Id$
+ *
+ */
+@Documented
+@Inherited
+@Retention(RetentionPolicy.RUNTIME)
+@Target([ElementType.TYPE, ElementType.METHOD])
+@interface Command {
+
+	/**	
+	 * @return needs a connection
+	 */
+	boolean connection() default true
+	
+}

Propchange: incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/annotations/Command.groovy
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/annotations/Command.groovy
------------------------------------------------------------------------------
    svn:keywords = Id Author Date Rev

Propchange: incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/annotations/Command.groovy
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/annotations/Connector.groovy
URL: http://svn.apache.org/viewvc/incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/annotations/Connector.groovy?rev=1131237&view=auto
==============================================================================
--- incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/annotations/Connector.groovy (added)
+++ incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/annotations/Connector.groovy Fri Jun  3 20:58:18 2011
@@ -0,0 +1,22 @@
+package org.apache.kitty.annotations
+
+import java.lang.annotation.Documented
+import java.lang.annotation.ElementType
+import java.lang.annotation.Inherited
+import java.lang.annotation.Retention
+import java.lang.annotation.RetentionPolicy
+import java.lang.annotation.Target
+
+/**
+ * @author $Id$
+ *
+ */
+@Documented
+@Inherited
+@Retention(RetentionPolicy.RUNTIME)
+@Target([ElementType.TYPE, ElementType.METHOD])
+@interface Connector {
+
+	// marker annotation presently
+
+}

Propchange: incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/annotations/Connector.groovy
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/annotations/Connector.groovy
------------------------------------------------------------------------------
    svn:keywords = Id Author Date Rev

Propchange: incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/annotations/Connector.groovy
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/annotations/Library.groovy
URL: http://svn.apache.org/viewvc/incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/annotations/Library.groovy?rev=1131237&view=auto
==============================================================================
--- incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/annotations/Library.groovy (added)
+++ incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/annotations/Library.groovy Fri Jun  3 20:58:18 2011
@@ -0,0 +1,25 @@
+package org.apache.kitty.annotations
+
+import java.lang.annotation.Documented
+import java.lang.annotation.ElementType
+import java.lang.annotation.Inherited
+import java.lang.annotation.Retention
+import java.lang.annotation.RetentionPolicy
+import java.lang.annotation.Target
+
+/**
+ * @author $Id$
+ *
+ */
+@Documented
+@Inherited
+@Retention(RetentionPolicy.RUNTIME)
+@Target([ElementType.TYPE, ElementType.METHOD])
+@interface Library {
+	
+	// presently a marker annotation
+	
+	// TODO Possibly create AST transformation to inject:
+	// 'KittyShell shell' and 'JmxConnection connection' fields
+	
+}

Propchange: incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/annotations/Library.groovy
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/annotations/Library.groovy
------------------------------------------------------------------------------
    svn:keywords = Id Author Date Rev

Propchange: incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/annotations/Library.groovy
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/commands/Common.groovy
URL: http://svn.apache.org/viewvc/incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/commands/Common.groovy?rev=1131237&view=auto
==============================================================================
--- incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/commands/Common.groovy (added)
+++ incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/commands/Common.groovy Fri Jun  3 20:58:18 2011
@@ -0,0 +1,77 @@
+package org.apache.kitty.commands
+
+import javax.management.MBeanServerConnection as JmxConnection
+
+import groovy.util.GroovyMBean
+
+import org.apache.kitty.KittyShell
+import org.apache.kitty.annotations.Command
+import org.apache.kitty.annotations.Library
+
+/**
+ * @author $Id$
+ *
+ */
+@Library
+class Common {
+	
+	private KittyShell shell
+	
+	private JmxConnection connection
+
+	@Command
+	def clear(String... arguments) {
+		shell.clear()
+		shell.display ''
+	}
+	
+	@Command
+	def domains() {
+		shell.display "Domains: "
+		connection.getDomains().sort().eachWithIndex { domain, i->
+			shell.display " %-2s - %s", i, domain
+		}
+	}
+
+	@Command
+	def info() {
+		GroovyMBean os = new GroovyMBean(connection, 'java.lang:type=OperatingSystem')
+		GroovyMBean rt = new GroovyMBean(connection, 'java.lang:type=Runtime')
+		
+		def sysprops = rt.SystemProperties as Map
+		
+		shell.display "Connected to @|bold %s|@ [%s %s] %s %s", rt.Name, os.Name, os.Version, rt.VmName, rt.VmVersion
+
+		if (sysprops.containsKey(['catalina.base'] as String[])) {
+			def serverInfo = new GroovyMBean(connection, 'Catalina:type=Server').serverInfo
+			shell.display "%s", serverInfo
+		}
+	}
+	
+	@Command
+	def bean(String name) {
+		def mbean = new GroovyMBean(connection, name)
+		shell.display mbean.toString()
+	}
+
+	@Command
+	def runtime() {
+		bean('java.lang:type=Runtime')
+	}
+
+	@Command
+	def os() {
+		bean('java.lang:type=OperatingSystem')
+	}
+
+	@Command
+	def threading() {
+		bean('java.lang:type=Threading')
+	}
+
+	@Command
+	def memory() {
+		bean('java.lang:type=Memory')
+	}
+	
+}
\ No newline at end of file

Propchange: incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/commands/Common.groovy
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/commands/Common.groovy
------------------------------------------------------------------------------
    svn:keywords = Id Author Date Rev

Propchange: incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/commands/Common.groovy
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/commands/Connect.groovy
URL: http://svn.apache.org/viewvc/incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/commands/Connect.groovy?rev=1131237&view=auto
==============================================================================
--- incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/commands/Connect.groovy (added)
+++ incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/commands/Connect.groovy Fri Jun  3 20:58:18 2011
@@ -0,0 +1,112 @@
+package org.apache.kitty.commands
+
+import java.util.Map;
+
+import groovy.jmx.builder.JmxBuilder
+import groovy.util.GroovyMBean
+
+import org.apache.kitty.KittyShell
+import org.apache.kitty.annotations.Command
+import org.apache.kitty.annotations.Connector
+import org.apache.kitty.annotations.Library
+import org.apache.kitty.util.ConnectionURLParser
+
+import com.sun.tools.attach.VirtualMachine
+
+/**
+ * @author $Id$
+ *
+ */
+@Library
+class Connect {
+	
+	private KittyShell shell
+		
+	
+	@Command(connection = false)
+	def local() {
+		shell.display " %6s - %s", 'PID', 'Process Name'
+
+		VirtualMachine.list().sort { one, two->
+			return (one.id() as int) - (two.id() as int)
+
+		}.each { vmd->
+			def displayName = vmd.displayName() ?: "<unknown>"
+			shell.display " %6s - %s", vmd.id(), displayName
+		}
+
+		shell.display ""  // display a clear line
+	}
+
+	@Command(connection = false)
+	@Connector
+	def connect(String... arguments) {
+
+		// build a map to pass to JmxBuilder
+		def map = [:]
+		
+		// YUCK - surely there's a better way...
+		switch (arguments.length) {
+			case 3 :  // username, hostname, port
+				map['host'] = arguments[1]
+				map['port'] = arguments[2]
+				map['properties'] = ['jmx.remote.credentials': ["${arguments[0]}", "QED"] as String[]]
+				break
+			case 2 :  // hostname, port
+				map['host'] = arguments[0]
+				map['port'] = arguments[1]
+				break
+			case 1 :  // various
+				def cup = new ConnectionURLParser()
+				map = cup.parse(arguments[0])
+				break
+			default:  // fail!
+				shell.error "Unrecognised number of arguments"
+				break
+		}
+
+		// use constructed map, delegate to next method
+		return map.clone()
+	}
+
+
+	@Command(connection = false)
+	@Connector
+	def attach(String... args) {
+		
+		def vm = VirtualMachine.attach(args[0])
+		def system = vm.getSystemProperties()
+		def LCA = "com.sun.management.jmxremote.localConnectorAddress"
+
+		try {
+			String props = ""
+			if (args.length > 1) {
+				props = args[1..-1].join(",")
+			}
+
+			if (!vm.agentProperties.containsKey(LCA)) {
+				// construct path to management agent
+				def Fs = File.separator
+				def agent = "${system['java.home']}${Fs}lib${Fs}management-agent.jar"
+				// load agent into target VM
+				vm?.loadAgent(agent, props)
+			}
+
+			// extract JMX URL from agent properties
+			def url = vm?.agentProperties?.getProperty(LCA)
+			shell.display "Attaching to PID: ${args[0]}"
+			
+			def creds = ['jmx.remote.credentials' : ['local', ''] as String[]]
+						
+			return ['url': url, 'host': 'localhost', 'properties': creds]
+		}
+		catch (Exception e) {
+			shell.error "%s", e.getMessage()
+		}
+		finally {
+			// detach safely
+			vm?.detach()
+		}
+	}
+
+}
\ No newline at end of file

Propchange: incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/commands/Connect.groovy
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/commands/Connect.groovy
------------------------------------------------------------------------------
    svn:keywords = Id Author Date Rev

Propchange: incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/commands/Connect.groovy
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/commands/Tomcat.groovy
URL: http://svn.apache.org/viewvc/incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/commands/Tomcat.groovy?rev=1131237&view=auto
==============================================================================
--- incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/commands/Tomcat.groovy (added)
+++ incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/commands/Tomcat.groovy Fri Jun  3 20:58:18 2011
@@ -0,0 +1,45 @@
+package org.apache.kitty.commands
+
+import javax.management.ObjectName
+import javax.management.MBeanServerConnection as JmxConnection
+
+import groovy.jmx.builder.JmxBuilder
+import groovy.util.GroovyMBean
+
+import org.apache.kitty.KittyShell
+import org.apache.kitty.annotations.Command
+import org.apache.kitty.annotations.Library
+
+/**
+ * @author $Id$
+ *
+ */
+@Library
+class Tomcat {
+	
+	private KittyShell shell
+	
+	private JmxConnection connection
+
+	@Command
+	def webapps(host) {
+
+		host = host ?: '*'
+
+		def query = new ObjectName("Catalina:j2eeType=WebModule,name=//${host}/,J2EEApplication=none,J2EEServer=none")
+		String[] result = connection.queryNames(query, null)
+		def modules = result.findAll{ name ->
+			name.contains('j2eeType=WebModule')
+		}.collect{ new GroovyMBean(connection, it) }
+		
+		for (def mbean : modules) {
+			shell.display mbean.toString()
+		}
+	}
+	
+	@Command
+	def top() {
+		shell.display "top!!"
+	}
+
+}
\ No newline at end of file

Propchange: incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/commands/Tomcat.groovy
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/commands/Tomcat.groovy
------------------------------------------------------------------------------
    svn:keywords = Id Author Date Rev

Propchange: incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/commands/Tomcat.groovy
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/util/ConnectionURLParser.groovy
URL: http://svn.apache.org/viewvc/incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/util/ConnectionURLParser.groovy?rev=1131237&view=auto
==============================================================================
--- incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/util/ConnectionURLParser.groovy (added)
+++ incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/util/ConnectionURLParser.groovy Fri Jun  3 20:58:18 2011
@@ -0,0 +1,38 @@
+package org.apache.kitty.util
+
+import java.util.regex.Pattern
+
+/**
+ * @author $Id$
+ *
+ */
+class ConnectionURLParser {
+
+	private static final String PATTERN = Pattern.compile("([^@]+(?:@))?([^@\\:]+)?((?:\\:)\\d{4,5})?")
+
+	def map = [:]
+
+	def ConnectionURLParser() {
+		map['host'] = 'localhost'
+		map['port'] = '1099'
+	}
+
+	def parse(String argument) {
+
+		argument.find PATTERN, { full, user, host, port->
+
+			map['host'] = host ?: 'localhost'
+			map['port'] = port?.replaceAll('\\D+', '') ?: '1099'
+
+			if (user != null) {
+				def credentials = [user?.replaceAll('@', ''), 'QED'] as String[]
+				map['properties'] = [
+					'jmx.remote.credentials': credentials
+				]
+			}
+		}
+
+		return map
+	}
+
+}
\ No newline at end of file

Propchange: incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/util/ConnectionURLParser.groovy
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/util/ConnectionURLParser.groovy
------------------------------------------------------------------------------
    svn:keywords = Id Author Date Rev

Propchange: incubator/kitty/sandbox/trunk/groovy1.8/src/main/groovy/org/apache/kitty/util/ConnectionURLParser.groovy
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/kitty/sandbox/trunk/groovy1.8/src/test/java/org/apache/kitty/KittyTest1.java
URL: http://svn.apache.org/viewvc/incubator/kitty/sandbox/trunk/groovy1.8/src/test/java/org/apache/kitty/KittyTest1.java?rev=1131237&view=auto
==============================================================================
--- incubator/kitty/sandbox/trunk/groovy1.8/src/test/java/org/apache/kitty/KittyTest1.java (added)
+++ incubator/kitty/sandbox/trunk/groovy1.8/src/test/java/org/apache/kitty/KittyTest1.java Fri Jun  3 20:58:18 2011
@@ -0,0 +1,13 @@
+package org.apache.kitty;
+
+import org.junit.Test;
+
+public class KittyTest1 {
+
+	@Test
+	public void simpleTest() {
+
+		
+	}
+	
+}

Propchange: incubator/kitty/sandbox/trunk/groovy1.8/src/test/java/org/apache/kitty/KittyTest1.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/kitty/sandbox/trunk/groovy1.8/src/test/java/org/apache/kitty/KittyTest1.java
------------------------------------------------------------------------------
    svn:keywords = "Id Author Date Rev"

Propchange: incubator/kitty/sandbox/trunk/groovy1.8/src/test/java/org/apache/kitty/KittyTest1.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/kitty/sandbox/trunk/settings.gradle
URL: http://svn.apache.org/viewvc/incubator/kitty/sandbox/trunk/settings.gradle?rev=1131237&view=auto
==============================================================================
--- incubator/kitty/sandbox/trunk/settings.gradle (added)
+++ incubator/kitty/sandbox/trunk/settings.gradle Fri Jun  3 20:58:18 2011
@@ -0,0 +1,19 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+	http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+include 'agent'
+include 'groovy1.8'

Propchange: incubator/kitty/sandbox/trunk/settings.gradle
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/kitty/sandbox/trunk/settings.gradle
------------------------------------------------------------------------------
    svn:keywords = Id Author Date Rev

Propchange: incubator/kitty/sandbox/trunk/settings.gradle
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message