summaryrefslogtreecommitdiffstats
path: root/container-core/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'container-core/src/main/java')
-rw-r--r--container-core/src/main/java/com/yahoo/processing/Request.java4
-rw-r--r--container-core/src/main/java/com/yahoo/processing/Response.java2
-rw-r--r--container-core/src/main/java/com/yahoo/processing/handler/AbstractProcessingHandler.java9
-rw-r--r--container-core/src/main/java/com/yahoo/processing/request/CompoundName.java56
4 files changed, 44 insertions, 27 deletions
diff --git a/container-core/src/main/java/com/yahoo/processing/Request.java b/container-core/src/main/java/com/yahoo/processing/Request.java
index cff546f1fd4..313df855cd4 100644
--- a/container-core/src/main/java/com/yahoo/processing/Request.java
+++ b/container-core/src/main/java/com/yahoo/processing/Request.java
@@ -30,13 +30,13 @@ public class Request extends FreezableClass implements Cloneable {
* The name of the chain of Processor instances which will be invoked when
* executing a request.
*/
- public static final CompoundName CHAIN = new CompoundName("chain");
+ public static final CompoundName CHAIN = CompoundName.from("chain");
/**
* The name of the request property used in the processing framework to
* store the incoming JDisc request.
*/
- public static final CompoundName JDISC_REQUEST = new CompoundName("jdisc.request");
+ public static final CompoundName JDISC_REQUEST = CompoundName.from("jdisc.request");
/**
* Creates a request with no properties
diff --git a/container-core/src/main/java/com/yahoo/processing/Response.java b/container-core/src/main/java/com/yahoo/processing/Response.java
index 59533900a0c..9f87f42ba65 100644
--- a/container-core/src/main/java/com/yahoo/processing/Response.java
+++ b/container-core/src/main/java/com/yahoo/processing/Response.java
@@ -35,7 +35,7 @@ import java.util.concurrent.TimeoutException;
*/
public class Response extends ListenableFreezableClass {
- private final static CompoundName freezeListenerKey =new CompoundName("processing.freezeListener");
+ private final static CompoundName freezeListenerKey = CompoundName.from("processing.freezeListener");
private final DataList<?> data;
diff --git a/container-core/src/main/java/com/yahoo/processing/handler/AbstractProcessingHandler.java b/container-core/src/main/java/com/yahoo/processing/handler/AbstractProcessingHandler.java
index f7aea8abbd1..837f356d4d9 100644
--- a/container-core/src/main/java/com/yahoo/processing/handler/AbstractProcessingHandler.java
+++ b/container-core/src/main/java/com/yahoo/processing/handler/AbstractProcessingHandler.java
@@ -46,7 +46,7 @@ import static com.yahoo.component.chain.ChainsConfigurer.prepareChainRegistry;
@SuppressWarnings("deprecation") // super class is deprecated
public abstract class AbstractProcessingHandler<COMPONENT extends Processor> extends LoggingRequestHandler {
- private final static CompoundName freezeListenerKey =new CompoundName("processing.freezeListener");
+ private final static CompoundName freezeListenerKey = CompoundName.from("processing.freezeListener");
public final static String DEFAULT_RENDERER_ID = "default";
@@ -112,7 +112,7 @@ public abstract class AbstractProcessingHandler<COMPONENT extends Processor> ext
public HttpResponse handle(HttpRequest request, ContentChannel channel) {
com.yahoo.processing.Request processingRequest = new com.yahoo.processing.Request();
populate("", request.propertyMap(), processingRequest.properties());
- populate("context", request.getJDiscRequest().context(), processingRequest.properties());
+ populate("context.", request.getJDiscRequest().context(), processingRequest.properties());
processingRequest.properties().set(Request.JDISC_REQUEST, request);
FreezeListener freezeListener = new FreezeListener(processingRequest, renderers, defaultRenderer, channel, renderingExecutor);
@@ -183,10 +183,9 @@ public abstract class AbstractProcessingHandler<COMPONENT extends Processor> ext
return properties.getString(Request.CHAIN,"default");
}
- private void populate(String prefixName,Map<String,?> parameters,Properties properties) {
- CompoundName prefix = new CompoundName(prefixName);
+ private void populate(String prefixName, Map<String,?> parameters,Properties properties) {
for (Map.Entry<String,?> entry : parameters.entrySet())
- properties.set(prefix.append(entry.getKey()), entry.getValue());
+ properties.set(CompoundName.from(prefixName + entry.getKey()), entry.getValue());
}
private static class FreezeListener implements Runnable, ResponseReceiver {
diff --git a/container-core/src/main/java/com/yahoo/processing/request/CompoundName.java b/container-core/src/main/java/com/yahoo/processing/request/CompoundName.java
index ac7b3d24d08..0edff9162b5 100644
--- a/container-core/src/main/java/com/yahoo/processing/request/CompoundName.java
+++ b/container-core/src/main/java/com/yahoo/processing/request/CompoundName.java
@@ -21,9 +21,12 @@ import static com.yahoo.text.Lowercase.toLowerCase;
*/
public final class CompoundName {
- /**
- * The string name of this compound.
- */
+ private static final int MAX_CACHE_SIZE = 10_000;
+ private static final Map<String, CompoundName> cache = new CopyOnWriteHashMap<>();
+ /** The empty compound */
+ public static final CompoundName empty = CompoundName.from("");
+
+ /* The string name of this compound. */
private final String name;
private final String lowerCasedName;
@@ -37,17 +40,16 @@ public final class CompoundName {
/** This name with the last component removed */
private final CompoundName first;
- /** The empty compound */
- public static final CompoundName empty = new CompoundName("");
- private static final Map<String, CompoundName> cache = new CopyOnWriteHashMap<>();
- private static final int MAX_CACHE_SIZE = 10_000;
/**
* Constructs this from a string which may contains dot-separated components
*
* @throws NullPointerException if name is null
*/
public CompoundName(String name) {
- this(name, parse(name).toArray(new String[1]));
+ this(name, false);
+ }
+ private CompoundName(String name, boolean useCache) {
+ this(name, parse(name).toArray(new String[0]), useCache);
}
/** Constructs this from an array of name components which are assumed not to contain dots */
@@ -61,7 +63,7 @@ public final class CompoundName {
}
private CompoundName(String [] compounds) {
- this(toCompoundString(compounds), compounds);
+ this(toCompoundString(compounds), compounds, false);
}
/**
@@ -71,7 +73,7 @@ public final class CompoundName {
* @param name the string representation of the compounds
* @param compounds the compounds of this name
*/
- private CompoundName(String name, String [] compounds) {
+ private CompoundName(String name, String [] compounds, boolean useCache) {
if (name == null) throw new NullPointerException("Name can not be null");
this.name = name;
@@ -86,12 +88,27 @@ public final class CompoundName {
this.compounds = new ImmutableArrayList(compounds);
this.hashCode = this.compounds.hashCode();
- rest = (compounds.length > 1)
- ? new CompoundName(name.substring(compounds[0].length()+1), Arrays.copyOfRange(compounds, 1, compounds.length))
- : empty;
- first = (compounds.length > 1)
- ? new CompoundName(name.substring(0, name.length() - (compounds[compounds.length-1].length()+1)), Arrays.copyOfRange(compounds, 0, compounds.length-1))
- : empty;
+ if (compounds.length > 1) {
+ String restName = name.substring(compounds[0].length()+1);
+ if (useCache) {
+ rest = cache.computeIfAbsent(restName, (key) -> new CompoundName(key, Arrays.copyOfRange(compounds, 1, compounds.length), useCache));
+ } else {
+ rest = new CompoundName(restName, Arrays.copyOfRange(compounds, 1, compounds.length), useCache);
+ }
+ } else {
+ rest = empty;
+ }
+
+ if (compounds.length > 1) {
+ String firstName = name.substring(0, name.length() - (compounds[compounds.length-1].length()+1));
+ if (useCache) {
+ first = cache.computeIfAbsent(firstName, (key) -> new CompoundName(key, Arrays.copyOfRange(compounds, 0, compounds.length-1), useCache));
+ } else {
+ first = new CompoundName(firstName, Arrays.copyOfRange(compounds, 0, compounds.length-1), useCache);
+ }
+ } else {
+ first = empty;
+ }
}
private static List<String> parse(String s) {
@@ -138,7 +155,7 @@ public final class CompoundName {
int count = 0;
for (String s : compounds) { newCompounds[count++] = s; }
for (String s : name.compounds) { newCompounds[count++] = s; }
- return new CompoundName(concat(this.name, name.name), newCompounds);
+ return new CompoundName(concat(this.name, name.name), newCompounds, false);
}
private static String concat(String name1, String name2) {
@@ -310,11 +327,12 @@ public final class CompoundName {
CompoundName found = cache.get(name);
if (found != null) return found;
- CompoundName compound = new CompoundName(name);
if (cache.size() < MAX_CACHE_SIZE) {
+ CompoundName compound = new CompoundName(name, true);
cache.put(name, compound);
+ return compound;
}
- return compound;
+ return new CompoundName(name, false);
}
private static class ImmutableArrayList extends AbstractList<String> {