Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,11 @@ public class H2Config {
private final int maxHeaderListSize;
private final boolean compressionEnabled;
private final int maxContinuations;
private final H2PingPolicy pingPolicy;

H2Config(final int headerTableSize, final boolean pushEnabled, final int maxConcurrentStreams,
final int initialWindowSize, final int maxFrameSize, final int maxHeaderListSize,
final boolean compressionEnabled, final int maxContinuations) {
final boolean compressionEnabled, final int maxContinuations, final H2PingPolicy pingPolicy) {
super();
this.headerTableSize = headerTableSize;
this.pushEnabled = pushEnabled;
Expand All @@ -64,6 +65,7 @@ public class H2Config {
this.maxHeaderListSize = maxHeaderListSize;
this.compressionEnabled = compressionEnabled;
this.maxContinuations = maxContinuations;
this.pingPolicy = pingPolicy;
}

public int getHeaderTableSize() {
Expand Down Expand Up @@ -98,6 +100,15 @@ public int getMaxContinuations() {
return maxContinuations;
}

/**
* Optional keep-alive PING policy.
*
* @since 5.5
*/
public H2PingPolicy getPingPolicy() {
return pingPolicy;
}

@Override
public String toString() {
final StringBuilder builder = new StringBuilder();
Expand All @@ -109,6 +120,7 @@ public String toString() {
.append(", maxHeaderListSize=").append(this.maxHeaderListSize)
.append(", compressionEnabled=").append(this.compressionEnabled)
.append(", maxContinuations=").append(this.maxContinuations)
.append(", pingPolicy=").append(this.pingPolicy)
.append("]");
return builder.toString();
}
Expand Down Expand Up @@ -142,7 +154,9 @@ public static H2Config.Builder copy(final H2Config config) {
.setInitialWindowSize(config.getInitialWindowSize())
.setMaxFrameSize(config.getMaxFrameSize())
.setMaxHeaderListSize(config.getMaxHeaderListSize())
.setCompressionEnabled(config.isCompressionEnabled());
.setCompressionEnabled(config.isCompressionEnabled())
.setMaxContinuations(config.getMaxContinuations())
.setPingPolicy(config.getPingPolicy());
}

public static class Builder {
Expand All @@ -155,6 +169,7 @@ public static class Builder {
private int maxHeaderListSize;
private boolean compressionEnabled;
private int maxContinuations;
private H2PingPolicy pingPolicy;

Builder() {
this.headerTableSize = INIT_HEADER_TABLE_SIZE * 2;
Expand All @@ -165,6 +180,7 @@ public static class Builder {
this.maxHeaderListSize = FrameConsts.MAX_FRAME_SIZE;
this.compressionEnabled = true;
this.maxContinuations = 100;
this.pingPolicy = null;
}

public Builder setHeaderTableSize(final int headerTableSize) {
Expand Down Expand Up @@ -211,14 +227,24 @@ public Builder setCompressionEnabled(final boolean compressionEnabled) {
* Sets max limit on number of continuations.
* <p>value zero represents no limit</p>
*
* @since 5,4
* @since 5.4
*/
public Builder setMaxContinuations(final int maxContinuations) {
Args.positive(maxContinuations, "Max continuations");
this.maxContinuations = maxContinuations;
return this;
}

/**
* Sets optional keep-alive PING policy.
*
* @since 5.5
*/
public Builder setPingPolicy(final H2PingPolicy pingPolicy) {
this.pingPolicy = pingPolicy;
return this;
}

public H2Config build() {
return new H2Config(
headerTableSize,
Expand All @@ -228,7 +254,8 @@ public H2Config build() {
maxFrameSize,
maxHeaderListSize,
compressionEnabled,
maxContinuations);
maxContinuations,
pingPolicy);
}

}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*
* ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/

package org.apache.hc.core5.http2.config;

import org.apache.hc.core5.util.Args;
import org.apache.hc.core5.util.TimeValue;
import org.apache.hc.core5.util.Timeout;

/**
* HTTP/2 keep-alive ping policy.
*
* @since 5.5
*/
public final class H2PingPolicy {

private static final H2PingPolicy DISABLED = new H2PingPolicy(Timeout.DISABLED, Timeout.DISABLED);

private final Timeout idleTime;
private final Timeout ackTimeout;

private H2PingPolicy(final Timeout idleTime, final Timeout ackTimeout) {
this.idleTime = idleTime;
this.ackTimeout = ackTimeout;
}

public static H2PingPolicy disabled() {
return DISABLED;
}

public static Builder custom() {
return new Builder();
}

public Timeout getIdleTime() {
return idleTime;
}

public Timeout getAckTimeout() {
return ackTimeout;
}

public boolean isEnabled() {
return isActive(idleTime) && isActive(ackTimeout);
}

private static boolean isActive(final Timeout timeout) {
return timeout != null && timeout.isEnabled() && TimeValue.isPositive(timeout);
}

public static final class Builder {

private Timeout idleTime;
private Timeout ackTimeout;

private Builder() {
this.idleTime = Timeout.DISABLED;
this.ackTimeout = Timeout.DISABLED;
}

public Builder setIdleTime(final Timeout idleTime) {
this.idleTime = Args.notNull(idleTime, "idleTime");
return this;
}

public Builder setAckTimeout(final Timeout ackTimeout) {
this.ackTimeout = Args.notNull(ackTimeout, "ackTimeout");
return this;
}

public H2PingPolicy build() {
if (isActive(idleTime)) {
Args.check(isActive(ackTimeout), "ackTimeout must be positive when idleTime is enabled");
}
return new H2PingPolicy(idleTime, ackTimeout);
}
}

}
Loading
Loading