diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2017-01-10 23:46:09 +0100 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2017-01-10 23:46:35 +0100 |
commit | 8d075ce39d71ed881969e1a2cf00abe7f5b546b7 (patch) | |
tree | cb38e0047ba79d58690266b9519d92dab6b85a9d /component/src | |
parent | 697fa08ac031476eee46f7b9cc8b902617ad2371 (diff) |
Use a method cache in front of the "deconstruct" method lookup
Diffstat (limited to 'component/src')
-rw-r--r-- | component/src/main/java/com/yahoo/component/AbstractComponent.java | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/component/src/main/java/com/yahoo/component/AbstractComponent.java b/component/src/main/java/com/yahoo/component/AbstractComponent.java index 2fe11425d20..7e4eb665278 100644 --- a/component/src/main/java/com/yahoo/component/AbstractComponent.java +++ b/component/src/main/java/com/yahoo/component/AbstractComponent.java @@ -1,6 +1,8 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.component; +import com.yahoo.collections.MethodCache; + import java.lang.reflect.Method; /** @@ -11,6 +13,8 @@ import java.lang.reflect.Method; */ public class AbstractComponent implements Component { + static final MethodCache deconstructMethods = new MethodCache("deconstruct"); + // All accesses to id MUST go through getId. private ComponentId id; @@ -129,16 +133,12 @@ public class AbstractComponent implements Component { } protected boolean setIsDeconstructable() { - try { - Method deconstruct = getClass().getMethod("deconstruct"); - @SuppressWarnings("rawtypes") - Class declaringClass = deconstruct.getDeclaringClass(); - if (declaringClass != AbstractComponent.class) { - return true; - } - } catch (NoSuchMethodException e) { + Method deconstruct = deconstructMethods.get(this); + if (deconstruct == null) { com.yahoo.protect.Process.logAndDie("Component " + this + " does not have method deconstruct() - impossible!"); } - return false; + @SuppressWarnings("rawtypes") + Class declaringClass = deconstruct.getDeclaringClass(); + return (declaringClass != AbstractComponent.class); } } |