[GLASSFISH-15365] [OSGi/CDI] CDI + OSGi event admin Created: 27/Dec/10  Updated: 11/Dec/12

Status: Open
Project: glassfish
Component/s: OSGi-JavaEE
Affects Version/s: None
Fix Version/s: future release

Type: New Feature Priority: Major
Reporter: Sanjeeb Sahoo Assignee: Sanjeeb Sahoo
Resolution: Unresolved Votes: 1
Labels: None
Σ Remaining Estimate: Not Specified Remaining Estimate: Not Specified
Σ Time Spent: Not Specified Time Spent: Not Specified
Σ Original Estimate: Not Specified Original Estimate: Not Specified

Attachments: Zip Archive GLASSFISH-15365-patch-20121211.zip    
Sub-Tasks:
Key
Summary
Type
Status
Assignee
GLASSFISH-19358 Adding fighterfish test cases Sub-task Open Sanjeeb Sahoo  
Tags: 3_1_x-exclude

 Description   

We should explore use of CDI event mechanism for OSGi event admin



 Comments   
Comment by TangYong [ 19/Nov/12 ]

CDI/OSGi Event Integration is in progress. Now, desgin of the integration is as following:

1 CDI/OSGi Event API

1) defining three CDI/OSGi Events

・ServiceRegistered
・ServiceModified
・ServiceUnregistering

2) defining a @ServiceContract Qualifier used for qualifying CDI/OSGi event

@Target(

{ PARAMETER }

)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Qualifier
public @interface ServiceContract {
/**

  • The specification class filtering the received
  • {@link javax.enterprise.event.Event}

    .
    */
    Class<?> value();
    }

By 1) and 2), a user can write the following observer method:

public void postOnActivator(@Observes @ServiceContract(StockQuoteService.class) ServiceRegistered event)

{ System.out.println("postOnActivator() method is getting : " + event.getServiceContractNames()); Set<String> set = ((StockQuoteService)event.getService()).getSymbols(); ... }

2 OSGi Service Listening
Adding ServiceListener into OSGiCDIContainerActivator and wraping OSGi Service Event into CDI/OSGi Event

3 Firing CDI/OSGi Event using CDI Event Interface
Here, I use Instance<Object> to select Event<Object> and fire CDI/OSGi Event. In order to get Instance<Object>, I need to register Instance<Object> related each Weld Container Instance as OSGi Services while getting Instance<Object> from OSGiServiceExtension class.

Note: while using Instance<Object> to select Event<Object>, Weld will call ACLSingletonProvider.get() , so we must take care of set TCCL.

4 Handling Instance<Object>'s Unregistering
While a bundle is in process of stopping or uninstalled, we must unregister OSGi Service of Instance<Object> which belongs to current bundle.

[Current State Of Integration]
Prototype has been made and fixing some bugs.

Comment by TangYong [ 19/Nov/12 ]

Currently, event integration has been tested between multi plain osgi bundles successfully, the following displayed that event callback method(OnServiceRegistered) can be called many times once MyServiceInf's implementation is available.

[#|2012-11-19T22:44:35.656+0900|INFO|44.0|javax.enterprise.logging.stdout|_ThreadID=12;_ThreadName=admin-listener(1);_TimeMillis=1353332675656;_LevelValue=800;|MyService has been registered OSGi Service!|#]

[#|2012-11-19T22:44:35.656+0900|INFO|44.0|javax.enterprise.logging.stdout|_ThreadID=12;_ThreadName=admin-listener(1);_TimeMillis=1353332675656;_LevelValue=800;|SimpleStockQuoteServiceImpl::Initializing quotes|#]

[#|2012-11-19T22:44:35.656+0900|INFO|44.0|javax.enterprise.logging.stdout|_ThreadID=12;_ThreadName=admin-listener(1);_TimeMillis=1353332675656;_LevelValue=800;|SimpleStockQuoteServiceImpl::getSymbols|#]

[#|2012-11-19T22:44:35.656+0900|INFO|44.0|javax.enterprise.logging.stdout|_ThreadID=12;_ThreadName=admin-listener(1);_TimeMillis=1353332675656;_LevelValue=800;|Registered:[IBM, MSFT, HPQ, ORCL]|#]

[#|2012-11-19T22:44:35.656+0900|INFO|44.0|javax.enterprise.logging.stdout|_ThreadID=12;_ThreadName=admin-listener(1);_TimeMillis=1353332675656;_LevelValue=800;|OnServiceRegistered() method is getting : [org.acme.myservice.api.MyServiceInf]|#]

[#|2012-11-19T22:44:35.656+0900|INFO|44.0|javax.enterprise.logging.stdout|_ThreadID=12;_ThreadName=admin-listener(1);_TimeMillis=1353332675656;_LevelValue=800;|OnServiceRegistered(): MyService: Hello Word!|#]

[#|2012-11-19T22:44:35.656+0900|INFO|44.0|javax.enterprise.logging.stdout|_ThreadID=12;_ThreadName=admin-listener(1);_TimeMillis=1353332675656;_LevelValue=800;|Started sample.osgicdi.myservice [284]|#]

[#|2012-11-19T22:44:35.671+0900|INFO|44.0|javax.enterprise.system.tools.admin.org.glassfish.deployment.admin|_ThreadID=12;_ThreadName=admin-listener(1);_TimeMillis=1353332675671;_LevelValue=800;|myservice was successfully deployed in 109 milliseconds.|#]

[#|2012-11-19T22:45:09.906+0900|INFO|44.0|javax.enterprise.logging.stdout|_ThreadID=12;_ThreadName=admin-listener(1);_TimeMillis=1353332709906;_LevelValue=800;|Stopped sample.osgicdi.myservice [284]|#]

[#|2012-11-19T22:45:09.921+0900|INFO|44.0|javax.enterprise.logging.stdout|_ThreadID=12;_ThreadName=admin-listener(1);_TimeMillis=1353332709921;_LevelValue=800;|Uninstalled sample.osgicdi.myservice [284]|#]

[#|2012-11-19T22:45:19.250+0900|INFO|44.0|javax.enterprise.logging.stdout|_ThreadID=12;_ThreadName=admin-listener(1);_TimeMillis=1353332719250;_LevelValue=800;|Installed sample.osgicdi.myservice [285] from reference:file:/D:/gf/1102/glassfish3/glassfish/domains/domain1/applications/myservice/|#]

[#|2012-11-19T22:45:19.250+0900|INFO|44.0|javax.enterprise.logging.stdout|_ThreadID=12;_ThreadName=admin-listener(1);_TimeMillis=1353332719250;_LevelValue=800;|Hello!|#]

[#|2012-11-19T22:45:19.265+0900|INFO|44.0|org.jboss.weld.Bootstrap|_ThreadID=12;_ThreadName=admin-listener(1);_TimeMillis=1353332719265;_LevelValue=800;|WELD-000101 Transactional services not available. Injection of @Inject UserTransaction not available. Transactional observers will be invoked synchronously.|#]

[#|2012-11-19T22:45:19.281+0900|INFO|44.0|javax.enterprise.logging.stdout|_ThreadID=12;_ThreadName=admin-listener(1);_TimeMillis=1353332719281;_LevelValue=800;|MyService has been registered OSGi Service!|#]

[#|2012-11-19T22:45:19.281+0900|INFO|44.0|javax.enterprise.logging.stdout|_ThreadID=12;_ThreadName=admin-listener(1);_TimeMillis=1353332719281;_LevelValue=800;|SimpleStockQuoteServiceImpl::Initializing quotes|#]

[#|2012-11-19T22:45:19.281+0900|INFO|44.0|javax.enterprise.logging.stdout|_ThreadID=12;_ThreadName=admin-listener(1);_TimeMillis=1353332719281;_LevelValue=800;|SimpleStockQuoteServiceImpl::getSymbols|#]

[#|2012-11-19T22:45:19.281+0900|INFO|44.0|javax.enterprise.logging.stdout|_ThreadID=12;_ThreadName=admin-listener(1);_TimeMillis=1353332719281;_LevelValue=800;|Registered:[IBM, MSFT, HPQ, ORCL]|#]

[#|2012-11-19T22:45:19.281+0900|INFO|44.0|javax.enterprise.logging.stdout|_ThreadID=12;_ThreadName=admin-listener(1);_TimeMillis=1353332719281;_LevelValue=800;|OnServiceRegistered() method is getting : [org.acme.myservice.api.MyServiceInf]|#]

[#|2012-11-19T22:45:19.281+0900|INFO|44.0|javax.enterprise.logging.stdout|_ThreadID=12;_ThreadName=admin-listener(1);_TimeMillis=1353332719281;_LevelValue=800;|OnServiceRegistered(): MyService: Hello Word!|#]

[#|2012-11-19T22:45:19.281+0900|INFO|44.0|javax.enterprise.logging.stdout|_ThreadID=12;_ThreadName=admin-listener(1);_TimeMillis=1353332719281;_LevelValue=800;|Started sample.osgicdi.myservice [285]|#]

Comment by TangYong [ 19/Nov/12 ]

However, there is a bug which is in process of investigation.
Once the observer method is in a servlet of WAB, the observer has not been triggered.

Comment by TangYong [ 20/Nov/12 ]

Currently, WAB's OSGi/CDI event integration is blocked by GLASSFISH-19359 and waiting for siva and sahoo's confirmation.

Comment by TangYong [ 22/Nov/12 ]

Because GLASSFISH-19359 has been resolved, now, starting to enter into fighterfish test phrase.

Comment by TangYong [ 11/Dec/12 ]

Splited patch for GLASSFISH-15365 is uploaded, please seeing GLASSFISH-15365-patch-20121211.zip.

Generated at Fri Feb 27 05:58:32 UTC 2015 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.