I see, the utility methods can be called from an arbitrary nested level though, so parsing in the CarbonContext is not always possible .. for example .. Deployer -> Initializing a Data Service -> Init. A Data Source -> Lookup a Registry Resource -> Lookup Tenant Registry. It will be ugly in that case to always parse a CarbonContext throughout all the classes/methods being used. Anyways for data services use case it seems I'll always get the requirement to get the tenant id etc.. in the deployment, and not in any other places, so it wont be a problem. And yeah, if I need it in any other message processing path in the future, I can use the other approach.
Cheers, Anjana. On Sat, Sep 22, 2012 at 12:24 AM, Afkham Azeez <[email protected]> wrote: > *PrivilegedCarbonContext.getThreadLocalCarbonContext() *performs better. > This is because, PrivilegedCarbonContext.getContext() will first try to get > the data from Axis2 MessageContext, failing which it will try > ConfigurationContext & AxisConfiguration, and only finally try to get the > data from the ThreadLocal variable. So, in cases like the deployers where > you can be sure that the deployment scheduler thread would set the > ThreadLocal data, you should directly call the getThreadLocalCarbonContext > method. > > Generally, you should have an idea of what thread you are executing under. > So in the case of util methods, it is better to resolve the CarbonContext > outside that util method. In order to be able to properly retrieve a CC, > anyway the relevant data should be available somewhere (ThreadLocal, > AxisConfig, ConfigContext, MessageContext etc) so generally. If calling > CarbonContext.getCurrentContext returns a CC with tenant ID = -1 or tenant > domain = null, that means, some up stream code had not populated the data > needed for the CC, so you have to first look into fixing that issue. > > Azeez > > On Fri, Sep 21, 2012 at 10:43 PM, Anjana Fernando <[email protected]> wrote: > >> *PrivilegedCarbonContext.getThreadLocalCarbonContext()* > > > > > -- > *Afkham Azeez* > Director of Architecture; WSO2, Inc.; http://wso2.com > Member; Apache Software Foundation; http://www.apache.org/ > * <http://www.apache.org/>** > email: **[email protected]* <[email protected]>* cell: +94 77 3320919 > blog: **http://blog.afkham.org* <http://blog.afkham.org>* > twitter: **http://twitter.com/afkham_azeez*<http://twitter.com/afkham_azeez> > * > linked-in: **http://lk.linkedin.com/in/afkhamazeez* > * > * > *Lean . Enterprise . Middleware* > > -- *Anjana Fernando* Associate Technical Lead WSO2 Inc. | http://wso2.com lean . enterprise . middleware
_______________________________________________ Dev mailing list [email protected] http://wso2.org/cgi-bin/mailman/listinfo/dev
