Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2013 Red Hat, Inc. and/or its affiliates.
   *
   * Licensed under the Eclipse Public License version 1.0, available at
   * http://www.eclipse.org/legal/epl-v10.html
   */
  package org.jboss.forge.arquillian.services;
  
 import java.net.URL;
 import java.util.Map;
 import java.util.Set;
 

Author(s):
Lincoln Baxter, III
 
 public class LocalServices implements AddonLifecycleProvider
 {
    private static final String SERVICE_REGISTRATION_FILE_NAME = "org.jboss.forge.furnace.services.Exported";
    private Furnace furnace;
    private static Map<ClassLoaderFurnacestarted = new ConcurrentHashMap<ClassLoaderFurnace>();
 
    @Override
    public void initialize(Furnace furnaceAddonRegistry registryAddon selfthrows Exception
    {
       this. = furnace;
    }
 
    @Override
    public void start(Addon addonthrows Exception
    {
       .put(addon.getClassLoader(), );
    }
 
    @Override
    public void stop(Addon addonthrows Exception
    {
       .remove(addon.getClassLoader());
    }

   
Get a reference to the org.jboss.forge.furnace.Furnace instance from which the given java.lang.ClassLoader was produced. (May be null if the loader was not produced by org.jboss.forge.furnace.Furnace).
 
    public static Furnace getFurnace(ClassLoader loader)
    {
       return .get(loader);
    }

   
Get a reference to the org.jboss.forge.furnace.addons.Addon from which the given java.lang.ClassLoader was produced. (May be null if the java.lang.ClassLoader does not represent a loaded org.jboss.forge.furnace.addons.Addon).
 
    public static Addon getAddon(final ClassLoader loader)
    {
       Furnace furnace = .get(loader);
       Set<Addonaddons = furnace.getAddonRegistry().getAddons(new AddonFilter()
       {
          @Override
          public boolean accept(Addon addon)
          {
             return addon.getClassLoader() == loader;
          }
       });
 
       if (addons.size() > 1)
          throw new IllegalStateException("ClassLoader represents multiple addons; this should never happen.");
 
       if (addons.size() == 1)
          return addons.iterator().next();
 
       return null;
    }
 
    @Override
    public EventManager getEventManager(Addon addon)
    {
       return new LazyServiceRegistryEventManager(addon);
    }
 
    @Override
    public ServiceRegistry getServiceRegistry(Addon addonthrows Exception
   {
      URL resource = addon.getClassLoader().getResource("/META-INF/services/" + );
      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(addonserviceTypes);
   }
   public void postStartup(Addon addonthrows Exception
   {
      getEventManager(addon).fireEvent(new PostStartup(addon));
   }
   public void preShutdown(Addon addonthrows Exception
   {
      getEventManager(addon).fireEvent(new PreShutdown(addon));
   }
   {
      return .;
   }
New to GrepCode? Check out our FAQ X