Hi Geesara, Thanks for the explanation. I will try this way.
Regards, Dilhasha On 1 Jun 2016 21:42, "Geesara Prathap" <[email protected]> wrote: > > getOSGiService(Class clazz) method has been deprecated. You can verify > it by looking its implementation class: > org.wso2.carbon.context.PrivilegedCarbonContext. How about this way > > public static AnalyticsDataAPI getAnalyticsDataAPI() { > PrivilegedCarbonContext ctx = > PrivilegedCarbonContext.getThreadLocalCarbonContext(); > AnalyticsDataAPI analyticsDataAPI = > (AnalyticsDataAPI) > ctx.getOSGiService(AnalyticsDataAPI.class, null); > if (analyticsDataAPI == null) { > String msg = "Analytics api service has not initialized."; > log.error(msg); > throw new IllegalStateException(msg); > } > return analyticsDataAPI; > } > > > > On Wed, Jun 1, 2016 at 12:19 PM, Fathima Dilhasha <[email protected]> > wrote: > >> Hi, >> >> I have an Admin Service which accesses a method in an already available >> osgi service. >> I am using the following code segment to achieve this. >> >> PrivilegedCarbonContext.startTenantFlow(); >> Object service = >> PrivilegedCarbonContext.getThreadLocalCarbonContext().getOSGiService(AnalyticsDataAPI.class); >> if(service instanceof AnalyticsDataAPI) { >> this.analyticsDataAPI = (AnalyticsDataAPI) service; >> } >> >> I need to know whether there is any better way of achieving this. >> >> Thanks. >> Regards, >> Dilhasha >> -- >> Fathima Dilhasha >> *Software Engineer* >> Mobile : +94 (0) 771663314 <%2B94%20%280%29%20773655496> >> <%2B94%20%280%29%20773%20451194> >> [email protected] <[email protected]> >> >> _______________________________________________ >> Dev mailing list >> [email protected] >> http://wso2.org/cgi-bin/mailman/listinfo/dev >> >> > > > -- > Geesara Prathap Kulathunga > Software Engineer > WSO2 Inc; http://wso2.com > Mobile : +940772684174 > >
_______________________________________________ Dev mailing list [email protected] http://wso2.org/cgi-bin/mailman/listinfo/dev
