summaryrefslogtreecommitdiffstats
path: root/container-search/src/main/java/com/yahoo/search/debug/TracePackets.java
blob: de71b2e3f264a805e5fd228e757ad258e73c6263 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.search.debug;

import static com.yahoo.search.debug.SearcherUtils.clusterSearchers;

import java.util.Collection;

import com.yahoo.jrt.Request;
import com.yahoo.jrt.Value;
import com.yahoo.prelude.cluster.ClusterSearcher;
import com.yahoo.fs4.PacketDumper;
import com.yahoo.yolean.Exceptions;

/**
 * Rpc method for enabling packet dumping for a specific packet type.
 *
 * @author tonytv
 */
final class TracePackets implements DebugMethodHandler {
    private final PacketDumper.PacketType packetType;

    public void invoke(Request request) {
        try {
            Collection<ClusterSearcher> searchers = clusterSearchers(request);
            boolean on = request.parameters().get(1).asInt8() != 0;

            for (ClusterSearcher searcher : searchers)
                searcher.dumpPackets(packetType, on);

        } catch (Exception e) {
            request.setError(1000, Exceptions.toMessageString(e));
        }
    }

    TracePackets(PacketDumper.PacketType packetType) {
        this.packetType = packetType;
    }

    public JrtMethodSignature getSignature() {
        String returnTypes = "";
        String parametersTypes = "" + (char)Value.STRING + (char)Value.INT8;
        return new JrtMethodSignature(returnTypes, parametersTypes);
    }
}