當前位置: 首頁>>代碼示例>>Java>>正文


Java ClassLoaders類代碼示例

本文整理匯總了Java中org.jboss.forge.furnace.util.ClassLoaders的典型用法代碼示例。如果您正苦於以下問題:Java ClassLoaders類的具體用法?Java ClassLoaders怎麽用?Java ClassLoaders使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ClassLoaders類屬於org.jboss.forge.furnace.util包,在下文中一共展示了ClassLoaders類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: lookup

import org.jboss.forge.furnace.util.ClassLoaders; //導入依賴的package包/類
public <T> T lookup(final Class<T> type)
{
   try
   {
      return ClassLoaders.executeIn(Thread.currentThread().getContextClassLoader(), new Callable<T>()
      {
         @Override
         public T call() throws Exception
         {
            return getPlexusContainer().lookup(type);
         }
      });
   }
   catch (Exception e)
   {
      throw new RuntimeException("Could not look up component of type [" + type.getName() + "]", e);
   }
}
 
開發者ID:forge,項目名稱:furnace,代碼行數:19,代碼來源:PlexusContainer.java

示例2: getServiceRegistry

import org.jboss.forge.furnace.util.ClassLoaders; //導入依賴的package包/類
@Override
public ServiceRegistry getServiceRegistry(Addon addon) throws Exception
{
   URL resource = addon.getClassLoader().getResource("/META-INF/services/" + SERVICE_REGISTRATION_FILE_NAME);
   Set<Class<?>> serviceTypes = new HashSet<Class<?>>();
   if (resource != null)
   {
      InputStream stream = resource.openStream();
      String services = Streams.toString(stream);
      for (String serviceType : services.split("\n"))
      {
         if (ClassLoaders.containsClass(addon.getClassLoader(), serviceType))
         {
            Class<?> type = ClassLoaders.loadClass(addon.getClassLoader(), serviceType);
            serviceTypes.add(type);
         }
      }

   }
   return new ReflectionServiceRegistry(furnace, addon, serviceTypes);
}
 
開發者ID:forge,項目名稱:furnace,代碼行數:22,代碼來源:LocalServices.java

示例3: getExportedInstance

import org.jboss.forge.furnace.util.ClassLoaders; //導入依賴的package包/類
@Override
@SuppressWarnings("unchecked")
public <T> ExportedInstance<T> getExportedInstance(final Class<T> requestedType)
{
   Assert.notNull(requestedType, "Requested Class type may not be null");
   if (!ClassLoaders.ownsClass(addon.getClassLoader(), requestedType))
   {
      log.fine("Class " + requestedType.getName() + " is not present in this addon [" + addon + "]");
   }

   for (Class<?> type : serviceTypes)
   {
      if (requestedType.isAssignableFrom(type))
      {
         return new ReflectionExportedInstance<T>(addon, (Class<T>) type);
      }
   }
   return null;
}
 
開發者ID:forge,項目名稱:furnace,代碼行數:20,代碼來源:ReflectionServiceRegistry.java

示例4: run

import org.jboss.forge.furnace.util.ClassLoaders; //導入依賴的package包/類
@Override
public void run()
{
   try
   {
      ClassLoaders.executeIn(loader, new Callable<Object>()
      {
         @Override
         public Object call() throws Exception
         {
            System.setProperty(FurnaceImpl.TEST_MODE_PROPERTY, "true");

            furnace.setServerMode(true);
            furnace.start(loader);

            SecurityActions.cleanupThreadLocals(thread);
            return null;
         }
      });
   }
   catch (Exception e)
   {
      throw new RuntimeException("Failed to start Furnace container.", e);
   }
}
 
開發者ID:forge,項目名稱:furnace,代碼行數:26,代碼來源:FurnaceDeployableContainer.java

示例5: exceptionNeedsEnhancement

import org.jboss.forge.furnace.util.ClassLoaders; //導入依賴的package包/類
@SuppressWarnings("unchecked")
private boolean exceptionNeedsEnhancement(Exception exception)
{
   final Class<? extends Exception> exceptionType = exception.getClass();
   final Class<? extends Exception> unwrappedExceptionType = (Class<? extends Exception>) Proxies.unwrap(exception)
            .getClass();

   if (Proxies.isPassthroughType(unwrappedExceptionType))
   {
      return false;
   }

   if (unwrappedExceptionType.getClassLoader() != null
            && !exceptionType.getClassLoader().equals(getCallingLoader()))
   {
      if (ClassLoaders.containsClass(getCallingLoader(), exceptionType))
      {
         return false;
      }
   }
   return true;
}
 
開發者ID:forge,項目名稱:furnace,代碼行數:23,代碼來源:ClassLoaderAdapterCallback.java

示例6: run

import org.jboss.forge.furnace.util.ClassLoaders; //導入依賴的package包/類
@Override
public void run()
{
   try
   {
      ClassLoaders.executeIn(loader, new Callable<Object>()
      {
         @Override
         public Object call() throws Exception
         {
            furnace.setServerMode(true);
            furnace.start(loader);

            SecurityActions.cleanupThreadLocals(thread);
            return null;
         }
      });
   }
   catch (Exception e)
   {
      throw new RuntimeException("Failed to start Furnace container.", e);
   }
}
 
開發者ID:koentsje,項目名稱:forge-furnace,代碼行數:24,代碼來源:ForgeDeployableContainer.java

示例7: exceptionNeedsEnhancement

import org.jboss.forge.furnace.util.ClassLoaders; //導入依賴的package包/類
@SuppressWarnings("unchecked")
private boolean exceptionNeedsEnhancement(Exception exception)
{
   Class<? extends Exception> exceptionType = exception.getClass();
   Class<? extends Exception> unwrappedExceptionType =
            (Class<? extends Exception>) Proxies.unwrap(exception).getClass();

   if (Proxies.isPassthroughType(unwrappedExceptionType))
   {
      return false;
   }

   if (unwrappedExceptionType.getClassLoader() != null
            && !exceptionType.getClassLoader().equals(getCallingLoader()))
   {
      if (ClassLoaders.containsClass(getCallingLoader(), exceptionType))
      {
         return false;
      }
   }
   return true;
}
 
開發者ID:koentsje,項目名稱:forge-furnace,代碼行數:23,代碼來源:ClassLoaderAdapterCallback.java

示例8: returnTypeNeedsEnhancement

import org.jboss.forge.furnace.util.ClassLoaders; //導入依賴的package包/類
private boolean returnTypeNeedsEnhancement(Class<?> methodReturnType, Object returnValue,
         Class<?> unwrappedReturnValueType)
{
   if (Proxies.isPassthroughType(unwrappedReturnValueType))
   {
      return false;
   }
   else if (!Object.class.equals(methodReturnType) && Proxies.isPassthroughType(methodReturnType))
   {
      return false;
   }

   if (unwrappedReturnValueType.getClassLoader() != null
            && !unwrappedReturnValueType.getClassLoader().equals(getCallingLoader()))
   {
      if (ClassLoaders.containsClass(getCallingLoader(), unwrappedReturnValueType)
               && ClassLoaders.containsClass(getCallingLoader(), methodReturnType))
      {
         return false;
      }
   }
   return true;
}
 
開發者ID:koentsje,項目名稱:forge-furnace,代碼行數:24,代碼來源:ClassLoaderAdapterCallback.java

示例9: getExportedInstances

import org.jboss.forge.furnace.util.ClassLoaders; //導入依賴的package包/類
@Override
@SuppressWarnings("unchecked")
public <T> Set<ExportedInstance<T>> getExportedInstances(String typeName)
{
   Set<ExportedInstance<T>> result = new HashSet<ExportedInstance<T>>();
   if (ClassLoaders.containsClass(addon.getClassLoader(), typeName))
   {
      Class<T> type = (Class<T>) ClassLoaders.loadClass(addon.getClassLoader(), typeName);
      result.addAll(getExportedInstances(type));
   }
   return result;
}
 
開發者ID:forge,項目名稱:furnace,代碼行數:13,代碼來源:ReflectionServiceRegistry.java

示例10: hasService

import org.jboss.forge.furnace.util.ClassLoaders; //導入依賴的package包/類
@Override
public boolean hasService(String clazz)
{
   if (ClassLoaders.containsClass(addon.getClassLoader(), clazz))
      return hasService(ClassLoaders.loadClass(addon.getClassLoader(), clazz));
   return false;
}
 
開發者ID:forge,項目名稱:furnace,代碼行數:8,代碼來源:ReflectionServiceRegistry.java

示例11: returnTypeNeedsEnhancement

import org.jboss.forge.furnace.util.ClassLoaders; //導入依賴的package包/類
private boolean returnTypeNeedsEnhancement(Method method, Class<?> methodReturnType,
         Class<?> unwrappedReturnValueType)
{

   String key = getReturnTypeNeedsEnhancementCacheKey(methodReturnType, unwrappedReturnValueType);
   Boolean result = returnTypeNeedsEnhancementCache.get(key);

   if (result == null)
   {
      result = true;
      if (Proxies.isPassthroughType(unwrappedReturnValueType))
      {
         result = false;
      }
      else if (!Object.class.equals(methodReturnType) && Proxies.isPassthroughType(methodReturnType))
      {
         result = false;
      }
      else if (unwrappedReturnValueType.getClassLoader() != null
               && !unwrappedReturnValueType.getClassLoader().equals(getCallingLoader()))
      {
         if (ClassLoaders.containsClass(getCallingLoader(), unwrappedReturnValueType)
                  && ClassLoaders.containsClass(getCallingLoader(), methodReturnType))
         {
            result = false;
         }
      }
      returnTypeNeedsEnhancementCache.put(key, result);
   }

   return result;

}
 
開發者ID:forge,項目名稱:furnace,代碼行數:34,代碼來源:ClassLoaderAdapterCallback.java

示例12: getCompatibleClassHierarchy

import org.jboss.forge.furnace.util.ClassLoaders; //導入依賴的package包/類
public static Class<?>[] getCompatibleClassHierarchy(ClassLoader loader, Class<?> origin)
{
   Set<Class<?>> hierarchy = new LinkedHashSet<Class<?>>();

   Class<?> baseClass = origin;

   while (baseClass != null && Modifier.isFinal(baseClass.getModifiers()))
   {
      baseClass = baseClass.getSuperclass();
   }

   while (baseClass != null
            && !baseClass.isInterface()
            && baseClass.getSuperclass() != null
            && !baseClass.getSuperclass().equals(Object.class)
            && !Proxies.isInstantiable(baseClass))
   {
      baseClass = baseClass.getSuperclass();
   }

   if (baseClass != null && ClassLoaders.containsClass(loader, baseClass.getName())
            && !Object.class.equals(baseClass)
            && (Proxies.isInstantiable(baseClass) || baseClass.isInterface()))
   {
      hierarchy.add(ClassLoaders.loadClass(loader, baseClass));
   }

   baseClass = origin;
   while (baseClass != null)
   {
      for (Class<?> type : baseClass.getInterfaces())
      {
         if (ClassLoaders.containsClass(loader, type.getName()))
            hierarchy.add(ClassLoaders.loadClass(loader, type));
         else
            hierarchy.addAll(java.util.Arrays.asList(getCompatibleClassHierarchy(loader, type)));
      }
      baseClass = baseClass.getSuperclass();
   }

   return hierarchy.toArray(new Class<?>[hierarchy.size()]);
}
 
開發者ID:forge,項目名稱:furnace,代碼行數:43,代碼來源:ProxyTypeInspector.java

示例13: enhanceException

import org.jboss.forge.furnace.util.ClassLoaders; //導入依賴的package包/類
private Exception enhanceException(final Method method, final Exception exception)
{
   Exception result = exception;
   try
   {
      if (exception != null)
      {
         final Class<?> unwrappedExceptionType = Proxies.unwrap(exception).getClass();

         ClassLoader exceptionLoader = delegateLoader;
         if (!ClassLoaders.containsClass(delegateLoader, unwrappedExceptionType))
         {
            exceptionLoader = Proxies.unwrapProxyTypes(unwrappedExceptionType, getCallingLoader(), delegateLoader,
                     unwrappedExceptionType.getClassLoader()).getClassLoader();
            if (exceptionLoader == null)
            {
               exceptionLoader = getClass().getClassLoader();
            }
         }

         if (exceptionNeedsEnhancement(exception))
         {
            final Class<?>[] exceptionHierarchy = ProxyTypeInspector.getCompatibleClassHierarchy(getCallingLoader(),
                     Proxies.unwrapProxyTypes(exception.getClass(), getCallingLoader(), delegateLoader,
                              exceptionLoader));

            if (!Modifier.isFinal(unwrappedExceptionType.getModifiers()))
            {
               result = enhance(whitelist, getCallingLoader(), exceptionLoader, method, exception,
                        exceptionHierarchy);
            }
         }
      }
   }
   catch (final Exception e)
   {
      log.log(Level.WARNING,
               "Could not enhance exception for passing through ClassLoader boundary. Exception type ["
                        + exception.getClass().getName() + "], Caller [" + getCallingLoader() + "], Delegate ["
                        + delegateLoader + "]");
      return exception;
   }
   return result;
}
 
開發者ID:forge,項目名稱:furnace,代碼行數:45,代碼來源:ClassLoaderAdapterCallback.java

示例14: run

import org.jboss.forge.furnace.util.ClassLoaders; //導入依賴的package包/類
@Override
public void run()
{
   Thread currentThread = Thread.currentThread();
   String name = currentThread.getName();
   currentThread.setName(addon.getId().toCoordinates());
   try
   {
      logger.fine("> Starting container [" + addon.getId() + "] [" + addon.getRepository().getRootDirectory() + "]");
      long start = System.currentTimeMillis();

      lifecycleProviderEntry = detectLifecycleProvider();
      if (lifecycleProviderEntry != null)
      {
         final AddonLifecycleProvider lifecycleProvider = lifecycleProviderEntry.getProvider();
         ClassLoaders.executeIn(addon.getClassLoader(), new Callable<Void>()
         {
            @Override
            public Void call() throws Exception
            {
               lifecycleProvider.initialize(furnace, furnace.getAddonRegistry(getRepositories()),
                        lifecycleProviderEntry.getAddon());
               lifecycleProvider.start(addon);
               stateManager.setServiceRegistry(addon, lifecycleProvider.getServiceRegistry(addon));
               stateManager.setEventManager(addon, lifecycleProvider.getEventManager(addon));

               firePostStartup(lifecycleProvider);
               return null;
            }

         });
      }

      logger.fine(">> Started container [" + addon.getId() + "] - " + (System.currentTimeMillis() - start) + "ms");

   }
   catch (Throwable e)
   {
      addon.getFuture().cancel(false);
      stateManager.setHandles(addon, new ExceptionFuture<Void>(e), this);

      Level level = Level.FINEST;
      if (!shutdownRequested)
         level = Level.SEVERE;
      logger.log(level, "Failed to start addon [" + addon.getId() + "] with classloader ["
               + stateManager.getClassLoaderOf(addon)
               + "]", e);
   }
   finally
   {
      lifecycleManager.finishedStarting(addon);
      SecurityActions.cleanupThreadLocals(Thread.currentThread());
      currentThread.setName(name);
      currentThread.setContextClassLoader(null);
   }
}
 
開發者ID:forge,項目名稱:furnace,代碼行數:57,代碼來源:AddonRunnable.java

示例15: detectLifecycleProviderDependencies

import org.jboss.forge.furnace.util.ClassLoaders; //導入依賴的package包/類
private AddonLifecycleProviderEntry detectLifecycleProviderDependencies()
{
   List<AddonLifecycleProviderEntry> results = new ArrayList<AddonRunnable.AddonLifecycleProviderEntry>();

   for (AddonDependency addonDependency : addon.getDependencies())
   {
      final Addon dependency = addonDependency.getDependency();
      final ClassLoader classLoader = dependency.getClassLoader();
      try
      {
         AddonLifecycleProviderEntry result = null;

         ServiceLoader<AddonLifecycleProvider> serviceLoader = ServiceLoader.load(
                  AddonLifecycleProvider.class, classLoader);

         Iterator<AddonLifecycleProvider> iterator = serviceLoader.iterator();
         if (serviceLoader != null && iterator.hasNext())
         {
            AddonLifecycleProvider provider = iterator.next();
            if (ClassLoaders.ownsClass(classLoader, provider.getClass()))
            {
               if (ControlType.ALL.equals(provider.getControlType()))
               {
                  result = new AddonLifecycleProviderEntry(dependency, provider);
               }
               else if (ControlType.DEPENDENTS.equals(provider.getControlType()))
               {
                  result = new AddonLifecycleProviderEntry(dependency, provider);
               }

               if (result != null && iterator.hasNext())
               {
                  throw new ContainerException(
                           "Expected only one ["
                                    + AddonLifecycleProvider.class.getName()
                                    + "] but found multiple. Remove all but one redundant container implementations: "
                                    +
                                    Iterators.asList(serviceLoader));
               }
            }
         }

         if (result != null)
            results.add(result);
      }
      catch (Throwable e)
      {
         // FIXME Figure out why ServiceLoader is trying to load things from the wrong ClassLoader
         logger.log(Level.FINEST, "ServiceLoader misbehaved when loading AddonLifecycleProvider instances.", e);
      }
   }

   if (results.size() > 1)
   {
      throw new ContainerException("Expected only one [" + AddonLifecycleProvider.class.getName()
               + "] but found multiple. Remove all but one redundant container implementations: " +
               results);
   }

   return results.isEmpty() ? null : results.get(0);
}
 
開發者ID:forge,項目名稱:furnace,代碼行數:62,代碼來源:AddonRunnable.java


注:本文中的org.jboss.forge.furnace.util.ClassLoaders類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。