• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

grpc / grpc-java / #18889

08 Nov 2023 11:00PM UTC coverage: 88.264% (+0.01%) from 88.25%
#18889

push

github

web-flow
stub: Deprecate StreamObservers (#10654)

This class is of questionable utility and generally not used.

30377 of 34416 relevant lines covered (88.26%)

0.88 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/../stub/src/main/java/io/grpc/stub/StreamObservers.java
1
/*
2
 * Copyright 2015 The gRPC Authors
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *     http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16

17
package io.grpc.stub;
18

19
import com.google.common.base.Preconditions;
20
import io.grpc.ExperimentalApi;
21
import java.util.Iterator;
22

23
/**
24
 * Utility functions for working with {@link StreamObserver} and it's common subclasses like
25
 * {@link CallStreamObserver}.
26
 *
27
 * @deprecated Of questionable utility and generally not used.
28
 */
29
@Deprecated
30
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/4694")
31
public final class StreamObservers {
×
32
  /**
33
   * Copy the values of an {@link Iterator} to the target {@link CallStreamObserver} while properly
34
   * accounting for outbound flow-control.  After calling this method, {@code target} should no
35
   * longer be used.
36
   *
37
   * <p>For clients this method is safe to call inside {@link ClientResponseObserver#beforeStart},
38
   * on servers it is safe to call inside the service method implementation.
39
   * </p>
40
   *
41
   * @param source of values expressed as an {@link Iterator}.
42
   * @param target {@link CallStreamObserver} which accepts values from the source.
43
   */
44
  public static <V> void copyWithFlowControl(final Iterator<V> source,
45
      final CallStreamObserver<V> target) {
46
    Preconditions.checkNotNull(source, "source");
×
47
    Preconditions.checkNotNull(target, "target");
×
48

49
    final class FlowControllingOnReadyHandler implements Runnable {
×
50
      private boolean completed;
51

52
      @Override
53
      public void run() {
54
        if (completed) {
×
55
          return;
×
56
        }
57

58
        while (target.isReady() && source.hasNext()) {
×
59
          target.onNext(source.next());
×
60
        }
61

62
        if (!source.hasNext()) {
×
63
          completed = true;
×
64
          target.onCompleted();
×
65
        }
66
      }
×
67
    }
68

69
    target.setOnReadyHandler(new FlowControllingOnReadyHandler());
×
70
  }
×
71

72
  /**
73
   * Copy the values of an {@link Iterable} to the target {@link CallStreamObserver} while properly
74
   * accounting for outbound flow-control.  After calling this method, {@code target} should no
75
   * longer be used.
76
   *
77
   * <p>For clients this method is safe to call inside {@link ClientResponseObserver#beforeStart},
78
   * on servers it is safe to call inside the service method implementation.
79
   * </p>
80
   *
81
   * @param source of values expressed as an {@link Iterable}.
82
   * @param target {@link CallStreamObserver} which accepts values from the source.
83
   */
84
  public static <V> void copyWithFlowControl(final Iterable<V> source,
85
      CallStreamObserver<V> target) {
86
    Preconditions.checkNotNull(source, "source");
×
87
    copyWithFlowControl(source.iterator(), target);
×
88
  }
×
89
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc