-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from civitaspo/limit-the-usage-of-ContextClass…
…Loader Limit the usage of swapping ContextClassLoader
- Loading branch information
Showing
6 changed files
with
67 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/main/scala/org/embulk/output/s3_parquet/ContextClassLoaderSwapper.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package org.embulk.output.s3_parquet | ||
|
||
// WARNING: This object should be used for limited purposes only. | ||
object ContextClassLoaderSwapper { | ||
|
||
def using[A](klass: Class[_])(f: => A): A = { | ||
val currentTread = Thread.currentThread() | ||
val original = currentTread.getContextClassLoader | ||
val target = klass.getClassLoader | ||
currentTread.setContextClassLoader(target) | ||
try f | ||
finally currentTread.setContextClassLoader(original) | ||
} | ||
|
||
def usingPluginClass[A](f: => A): A = { | ||
using(classOf[S3ParquetOutputPlugin])(f) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters