FileDocCategorySizeDatePackage
MCKernelAbstraction.javaAPI DocJBoss 4.2.17244Fri Jul 13 20:53:58 BST 2007org.jboss.ejb3

MCKernelAbstraction

public class MCKernelAbstraction extends MCClientKernelAbstraction implements KernelAbstraction
Abstraction layer for installing beans into the micro container.
author
Bill Burke
version
$Revision: 61280 $

Fields Summary
private static final Logger
log
private MBeanServer
server
Constructors Summary
public MCKernelAbstraction(org.jboss.kernel.Kernel kernel, MBeanServer server)

      super(kernel);
      this.server = server;
   
Methods Summary
private booleanhasOperation(javax.management.MBeanInfo info, java.lang.String operationName)

      for(MBeanOperationInfo operationInfo : info.getOperations())
      {
         if(operationInfo.getName().equals(operationName) == false)
            continue;
         
         // void return type
         if(operationInfo.getReturnType().equals("void") == false)
            continue;
         
         // no parameters
         if(operationInfo.getSignature().length != 0)
            continue;
         
         return true;
      }
      
      return false;
   
public voidinstall(java.lang.String name, DependencyPolicy dependencies, java.lang.Object service)

      AbstractBeanMetaData bean = new AbstractBeanMetaData(name, service.getClass().getName());
      bean.setConstructor(new AlreadyInstantiated(service));
      MCDependencyPolicy policy = (MCDependencyPolicy) dependencies;
      bean.setDemands(policy.getDependencies());
      log.info("installing bean: " + name + " with dependencies:");
      for (Object obj : policy.getDependencies())
      {
         String msg;
         if (obj instanceof AbstractDemandMetaData)
         {
            msg = ((AbstractDemandMetaData)obj).getDemand().toString();
         }
         else
         {
            msg = obj.toString();
         }
         log.info("\t" + msg);
      }
      try
      {
         try 
         {
            kernel.getController().uninstall(name);
         }
         catch (IllegalStateException e){}
               
         kernel.getController().install(bean);
      }
      catch (Throwable throwable)
      {
         throw new RuntimeException(throwable);
      }
   
public voidinstallMBean(javax.management.ObjectName on, DependencyPolicy dependencies, java.lang.Object service)

      try
      {
         server.registerMBean(service, on);
         install(on.getCanonicalName(), dependencies, service);
         
         // EJBTHREE-606: emulate the ServiceController calls
         MBeanInfo info = server.getMBeanInfo(on); // redundant call for speed
         invokeOptionalMethod(on, info, "create");
         invokeOptionalMethod(on, info, "start");
      }
      catch (Exception e)
      {
         e.printStackTrace();
         throw new RuntimeException(e);
      }
   
public java.lang.Objectinvoke(javax.management.ObjectName objectName, java.lang.String operationName, java.lang.Object[] params, java.lang.String[] signature)

      String name = objectName.getCanonicalName();
      KernelRegistryEntry entry = kernel.getRegistry().getEntry(name);
      if (entry != null)
      {
         Object target = entry.getTarget();
         if (target instanceof RARDeployment)
         {
            RARDeployment deployment = (RARDeployment)target;
            return deployment.invoke(operationName, params, signature);
         } 
         else
         {
            Class[] types = new Class[signature.length];
            for (int i = 0; i < signature.length; ++i)
            {
               types[i] = Thread.currentThread().getContextClassLoader().loadClass(signature[i]);
            }
            Method method = target.getClass().getMethod(operationName, types);
            return method.invoke(target, params);
         }
      }
      return null;
   
private voidinvokeOptionalMethod(javax.management.ObjectName on, javax.management.MBeanInfo info, java.lang.String operationName)

      Object params[] = { };
      String signature[] = { };
      if(hasOperation(info, operationName))
         server.invoke(on, operationName, params, signature);
   
public voidsetMbeanServer(javax.management.MBeanServer server)

      this.server = server;
   
public voiduninstall(java.lang.String name)

      try
      {
         log.info("uninstalling bean: " + name);
         kernel.getController().uninstall(name);
      }
      catch (Exception e)
      {
         throw new RuntimeException(e);
      }
   
public voiduninstallMBean(javax.management.ObjectName on)

      try
      {
         // EJBTHREE-606: emulate the ServiceController calls
         MBeanInfo info = server.getMBeanInfo(on); // redundant call for speed
         invokeOptionalMethod(on, info, "stop");
         invokeOptionalMethod(on, info, "destroy");
         
         server.unregisterMBean(on);
         kernel.getController().uninstall(on.toString());
      }
      catch (Exception e)
      {
         throw new RuntimeException(e);
      }