Package org.wso2.carbon.context

Examples of org.wso2.carbon.context.PrivilegedCarbonContext


          expectedExceptions = {javax.cache.CacheException.class},
          description = "")
    public void testCreateExistingCache() {
        try {
            PrivilegedCarbonContext.startTenantFlow();
            PrivilegedCarbonContext cc = PrivilegedCarbonContext.getThreadLocalCarbonContext();
            cc.setTenantDomain("apple.com");
            cc.setTenantId(1);
            CacheManager cacheManager = Caching.getCacheManagerFactory().getCacheManager("test");
            String cacheName = "testCreateExistingCache";
            cacheManager.<String, Integer>createCacheBuilder(cacheName).
                    setExpiry(CacheConfiguration.ExpiryType.MODIFIED,
                              new CacheConfiguration.Duration(TimeUnit.SECONDS, 10)).
View Full Code Here


    @Test(groups = {"org.wso2.carbon.clustering.hazelcast.jsr107.mt"},
          description = "")
    public void testCacheLoaderForTenants() {
        try {
            PrivilegedCarbonContext.startTenantFlow();
            PrivilegedCarbonContext cc = PrivilegedCarbonContext.getThreadLocalCarbonContext();
            cc.setTenantDomain("bikes.com");
            cc.setTenantId(1);
            CacheManager cacheManager = Caching.getCacheManagerFactory().getCacheManager("test");
            String cacheName = "testCacheLoaderForTenants";
            Cache<String, String> cache =
                    cacheManager.<String, String>createCacheBuilder(cacheName).
                            setCacheLoader(new TestCacheLoader<String, String>()).build();
View Full Code Here

        @Override
        public V call() throws Exception {
            Entry<K, ? extends V> entry;
            try {
                PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
                carbonContext.setTenantDomain(tenantDomain);
                carbonContext.setTenantId(tenantId);
                entry = cacheLoader.load(key);
                cache.put(entry.getKey(), entry.getValue());
            } catch (Exception e) {
                log.error("Could not load cache item with key " + key + " into cache " +
                          cache.getName() + " owned by tenant ", e);
View Full Code Here

        @Override
        public Map<K, ? extends V> call() throws Exception {
            Map<K, ? extends V> value;
            try {
                PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
                carbonContext.setTenantDomain(tenantDomain);
                carbonContext.setTenantId(tenantId);
                ArrayList<K> keysNotInStore = new ArrayList<K>();
                for (K key : keys) {
                    if (!cache.containsKey(key)) {
                        keysNotInStore.add(key);
                    }
View Full Code Here

        // Get all the caches
        // Get the configurations from the caches
        // Check the timeout policy and clear out old values
        try {
            PrivilegedCarbonContext.startTenantFlow();
            PrivilegedCarbonContext cc = PrivilegedCarbonContext.getThreadLocalCarbonContext();
            cc.setTenantId(MultitenantConstants.SUPER_TENANT_ID);
            cc.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
            for (CacheImpl cache : caches) {
                cache.runCacheExpiry();
            }
        } catch (Throwable e) {
            log.error("Error occurred while running CacheCleanupTask", e);
View Full Code Here

public class ThrottlingJob implements Job {
    private static final Log log = LogFactory.getLog(ThrottlingJob.class);
    public static final String THROTTLING_TASK_CONTEXT_KEY = "throttlingTask";

    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
        carbonContext.setTenantId(MultitenantConstants.SUPER_TENANT_ID);
        Task task = (Task) jobExecutionContext.getMergedJobDataMap().get(THROTTLING_TASK_CONTEXT_KEY);
        executeTask(task);
    }
View Full Code Here

        return PrivilegedCarbonContext.getCurrentContext(messageContext).getTenantDomain();
    }

    private int getTenantId(MessageContext messageContext) {
        //Ideally this should take from thread local carbon context change this temporary
        PrivilegedCarbonContext carbonContext =
                PrivilegedCarbonContext.getCurrentContext(messageContext);
        int tenantId = carbonContext.getTenantId();
        if (tenantId > -1 || tenantId == MultitenantConstants.SUPER_TENANT_ID) {
            return tenantId;
        }
        String domain = carbonContext.getTenantDomain();
        if (domain == null) {
            SOAPBody soapBody = messageContext.getEnvelope().getBody();
            if (soapBody != null && soapBody.getFirstElement() != null) {
                OMElement usernameElem = soapBody.getFirstElement().getFirstChildWithName(
                        new QName(ServerConstants.AUTHENTICATION_SERVICE_NS,
View Full Code Here

     * @param dataObj object to be persisted.
     */
    public synchronized void persist(FasterLookUpDataHolder dataObj) throws RegistryException {
        try {
         
          PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
          ctx.setTenantId(MultitenantConstants.SUPER_TENANT_ID);
          ctx.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
         
            registryService.beginTransaction();

            Resource nodeResource = registryService.newResource();

View Full Code Here

    }

    public synchronized void persistTopology(Topology topology) throws RegistryException {
        try {
         
          PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
          ctx.setTenantId(MultitenantConstants.SUPER_TENANT_ID);
          ctx.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
         
            registryService.beginTransaction();

            Resource nodeResource = registryService.newResource();
View Full Code Here


    public synchronized Object retrieve() {

        try {
          PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
          ctx.setTenantId(MultitenantConstants.SUPER_TENANT_ID);
          ctx.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
            Resource resource = registryService.get(
                CloudControllerConstants.CLOUD_CONTROLLER_RESOURCE + CloudControllerConstants.DATA_RESOURCE);

            return resource.getContent();
View Full Code Here

TOP

Related Classes of org.wso2.carbon.context.PrivilegedCarbonContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.