Class GrpcFacade
- java.lang.Object
-
- org.hansken.plugin.extraction.runtime.grpc.server.proxy.GrpcFacade
-
public class GrpcFacade extends Object
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
Constructors Constructor Description 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.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidbeginChild(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.voidonCompleted()Signal completion of the stream to the outgoing observer, seeStreamObserver.onCompleted().voidonError(io.grpc.Status.Code statusCode, Throwable t)Signal 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().SearchResultsearchTraces(String query, int count, TraceSearcher.SearchScope scope)Asks the client to perform a search request in Hansken to retrieve traces.voidwriteData(String id, String dataType, byte[] data, int offset, int length)Send a data chunk of the current data stream to the client.
-
-
-
Constructor Detail
-
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 Detail
-
readFromTraceData
public byte[] readFromTraceData(long position, int count, String traceUid, String type)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
public void beginChild(String id, String name)
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
public void finishChild(String id)
Signal that we exited the last created childTracescope.- Parameters:
id- the id of the closed child
-
beginWritingData
public void beginWritingData(String id, String dataType)
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
public void writeData(String id, String dataType, byte[] data, int offset, int length)
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
public void finishWritingData(String id, String dataType)
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
public SearchResult searchTraces(String query, int count, TraceSearcher.SearchScope scope)
Asks the client to perform a search request in Hansken to retrieve traces.- Parameters:
query- the query to performcount- maximum traces to returnscope- scope to limit the search to (project or image)- Returns:
- a SearchResult containing the total number of traces and the traces
- Throws:
IllegalArgumentException- if the request's count exceeds the limit ofSEARCH_REQUEST_COUNT_LIMIT
-
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
public void onError(io.grpc.Status.Code statusCode, Throwable t)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
public void processPartialResultOrError(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.- Parameters:
t- the cause of the errorduration- The duration of the process()-execution in seconds (to be included in the execution profile)
-
-