View Javadoc

1   /*
2    * Copyright 2010 The Apache Software Foundation
3    *
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *     http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing, software
15   * distributed under the License is distributed on an "AS IS" BASIS,
16   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17   * See the License for the specific language governing permissions and
18   * limitations under the License.
19   */
20  package org.apache.hadoop.hbase.ipc;
21  
22  import java.io.DataInput;
23  import java.io.DataOutput;
24  import java.io.IOException;
25  
26  import org.apache.hadoop.io.Text;
27  import org.apache.hadoop.io.Writable;
28  import org.apache.hadoop.hbase.security.User;
29  
30  /**
31   * The IPC connection header sent by the client to the server
32   * on connection establishment.
33   */
34  class ConnectionHeader implements Writable {
35    protected String protocol;
36  
37    public ConnectionHeader() {}
38  
39    /**
40     * Create a new {@link ConnectionHeader} with the given <code>protocol</code>
41     * and {@link User}.
42     * @param protocol protocol used for communication between the IPC client
43     *                 and the server
44     * @param user {@link User} of the client communicating with
45     *            the server
46     */
47    public ConnectionHeader(String protocol, User user) {
48      this.protocol = protocol;
49    }
50  
51    @Override
52    public void readFields(DataInput in) throws IOException {
53      protocol = Text.readString(in);
54      if (protocol.isEmpty()) {
55        protocol = null;
56      }
57    }
58  
59    @Override
60    public void write(DataOutput out) throws IOException {
61      Text.writeString(out, (protocol == null) ? "" : protocol);
62    }
63  
64    public String getProtocol() {
65      return protocol;
66    }
67  
68    public User getUser() {
69      return null;
70    }
71  
72    public String toString() {
73      return protocol;
74    }
75  }