WEB开发网
开发学院软件开发Java 在 Geronimo 中管理 Apache Pluto 阅读

在 Geronimo 中管理 Apache Pluto

 2010-03-30 00:00:00 来源:WEB开发网   
核心提示: 在为 ConfigService 组件创建了标准 Geronimo GBean 后,必须由 Geronimo 内核装入和启动它,在 Geronimo 中管理 Apache Pluto(7),您可以使用 org.apache.geronimo.kernel.KernelRegistry 类的 ge

在为 ConfigService 组件创建了标准 Geronimo GBean 后,必须由 Geronimo 内核装入和启动它。您可以使用 org.apache.geronimo.kernel.KernelRegistry 类的 getSingleKernel 方法检索 Geronimo 内核。

通过对内核的引用,可以使用 GBeanData 实例描述 GBean。该 GBean 随后被内核装入和启动,如清单 3 中所示:

清单 3. 使用 GBeanManager 装入和启动 GBean

public class GBeanManager 
{ 
 public static void loadAndStartGBean(Class gBeanCls, 
                    GBeanInfo gBeanInfo, 
                    String serviceType) 
 { 
  java.net.URI gBeanURI = 
   java.net.URI.create("devworks/" + gBeanCls.getName() + "/1.0.0/?service=" 
             + serviceType); 
  org.apache.geronimo.gbean.AbstractName abstractName = 
   new org.apache.geronimo.gbean.AbstractName(gBeanURI); 
 
  org.apache.geronimo.gbean.GBeanData gBeanData = 
   new org.apache.geronimo.gbean.GBeanData(abstractName, gBeanInfo); 
  System.out.println("Loaded gBeanData for class: " + gBeanCls.getName()); 
 
  org.apache.geronimo.kernel.Kernel geronimoKernel = 
   org.apache.geronimo.kernel.KernelRegistry.getSingleKernel(); 
  System.out.println("Found kernel: " + geronimoKernel.getKernelName()); 
 
  ClassLoader clsLoader = Thread.currentThread().getContextClassLoader(); 
 
  try 
  { 
   geronimoKernel.loadGBean(gBeanData, clsLoader); 
   System.out.println("Loaded gBean: " + gBeanCls.getName()); 
  } 
  catch (GBeanAlreadyExistsException e) 
  { 
   System.out.println("GBean [" + gBeanCls.getName() + "] already loaded"); 
  } 
 
  try 
  { 
   geronimoKernel.startGBean(gBeanCls); 
   System.out.println("Started gBean: " + gBeanCls.getName()); 
  } 
  catch (GBeanNotFoundException e) 
  { 
   System.err.println("GBean [" + gBeanCls.getName() + "] not found"); 
  } 
 } 
 
 public static void stopAndUnloadGBean(Class gBeanCls) 
 { 
  org.apache.geronimo.kernel.Kernel geronimoKernel = 
   org.apache.geronimo.kernel.KernelRegistry.getSingleKernel(); 
  System.out.println("Found kernel: " + geronimoKernel.getKernelName()); 
 
  try 
  { 
   geronimoKernel.stopGBean(gBeanCls); 
   System.out.println("Stopped gBean: " + gBeanCls.getName()); 
  } 
  catch (GBeanNotFoundException e) 
  { 
   System.err.println("GBean [" + gBeanCls.getName() + "] not found"); 
   return; 
  } 
 
  try 
  { 
   geronimoKernel.unloadGBean(gBeanCls); 
   System.out.println("Unloaded gBean: " + gBeanCls.getName()); 
  } 
  catch (GBeanNotFoundException e) 
  { 
   System.err.println("GBean [" + gBeanCls.getName() + "] not found"); 
   return; 
  } 
 } 
 
 public static Object getGBean(Class gBeanCls) 
  throws GBeanNotFoundException 
 { 
  org.apache.geronimo.kernel.Kernel geronimoKernel = 
   org.apache.geronimo.kernel.KernelRegistry.getSingleKernel(); 
  System.out.println("Found kernel: " + geronimoKernel.getKernelName()); 
 
  return geronimoKernel.getGBean(gBeanCls); 
 } 
} 

上一页  2 3 4 5 6 7 8 9 10  下一页

Tags:Geronimo 管理 Apache

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接