Package org.jboss.util.loading.ContextClassLoaderSwitcher

Examples of org.jboss.util.loading.ContextClassLoaderSwitcher.SwitchContext


               log.trace("No loader, reset filePath = " + filePath);
               loader = Thread.currentThread().getContextClassLoader();
            }
            log.trace("loader = " + loader);
            byte[] bytes = {};
            SwitchContext tclSwitchContext = null;
            try
            {
               tclSwitchContext = this.tclSwitcher.getSwitchContext(this.getClass().getClassLoader());
               if (loader != null && filePath.endsWith(".class"))
               {
                  // A request for a class file
                  String className = filePath.substring(0, filePath.length() - 6).replace('/', '.');
                  log.trace("loading className = " + className);
                  Class<?> clazz = loader.loadClass(className);
                  URL clazzUrl = clazz.getProtectionDomain().getCodeSource().getLocation();
                  log.trace("clazzUrl = " + clazzUrl);
                  if (clazzUrl == null)
                  {
                     // Does the WebClassLoader of clazz
                     // have the ability to obtain the bytecodes of clazz?
                     bytes = ((WebClassLoader) clazz.getClassLoader()).getBytes(clazz);
                     if (bytes == null)
                        throw new Exception("Class not found: " + className);
                  }
                  else
                  {
                     if (clazzUrl.getFile().endsWith("/") == false)
                     {
                        clazzUrl = new URL("jar:" + clazzUrl + "!/" + filePath);
                     }
                     // this is a hack for the AOP ClassProxyFactory
                     else if (clazzUrl.getFile().indexOf("/org_jboss_aop_proxy$") < 0)
                     {
                        clazzUrl = new URL(clazzUrl, filePath);
                     }
  
                     // Retrieve bytecodes
                     log.trace("new clazzUrl: " + clazzUrl);
                     bytes = getBytes(clazzUrl);
                  }
               }
               else if (loader != null && filePath.length() > 0 && downloadServerClasses && downloadResources)
               {
                  // Try getting resource
                  log.trace("loading resource = " + filePath);
                  URL resourceURL = loader.getResource(filePath);
                  if (resourceURL == null)
                     httpCode = "404 Resource not found:" + filePath;
                  else
                  {
                     // Retrieve bytes
                     log.trace("resourceURL = " + resourceURL);
                     bytes = getBytes(resourceURL);
                  }
               }
               else
               {
                  httpCode = "404 Not Found";
               }
            }
            finally
            {
               if (tclSwitchContext != null)
               {
                  tclSwitchContext.reset();
               }
            }


            // Send bytecodes/resource data in response (assumes HTTP/1.0 or later)
View Full Code Here


        if (buffer == null) {
            return null;
        }

        ByteArrayInputStream bais = new ByteArrayInputStream(buffer);
        SwitchContext context = classLoaderSwitcher.getSwitchContext(this.getClass().getClassLoader());
        try {
            MarshalledValueInputStream mvis = new MarshalledValueInputStream(bais);
            return mvis.readObject();
        } finally {
            context.reset();
        }
    }
View Full Code Here

        }

        ByteArrayInputStream bais = new ByteArrayInputStream(buffer);
        // read past the null/serializable byte
        bais.read();
        SwitchContext context = classLoaderSwitcher.getSwitchContext(this.getClass().getClassLoader());
        try {
            MarshalledValueInputStream mvis = new MarshalledValueInputStream(bais);
            return mvis.readObject();
        } finally {
            context.reset();
        }
    }
View Full Code Here

            String serviceName = ((HAServiceResponse) retval).getServiceName();
            byte[] payload = ((HAServiceResponse) retval).getPayload();

            WeakReference<ClassLoader> weak = CoreGroupCommunicationService.this.clmap.get(serviceName);
            SwitchContext context = CoreGroupCommunicationService.this.classLoaderSwitcher.getSwitchContext((weak != null) ? weak.get() : CoreGroupCommunicationService.class.getClassLoader());
            try {
                retval = CoreGroupCommunicationService.this.objectFromByteBufferResponseInternal(payload);

                return retval;
            } finally {
                context.reset();
            }
        }
View Full Code Here

                return null;
            }

            // If client registered the service with a classloader, override the thread classloader here
            WeakReference<ClassLoader> weak = CoreGroupCommunicationService.this.clmap.get(service);
            SwitchContext context = CoreGroupCommunicationService.this.classLoaderSwitcher.getSwitchContext((weak != null) ? weak.get() : CoreGroupCommunicationService.class.getClassLoader());
            try {
                body = CoreGroupCommunicationService.this.objectFromByteBufferInternal(request_bytes);
            } catch (Exception e) {
                this.log.warn("Partition " + CoreGroupCommunicationService.this.getGroupName()
                        + " failed extracting message body from request bytes", e);
                return null;
            } finally {
                context.reset();
            }

            if (body == null || !(body instanceof MethodCall)) {
                this.log.warn("Partition " + CoreGroupCommunicationService.this.getGroupName()
                        + " message does not contain a MethodCall object!");
View Full Code Here

        }

        @Override
        protected void setStateInternal(InputStream is) throws IOException, ClassNotFoundException {
            ClassLoader cl = getStateTransferClassLoader();
            SwitchContext switchContext = CoreGroupCommunicationService.this.classLoaderSwitcher.getSwitchContext(cl);
            try {
                MarshalledValueInputStream mvis = new MarshalledValueInputStream(is);
                this.state = (Serializable) mvis.readObject();
            } finally {
                switchContext.reset();
            }
        }
View Full Code Here

     * {@inheritDoc}
     * @see org.infinispan.manager.CacheContainer#getCache()
     */
    @Override
    public <K, V> Cache<K, V> getCache() {
        SwitchContext context = this.switcher.getSwitchContext(this.getClass().getClassLoader());
        try {
            return this.container.getCache(this.defaultCache);
        } finally {
            context.reset();
        }
    }
View Full Code Here

     * {@inheritDoc}
     * @see org.infinispan.manager.CacheContainer#getCache(java.lang.String)
     */
    @Override
    public <K, V> Cache<K, V> getCache(String cacheName) {
        SwitchContext context = this.switcher.getSwitchContext(this.getClass().getClassLoader());
        try {
            return this.container.getCache(this.getCacheName(cacheName));
        } finally {
            context.reset();
        }
    }
View Full Code Here

        if (url == null) {
            throw new IllegalStateException(String.format("Failed to locate %s", resource));
        }
        try {
            InputStream input = url.openStream();
            SwitchContext context = this.switcher.getSwitchContext(InfinispanConfiguration.class.getClassLoader());
            try {
                return InfinispanConfiguration.newInfinispanConfiguration(input);
            } finally {
                context.reset();
                try {
                    input.close();
                } catch (IOException e) {
                    log.warn(e.getMessage(), e);
                }
View Full Code Here

        TransactionManager transactionManager = this.transactionManager.getOptionalValue();
        if (transactionManager != null) {
            this.defaultConfiguration.setTransactionManagerLookup(new TransactionManagerProvider(transactionManager));
        }

        SwitchContext switchContext = this.switcher.getSwitchContext(this.getClass().getClassLoader());

        try {
            EmbeddedCacheManager manager = new DefaultCacheManager(this.globalConfiguration, this.defaultConfiguration, false);

            // Add named configurations
            for (Map.Entry<String, Configuration> entry: this.configurations.entrySet()) {
               manager.defineConfiguration(entry.getKey(), entry.getValue());
            }

            this.container = new DefaultCacheContainer(manager, this.defaultCache);
            this.container.start();
        } finally {
            switchContext.reset();
        }
    }
View Full Code Here

TOP

Related Classes of org.jboss.util.loading.ContextClassLoaderSwitcher.SwitchContext

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.