diff options
Diffstat (limited to 'jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/util/ThreadClassLoaderScope.java')
-rw-r--r-- | jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/util/ThreadClassLoaderScope.java | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/util/ThreadClassLoaderScope.java b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/util/ThreadClassLoaderScope.java new file mode 100644 index 0000000000..5322583333 --- /dev/null +++ b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/util/ThreadClassLoaderScope.java @@ -0,0 +1,45 @@ +// +// ======================================================================== +// Copyright (c) 1995-2015 Mort Bay Consulting Pty. Ltd. +// ------------------------------------------------------------------------ +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the Eclipse Public License v1.0 +// and Apache License v2.0 which accompanies this distribution. +// +// The Eclipse Public License is available at +// http://www.eclipse.org/legal/epl-v10.html +// +// The Apache License v2.0 is available at +// http://www.opensource.org/licenses/apache2.0.php +// +// You may elect to redistribute this code under either of these licenses. +// ======================================================================== +// + +package org.eclipse.jetty.websocket.common.util; + +import java.io.Closeable; + +public class ThreadClassLoaderScope implements Closeable +{ + private final ClassLoader old; + private final ClassLoader scopedClassLoader; + + public ThreadClassLoaderScope(ClassLoader cl) + { + old = Thread.currentThread().getContextClassLoader(); + scopedClassLoader = cl; + Thread.currentThread().setContextClassLoader(scopedClassLoader); + } + + @Override + public void close() + { + Thread.currentThread().setContextClassLoader(old); + } + + public ClassLoader getScopedClassLoader() + { + return scopedClassLoader; + } +} |