Hi Lochana, Here is a sample code in platform where it uses the Service Component approach. [1], Maybe that should work for your requirement. Haven't tried it though.
[1]. https://svn.wso2.org/repos/wso2/carbon/platform/trunk/components/analytics/org.wso2.carbon.hive.data.source.access/src/main/java/org/wso2/carbon/hive/data/source/access/internal/DataSourceAccessComponent.java On Fri, Nov 14, 2014 at 7:27 AM, Prabath Abeysekera <[email protected]> wrote: > Hi Lochana, > > On Thu, Nov 13, 2014 at 5:39 PM, Lochana Menikarachchi <[email protected]> > wrote: > >> Wonder whether it is due to bundle load order.. Is there anyway to change >> it.. >> > > This could well be an issue with the bundle start up order. However, have > we tried putting a few logs in ndatasource bundle activator too and made > sure that this really is the reason why the JNDI look-up failed? > > On a side note, I'm seeing you guys've extended "BundleActivator" to > implement the bundle initializer. I'd recommend you guys follow the > "Service Component" approach where it is purely declarative and much > appropriate for implementations that require access to a lot of external > declarative service dependencies, which is quite common across most of the > components we've got in the platform. Not only that, the former is > generally considered an "old" approach of activating a bundle, which could, > however, be used if you need to get hold of some of the very lower level > controls of the bundle activation process. There's a quite a few other > advantages too like being able to define more than one Service Components > within an OSGi bundle etc, but IMO, this is not quite needed in most of the > cases we often tend to deal with, within the platform. > > Cheers, > Prabath > > >> >> [2014-11-13 17:32:04,594] INFO >> {org.wso2.carbon.ml.dataset.DatasetServiceActivator} - Dataset service >> started >> [2014-11-13 17:32:04,596] INFO >> {org.wso2.carbon.ml.model.ModelServiceActivator} - Model service started >> [2014-11-13 17:32:04,597] INFO >> {org.wso2.carbon.ml.project.mgt.ProjectManagementServiceActivator} - >> Project management service started >> [2014-11-13 17:32:04,597] INFO >> {org.wso2.carbon.ml.project.mgt.ProjectManagementServiceActivator} - ML >> Wizard URL : http://localhost:9763/mlUI >> [2014-11-13 17:32:05,536] INFO >> {org.wso2.carbon.user.core.ldap.ReadWriteLDAPUserStoreManager} - LDAP >> connection created successfully in read-write mode >> [2014-11-13 17:32:05,709] INFO >> {org.wso2.carbon.registry.core.jdbc.EmbeddedRegistryService} - Configured >> Registry in 83ms >> >> >> On Thu, Nov 13, 2014 at 4:59 PM, Lochana Menikarachchi <[email protected]> >> wrote: >> >>> >>> Is it possible access a database within osgi bundle's start method? >>> >>> public void start(BundleContext context) throws Exception { >>> ModelService modelService = new ModelService(); >>> context.registerService(ModelService.class.getName(), >>> modelService, null); >>> >>> * MLAlgorithmConfiguration mlAlgorithmConfiguration = new >>> MLAlgorithmConfiguration(); >>> mlAlgorithmConfiguration.loadMLAlgorithmConfigurations();* >>> logger.info("Model service started"); >>> } >>> >>> loadMLConfigurations loads some default values to a database. Adding >>> bold lettered lines throws following exception >>> >>> INFO {org.wso2.carbon.ml.dataset.DatasetServiceActivator} - Dataset >>> service started >>> [2014-11-13 16:48:49,589] ERROR >>> {org.wso2.carbon.ml.model.DatabaseHandler} - An error occurred while >>> connecting to database. Name [jdbc/WSO2ML_DB] is not bound in this Context. >>> Unable to find [jdbc]. >>> javax.naming.NameNotFoundException: Name [jdbc/WSO2ML_DB] is not bound >>> in this Context. Unable to find [jdbc]. >>> at org.apache.naming.NamingContext.lookup(NamingContext.java:819) >>> at org.apache.naming.NamingContext.lookup(NamingContext.java:167) >>> at >>> org.wso2.carbon.context.internal.CarbonContextDataHolder$CarbonInitialJNDIContext.lookup(CarbonContextDataHolder.java:705) >>> at javax.naming.InitialContext.lookup(InitialContext.java:411) >>> at >>> org.wso2.carbon.ml.model.DatabaseHandler.getDatabaseHandler(DatabaseHandler.java:62) >>> >>> -- >>> Lochana Menikarachchi >>> Senior Tech Lead >>> WSO2 Inc. >>> >> >> >> >> -- >> Lochana Menikarachchi >> Senior Tech Lead >> WSO2 Inc. >> >> _______________________________________________ >> Dev mailing list >> [email protected] >> http://wso2.org/cgi-bin/mailman/listinfo/dev >> >> > > > -- > Prabath Abeysekara > Associate Technical Lead, Data TG. > WSO2 Inc. > Email: [email protected] > Mobile: +94774171471 > > _______________________________________________ > Dev mailing list > [email protected] > http://wso2.org/cgi-bin/mailman/listinfo/dev > > -- *Aruna Sujith Karunarathna* | Software Engineer WSO2, Inc | lean. enterprise. middleware. #20, Palm Grove, Colombo 03, Sri Lanka Mobile: +94 71 9040362 | Work: +94 112145345 Email: [email protected] | Web: www.wso2.com
_______________________________________________ Dev mailing list [email protected] http://wso2.org/cgi-bin/mailman/listinfo/dev
