[jboss-cvs] JBossAS SVN: r88021 - in projects/fresh/trunk: fresh-shell and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Apr 29 16:27:38 EDT 2009


Author: alesj
Date: 2009-04-29 16:27:38 -0400 (Wed, 29 Apr 2009)
New Revision: 88021

Added:
   projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/shell/commands/AbstractInvokeExe.java
   projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/shell/commands/MCBeanInvokeExe.java
Modified:
   projects/fresh/trunk/fresh-shell/pom.xml
   projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/shell/commands/MBeanInvokeExe.java
   projects/fresh/trunk/pom.xml
Log:
Add MC dependencies.
Impl MC KernelBus invoke cmd.

Modified: projects/fresh/trunk/fresh-shell/pom.xml
===================================================================
--- projects/fresh/trunk/fresh-shell/pom.xml	2009-04-29 20:18:07 UTC (rev 88020)
+++ projects/fresh/trunk/fresh-shell/pom.xml	2009-04-29 20:27:38 UTC (rev 88021)
@@ -31,6 +31,15 @@
   </build>
 
   <dependencies>
+      <dependency>
+        <groupId>org.jboss.microcontainer</groupId>
+        <artifactId>jboss-dependency</artifactId>
+      </dependency>
+      <dependency>
+        <groupId>org.jboss.microcontainer</groupId>
+        <artifactId>jboss-kernel</artifactId>
+      </dependency>
+
     <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>

Copied: projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/shell/commands/AbstractInvokeExe.java (from rev 88017, projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/shell/commands/MBeanInvokeExe.java)
===================================================================
--- projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/shell/commands/AbstractInvokeExe.java	                        (rev 0)
+++ projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/shell/commands/AbstractInvokeExe.java	2009-04-29 20:27:38 UTC (rev 88021)
@@ -0,0 +1,186 @@
+package org.jboss.fresh.shell.commands;
+
+import java.io.PrintWriter;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.StringTokenizer;
+
+import org.apache.log4j.Logger;
+import org.jboss.fresh.io.BufferObjectReader;
+import org.jboss.fresh.io.BufferObjectWriter;
+import org.jboss.fresh.io.BufferWriter;
+import org.jboss.fresh.io.PrintWriter2;
+import org.jboss.fresh.shell.AbstractExecutable;
+import org.jboss.fresh.util.TxSupport;
+
+/**
+ * @author ales.justin at jboss.org
+ */
+public abstract class AbstractInvokeExe extends AbstractExecutable
+{
+   protected abstract Logger getLog();
+
+   protected abstract String getCmd();
+
+   //	cat [PATHS]
+   public void process(String exename, String[] params) throws Exception
+   {
+      getLog().debug("entered");
+
+      if (helpRequested())
+      {
+         PrintWriter2 out = new PrintWriter2(new BufferWriter(getStdOut()));
+         out.println("Usage: " + getCmd() + " [-ex] [-notx] <service name> <method sig>");
+         out.println("			--help : this help");
+         out.close();
+         getLog().debug("done");
+         return;
+      }
+
+      // zaklju�imo transakcijo �e je za�eta
+      // get mbean name
+      // get method
+      PrintWriter out = new PrintWriter(new BufferWriter(getStdOut()));
+
+      if (params.length < 2)
+      {
+         if (canThrowEx())
+         {
+            throw new Exception("Wrong number of parameters. Usage: " + getCmd() + " [-notx] <service name> <method sig>");
+         }
+         else
+         {
+            printUsage(out);
+            return;
+         }
+      }
+
+      String mbeanName = params[0];
+      String method = params[1];
+
+      boolean notx = false;
+      boolean wasActive = false;
+
+      if (params[0].equals("-notx"))
+      {
+         notx = true;
+         mbeanName = params[1];
+
+         if (params.length < 3)
+         {
+            if (canThrowEx())
+            {
+               throw new Exception("Wrong number of parameters. Usage: " + getCmd() + " [-notx] <mbean name> <method sig>");
+            }
+            else
+            {
+               printUsage(out);
+               return;
+            }
+         }
+
+         method = params[2];
+      }
+
+
+      String methodName;
+      String[] sig = null;
+      Object[] vals = null;
+
+      int pos = method.indexOf("(");
+
+      if (pos >= 0)
+      {
+         methodName = method.substring(0, pos);
+         int epos = method.lastIndexOf(")");
+         String prs;
+         if (epos != -1)
+         {
+            prs = method.substring(pos + 1, epos);
+         }
+         else
+         {
+            prs = method.substring(pos + 1);
+         }
+
+         LinkedList l = new LinkedList();
+         StringTokenizer st = new StringTokenizer(prs, ",");
+         while (st.hasMoreTokens())
+         {
+            l.add(st.nextToken());
+         }
+
+         sig = new String[l.size()];
+         Iterator it = l.iterator();
+         for (int i = 0; i < sig.length && it.hasNext(); i++)
+         {
+            sig[i] = (String)it.next();
+         }
+
+         vals = new Object[sig.length];
+      }
+      else
+      {
+         methodName = method;
+      }
+
+      BufferObjectWriter oout = new BufferObjectWriter(getStdOut());
+      BufferObjectReader oin = new BufferObjectReader(getStdIn());
+
+      if (vals != null)
+      {
+         for (int i = 0; i < vals.length; i++)
+         {
+
+            if (!oin.isFinished())
+               vals[i] = oin.readObject();
+            else if (canThrowEx())
+            {
+               throw new Exception("Not enough input objects on stdin.");
+            }
+            else
+            {
+               out.println("Not enough input objects on stdin.");
+               return;
+            }
+         }
+      }
+
+
+      if (notx)
+      {
+         // if in tx, do this in another thread - through remote
+         // or
+         if (TxSupport.isActive())
+         {
+            wasActive = true;
+            TxSupport.commit();
+         }
+      }
+
+      try
+      {
+         invoke(out, mbeanName, methodName, sig, vals, oout);
+      }
+      finally
+      {
+         if (wasActive && !TxSupport.isActive())
+         {
+            TxSupport.begin();
+         }
+      }
+
+      oout.close();
+      oin.close();
+
+      getLog().debug("done");
+   }
+
+   protected abstract void invoke(PrintWriter out, String mbeanName, String methodName, String[] sig, Object[] vals, BufferObjectWriter oout) throws Exception;
+
+   private void printUsage(PrintWriter pout)
+   {
+      pout.println(" Usage: " + getCmd() + " [-notx] <mbean name> <method sig>");
+      pout.println();
+   }
+}
\ No newline at end of file

Modified: projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/shell/commands/MBeanInvokeExe.java
===================================================================
--- projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/shell/commands/MBeanInvokeExe.java	2009-04-29 20:18:07 UTC (rev 88020)
+++ projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/shell/commands/MBeanInvokeExe.java	2009-04-29 20:27:38 UTC (rev 88021)
@@ -1,183 +1,57 @@
 package org.jboss.fresh.shell.commands;
 
-import org.jboss.fresh.io.BufferObjectReader;
-import org.jboss.fresh.io.BufferObjectWriter;
-import org.jboss.fresh.io.BufferWriter;
-import org.jboss.fresh.io.PrintWriter2;
-import org.jboss.fresh.shell.AbstractExecutable;
-import org.jboss.fresh.util.TxSupport;
-
-import javax.management.MBeanInfo;
+import java.io.PrintWriter;
+import java.util.Set;
+import java.util.Iterator;
 import javax.management.MBeanServer;
 import javax.management.MBeanServerFactory;
-import javax.management.ObjectInstance;
 import javax.management.ObjectName;
-import java.io.PrintWriter;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.Set;
-import java.util.StringTokenizer;
+import javax.management.ObjectInstance;
+import javax.management.MBeanInfo;
 
-public class MBeanInvokeExe extends AbstractExecutable {
+import org.apache.log4j.Logger;
+import org.jboss.fresh.io.BufferObjectWriter;
+
+public class MBeanInvokeExe extends AbstractInvokeExe {
 	private static transient org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger(MBeanInvokeExe.class);
 
-	//	cat [PATHS]
-	public void process(String exename, String[] params) throws Exception {
-		log.debug("entered");
+   protected Logger getLog()
+   {
+      return log;
+   }
 
-		if (helpRequested()) {
-			PrintWriter2 out = new PrintWriter2(new BufferWriter(getStdOut()));
-			out.println("Usage: mbinvoke [-ex] [-notx] <mbean name> <method sig>");
-			out.println("			--help : this help");
-			out.close();
-			log.debug("done");
-			return;
-		}
+   protected String getCmd()
+   {
+      return "mbinvoke";
+   }
 
-		// zaklju�imo transakcijo �e je za�eta
-		// get mbean name
-		// get method
-		PrintWriter out = new PrintWriter(new BufferWriter(getStdOut()));
+   protected void invoke(PrintWriter out, String mbeanName, String methodName, String[] sig, Object[] vals, BufferObjectWriter oout) throws Exception
+   {
+      MBeanServer mbs = (MBeanServer)MBeanServerFactory.findMBeanServer(null).get(0);
+      Set svcobjs = mbs.queryMBeans(new ObjectName(mbeanName), null);
+      Iterator it = svcobjs.iterator();
+      if (it.hasNext())
+      {
+         ObjectInstance oi = (ObjectInstance)it.next();
 
-		if (params.length < 2) {
-			if (canThrowEx()) {
-				throw new Exception("Wrong number of parameters. Usage: mbinvoke [-notx] <mbean name> <method sig>");
-			} else {
-				printUsage(out);
-				return;
-			}
-		}
+         MBeanInfo minf = mbs.getMBeanInfo(oi.getObjectName());
+         System.out.println(" MBean: " + minf.getClassName() + " - " + oi.getObjectName() + " (" + minf.getDescription() + ")");
 
-
-		String mbeanName = params[0];
-		String method = params[1];
-
-		boolean notx = false;
-		boolean wasActive = false;
-
-		if (params[0].equals("-notx")) {
-			notx = true;
-			mbeanName = params[1];
-
-			if (params.length < 3) {
-				if (canThrowEx()) {
-					throw new Exception("Wrong number of parameters. Usage: mbinvoke [-notx] <mbean name> <method sig>");
-				} else {
-					printUsage(out);
-					return;
-				}
-			}
-
-			method = params[2];
-		}
-
-
-		String name = null;
-		String[] sig = null;
-		Object[] vals = null;
-
-
-		int pos = method.indexOf("(");
-
-		if (pos >= 0) {
-			name = method.substring(0, pos);
-			int epos = method.lastIndexOf(")");
-			String prs;
-			if (epos != -1) {
-				prs = method.substring(pos + 1, epos);
-			} else {
-				prs = method.substring(pos + 1);
-			}
-
-			LinkedList l = new LinkedList();
-			StringTokenizer st = new StringTokenizer(prs, ",");
-			while (st.hasMoreTokens()) {
-				l.add(st.nextToken());
-			}
-
-			sig = new String[l.size()];
-			Iterator it = l.iterator();
-			for (int i = 0; i < sig.length && it.hasNext(); i++) {
-				sig[i] = (String) it.next();
-			}
-
-			vals = new Object[sig.length];
-		} else {
-			name = method;
-		}
-
-		BufferObjectWriter oout = new BufferObjectWriter(getStdOut());
-		BufferObjectReader oin = new BufferObjectReader(getStdIn());
-
-		if (vals != null) {
-			for (int i = 0; i < vals.length; i++) {
-
-				if (!oin.isFinished())
-					vals[i] = oin.readObject();
-				else if (canThrowEx()) {
-					throw new Exception("Not enough input objects on stdin.");
-				} else {
-					out.println("Not enough input objects on stdin.");
-					return;
-				}
-			}
-		}
-
-
-		if (notx) {
-			// if in tx, do this in another thread - through remote
-			// or
-			if (TxSupport.isActive()) {
-				wasActive = true;
-				TxSupport.commit();
-			}
-		}
-
-		try {
-
-			MBeanServer mbs = (MBeanServer) MBeanServerFactory.findMBeanServer(null).get(0);
-			Set svcobjs = mbs.queryMBeans(new ObjectName(mbeanName), null);
-			Iterator it = svcobjs.iterator();
-			if (it.hasNext()) {
-				ObjectInstance oi = (ObjectInstance) it.next();
-
-				MBeanInfo minf = mbs.getMBeanInfo(oi.getObjectName());
-				System.out.println(" MBean: " + minf.getClassName() + " - " + oi.getObjectName() + " (" + minf.getDescription() + ")");
-
-				mbeanName = oi.getObjectName().toString();
-
-				//sobj=mbs.getAttribute( oi.getObjectName(), "ServiceObject");
-				Object retobj = mbs.invoke(oi.getObjectName(), name, vals, sig); // the one that takes no parameters
-				oout.writeObject(retobj);
-
-			} else {
-				// error bean not found
-				if (canThrowEx()) {
-					throw new Exception("The specified MBean is not registered: " + mbeanName);
-				} else {
-					out.println("The specified MBean is not registered: " + mbeanName);
-					return;
-				}
-			}
-
-		} finally {
-			if (wasActive && !TxSupport.isActive()) {
-				TxSupport.begin();
-			}
-		}
-
-		oout.close();
-		oin.close();
-
-		log.debug("done");
-
-	}
-
-
-	private void printUsage(PrintWriter pout) {
-		pout.println(" Usage: mbinvoke [-notx] <mbean name> <method sig>");
-		pout.println();
-	}
-
-
+         //sobj=mbs.getAttribute( oi.getObjectName(), "ServiceObject");
+         Object retobj = mbs.invoke(oi.getObjectName(), methodName, vals, sig); // the one that takes no parameters
+         oout.writeObject(retobj);
+      }
+      else
+      {
+         // error bean not found
+         if (canThrowEx())
+         {
+            throw new Exception("The specified MBean is not registered: " + mbeanName);
+         }
+         else
+         {
+            out.println("The specified MBean is not registered: " + mbeanName);
+         }
+      }
+   }
 }

Copied: projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/shell/commands/MCBeanInvokeExe.java (from rev 88017, projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/shell/commands/MBeanInvokeExe.java)
===================================================================
--- projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/shell/commands/MCBeanInvokeExe.java	                        (rev 0)
+++ projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/shell/commands/MCBeanInvokeExe.java	2009-04-29 20:27:38 UTC (rev 88021)
@@ -0,0 +1,47 @@
+package org.jboss.fresh.shell.commands;
+
+import java.io.PrintWriter;
+
+import org.apache.log4j.Logger;
+import org.jboss.fresh.io.BufferObjectWriter;
+import org.jboss.kernel.spi.registry.KernelBus;
+
+/**
+ * @author ales.justin at jboss.org
+ */
+public class MCBeanInvokeExe extends AbstractInvokeExe
+{
+   private static transient Logger log = Logger.getLogger(MCBeanInvokeExe.class);
+
+   private KernelBus bus;
+
+   public MCBeanInvokeExe(KernelBus bus)
+   {
+      if (bus == null)
+         throw new IllegalArgumentException("Null bus");
+
+      this.bus = bus;
+   }
+
+   protected Logger getLog()
+   {
+      return log;
+   }
+
+   protected String getCmd()
+   {
+      return "invoke";
+   }
+
+   protected void invoke(PrintWriter out, String beanName, String methodName, String[] sig, Object[] vals, BufferObjectWriter oout) throws Exception
+   {
+      try
+      {
+         bus.invoke(beanName, methodName, vals, sig);
+      }
+      catch (Throwable t)
+      {
+         throw new Exception(t);
+      }
+   }
+}
\ No newline at end of file

Modified: projects/fresh/trunk/pom.xml
===================================================================
--- projects/fresh/trunk/pom.xml	2009-04-29 20:18:07 UTC (rev 88020)
+++ projects/fresh/trunk/pom.xml	2009-04-29 20:27:38 UTC (rev 88021)
@@ -30,23 +30,14 @@
   <properties>
     <version.jboss.vfs>2.1.1.GA</version.jboss.vfs>
     <version.jboss.man>2.1.0.CR8</version.jboss.man>
-    <version.jboss.mdr>2.0.1.GA</version.jboss.mdr>
     <version.jboss.microcontainer>2.0.5.GA</version.jboss.microcontainer>
-    <version.jboss.classloader>2.0.5.GA</version.jboss.classloader>
-    <version.jboss.deployers>2.0.6.GA</version.jboss.deployers>
     <version.jboss.common.core>2.2.13.GA</version.jboss.common.core>
     <version.jboss.common.logging.spi>2.0.5.GA</version.jboss.common.logging.spi>
     <version.jboss.common.logging.log4j>2.0.5.GA</version.jboss.common.logging.log4j>
     <version.jbossxb>2.0.1.GA</version.jbossxb>
-    <version.jboss.aop>2.0.1.GA</version.jboss.aop>
-    <version.jboss.pojocache>3.0.0.GA</version.jboss.pojocache>
     <version.org.jboss.test>1.0.5.GA</version.org.jboss.test>
     <version.junit>4.4</version.junit>
-    <version.javassist>3.10.0.GA</version.javassist>
-    <version.javaee>3.0.0.GA</version.javaee>
     <version.xerces>2.9.1</version.xerces>
-    <version.aopalliance>1.0</version.aopalliance>
-    <version.spring>2.5.6</version.spring>
   </properties>
 
   <build>
@@ -257,6 +248,16 @@
       <!-- JBoss dependencies -->      
 
       <dependency>
+        <groupId>org.jboss.microcontainer</groupId>
+        <artifactId>jboss-dependency</artifactId>
+        <version>${version.jboss.microcontainer}</version>
+      </dependency>
+      <dependency>
+        <groupId>org.jboss.microcontainer</groupId>
+        <artifactId>jboss-kernel</artifactId>
+        <version>${version.jboss.microcontainer}</version>
+      </dependency>
+      <dependency>
         <groupId>org.jboss</groupId>
         <artifactId>jboss-common-core</artifactId>
         <version>${version.jboss.common.core}</version>




More information about the jboss-cvs-commits mailing list