Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*     */ package org.jboss.ejb3;
  /*     */ 
  /*     */ import java.lang.reflect.Method;
  /*     */ import javax.management.InstanceNotFoundException;
  /*     */ import javax.management.MBeanException;
  /*     */ import javax.management.MBeanInfo;
  /*     */ import javax.management.MBeanOperationInfo;
  /*     */ import javax.management.MBeanServer;
  /*     */ import javax.management.ObjectName;
 /*     */ import javax.management.ReflectionException;
 /*     */ import org.jboss.kernel.Kernel;
 /*     */ import org.jboss.logging.Logger;
 /*     */ 
 /*     */ public class MCKernelAbstraction extends MCClientKernelAbstraction
 /*     */   implements KernelAbstraction
 /*     */ {
 /*  56 */   private static final Logger log = Logger.getLogger(MCKernelAbstraction.class);
 /*     */   private MBeanServer server;
 /*     */ 
 /*     */   public MCKernelAbstraction(Kernel kernelMBeanServer server)
 /*     */   {
 /*  86 */     super(kernel);
 /*  87 */     this. = server;
 /*     */   }
 /*     */ 
 /*     */   public void setMbeanServer(MBeanServer server)
 /*     */   {
 /*  92 */     this. = server;
 /*     */   }
 /*     */ 
 /*     */   private boolean hasOperation(MBeanInfo infoString operationName)
 /*     */   {
 /*  97 */     for (MBeanOperationInfo operationInfo : info.getOperations())
 /*     */     {
 /*  99 */       if (!operationInfo.getName().equals(operationName))
 /*     */       {
 /*     */         continue;
 /*     */       }
 /* 103 */       if (!operationInfo.getReturnType().equals("void"))
 /*     */       {
 /*     */         continue;
 /*     */       }
 /* 107 */       if (operationInfo.getSignature().length == 0)
 /*     */       {
 /* 110 */         return true;
 /*     */       }
 /*     */     }
 /* 113 */     return false;
 /*     */   }
 /*     */ 
 /*     */   public void install(String nameDependencyPolicy dependenciesObject service)
 /*     */   {
 /* 118 */     AbstractBeanMetaData bean = new AbstractBeanMetaData(nameservice.getClass().getName());
 /* 119 */     bean.setConstructor(new AlreadyInstantiated(service));
 /* 120 */     MCDependencyPolicy policy = (MCDependencyPolicy)dependencies;
 /* 121 */     bean.setDepends(policy.getDependencies());
 /* 122 */     bean.setDemands(policy.getDemands());
 /* 123 */     bean.setSupplies(policy.getSupplies());
 /* 124 */     .info("installing bean: " + name + " with dependencies:");
 /* 125 */     for (Object obj : policy.getDependencies())
 /*     */     {
 /*     */       String msg;
 /*     */       String msg;
 /* 128 */       if ((obj instanceof AbstractDemandMetaData))
 /*     */       {
 /* 130 */         msg = ((AbstractDemandMetaData)obj).getDemand().toString();
 /*     */       }
 /*     */       else
 /*     */       {
 /* 134 */         msg = obj.toString();
 /*     */       }
 /* 136 */       .info("\t" + msg);
 /*     */     }
 /* 138 */     .info("  and supplies:");
 /* 139 */     for (SupplyMetaData smd : policy.getSupplies())
 /*     */     {
 /* 141 */       .info("\t" + smd.getSupply().toString());
 /*     */     }
 /*     */     try
 /*     */     {
 /*     */       try
 /*     */       {
 /* 147 */         this..getController().uninstall(name);
 /*     */       }
 /*     */       catch (IllegalStateException e) {
 /*     */       }
 /* 151 */       this..getController().install(bean);
 /*     */     }
 /*     */     catch (Throwable throwable)
 /*     */     {
/* 155 */       throw new RuntimeException(throwable);
/*     */     }
/*     */   }
/*     */ 
/*     */   public void installMBean(ObjectName onDependencyPolicy dependenciesObject service)
/*     */   {
/*     */     try
/*     */     {
/* 163 */       this..registerMBean(serviceon);
/* 164 */       install(on.getCanonicalName(), dependenciesservice);
/*     */ 
/* 167 */       MBeanInfo info = this..getMBeanInfo(on);
/* 168 */       invokeOptionalMethod(oninfo"create");
/* 169 */       invokeOptionalMethod(oninfo"start");
/*     */     }
/*     */     catch (Exception e)
/*     */     {
/* 173 */       e.printStackTrace();
/* 174 */       throw new RuntimeException(e);
/*     */     }
/*     */   }
/*     */ 
/*     */   private void invokeOptionalMethod(ObjectName onMBeanInfo infoString operationNamethrows InstanceNotFoundExceptionMBeanExceptionReflectionException
/*     */   {
/* 180 */     Object[] params = new Object[0];
/* 181 */     String[] signature = new String[0];
/* 182 */     if (hasOperation(infooperationName))
/* 183 */       this..invoke(onoperationNameparamssignature);
/*     */   }
/*     */ 
/*     */   public void uninstallMBean(ObjectName on)
/*     */   {
/*     */     try
/*     */     {
/* 191 */       MBeanInfo info = this..getMBeanInfo(on);
/*     */       try
/*     */       {
/* 194 */         invokeOptionalMethod(oninfo"stop");
/*     */       }
/*     */       catch (Exception e)
/*     */       {
/* 199 */         .warn("stop on " + on + " failed"e);
/*     */       }
/*     */       try
/*     */       {
/* 203 */         invokeOptionalMethod(oninfo"destroy");
/*     */       }
/*     */       catch (Exception e)
/*     */       {
/* 208 */         .warn("destroy on " + on + " failed"e);
/*     */       }
/*     */ 
/* 211 */       this..unregisterMBean(on);
/* 212 */       this..getController().uninstall(on.getCanonicalName());
/*     */     }
/*     */     catch (Exception e)
/*     */     {
/* 216 */       throw new RuntimeException(e);
/*     */     }
/*     */   }
/*     */ 
/*     */   public void uninstall(String name)
/*     */   {
/*     */     try
/*     */     {
/* 224 */       .info("uninstalling bean: " + name);
/* 225 */       this..getController().uninstall(name);
/*     */     }
/*     */     catch (Exception e)
/*     */     {
/* 229 */       throw new RuntimeException(e);
/*     */     }
/*     */   }
/*     */ 
/*     */   public Object invoke(ObjectName objectNameString operationNameObject[] paramsString[] signaturethrows Exception
/*     */   {
/* 235 */     String name = objectName.getCanonicalName();
/* 236 */     KernelRegistryEntry entry = this..getRegistry().getEntry(name);
/* 237 */     if (entry != null)
/*     */     {
/* 239 */       Object target = entry.getTarget();
/* 240 */       if ((target instanceof RARDeployment))
/*     */       {
/* 242 */         RARDeployment deployment = (RARDeployment)target;
/* 243 */         return deployment.invoke(operationNameparamssignature);
/*     */       }
/*     */ 
/* 247 */       Class[] types = new Class[signature.length];
/* 248 */       for (int i = 0; i < signature.lengthi++)
/*     */       {
/* 250 */         types[i] = Thread.currentThread().getContextClassLoader().loadClass(signature[i]);
/*     */       }
/* 252 */       Method method = target.getClass().getMethod(operationNametypes);
/* 253 */       return method.invoke(targetparams);
/*     */     }
/*     */ 
/* 256 */     return null;
/*     */   }
/*     */ 
/*     */   public static class AlreadyInstantiated extends AbstractConstructorMetaData
/*     */   {
/*     */     private static final long serialVersionUID = 8120833830553872619L;
/*     */     private Object bean;
/*     */ 
/*     */     public AlreadyInstantiated(Object bean)
/*     */     {
/*  75 */       this. = bean;
/*  76 */       setFactory(new AbstractValueMetaData(new Factory()));
/*  77 */       setFactoryClass(Factory.class.getName());
/*  78 */       setFactoryMethod("create");
/*     */     }
/*     */ 
/*     */     public class Factory
/*     */     {
/*     */       public Factory()
/*     */       {
/*     */       }
/*     */ 
/*     */       public Object create()
/*     */       {
/*  69 */         return MCKernelAbstraction.AlreadyInstantiated.this.;
/*     */       }
/*     */     }
/*     */   }
/*     */ }
/* Location:           /home/mnovotny/projects/EMBEDDED_JBOSS_BETA3_COMMUNITY/embedded/output/lib/embedded-jboss/lib/jboss-embedded-all.jar
 * Qualified Name:     org.jboss.ejb3.MCKernelAbstraction
 * JD-Core Version:    0.6.0
 */
New to GrepCode? Check out our FAQ X