1 /* 2 * Copyright 2021 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.netty; 18 19 import com.google.common.base.Preconditions; 20 import java.util.concurrent.TimeUnit; 21 22 /** 23 * A command to trigger close and allow streams naturally close. 24 */ 25 class GracefulServerCloseCommand extends WriteQueue.AbstractQueuedCommand { 26 private final String goAwayDebugString; 27 private final long graceTime; 28 private final TimeUnit graceTimeUnit; 29 GracefulServerCloseCommand(String goAwayDebugString)30 public GracefulServerCloseCommand(String goAwayDebugString) { 31 this(goAwayDebugString, -1, null); 32 } 33 GracefulServerCloseCommand( String goAwayDebugString, long graceTime, TimeUnit graceTimeUnit)34 public GracefulServerCloseCommand( 35 String goAwayDebugString, long graceTime, TimeUnit graceTimeUnit) { 36 this.goAwayDebugString = Preconditions.checkNotNull(goAwayDebugString, "goAwayDebugString"); 37 this.graceTime = graceTime; 38 this.graceTimeUnit = graceTimeUnit; 39 } 40 getGoAwayDebugString()41 public String getGoAwayDebugString() { 42 return goAwayDebugString; 43 } 44 45 /** Has no meaning if {@code getGraceTimeUnit() == null}. */ getGraceTime()46 public long getGraceTime() { 47 return graceTime; 48 } 49 getGraceTimeUnit()50 public TimeUnit getGraceTimeUnit() { 51 return graceTimeUnit; 52 } 53 } 54