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     */
018    
019    package org.apache.hadoop.ipc.protocolPB;
020    
021    import java.io.Closeable;
022    import java.io.IOException;
023    
024    import org.apache.hadoop.ipc.ProtobufHelper;
025    import org.apache.hadoop.ipc.ProtocolMetaInterface;
026    import org.apache.hadoop.ipc.RPC;
027    import org.apache.hadoop.ipc.RpcClientUtil;
028    import org.apache.hadoop.ipc.RefreshCallQueueProtocol;
029    import org.apache.hadoop.ipc.proto.RefreshCallQueueProtocolProtos.RefreshCallQueueRequestProto;
030    import org.apache.hadoop.ipc.protocolPB.RefreshCallQueueProtocolPB;
031    
032    import com.google.protobuf.RpcController;
033    import com.google.protobuf.ServiceException;
034    
035    public class RefreshCallQueueProtocolClientSideTranslatorPB implements
036        ProtocolMetaInterface, RefreshCallQueueProtocol, Closeable {
037    
038      /** RpcController is not used and hence is set to null */
039      private final static RpcController NULL_CONTROLLER = null;
040      private final RefreshCallQueueProtocolPB rpcProxy;
041      
042      private final static RefreshCallQueueRequestProto
043      VOID_REFRESH_CALL_QUEUE_REQUEST =
044          RefreshCallQueueRequestProto.newBuilder().build();
045    
046      public RefreshCallQueueProtocolClientSideTranslatorPB(
047          RefreshCallQueueProtocolPB rpcProxy) {
048        this.rpcProxy = rpcProxy;
049      }
050    
051      @Override
052      public void close() throws IOException {
053        RPC.stopProxy(rpcProxy);
054      }
055    
056      @Override
057      public void refreshCallQueue() throws IOException {
058        try {
059          rpcProxy.refreshCallQueue(NULL_CONTROLLER,
060              VOID_REFRESH_CALL_QUEUE_REQUEST);
061        } catch (ServiceException se) {
062          throw ProtobufHelper.getRemoteException(se);
063        }
064      }
065    
066      @Override
067      public boolean isMethodSupported(String methodName) throws IOException {
068        return RpcClientUtil.isMethodSupported(rpcProxy,
069            RefreshCallQueueProtocolPB.class,
070            RPC.RpcKind.RPC_PROTOCOL_BUFFER,
071            RPC.getProtocolVersion(RefreshCallQueueProtocolPB.class),
072            methodName);
073      }
074    }