Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

/**
* Builds a Search chain from xml.
*
* @author Tony Vaagenes
*/
public class DomSearchChainBuilder extends DomChainBuilderBase<Searcher<?>, SearchChain> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public FederationOptions federationOptions() {
return new FederationOptions().setUseByDefault(true);
}

//A list of documents types that this search chain provides results for, empty if unknown
/** A list of documents types that this search chain provides results for, empty if unknown. */
public List<String> getDocumentTypes() {
return List.of();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,33 +30,10 @@
// TODO: refactor
public class VespaSearchChainsCreator {

private static class PhasesCreator {

private static Set<String> set(String successor) {
return successor == null ? null : new LinkedHashSet<>(List.of(successor));
}

private static String lastElement(String[] phases) {
return phases[phases.length - 1];
}

private static Phase createPhase(String phase, String before) {
return new Phase(phase, set(before), null);
}

static Collection<Phase> linearPhases(String... phases) {
List<Phase> result = new ArrayList<>();

for (int i=0; i < phases.length - 1; ++i) {
result.add(createPhase(phases[i], phases[i+1]));
}

if (phases.length > 0) {
result.add(createPhase(lastElement(phases), null));
}

return result;
}
public static void addVespaSearchChains(SearchChains searchChains) {
searchChains.add(createVespaPhases());
searchChains.add(createNative());
searchChains.add(createVespa());
}

private static Set<ComponentSpecification> noSearcherReferences() {
Expand Down Expand Up @@ -133,10 +110,33 @@ private static SearchChain createVespa() {
return vespaChain;
}

public static void addVespaSearchChains(SearchChains searchChains) {
searchChains.add(createVespaPhases());
searchChains.add(createNative());
searchChains.add(createVespa());
private static class PhasesCreator {

private static Set<String> set(String successor) {
return successor == null ? null : new LinkedHashSet<>(List.of(successor));
}

private static String lastElement(String[] phases) {
return phases[phases.length - 1];
}

private static Phase createPhase(String phase, String before) {
return new Phase(phase, set(before), null);
}

static Collection<Phase> linearPhases(String... phases) {
List<Phase> result = new ArrayList<>();

for (int i=0; i < phases.length - 1; ++i) {
result.add(createPhase(phases[i], phases[i+1]));
}

if (phases.length > 0) {
result.add(createPhase(lastElement(phases), null));
}

return result;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,7 @@ public Chain(ComponentId id, COMPONENT... components) {

/** Create a chain by using a builder. This will order the chain by the ordering constraints. */
public Chain(ComponentId id, Collection<COMPONENT> components, Collection<Phase> phases) {
this(id, buildChain(
emptyListIfNull(components),
emptyListIfNull(phases)).components());

this(id, buildChain(emptyListIfNull(components), emptyListIfNull(phases)).components());
}

public ComponentId getId() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,8 @@ private static <COMPONENT extends ChainedComponent> void initDependencies(
}
}

private static <COMPONENT extends ChainedComponent> COMPONENT getComponentOrThrow(
ComponentRegistry<COMPONENT> registry,
ComponentSpecification specification) {

private static <COMPONENT extends ChainedComponent> COMPONENT getComponentOrThrow(ComponentRegistry<COMPONENT> registry,
ComponentSpecification specification) {
COMPONENT component = registry.getComponent(specification);
if (component == null) {
throw new ConfigurationRuntimeException("No such component '" + specification + "'");
Expand All @@ -59,18 +57,17 @@ private static <COMPONENT extends ChainedComponent> void instantiateChains(
for (ChainSpecification chain : model.allChainsFlattened()) {
try {
Chain<COMPONENT> componentChain = new Chain<>(chain.componentId,
resolveComponents(chain.componentReferences, allComponents),
chain.phases());
resolveComponents(chain.componentReferences, allComponents),
chain.phases());
chainRegistry.register(chain.componentId, componentChain);
} catch (Exception e) {
throw new ConfigurationRuntimeException("Invalid chain '" + chain.componentId + "'", e);
}
}
}

private static <T extends ChainedComponent> List<T> resolveComponents(
Set<ComponentSpecification> componentSpecifications,
ComponentRegistry<T> allComponents) {
private static <T extends ChainedComponent> List<T> resolveComponents(Set<ComponentSpecification> componentSpecifications,
ComponentRegistry<T> allComponents) {

List<T> components = new ArrayList<>(componentSpecifications.size());
for (ComponentSpecification componentSpec : componentSpecifications) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ public abstract class ThreadedHttpRequestHandler extends ThreadedRequestHandler
/** Logger for subclasses */
protected final Logger log;



public ThreadedHttpRequestHandler(Executor executor) {
this(executor, null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ private void processRequest() {

@Override
public ContentChannel handleResponse(Response response) {
if ( tryHasResponded()) throw new IllegalStateException("Response already handled");
if (tryHasResponded()) throw new IllegalStateException("Response already handled");
if (getRequestType().isPresent() && response.getRequestType() == null)
response.setRequestType(getRequestType().get());
ContentChannel cc = responseHandler.handleResponse(response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@

/**
* Responsible for metric reporting for JDisc http request handler support.
*
* @author Tony Vaagenes
*/
class RequestMetricReporter {

private final Metric metric;
private final Context context;

Expand Down Expand Up @@ -48,17 +50,13 @@ void failedWrite() {

void successfulResponse() {
setTimeToFirstByteFirstTime();

long requestLatency = getRequestLatency();

metric.set(MetricDefinitions.TOTAL_SUCCESSFUL_LATENCY, requestLatency, context);

metric.add(MetricDefinitions.NUM_SUCCESSFUL_RESPONSES, 1, context);
}

void failedResponse() {
setTimeToFirstByteFirstTime();

metric.set(MetricDefinitions.TOTAL_FAILED_LATENCY, getRequestLatency(), context);
metric.add(MetricDefinitions.NUM_FAILED_RESPONSES, 1, context);
}
Expand All @@ -82,4 +80,5 @@ void uriLength(int length) {
void contentSize(long size) {
metric.set(MetricDefinitions.CONTENT_SIZE, size, context);
}

}
Loading
Loading