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 Details

    • GrpcFacade

      public GrpcFacade(BlockingQueue<com.google.protobuf.Any> incomingMessages, io.grpc.stub.StreamObserver<com.google.protobuf.Any> outgoingMessages, int maximumMessageSize)
      Create a new RPC facade, which will send the request on the given StreamObserver, and if necessary, wait for reply on given BlockingQueue.
      Parameters:
      incomingMessages - queue where results of a request are pushed on
      outgoingMessages - observer on which to publish requests
      maximumMessageSize - the maximum size of the wire format of a single RPC message
      Throws:
      IllegalArgumentException - if the maximum message size is less than MINIMUM_MESSAGE_SIZE
  • Method Details

    • readFromTraceData

      public byte[] readFromTraceData(long position, int count, String traceUid, String type)
      Read from the data sequence currently processed by the trace, see DataContext.data().

      Note: callers must ensure that the trace data contains at least count bytes from given position, else the result if this call is undefined.

      Parameters:
      position - the position to seek to and read from
      count - the number of bytes to read
      traceUid - the uid of the trace to read from
      type - 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 enrich
      types - the types to add
      properties - the properties to add
      tracelets - the tracelets to add
      transformations - the transformations to add
    • beginChild

      public void beginChild(String id, String name)
      Signal that we are in the scope of a newly created child Trace.
      Parameters:
      id - the id of the new child
      name - the name of the new child
    • finishChild

      public void finishChild(String id)
      Signal that we exited the last created child Trace scope.
      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 to
      dataType - 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 if data.length > _maximumWriteChunkSize. Multiple calls to this method are regarded as sequential data writes.
      Parameters:
      id - the id of the trace to write the data to
      dataType - the stream data type
      data - the chunk to write
      offset - the offset in the buffer to write from
      length - 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 to
      dataType - 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 perform
      count - maximum traces to return
      scope - 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 of SEARCH_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 code
      t - the cause of the error
    • onCompleted

      public void onCompleted()
      Signal completion of the stream to the outgoing observer, see StreamObserver.onCompleted().
    • finishProcessing

      public void finishProcessing(double duration)
      Send a finish message 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 an RpcPartialFinishWithError message 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 error
      duration - The duration of the process()-execution in seconds (to be included in the execution profile)