Class GrpcFacade
java.lang.Object
org.hansken.plugin.extraction.runtime.grpc.server.proxy.GrpcFacade
Facade through which the server can take and receive calls over RPC. It translates method calls
to the necessary gRPC messages and blocks for response if necessary.
-
Constructor Summary
ConstructorsConstructorDescriptionGrpcFacade(BlockingQueue<com.google.protobuf.Any> incomingMessages, io.grpc.stub.StreamObserver<com.google.protobuf.Any> outgoingMessages, int maximumMessageSize) Create a newRPC facade, which will send the request on the givenStreamObserver, and if necessary, wait for reply on givenBlockingQueue. -
Method Summary
Modifier and TypeMethodDescriptionvoidbeginChild(String id, String name) Signal that we are in the scope of a newly created childTrace.voidbeginWritingData(String id, String dataType) Signal that we start writing a data stream of given type.voidenrichTrace(String id, Set<String> types, Map<String, Object> properties, List<Trace.Tracelet> tracelets, Map<String, List<DataTransformation>> transformations) Add types and properties to the currently processed trace.voidfinishChild(String id) Signal that we exited the last created childTracescope.voidfinishProcessing(double duration) Send afinishmessage to the client, containing a set of actions to execute.voidfinishWritingData(String id, String dataType) Signal that we finished writing to the data stream of given type.voidhandleResponse(com.google.protobuf.Any any) Receive a response for a request and handle it.voidSignal completion of the stream to the outgoing observer, seeStreamObserver.onCompleted().voidSignal completion of the stream due to an error.voidprocessPartialResultOrError(Throwable t, double duration) This method sends anRpcPartialFinishWithErrormessage to the client in case an error occurs, containing a partial(or empty) set of actions that have been cached so far, and a description of the error.byte[]readFromTraceData(long position, int count, String traceUid, String type) Read from the data sequence currently processed by the trace, seeDataContext.data().searchTraces(String query) Asks the client to perform a search request in Hansken to retrieve traces.searchTraces(String query, int count) Asks the client to perform a search request in Hansken to retrieve traces.searchTraces(String query, int count, SearchOptions options) Asks the client to perform a search request in Hansken to retrieve traces.searchTraces(String query, int count, SearchScope scope, int start, List<SearchSortOption> sort) Asks the client to perform a search request in Hansken to retrieve traces.searchTraces(String query, SearchOptions options) Asks the client to perform a search request in Hansken to retrieve traces.voidSend a data chunk of the current data stream to the client.
-
Constructor Details
-
GrpcFacade
public GrpcFacade(BlockingQueue<com.google.protobuf.Any> incomingMessages, io.grpc.stub.StreamObserver<com.google.protobuf.Any> outgoingMessages, int maximumMessageSize) Create a newRPC facade, which will send the request on the givenStreamObserver, and if necessary, wait for reply on givenBlockingQueue.- Parameters:
incomingMessages- queue where results of a request are pushed onoutgoingMessages- observer on which to publish requestsmaximumMessageSize- the maximum size of the wire format of a single RPC message- Throws:
IllegalArgumentException- if the maximum message size is less thanMINIMUM_MESSAGE_SIZE
-
-
Method Details
-
readFromTraceData
Read from the data sequence currently processed by the trace, seeDataContext.data().Note: callers must ensure that the trace data contains at least
countbytes from givenposition, else the result if this call is undefined.- Parameters:
position- the position to seek to and read fromcount- the number of bytes to readtraceUid- the uid of the trace to read fromtype- the type of the data stream to read from- Returns:
- the read bytes
-
enrichTrace
public void enrichTrace(String id, Set<String> types, Map<String, Object> properties, List<Trace.Tracelet> tracelets, Map<String, List<DataTransformation>> transformations) Add types and properties to the currently processed trace.- Parameters:
id- the id of the trace to enrichtypes- the types to addproperties- the properties to addtracelets- the tracelets to addtransformations- the transformations to add
-
beginChild
Signal that we are in the scope of a newly created childTrace.- Parameters:
id- the id of the new childname- the name of the new child
-
finishChild
Signal that we exited the last created childTracescope.- Parameters:
id- the id of the closed child
-
beginWritingData
Signal that we start writing a data stream of given type.- Parameters:
id- the id of the trace to write the data todataType- type of the data stream we will be writing to (raw, html...)
-
writeData
Send a data chunk of the current data stream to the client. Will send multiple messages ifdata.length > _maximumWriteChunkSize. Multiple calls to this method are regarded as sequential data writes.- Parameters:
id- the id of the trace to write the data todataType- the stream data typedata- the chunk to writeoffset- the offset in the buffer to write fromlength- the amount of data from the buffer to write
-
finishWritingData
Signal that we finished writing to the data stream of given type.- Parameters:
id- the id of the trace we were writing data todataType- type of the data stream we were writing to (raw, html...)
-
searchTraces
Asks the client to perform a search request in Hansken to retrieve traces.- Parameters:
query- the query to perform- Returns:
- a SearchResult containing the total number of traces and the traces
-
searchTraces
Asks the client to perform a search request in Hansken to retrieve traces.- Parameters:
query- the query to performcount- maximum traces to return- Returns:
- a SearchResult containing the total number of traces and the traces
-
searchTraces
Asks the client to perform a search request in Hansken to retrieve traces.- Parameters:
query- the query to performoptions-SearchOptionsobject containing various search options- Returns:
- a SearchResult containing the total number of traces and the traces
-
searchTraces
Asks the client to perform a search request in Hansken to retrieve traces.- Parameters:
query- the query to performcount- maximum traces to returnoptions-SearchOptionsobject containing various search options- Returns:
- a SearchResult containing the total number of traces and the traces
-
searchTraces
public SearchResult searchTraces(String query, int count, SearchScope scope, int start, List<SearchSortOption> sort) Asks the client to perform a search request in Hansken to retrieve traces.- Parameters:
query- the query to performcount- maximum traces to return, -1 indicates all traces, see:TraceSearcher.ALL_SEARCH_RESULTS.scope- scope to limit the search to (project or image)start- the starting offset of the traces to getsort- a list ofSearchSortOptioncontaining fields and directions to sort on- Returns:
- a SearchResult containing the total number of traces and the traces
-
handleResponse
public void handleResponse(com.google.protobuf.Any any) Receive a response for a request and handle it.- Parameters:
any- the response received- Throws:
IllegalStateException- if no response was expected
-
onError
Signal completion of the stream due to an error.- Parameters:
statusCode- the error codet- the cause of the error
-
onCompleted
public void onCompleted()Signal completion of the stream to the outgoing observer, seeStreamObserver.onCompleted(). -
finishProcessing
public void finishProcessing(double duration) Send afinishmessage to the client, containing a set of actions to execute.- Parameters:
duration- The duration of the process()-execution in seconds (to be included in the execution profile)
-
processPartialResultOrError
This method sends anRpcPartialFinishWithErrormessage to the client in case an error occurs, containing a partial(or empty) set of actions that have been cached so far, and a description of the error.- Parameters:
t- the cause of the errorduration- The duration of the process()-execution in seconds (to be included in the execution profile)
-