X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fnetconf%2Fnetconf-netty-util%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Fnettyutil%2Fhandler%2FNetconfEXICodec.java;fp=opendaylight%2Fnetconf%2Fnetconf-netty-util%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Fnettyutil%2Fhandler%2FNetconfEXICodec.java;h=16da7a7f9dcf3eabb7fee06e8c3201fce1c41155;hp=8f67da670a9231369cc8914dfb490b02428d88a5;hb=dcf48864ca54fe1b27d44de10e0bcb6e241cc5c4;hpb=9333dcc739a7bf89a2e78886c7dd43fef1c09b8b diff --git a/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/NetconfEXICodec.java b/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/NetconfEXICodec.java index 8f67da670a..16da7a7f9d 100644 --- a/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/NetconfEXICodec.java +++ b/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/NetconfEXICodec.java @@ -1,6 +1,9 @@ package org.opendaylight.controller.netconf.nettyutil.handler; import com.google.common.base.Preconditions; +import com.google.common.cache.CacheBuilder; +import com.google.common.cache.CacheLoader; +import com.google.common.cache.LoadingCache; import org.openexi.proc.HeaderOptionsOutputType; import org.openexi.proc.common.EXIOptions; import org.openexi.proc.common.EXIOptionsException; @@ -30,6 +33,17 @@ public final class NetconfEXICodec { } }; + /** + * Since we have a limited number of options we can have, instantiating a weak cache + * will allow us to reuse instances where possible. + */ + private static final LoadingCache GRAMMAR_CACHES = CacheBuilder.newBuilder().weakValues().build(new CacheLoader() { + @Override + public GrammarCache load(final Short key) { + return new GrammarCache(key); + } + }); + /** * Grammar cache acts as a template and is duplicated by the Transmogrifier and the Reader * before use. It is safe to reuse a single instance. @@ -57,7 +71,7 @@ public final class NetconfEXICodec { go = GrammarOptions.addPI(go); } - return new GrammarCache(go); + return GRAMMAR_CACHES.getUnchecked(go); } EXIReader getReader() throws EXIOptionsException {