コード例 #1
0
ファイル: TaskContext.java プロジェクト: Jedmond/orbit
 /**
  * Wraps a BiConsumer in such a way the it will push the current execution context before any code
  * gets executed and pop it afterwards
  *
  * @param w the functional interface to be wrapped
  * @return wrapped object if there is a current execution context, or the same object if not.
  */
 public static <T, U> BiConsumer<T, U> wrap(BiConsumer<T, U> w) {
   TaskContext c = current();
   if (c != null) {
     return (t, u) -> {
       c.push();
       try {
         w.accept(t, u);
       } finally {
         c.pop();
       }
     };
   }
   return w;
 }
コード例 #2
0
ファイル: TaskContext.java プロジェクト: Jedmond/orbit
 /**
  * Wraps a Supplier in such a way the it will push the current execution context before any code
  * gets executed and pop it afterwards
  *
  * @param w the functional interface to be wrapped
  * @return wrapped object if there is a current execution context, or the same object if not.
  */
 public static <T> Supplier<T> wrap(Supplier<T> w) {
   TaskContext c = current();
   if (c != null) {
     return () -> {
       c.push();
       try {
         return w.get();
       } finally {
         c.pop();
       }
     };
   }
   return w;
 }
コード例 #3
0
ファイル: TaskContext.java プロジェクト: Jedmond/orbit
 /**
  * Wraps a Runnable in such a way the it will push the current execution context before any code
  * gets executed and pop it afterwards
  *
  * @param w the functional interface to be wrapped
  * @return wrapped object if there is a current execution context, or the same object if not.
  */
 public static Runnable wrap(Runnable w) {
   TaskContext c = current();
   if (c != null) {
     return () -> {
       c.push();
       try {
         w.run();
       } finally {
         c.pop();
       }
     };
   }
   return w;
 }
コード例 #4
0
ファイル: TaskContext.java プロジェクト: Jedmond/orbit
 /**
  * Wraps a Function in such a way the it will push the current execution context before any code
  * gets executed and pop it afterwards
  *
  * @param w the functional interface to be wrapped
  * @return wrapped object if there is a current execution context, or the same object if not.
  */
 public static <T, U, R> BiFunction<T, U, R> wrap(BiFunction<T, U, R> w) {
   TaskContext c = current();
   if (c != null) {
     return (t, u) -> {
       c.push();
       try {
         return w.apply(t, u);
       } finally {
         c.pop();
       }
     };
   }
   return w;
 }