Home | History | Annotate | Download | only in internal
      1 /*
      2  * Copyright 2016 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.internal;
     18 
     19 import static com.google.common.base.Preconditions.checkNotNull;
     20 
     21 import com.google.common.base.Objects;
     22 import io.grpc.CallOptions;
     23 import io.grpc.LoadBalancer.PickSubchannelArgs;
     24 import io.grpc.Metadata;
     25 import io.grpc.MethodDescriptor;
     26 
     27 final class PickSubchannelArgsImpl extends PickSubchannelArgs {
     28   private final CallOptions callOptions;
     29   private final Metadata headers;
     30   private final MethodDescriptor<?, ?> method;
     31 
     32   /**
     33    * Creates call args object for given method with its call options, metadata.
     34    */
     35   PickSubchannelArgsImpl(MethodDescriptor<?, ?> method, Metadata headers, CallOptions callOptions) {
     36     this.method = checkNotNull(method, "method");
     37     this.headers = checkNotNull(headers, "headers");
     38     this.callOptions = checkNotNull(callOptions, "callOptions");
     39   }
     40 
     41   @Override
     42   public Metadata getHeaders() {
     43     return headers;
     44   }
     45 
     46   @Override
     47   public CallOptions getCallOptions() {
     48     return callOptions;
     49   }
     50 
     51   @Override
     52   public MethodDescriptor<?, ?> getMethodDescriptor() {
     53     return method;
     54   }
     55 
     56   @Override
     57   public boolean equals(Object o) {
     58     if (this == o) {
     59       return true;
     60     }
     61     if (o == null || getClass() != o.getClass()) {
     62       return false;
     63     }
     64     PickSubchannelArgsImpl that = (PickSubchannelArgsImpl) o;
     65     return Objects.equal(callOptions, that.callOptions)
     66         && Objects.equal(headers, that.headers)
     67         && Objects.equal(method, that.method);
     68   }
     69 
     70   @Override
     71   public int hashCode() {
     72     return Objects.hashCode(callOptions, headers, method);
     73   }
     74 
     75   @Override
     76   public final String toString() {
     77     return "[method=" + method + " headers=" + headers + " callOptions=" + callOptions + "]";
     78   }
     79 }
     80