Skip to content

Commit

Permalink
fix Jboss7 classloading compatibility in Service loader
Browse files Browse the repository at this point in the history
  • Loading branch information
alexsmirnov authored and Peter Neubauer committed May 11, 2012
1 parent 709fe3f commit d6e50b0
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions kernel/src/main/java/org/neo4j/helpers/Service.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import java.util.NoSuchElementException;
import java.util.Set;

import org.neo4j.helpers.collection.CombiningIterable;
import org.neo4j.helpers.collection.FilteringIterable;
import org.neo4j.helpers.collection.IterableWrapper;
import org.neo4j.helpers.collection.NestingIterable;
Expand Down Expand Up @@ -323,14 +324,23 @@ <T> Iterable<T> load( @SuppressWarnings( "unused" ) Class<T> type )
}
}

private static <T> Iterable<T> java6Loader( Class<T> type )
@SuppressWarnings("unchecked")
private static <T> Iterable<T> java6Loader( Class<T> type )
{
try
{
@SuppressWarnings( "unchecked" ) Iterable<T> result = (Iterable<T>)
Class.forName( "java.util.ServiceLoader" )
Class<?> serviceLoaderClass = Class.forName( "java.util.ServiceLoader" );
Iterable<T> contextClassLoaderServices = (Iterable<T>)
serviceLoaderClass
.getMethod( "load", Class.class )
.invoke( null, type );
// Jboss 7 does not export content of META-INF/services to context class loader,
// so this call adds implementations defined in Neo4j libraries from the same module.
Iterable<T> currentClassLoaderServices = (Iterable<T>)
serviceLoaderClass
.getMethod( "load", Class.class, ClassLoader.class )
.invoke( null, type, Service.class.getClassLoader() );
Iterable<T> result = new CombiningIterable<T>(Arrays.asList(contextClassLoaderServices,currentClassLoaderServices));
return filterExceptions( result );
}
catch ( Exception e )
Expand Down

0 comments on commit d6e50b0

Please sign in to comment.