View Javadoc
1   /**
2    * Copyright By Grandsoft Company Limited.  
3    * 2012-2-6 下午04:42:39
4    */
5   package gboat2.cxf;
6   
7   import gboat2.base.core.ActivatorInnerThread;
8   import gboat2.cxf.business.IWebServiceConfigBusiness;
9   
10  import org.apache.commons.lang3.time.DateUtils;
11  import org.osgi.framework.BundleActivator;
12  import org.osgi.framework.BundleContext;
13  import org.osgi.framework.ServiceReference;
14  import org.osgi.util.tracker.ServiceTracker;
15  
16  /**
17   * Bundle 启动类
18   * @author zhaic
19   * @since jdk1.6
20   * @date 2012-2-6
21   */
22  public class Activator implements BundleActivator {
23  	
24  	private ServiceTracker<IWebServiceConfigBusiness, Object> tracker;
25  	
26  	@Override
27  	public void start(final BundleContext bundleContext) throws Exception {
28  		tracker = new ServiceTracker<IWebServiceConfigBusiness, Object>(bundleContext, IWebServiceConfigBusiness.class.getName(), null) {
29  			@Override
30  			public Object addingService(final ServiceReference<IWebServiceConfigBusiness> ref) {
31  				new ActivatorInnerThread(DateUtils.MILLIS_PER_MINUTE * 2) { //延迟两分钟,不然查库返回空,有可能是 PO 还没有注册成功
32  					@Override
33                      public boolean task() {
34                          IWebServiceConfigBusiness busi = bundleContext.getService(ref);
35                          busi.startPublishAndTrackWebService();// 开始发布web服务
36                          tracker.close(); // 无需再跟踪,关闭跟踪器释放资源
37                          tracker = null;
38                          return true;
39                      }
40  				}.start();
41  				
42  				/*
43  				IWebServiceConfigBusiness busi = (IWebServiceConfigBusiness) bundleContext.getService(ref);
44  				busi.startPublishAndTrackWebService();//开始发布web服务
45  				tracker.close();//无需再跟踪,关闭跟踪器释放资源
46  				tracker = null;
47  				*/
48  				return super.addingService(ref);
49  			}
50  			
51  		};
52  		tracker.open();
53  	}
54  	
55  	@Override
56  	public void stop(BundleContext bundleContext) throws Exception {
57  	    /*
58  		IWebServiceConfigBusiness cxfSer = (IWebServiceConfigBusiness) SpringContextUtil.getInstance().getBeanOfId(
59  		        "cxfBusinessSer", bundleContext.getBundle());
60  		if (null != cxfSer) {
61  			cxfSer.unpublishAllServices();
62  		}
63  		
64  		if (null != bundleTracker) {
65  			bundleTracker.close();
66  		}
67           */
68  	}
69  }