aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/buildeventservice/client/BuildEventServiceClient.java
blob: f4f688ed9ad9f64efa1464023e0fb773434fad1e (plain)
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// Copyright 2017 The Bazel Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//    http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.devtools.build.lib.buildeventservice.client;

import com.google.common.base.Function;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.devtools.build.v1.PublishBuildToolEventStreamRequest;
import com.google.devtools.build.v1.PublishBuildToolEventStreamResponse;
import com.google.devtools.build.v1.PublishLifecycleEventRequest;
import io.grpc.Status;

/** Interface used to abstract both gRPC and Stubby BuildEventServiceBackend. */
public interface BuildEventServiceClient {

  /**
   * Makes a synchronous RPC that publishes the specified lifecycle event.
   *
   * @param lifecycleEvent Event to be published.
   * @return Status of the RPC.
   */
  Status publish(PublishLifecycleEventRequest lifecycleEvent) throws Exception;

  /**
   * Starts a new stream with the given ack callback. Throws an {@link IllegalStateException} if the
   * there is already opened stream. Callers should wait on the returned Future in order to
   * guarantee that all callback calls have been received.
   *
   * @param ackCallback Consumer called every time a ack message is received.
   * @return Listenable future that blocks until the onDone callback is called.
   * @throws Exception
   */
  ListenableFuture<Status> openStream(
      Function<PublishBuildToolEventStreamResponse, Void> ackCallback) throws Exception;

  /**
   * Sends an event to the most recently opened stream. This method may block due to flow control.
   *
   * @param buildEvent Event that should be sent.
   * @throws Exception
   */
  void sendOverStream(PublishBuildToolEventStreamRequest buildEvent) throws Exception;

  /**
   * Closes the currently opened opened stream. This method does not block. Callers should block on
   * the Future returned by {@link #openStream(Function)} in order to make sure that all
   * ackCallback calls have been received.
   */
  void closeStream();

  /**
   * Closes the currently opened stream with error. This method does not block. Callers should block
   * on the Future returned by {@link #openStream(Function)} if in order to make sure that all
   * ackCallback calls have been received. This method is NOOP if the stream was already finished.
   */
  void abortStream(Status status);

  /**
   * Checks if there is a currently active stream.
   *
   * @return True if the current stream is active, false otherwise.
   */
  boolean isStreamActive();

  /**
   * Called once to dispose resources that this client might be holding (such as thread pools). This
   * should be the last method called on this object.
   *
   * @throws InterruptedException
   */
  void shutdown() throws InterruptedException;

  /**
   * If possible, returns a user readable error message for a given {@link Throwable}.
   *
   * <p>As a last resort, it's valid to return {@link Throwable#getMessage()}.
   */
  String userReadableError(Throwable t);
}