本文整理汇总了Java中com.google.protobuf.util.Durations类的典型用法代码示例。如果您正苦于以下问题:Java Durations类的具体用法?Java Durations怎么用?Java Durations使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Durations类属于com.google.protobuf.util包,在下文中一共展示了Durations类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: CPSPublisherTask
import com.google.protobuf.util.Durations; //导入依赖的package包/类
private CPSPublisherTask(StartRequest request) {
super(request, "gcloud", MetricsHandler.MetricName.PUBLISH_ACK_LATENCY);
try {
this.publisher =
Publisher.defaultBuilder(TopicName.create(request.getProject(), request.getTopic()))
.setBatchingSettings(
BatchingSettings.newBuilder()
.setElementCountThreshold(950L)
.setRequestByteThreshold(9500000L)
.setDelayThreshold(
Duration.ofMillis(Durations.toMillis(request.getPublishBatchDuration())))
.build())
.build();
} catch (Exception e) {
throw new RuntimeException(e);
}
this.payload = ByteString.copyFromUtf8(LoadTestRunner.createMessage(request.getMessageSize()));
this.batchSize = request.getPublishBatchSize();
this.messageSize = request.getMessageSize();
this.id = (new Random()).nextInt();
}
开发者ID:GoogleCloudPlatform,项目名称:pubsub,代码行数:22,代码来源:CPSPublisherTask.java
示例2: anyInMaps
import com.google.protobuf.util.Durations; //导入依赖的package包/类
@Test
public void anyInMaps() throws Exception {
TestAny.Builder testAny = TestAny.newBuilder();
testAny.putAnyMap("int32_wrapper", Any.pack(Int32Value.newBuilder().setValue(123).build()));
testAny.putAnyMap("int64_wrapper", Any.pack(Int64Value.newBuilder().setValue(456).build()));
testAny.putAnyMap("timestamp", Any.pack(Timestamps.parse("1969-12-31T23:59:59Z")));
testAny.putAnyMap("duration", Any.pack(Durations.parse("12345.1s")));
testAny.putAnyMap("field_mask", Any.pack(FieldMaskUtil.fromString("foo.bar,baz")));
Value numberValue = Value.newBuilder().setNumberValue(1.125).build();
Struct.Builder struct = Struct.newBuilder();
struct.putFields("number", numberValue);
testAny.putAnyMap("struct", Any.pack(struct.build()));
Value nullValue = Value.newBuilder().setNullValue(NullValue.NULL_VALUE).build();
testAny.putAnyMap(
"list_value",
Any.pack(ListValue.newBuilder().addValues(numberValue).addValues(nullValue).build()));
testAny.putAnyMap("number_value", Any.pack(numberValue));
testAny.putAnyMap("any_value_number", Any.pack(Any.pack(numberValue)));
testAny.putAnyMap("any_value_default", Any.pack(Any.getDefaultInstance()));
testAny.putAnyMap("default", Any.getDefaultInstance());
assertMatchesUpstream(testAny.build(), TestAllTypes.getDefaultInstance());
}
开发者ID:curioswitch,项目名称:curiostack,代码行数:24,代码来源:MessageMarshallerTest.java
示例3: KafkaPublisherTask
import com.google.protobuf.util.Durations; //导入依赖的package包/类
private KafkaPublisherTask(StartRequest request) {
super(request, "kafka", MetricsHandler.MetricName.PUBLISH_ACK_LATENCY);
this.topic = request.getTopic();
this.payload = LoadTestRunner.createMessage(request.getMessageSize());
this.batchSize = request.getPublishBatchSize();
Properties props = new Properties();
props.putAll(new ImmutableMap.Builder<>()
.put("max.block.ms", "30000")
.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer")
.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer")
.put("acks", "all")
.put("bootstrap.servers", request.getKafkaOptions().getBroker())
.put("buffer.memory", Integer.toString(1000 * 1000 * 1000)) // 1 GB
// 10M, high enough to allow for duration to control batching
.put("batch.size", Integer.toString(10 * 1000 * 1000))
.put("linger.ms", Long.toString(Durations.toMillis(request.getPublishBatchDuration())))
.build()
);
this.publisher = new KafkaProducer<>(props);
}
开发者ID:GoogleCloudPlatform,项目名称:pubsub,代码行数:21,代码来源:KafkaPublisherTask.java
示例4: doMerge
import com.google.protobuf.util.Durations; //导入依赖的package包/类
@Override
public void doMerge(JsonParser parser, int unused, Message.Builder messageBuilder)
throws IOException {
Duration.Builder builder = (Duration.Builder) messageBuilder;
try {
builder.mergeFrom(Durations.parse(ParseSupport.parseString(parser)));
} catch (ParseException e) {
throw new InvalidProtocolBufferException(
"Failed to readValue duration: " + parser.getText());
}
}
开发者ID:curioswitch,项目名称:curiostack,代码行数:12,代码来源:WellKnownTypeMarshaller.java
示例5: mergeDuration
import com.google.protobuf.util.Durations; //导入依赖的package包/类
private void mergeDuration(JsonElement json, Message.Builder builder)
throws InvalidProtocolBufferException {
try {
Duration value = Durations.parse(json.getAsString());
builder.mergeFrom(value.toByteString());
} catch (ParseException e) {
throw new InvalidProtocolBufferException("Failed to parse duration: " + json);
}
}
开发者ID:SeldonIO,项目名称:seldon-core,代码行数:10,代码来源:JsonFormat.java
示例6: KafkaSubscriberTask
import com.google.protobuf.util.Durations; //导入依赖的package包/类
private KafkaSubscriberTask(StartRequest request) {
super(request, "kafka", MetricsHandler.MetricName.END_TO_END_LATENCY);
this.pollLength = Durations.toMillis(request.getKafkaOptions().getPollDuration());
Properties props = new Properties();
props.putAll(ImmutableMap.of(
"key.deserializer", "org.apache.kafka.common.serialization.StringDeserializer",
"value.deserializer", "org.apache.kafka.common.serialization.StringDeserializer",
"group.id", "SUBSCRIBER_ID",
"enable.auto.commit", "true",
"session.timeout.ms", "30000"
));
props.put("bootstrap.servers", request.getKafkaOptions().getBroker());
subscriber = new KafkaConsumer<>(props);
subscriber.subscribe(Collections.singletonList(request.getTopic()));
}
开发者ID:GoogleCloudPlatform,项目名称:pubsub,代码行数:16,代码来源:KafkaSubscriberTask.java
示例7: convert
import com.google.protobuf.util.Durations; //导入依赖的package包/类
@Override
public Duration convert(String value) {
try {
if (value.isEmpty()) {
return Durations.fromMillis(0);
}
long millis = 0;
boolean negative = value.startsWith("-");
int index = negative ? 1 : 0;
Pattern unitPattern =
Pattern.compile(
"(?x) (?<whole>[0-9]+)? (?<frac>\\.[0-9]*)? (?<unit>d|h|ms?|s)",
Pattern.CASE_INSENSITIVE);
Matcher matcher = unitPattern.matcher(value);
while (matcher.find(index) && matcher.start() == index) {
Preconditions.checkArgument(CharMatcher.inRange('0', '9').matchesAnyOf(matcher.group(0)));
long whole = Long.parseLong(MoreObjects.firstNonNull(matcher.group("whole"), "0"));
double frac =
Double.parseDouble("0" + MoreObjects.firstNonNull(matcher.group("frac"), ""));
int millisPerUnit = millisPerUnit(matcher.group("unit"));
millis += millisPerUnit * whole;
millis += (long) (millisPerUnit * frac);
index = matcher.end();
}
if (index < value.length()) {
throw new IllegalArgumentException("Could not parse entire duration");
}
if (negative) {
millis = -millis;
}
return Durations.fromMillis(millis);
} catch (Exception e) {
throw new ParameterException(
getErrorString(value, "A duration string must include units (d|h|m|s|ms)."));
}
}
开发者ID:GoogleCloudPlatform,项目名称:pubsub,代码行数:37,代码来源:Driver.java
示例8: buildInitialResponse
import com.google.protobuf.util.Durations; //导入依赖的package包/类
private static LoadBalanceResponse buildInitialResponse(long loadReportIntervalMillis) {
return LoadBalanceResponse.newBuilder()
.setInitialResponse(
InitialLoadBalanceResponse.newBuilder()
.setClientStatsReportInterval(Durations.fromMillis(loadReportIntervalMillis)))
.build();
}
开发者ID:grpc,项目名称:grpc-java,代码行数:8,代码来源:GrpclbLoadBalancerTest.java
示例9: doWrite
import com.google.protobuf.util.Durations; //导入依赖的package包/类
@Override
public void doWrite(Duration message, JsonGenerator gen) throws IOException {
gen.writeString(Durations.toString(message));
}
开发者ID:curioswitch,项目名称:curiostack,代码行数:5,代码来源:WellKnownTypeMarshaller.java
示例10: duration
import com.google.protobuf.util.Durations; //导入依赖的package包/类
@Test
public void duration() throws Exception {
TestDuration message =
TestDuration.newBuilder().setDurationValue(Durations.parse("12345s")).build();
assertMatchesUpstream(message);
}
开发者ID:curioswitch,项目名称:curiostack,代码行数:7,代码来源:MessageMarshallerTest.java
示例11: anyFields
import com.google.protobuf.util.Durations; //导入依赖的package包/类
@Test
public void anyFields() throws Exception {
TestAllTypes content = TestAllTypes.newBuilder().setOptionalInt32(1234).build();
TestAny message = TestAny.newBuilder().setAnyValue(Any.pack(content)).build();
assertMatchesUpstream(message, TestAllTypes.getDefaultInstance());
TestAny messageWithDefaultAnyValue =
TestAny.newBuilder().setAnyValue(Any.getDefaultInstance()).build();
assertMatchesUpstream(messageWithDefaultAnyValue);
// Well-known types have a special formatting when embedded in Any.
//
// 1. Any in Any.
Any anyMessage = Any.pack(Any.pack(content));
assertMatchesUpstream(anyMessage, TestAllTypes.getDefaultInstance());
// 2. Wrappers in Any.
anyMessage = Any.pack(Int32Value.newBuilder().setValue(12345).build());
assertMatchesUpstream(anyMessage, TestAllTypes.getDefaultInstance());
anyMessage = Any.pack(UInt32Value.newBuilder().setValue(12345).build());
assertMatchesUpstream(anyMessage, TestAllTypes.getDefaultInstance());
anyMessage = Any.pack(Int64Value.newBuilder().setValue(12345).build());
assertMatchesUpstream(anyMessage, TestAllTypes.getDefaultInstance());
anyMessage = Any.pack(UInt64Value.newBuilder().setValue(12345).build());
assertMatchesUpstream(anyMessage, TestAllTypes.getDefaultInstance());
anyMessage = Any.pack(FloatValue.newBuilder().setValue(12345).build());
assertMatchesUpstream(anyMessage, TestAllTypes.getDefaultInstance());
anyMessage = Any.pack(DoubleValue.newBuilder().setValue(12345).build());
assertMatchesUpstream(anyMessage, TestAllTypes.getDefaultInstance());
anyMessage = Any.pack(BoolValue.newBuilder().setValue(true).build());
assertMatchesUpstream(anyMessage, TestAllTypes.getDefaultInstance());
anyMessage = Any.pack(StringValue.newBuilder().setValue("Hello").build());
assertMatchesUpstream(anyMessage, TestAllTypes.getDefaultInstance());
anyMessage =
Any.pack(BytesValue.newBuilder().setValue(ByteString.copyFrom(new byte[] {1, 2})).build());
assertMatchesUpstream(anyMessage, TestAllTypes.getDefaultInstance());
// 3. Timestamp in Any.
anyMessage = Any.pack(Timestamps.parse("1969-12-31T23:59:59Z"));
assertMatchesUpstream(anyMessage, TestAllTypes.getDefaultInstance());
// 4. Duration in Any
anyMessage = Any.pack(Durations.parse("12345.10s"));
assertMatchesUpstream(anyMessage, TestAllTypes.getDefaultInstance());
// 5. FieldMask in Any
anyMessage = Any.pack(FieldMaskUtil.fromString("foo.bar,baz"));
assertMatchesUpstream(anyMessage, TestAllTypes.getDefaultInstance());
// 6. Struct in Any
Struct.Builder structBuilder = Struct.newBuilder();
structBuilder.putFields("number", Value.newBuilder().setNumberValue(1.125).build());
anyMessage = Any.pack(structBuilder.build());
assertMatchesUpstream(anyMessage, TestAllTypes.getDefaultInstance());
// 7. Value (number type) in Any
Value.Builder valueBuilder = Value.newBuilder();
valueBuilder.setNumberValue(1);
anyMessage = Any.pack(valueBuilder.build());
assertMatchesUpstream(anyMessage, TestAllTypes.getDefaultInstance());
// 8. Value (null type) in Any
anyMessage = Any.pack(Value.newBuilder().setNullValue(NullValue.NULL_VALUE).build());
assertMatchesUpstream(anyMessage, TestAllTypes.getDefaultInstance());
}
开发者ID:curioswitch,项目名称:curiostack,代码行数:66,代码来源:MessageMarshallerTest.java
示例12: printDuration
import com.google.protobuf.util.Durations; //导入依赖的package包/类
/** Prints google.protobuf.Duration */
private void printDuration(MessageOrBuilder message) throws IOException {
Duration value = Duration.parseFrom(toByteString(message));
generator.print("\"" + Durations.toString(value) + "\"");
}
开发者ID:SeldonIO,项目名称:seldon-core,代码行数:6,代码来源:JsonFormat.java
示例13: toProto
import com.google.protobuf.util.Durations; //导入依赖的package包/类
/**
* Converts a {@link WindowFn} into a {@link RunnerApi.MessageWithComponents} where {@link
* RunnerApi.MessageWithComponents#getFunctionSpec()} is a {@link RunnerApi.FunctionSpec} for the
* input {@link WindowFn}.
*/
public static SdkFunctionSpec toProto(
WindowFn<?, ?> windowFn, @SuppressWarnings("unused") SdkComponents components) {
// TODO: Set environment IDs
ByteString serializedFn = ByteString.copyFrom(SerializableUtils.serializeToByteArray(windowFn));
if (windowFn instanceof GlobalWindows) {
return SdkFunctionSpec.newBuilder()
.setSpec(FunctionSpec.newBuilder().setUrn(GLOBAL_WINDOWS_FN))
.build();
} else if (windowFn instanceof FixedWindows) {
FixedWindowsPayload fixedWindowsPayload =
FixedWindowsPayload.newBuilder()
.setSize(Durations.fromMillis(((FixedWindows) windowFn).getSize().getMillis()))
.setOffset(Timestamps.fromMillis(((FixedWindows) windowFn).getOffset().getMillis()))
.build();
return SdkFunctionSpec.newBuilder()
.setSpec(
FunctionSpec.newBuilder()
.setUrn(FIXED_WINDOWS_FN)
.setPayload(fixedWindowsPayload.toByteString()))
.build();
} else if (windowFn instanceof SlidingWindows) {
SlidingWindowsPayload slidingWindowsPayload = SlidingWindowsPayload.newBuilder()
.setSize(Durations.fromMillis(((SlidingWindows) windowFn).getSize().getMillis()))
.setOffset(Timestamps.fromMillis(((SlidingWindows) windowFn).getOffset().getMillis()))
.setPeriod(Durations.fromMillis(((SlidingWindows) windowFn).getPeriod().getMillis()))
.build();
return SdkFunctionSpec.newBuilder()
.setSpec(
FunctionSpec.newBuilder()
.setUrn(SLIDING_WINDOWS_FN)
.setPayload(slidingWindowsPayload.toByteString()))
.build();
} else if (windowFn instanceof Sessions) {
SessionsPayload sessionsPayload =
SessionsPayload.newBuilder()
.setGapSize(Durations.fromMillis(((Sessions) windowFn).getGapDuration().getMillis()))
.build();
return SdkFunctionSpec.newBuilder()
.setSpec(
FunctionSpec.newBuilder()
.setUrn(SESSION_WINDOWS_FN)
.setPayload(sessionsPayload.toByteString()))
.build();
} else {
return SdkFunctionSpec.newBuilder()
.setSpec(
FunctionSpec.newBuilder()
.setUrn(SERIALIZED_JAVA_WINDOWFN_URN)
.setPayload(serializedFn))
.build();
}
}
开发者ID:apache,项目名称:beam,代码行数:58,代码来源:WindowingStrategyTranslation.java
示例14: windowFnFromProto
import com.google.protobuf.util.Durations; //导入依赖的package包/类
public static WindowFn<?, ?> windowFnFromProto(SdkFunctionSpec windowFnSpec) {
try {
switch (windowFnSpec.getSpec().getUrn()) {
case GLOBAL_WINDOWS_FN:
return new GlobalWindows();
case FIXED_WINDOWS_FN:
StandardWindowFns.FixedWindowsPayload fixedParams = null;
fixedParams =
StandardWindowFns.FixedWindowsPayload.parseFrom(
windowFnSpec.getSpec().getPayload());
return FixedWindows.of(Duration.millis(Durations.toMillis(fixedParams.getSize())))
.withOffset(Duration.millis(Timestamps.toMillis(fixedParams.getOffset())));
case SLIDING_WINDOWS_FN:
StandardWindowFns.SlidingWindowsPayload slidingParams =
StandardWindowFns.SlidingWindowsPayload.parseFrom(
windowFnSpec.getSpec().getPayload());
return SlidingWindows.of(Duration.millis(Durations.toMillis(slidingParams.getSize())))
.every(Duration.millis(Durations.toMillis(slidingParams.getPeriod())))
.withOffset(Duration.millis(Timestamps.toMillis(slidingParams.getOffset())));
case SESSION_WINDOWS_FN:
StandardWindowFns.SessionsPayload sessionParams =
StandardWindowFns.SessionsPayload.parseFrom(windowFnSpec.getSpec().getPayload());
return Sessions.withGapDuration(
Duration.millis(Durations.toMillis(sessionParams.getGapSize())));
case SERIALIZED_JAVA_WINDOWFN_URN:
case OLD_SERIALIZED_JAVA_WINDOWFN_URN:
return (WindowFn<?, ?>)
SerializableUtils.deserializeFromByteArray(
windowFnSpec.getSpec().getPayload().toByteArray(), "WindowFn");
default:
throw new IllegalArgumentException(
"Unknown or unsupported WindowFn: " + windowFnSpec.getSpec().getUrn());
}
} catch (InvalidProtocolBufferException e) {
throw new IllegalArgumentException(
String.format(
"%s for %s with URN %s did not contain expected proto message for payload",
FunctionSpec.class.getSimpleName(),
WindowFn.class.getSimpleName(),
windowFnSpec.getSpec().getUrn()),
e);
}
}
开发者ID:apache,项目名称:beam,代码行数:44,代码来源:WindowingStrategyTranslation.java
示例15: handleResponse
import com.google.protobuf.util.Durations; //导入依赖的package包/类
private void handleResponse(LoadBalanceResponse response) {
if (closed) {
return;
}
logger.log(Level.FINE, "[{0}] Got an LB response: {1}", new Object[] {logId, response});
LoadBalanceResponseTypeCase typeCase = response.getLoadBalanceResponseTypeCase();
if (!initialResponseReceived) {
if (typeCase != LoadBalanceResponseTypeCase.INITIAL_RESPONSE) {
logger.log(
Level.WARNING,
"[{0}] : Did not receive response with type initial response: {1}",
new Object[] {logId, response});
return;
}
initialResponseReceived = true;
InitialLoadBalanceResponse initialResponse = response.getInitialResponse();
loadReportIntervalMillis =
Durations.toMillis(initialResponse.getClientStatsReportInterval());
scheduleNextLoadReport();
return;
}
if (typeCase != LoadBalanceResponseTypeCase.SERVER_LIST) {
logger.log(
Level.WARNING,
"[{0}] : Ignoring unexpected response type: {1}",
new Object[] {logId, response});
return;
}
balancerWorking = true;
// TODO(zhangkun83): handle delegate from initialResponse
ServerList serverList = response.getServerList();
List<DropEntry> newDropList = new ArrayList<DropEntry>();
List<BackendAddressGroup> newBackendAddrList = new ArrayList<BackendAddressGroup>();
// Construct the new collections. Create new Subchannels when necessary.
for (Server server : serverList.getServersList()) {
String token = server.getLoadBalanceToken();
if (server.getDrop()) {
newDropList.add(new DropEntry(loadRecorder, token));
} else {
newDropList.add(null);
InetSocketAddress address;
try {
address = new InetSocketAddress(
InetAddress.getByAddress(server.getIpAddress().toByteArray()), server.getPort());
} catch (UnknownHostException e) {
propagateError(
Status.UNAVAILABLE
.withDescription("Host for server not found: " + server)
.withCause(e));
continue;
}
EquivalentAddressGroup eag = new EquivalentAddressGroup(address);
newBackendAddrList.add(new BackendAddressGroup(eag, token));
}
}
// Stop using fallback backends as soon as a new server list is received from the balancer.
usingFallbackBackends = false;
cancelFallbackTimer();
useRoundRobinLists(newDropList, newBackendAddrList, loadRecorder);
maybeUpdatePicker();
}
开发者ID:grpc,项目名称:grpc-java,代码行数:65,代码来源:GrpclbState.java
注:本文中的com.google.protobuf.util.Durations类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论