Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -312,29 +312,21 @@ private DeploymentInfo quickDeploy(final Archive<?> archive, final TestClass tes
for (final WebModule w : module.getWebModules()) {
final String moduleId = w.getModuleId();
lightweightWebAppBuilder.setClassLoader(moduleId, w.getClassLoader());
cls.add(new Closeable() {
@Override
public void close() throws IOException {
lightweightWebAppBuilder.removeClassLoader(moduleId);
}
});
cls.add(() -> lightweightWebAppBuilder.removeClassLoader(moduleId));
}
}
final AppContext appCtx = assembler.createApplication(appInfo, module.getClassLoader());
if (isEmbeddedWebAppBuilder && PROPERTIES.containsKey(OpenEjbContainer.OPENEJB_EMBEDDED_REMOTABLE) && !appCtx.getWebContexts().isEmpty()) {
cls.add(new Closeable() {
@Override
public void close() throws IOException {
try {
final SessionManager sessionManager = SystemInstance.get().getComponent(SessionManager.class);
if (sessionManager != null) {
for (final WebContext web : appCtx.getWebContexts()) {
sessionManager.destroy(web);
}
cls.add(() -> {
try {
final SessionManager sessionManager = SystemInstance.get().getComponent(SessionManager.class);
if (sessionManager != null) {
for (final WebContext web : appCtx.getWebContexts()) {
sessionManager.destroy(web);
}
} catch (final Throwable e) {
// no-op
}
} catch (final Throwable e) {
// no-op
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,12 @@ private Collection<Resource> findResources(final String path, final String suffi
final Collection<Archive<?>> archives = SWClassLoader.class.cast(loader).getArchives();
final ClassLoader parent = loader.getParent();
for (final Archive<?> archive : archives) {
final Map<ArchivePath, Node> content = archive.getContent(new Filter<ArchivePath>() {
@Override
public boolean include(final ArchivePath object) {
final String currentPath = classloaderPath(object);
final Map<ArchivePath, Node> content = archive.getContent(object -> {
final String currentPath = classloaderPath(object);

return !(parent != null && parent.getResource(currentPath) != null)
&& currentPath.startsWith('/' + path) && currentPath.endsWith(suffix);
return !(parent != null && parent.getResource(currentPath) != null)
&& currentPath.startsWith('/' + path) && currentPath.endsWith(suffix);

}
});

for (final Map.Entry<ArchivePath, Node> entry : content.entrySet()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,25 +89,13 @@ public MultipleContextHandler(final Properties props, final Context initialConte
@Override
public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
Exception err = null;
// then contextual context, this can start an embedded container in some cases
// then existing context
// then try to create a remote context
for (final Callable<Context> callable : Arrays.asList( // order is important to avoid to start an embedded container for some cases
new Callable<Context>() { // then try to create a remote context
@Override
public Context call() throws Exception {
return new InitialContext(properties);
}
},
new Callable<Context>() { // then existing context
@Override
public Context call() throws Exception {
return context;
}
},
new Callable<Context>() { // then contextual context, this can start an embedded container in some cases
@Override
public Context call() throws Exception {
return new InitialContext();
}
}
() -> new InitialContext(properties),
(Callable<Context>) () -> context,
InitialContext::new

)) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -427,12 +427,7 @@ public static Map<File, String> addTomEELibraries(final File libFolder, final St

if (trim.startsWith("remove:")) { // like mvn plugin, needed to use plus but switch something like the jpa provider
final String prefix = trim.substring("remove:".length());
final File[] children = libFolder.listFiles(new FilenameFilter() {
@Override
public boolean accept(final File dir, final String name) {
return name.startsWith(prefix);
}
});
final File[] children = libFolder.listFiles((dir, name) -> name.startsWith(prefix));
if (children != null && children.length > 0) {
for (final File child : children) {
if (!IO.delete(child) && child.getName().endsWith(".jar")) { // try to rename it to have it ignored
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,7 @@ private HashMap<String, byte[]> entries() {
}

private String buildManifest() {
return Join.join("\r\n", new Join.NameCallback<Map.Entry<String, String>>() {
@Override
public String getName(final Map.Entry<String, String> entry) {
return entry.getKey() + ": " + entry.getValue();
}
}, manifest.entrySet());
return Join.join("\r\n", entry -> entry.getKey() + ": " + entry.getValue(), manifest.entrySet());
}

}
24 changes: 8 additions & 16 deletions arquillian/ziplock/src/main/java/org/apache/ziplock/Files.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,7 @@ public static List<File> collect(final File dir, final String regex) {
}

public static List<File> collect(final File dir, final Pattern pattern) {
return collect(dir, new FileFilter() {
@Override
public boolean accept(final File file) {
return pattern.matcher(file.getName()).matches();
}
});
return collect(dir, file -> pattern.matcher(file.getName()).matches());
}


Expand Down Expand Up @@ -126,18 +121,15 @@ public static File mkdir(final File file) {
final ClassLoader loader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(Files.class.getClassLoader());
try {
final Thread deleteShutdownHook = new Thread() {
@Override
public void run() {
for (final String path : delete) {
try {
remove(new File(path));
} catch (final Throwable e) {
System.err.println(e.getMessage());
}
final Thread deleteShutdownHook = new Thread(() -> {
for (final String path : delete) {
try {
remove(new File(path));
} catch (final Throwable e) {
System.err.println(e.getMessage());
}
}
};
});
try {
Runtime.getRuntime().addShutdownHook(deleteShutdownHook);
} catch (final Throwable e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,7 @@ public final class PreloadableTestWar {

static {
final ExecutorService es = Executors.newSingleThreadExecutor();
war = es.submit(new Callable<Archive<?>>() {
@Override
public Archive<?> call() throws Exception {
return Mvn.testWar();
}
});
war = es.submit(Mvn::testWar);
es.shutdown();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,7 @@ public final class PreloadableWar {

static {
final ExecutorService es = Executors.newSingleThreadExecutor();
war = es.submit(new Callable<Archive<?>>() {
@Override
public Archive<?> call() throws Exception {
return Mvn.war();
}
});
war = es.submit(Mvn::war);
es.shutdown();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,7 @@ public static void destroyClassLoader(final String appId, final String appPath)
}

public static ClassLoader getContextClassLoader() {
return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {

@Override
public ClassLoader run() {
return Thread.currentThread().getContextClassLoader();
}
});
return AccessController.doPrivileged((PrivilegedAction<ClassLoader>) () -> Thread.currentThread().getContextClassLoader());
}

public static File getUrlCachedName(final String appId, final URL url) {
Expand Down
28 changes: 11 additions & 17 deletions container/openejb-core/src/main/java/org/apache/openejb/Core.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,20 @@
*/
public class Core {
static {
final Thread preloadMessages = new Thread() {
@Override
public void run() {
new Messages("org.apache.openejb.util.resources");
new Messages("org.apache.openejb.config");
new Messages("org.apache.openejb.config.resources");
}
};
final Thread preloadMessages = new Thread(() -> {
new Messages("org.apache.openejb.util.resources");
new Messages("org.apache.openejb.config");
new Messages("org.apache.openejb.config.resources");
});
preloadMessages.start();

final Thread preloadServiceProviders = new Thread() {
@Override
public void run() {
try {
ServiceUtils.getServiceProviders();
} catch (final OpenEJBException e) {
// no-op
}
final Thread preloadServiceProviders = new Thread(() -> {
try {
ServiceUtils.getServiceProviders();
} catch (final OpenEJBException e) {
// no-op
}
};
});
preloadServiceProviders.start();

final int permits = 2 * Runtime.getRuntime().availableProcessors() + 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,14 +286,11 @@ public EJBContainer createEJBContainer(Map<?, ?> map) {

//Single close
if (isSingleClose()) {
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
if (instance != null) {
instance.doClose();
}
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
if (instance != null) {
instance.doClose();
}
});
}));
}

return openEjbContainer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1856,13 +1856,10 @@ private static List<BeanContext> sort(List<BeanContext> deployments) {
// Sort all the singletons to the back of the list. We want to make sure
// all non-singletons are created first so that if a singleton refers to them
// they are available.
deployments.sort(new Comparator<BeanContext>() {
@Override
public int compare(final BeanContext a, final BeanContext b) {
final int aa = a.getComponentType() == BeanType.SINGLETON ? 1 : 0;
final int bb = b.getComponentType() == BeanType.SINGLETON ? 1 : 0;
return aa - bb;
}
deployments.sort((a, b) -> {
final int aa = a.getComponentType() == BeanType.SINGLETON ? 1 : 0;
final int bb = b.getComponentType() == BeanType.SINGLETON ? 1 : 0;
return aa - bb;
});

// Sort all the beans with references to the back of the list. Beans
Expand All @@ -1882,13 +1879,10 @@ public Set<String> getReferences(final BeanContext t) {
// Now Sort all the MDBs to the back of the list. The Resource Adapter
// may attempt to use the MDB on endpointActivation and the MDB may have
// references to other ejbs that would need to be available first.
deployments.sort(new Comparator<BeanContext>() {
@Override
public int compare(final BeanContext a, final BeanContext b) {
final int aa = a.getComponentType() == BeanType.MESSAGE_DRIVEN ? 1 : 0;
final int bb = b.getComponentType() == BeanType.MESSAGE_DRIVEN ? 1 : 0;
return aa - bb;
}
deployments.sort((a, b) -> {
final int aa = a.getComponentType() == BeanType.MESSAGE_DRIVEN ? 1 : 0;
final int bb = b.getComponentType() == BeanType.MESSAGE_DRIVEN ? 1 : 0;
return aa - bb;
});

return deployments;
Expand Down Expand Up @@ -2048,12 +2042,7 @@ private void destroyResource(final String name, final String className, final Ob
final ExecutorService es = Executors.newSingleThreadExecutor(new DaemonThreadFactory("openejb-resource-destruction-" + name));
final Object o = object;
try {
es.submit(new Runnable() {
@Override
public void run() {
doResourceDestruction(name, className, o);
}
}).get(d.getTime(), d.getUnit());
es.submit(() -> doResourceDestruction(name, className, o)).get(d.getTime(), d.getUnit());
} catch (final InterruptedException e) {
Thread.interrupted();
} catch (final ExecutionException e) {
Expand Down Expand Up @@ -3055,24 +3044,21 @@ private boolean usesCdiPwdCipher(final ResourceInfo serviceInfo) {
}

private LazyResource newLazyResource(final Collection<ServiceInfo> infos, final ResourceInfo serviceInfo) {
return new LazyResource(new Callable<Object>() {
@Override
public Object call() throws Exception {
final boolean appClassLoader = "true".equals(serviceInfo.properties.remove("UseAppClassLoader"))
|| serviceInfo.originAppName != null;
return new LazyResource(() -> {
final boolean appClassLoader = "true".equals(serviceInfo.properties.remove("UseAppClassLoader"))
|| serviceInfo.originAppName != null;

final Thread thread = Thread.currentThread();
final ClassLoader old = thread.getContextClassLoader();
if (!appClassLoader) {
final ClassLoader classLoader = Assembler.class.getClassLoader();
thread.setContextClassLoader(classLoader == null ? ClassLoader.getSystemClassLoader() : classLoader);
} // else contextually we should have the app loader
final Thread thread = Thread.currentThread();
final ClassLoader old = thread.getContextClassLoader();
if (!appClassLoader) {
final ClassLoader classLoader = Assembler.class.getClassLoader();
thread.setContextClassLoader(classLoader == null ? ClassLoader.getSystemClassLoader() : classLoader);
} // else contextually we should have the app loader

try {
return doCreateResource(infos, serviceInfo);
} finally {
thread.setContextClassLoader(old);
}
try {
return doCreateResource(infos, serviceInfo);
} finally {
thread.setContextClassLoader(old);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,7 @@ public class CdiAppContextsService extends WebContextsService implements Context

private static final Logger logger = Logger.getInstance(LogCategory.OPENEJB.createChild("cdi"), CdiAppContextsService.class);

private static final ThreadLocal<Collection<Runnable>> endRequestRunnables = new ThreadLocal<Collection<Runnable>>() {
@Override
protected Collection<Runnable> initialValue() {
return new ArrayList<>();
}
};
private static final ThreadLocal<Collection<Runnable>> endRequestRunnables = ThreadLocal.withInitial(ArrayList::new);


public CdiAppContextsService(final WebBeansContext wbc) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,14 +263,11 @@ public Object getSessionBeanProxy(final Bean<?> inBean, final Class<?> interfce,
}

try {
instance = ProxyManager.newProxyInstance(interfaces.toArray(new Class<?>[interfaces.size()]), new InvocationHandler() {
@Override
public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
try {
return method.invoke(provider.get(), args);
} catch (final InvocationTargetException ite) {
throw ite.getCause();
}
instance = ProxyManager.newProxyInstance(interfaces.toArray(new Class<?>[interfaces.size()]), (proxy, method, args) -> {
try {
return method.invoke(provider.get(), args);
} catch (final InvocationTargetException ite) {
throw ite.getCause();
}
});
} catch (final IllegalAccessException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,7 @@ private static void addJarsToPath(final BasicURLClassPath.CustomizableURLClassLo
return;
}

final File[] jarFiles = folder.listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return name.endsWith(".jar");
}
});
final File[] jarFiles = folder.listFiles((dir, name) -> name.endsWith(".jar"));

for (final File jarFile : jarFiles) {
classLoader.add(jarFile.toURI().toURL());
Expand Down
Loading