001/**
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.hadoop.hdfs.server.namenode.ha;
019
020import java.io.IOException;
021
022import org.apache.hadoop.io.retry.FailoverProxyProvider;
023
024/**
025 * A NNFailoverProxyProvider implementation which wrapps old implementations
026 * directly implementing the {@link FailoverProxyProvider} interface.
027 *
028 * It is assumed that the old impelmentation is using logical URI.
029 */
030public class WrappedFailoverProxyProvider<T> extends
031    AbstractNNFailoverProxyProvider<T> {
032  private final FailoverProxyProvider<T> proxyProvider;
033
034  /**
035   * Wrap the given instance of an old FailoverProxyProvider.
036   */
037  public WrappedFailoverProxyProvider(FailoverProxyProvider<T> provider) {
038    proxyProvider = provider;
039  }
040
041  @Override
042  public Class<T> getInterface() {
043    return proxyProvider.getInterface();
044  }
045
046  @Override
047  public synchronized ProxyInfo<T> getProxy() {
048    return proxyProvider.getProxy();
049  }
050
051  @Override
052  public void performFailover(T currentProxy) {
053    proxyProvider.performFailover(currentProxy);
054  }
055
056  /**
057   * Close the proxy,
058   */
059  @Override
060  public synchronized void close() throws IOException {
061    proxyProvider.close();
062  }
063
064  /**
065   * Assume logical URI is used for old proxy provider implementations.
066   */
067  @Override
068  public boolean useLogicalURI() {
069    return true;
070  }
071}