Updated implementation of internal RPC Router for Binding-Aware Broker and added...
[controller.git] / opendaylight / md-sal / sal-binding-broker / src / main / java / org / opendaylight / controller / sal / binding / impl / osgi / ClassLoaderUtils.java
1 package org.opendaylight.controller.sal.binding.impl.osgi;
2
3
4
5 import java.util.concurrent.Callable;
6 import static com.google.common.base.Preconditions.*;
7
8 public class ClassLoaderUtils {
9     
10     public static <V> V withClassLoader(ClassLoader cls,Callable<V> function) throws Exception {
11         checkNotNull(cls);
12         checkNotNull(function);
13         ClassLoader oldCls = Thread.currentThread().getContextClassLoader();
14         try {
15             Thread.currentThread().setContextClassLoader(cls);
16             V result = function.call();
17             Thread.currentThread().setContextClassLoader(oldCls);
18             return result;
19         } catch (Exception e) {
20             Thread.currentThread().setContextClassLoader(oldCls);
21             throw new Exception(e);
22         }
23     }
24 }