Repository: incubator-reef Updated Branches: refs/heads/master 9b4b167d2 -> de9ff3b1b
[REEF-328] Lazily load the CLR ClassHierarchy JIRA: [REEF-328](https://issues.apache.org/jira/browse/REEF-328) This Closes #184 Author: Markus Weimer <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/incubator-reef/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-reef/commit/de9ff3b1 Tree: http://git-wip-us.apache.org/repos/asf/incubator-reef/tree/de9ff3b1 Diff: http://git-wip-us.apache.org/repos/asf/incubator-reef/diff/de9ff3b1 Branch: refs/heads/master Commit: de9ff3b1bc37b31a50bae1f271f414406e814b9a Parents: 9b4b167 Author: Markus Weimer <[email protected]> Authored: Thu May 14 16:01:17 2015 -0700 Committer: Julia Wang <[email protected]> Committed: Thu May 14 19:10:18 2015 -0700 ---------------------------------------------------------------------- .../javabridge/ActiveContextBridgeFactory.java | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/de9ff3b1/lang/java/reef-bridge-java/src/main/java/org/apache/reef/javabridge/ActiveContextBridgeFactory.java ---------------------------------------------------------------------- diff --git a/lang/java/reef-bridge-java/src/main/java/org/apache/reef/javabridge/ActiveContextBridgeFactory.java b/lang/java/reef-bridge-java/src/main/java/org/apache/reef/javabridge/ActiveContextBridgeFactory.java index bce91cc..77a06d7 100644 --- a/lang/java/reef-bridge-java/src/main/java/org/apache/reef/javabridge/ActiveContextBridgeFactory.java +++ b/lang/java/reef-bridge-java/src/main/java/org/apache/reef/javabridge/ActiveContextBridgeFactory.java @@ -18,6 +18,7 @@ */ package org.apache.reef.javabridge; +import net.jcip.annotations.GuardedBy; import net.jcip.annotations.ThreadSafe; import org.apache.reef.annotations.audience.DriverSide; import org.apache.reef.annotations.audience.Private; @@ -26,7 +27,6 @@ import org.apache.reef.tang.ClassHierarchy; import org.apache.reef.tang.formats.AvroConfigurationSerializer; import javax.inject.Inject; -import java.util.logging.Logger; /** * Factory for ActiveContextBridge instances. @@ -35,7 +35,8 @@ import java.util.logging.Logger; @ThreadSafe @Private public final class ActiveContextBridgeFactory { - private final ClassHierarchy clrClassHierarchy; + @GuardedBy("this") + private ClassHierarchy clrClassHierarchy; private final AvroConfigurationSerializer configurationSerializer; /** @@ -46,7 +47,6 @@ public final class ActiveContextBridgeFactory { @Inject private ActiveContextBridgeFactory(final AvroConfigurationSerializer configurationSerializer) { this.configurationSerializer = configurationSerializer; - this.clrClassHierarchy = Utilities.loadClassHierarchy(NativeInterop.CLASS_HIERARCHY_FILENAME); } /** @@ -56,6 +56,18 @@ public final class ActiveContextBridgeFactory { * @return a new ActiveContextBridge. */ public ActiveContextBridge getActiveContextBridge(final ActiveContext context) { - return new ActiveContextBridge(context, this.clrClassHierarchy, this.configurationSerializer); + return new ActiveContextBridge(context, this.getClrClassHierarchy(), this.configurationSerializer); + } + + /** + * Returns the clr ClassHierarchy. Loads it if needed. + * + * @return the clr ClassHierarchy. + */ + private synchronized ClassHierarchy getClrClassHierarchy() { + if (null == this.clrClassHierarchy) { + this.clrClassHierarchy = Utilities.loadClassHierarchy(NativeInterop.CLASS_HIERARCHY_FILENAME); + } + return this.clrClassHierarchy; } }
