svn merge -c 1505610 from trunk for HADOOP-9754. Remove unnecessary "throws IOException/InterruptedException", and fix generic and other javac warnings.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2@1505613 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Tsz-wo Sze 2013-07-22 07:41:33 +00:00
parent 9b8a60f44f
commit dbf8d190d2
14 changed files with 53 additions and 67 deletions

View File

@ -208,6 +208,9 @@ Release 2.1.0-beta - 2013-07-02
HADOOP-9751. Add clientId and retryCount to RpcResponseHeaderProto.
(szetszwo)
HADOOP-9754. Remove unnecessary "throws IOException/InterruptedException",
and fix generic and other javac warnings. (szetszwo)
OPTIMIZATIONS
HADOOP-9150. Avoid unnecessary DNS resolution attempts for logical URIs

View File

@ -36,10 +36,10 @@ public class RetryProxy {
* @param retryPolicy the policy for retrying method call failures
* @return the retry proxy
*/
public static Object create(Class<?> iface, Object implementation,
public static <T> Object create(Class<T> iface, T implementation,
RetryPolicy retryPolicy) {
return RetryProxy.create(iface,
new DefaultFailoverProxyProvider(iface, implementation),
new DefaultFailoverProxyProvider<T>(iface, implementation),
retryPolicy);
}
@ -53,8 +53,8 @@ public class RetryProxy {
* @param retryPolicy the policy for retrying or failing over method call failures
* @return the retry proxy
*/
public static Object create(Class<?> iface, FailoverProxyProvider proxyProvider,
RetryPolicy retryPolicy) {
public static <T> Object create(Class<T> iface,
FailoverProxyProvider<T> proxyProvider, RetryPolicy retryPolicy) {
return Proxy.newProxyInstance(
proxyProvider.getInterface().getClassLoader(),
new Class<?>[] { iface },
@ -73,10 +73,10 @@ public class RetryProxy {
* @param methodNameToPolicyMap a map of method names to retry policies
* @return the retry proxy
*/
public static Object create(Class<?> iface, Object implementation,
public static <T> Object create(Class<T> iface, T implementation,
Map<String,RetryPolicy> methodNameToPolicyMap) {
return create(iface,
new DefaultFailoverProxyProvider(iface, implementation),
new DefaultFailoverProxyProvider<T>(iface, implementation),
methodNameToPolicyMap,
RetryPolicies.TRY_ONCE_THEN_FAIL);
}
@ -92,7 +92,8 @@ public class RetryProxy {
* @param methodNameToPolicyMapa map of method names to retry policies
* @return the retry proxy
*/
public static Object create(Class<?> iface, FailoverProxyProvider proxyProvider,
public static <T> Object create(Class<T> iface,
FailoverProxyProvider<T> proxyProvider,
Map<String,RetryPolicy> methodNameToPolicyMap,
RetryPolicy defaultPolicy) {
return Proxy.newProxyInstance(

View File

@ -454,7 +454,7 @@ public class Client {
if (LOG.isDebugEnabled())
LOG.debug("Use " + authMethod + " authentication for protocol "
+ protocol.getSimpleName());
+ (protocol == null? null: protocol.getSimpleName()));
this.setName("IPC Client (" + socketFactory.hashCode() +") connection to " +
server.toString() +
@ -705,7 +705,7 @@ public class Client {
* a header to the server and starts
* the connection thread that waits for responses.
*/
private synchronized void setupIOstreams() throws InterruptedException {
private synchronized void setupIOstreams() {
if (socket != null || shouldCloseConnection.get()) {
return;
}
@ -1260,7 +1260,7 @@ public class Client {
* for RPC_BUILTIN
*/
public Writable call(Writable param, InetSocketAddress address)
throws InterruptedException, IOException {
throws IOException {
return call(RPC.RpcKind.RPC_BUILTIN, param, address);
}
@ -1272,7 +1272,7 @@ public class Client {
*/
@Deprecated
public Writable call(RPC.RpcKind rpcKind, Writable param, InetSocketAddress address)
throws InterruptedException, IOException {
throws IOException {
return call(rpcKind, param, address, null);
}
@ -1286,8 +1286,7 @@ public class Client {
*/
@Deprecated
public Writable call(RPC.RpcKind rpcKind, Writable param, InetSocketAddress addr,
UserGroupInformation ticket)
throws InterruptedException, IOException {
UserGroupInformation ticket) throws IOException {
ConnectionId remoteId = ConnectionId.getConnectionId(addr, null, ticket, 0,
conf);
return call(rpcKind, param, remoteId);
@ -1305,8 +1304,7 @@ public class Client {
@Deprecated
public Writable call(RPC.RpcKind rpcKind, Writable param, InetSocketAddress addr,
Class<?> protocol, UserGroupInformation ticket,
int rpcTimeout)
throws InterruptedException, IOException {
int rpcTimeout) throws IOException {
ConnectionId remoteId = ConnectionId.getConnectionId(addr, protocol,
ticket, rpcTimeout, conf);
return call(rpcKind, param, remoteId);
@ -1320,8 +1318,7 @@ public class Client {
*/
public Writable call(Writable param, InetSocketAddress addr,
Class<?> protocol, UserGroupInformation ticket,
int rpcTimeout, Configuration conf)
throws InterruptedException, IOException {
int rpcTimeout, Configuration conf) throws IOException {
ConnectionId remoteId = ConnectionId.getConnectionId(addr, protocol,
ticket, rpcTimeout, conf);
return call(RPC.RpcKind.RPC_BUILTIN, param, remoteId);
@ -1335,7 +1332,7 @@ public class Client {
public Writable call(Writable param, InetSocketAddress addr,
Class<?> protocol, UserGroupInformation ticket,
int rpcTimeout, int serviceClass, Configuration conf)
throws InterruptedException, IOException {
throws IOException {
ConnectionId remoteId = ConnectionId.getConnectionId(addr, protocol,
ticket, rpcTimeout, conf);
return call(RPC.RpcKind.RPC_BUILTIN, param, remoteId, serviceClass);
@ -1351,8 +1348,7 @@ public class Client {
*/
public Writable call(RPC.RpcKind rpcKind, Writable param, InetSocketAddress addr,
Class<?> protocol, UserGroupInformation ticket,
int rpcTimeout, Configuration conf)
throws InterruptedException, IOException {
int rpcTimeout, Configuration conf) throws IOException {
ConnectionId remoteId = ConnectionId.getConnectionId(addr, protocol,
ticket, rpcTimeout, conf);
return call(rpcKind, param, remoteId);
@ -1362,8 +1358,8 @@ public class Client {
* Same as {link {@link #call(RPC.RpcKind, Writable, ConnectionId)}
* except the rpcKind is RPC_BUILTIN
*/
public Writable call(Writable param, ConnectionId remoteId)
throws InterruptedException, IOException {
public Writable call(Writable param, ConnectionId remoteId)
throws IOException {
return call(RPC.RpcKind.RPC_BUILTIN, param, remoteId);
}
@ -1379,7 +1375,7 @@ public class Client {
* threw an exception.
*/
public Writable call(RPC.RpcKind rpcKind, Writable rpcRequest,
ConnectionId remoteId) throws InterruptedException, IOException {
ConnectionId remoteId) throws IOException {
return call(rpcKind, rpcRequest, remoteId, RPC.RPC_SERVICE_CLASS_DEFAULT);
}
@ -1396,8 +1392,7 @@ public class Client {
* threw an exception.
*/
public Writable call(RPC.RpcKind rpcKind, Writable rpcRequest,
ConnectionId remoteId, int serviceClass)
throws InterruptedException, IOException {
ConnectionId remoteId, int serviceClass) throws IOException {
final Call call = createCall(rpcKind, rpcRequest);
Connection connection = getConnection(remoteId, call, serviceClass);
try {
@ -1456,8 +1451,7 @@ public class Client {
/** Get a connection from the pool, or create a new one and add it to the
* pool. Connections to a given ConnectionId are reused. */
private Connection getConnection(ConnectionId remoteId,
Call call, int serviceClass)
throws IOException, InterruptedException {
Call call, int serviceClass) throws IOException {
if (!running.get()) {
// the client is stopped
throw new IOException("The client is stopped");

View File

@ -192,7 +192,6 @@ public class ProtobufRpcEngine implements RpcEngine {
}
RequestHeaderProto rpcRequestHeader = constructRpcRequestHeader(method);
RpcResponseWrapper val = null;
if (LOG.isTraceEnabled()) {
LOG.trace(Thread.currentThread().getId() + ": Call -> " +
@ -202,6 +201,7 @@ public class ProtobufRpcEngine implements RpcEngine {
Message theRequest = (Message) args[1];
final RpcResponseWrapper val;
try {
val = (RpcResponseWrapper) client.call(RPC.RpcKind.RPC_PROTOCOL_BUFFER,
new RpcRequestWrapper(rpcRequestHeader, theRequest), remoteId);

View File

@ -913,7 +913,7 @@ public class RPC {
// Register protocol and its impl for rpc calls
void registerProtocolAndImpl(RpcKind rpcKind, Class<?> protocolClass,
Object protocolImpl) throws IOException {
Object protocolImpl) {
String protocolName = RPC.getProtocolName(protocolClass);
long version;
@ -943,8 +943,6 @@ public class RPC {
}
}
@SuppressWarnings("unused") // will be useful later.
VerProtocolImpl[] getSupportedProtocolVersions(RPC.RpcKind rpcKind,
String protocolName) {
VerProtocolImpl[] resultk =
@ -999,8 +997,7 @@ public class RPC {
initProtocolMetaInfo(conf);
}
private void initProtocolMetaInfo(Configuration conf)
throws IOException {
private void initProtocolMetaInfo(Configuration conf) {
RPC.setProtocolEngine(conf, ProtocolMetaInfoPB.class,
ProtobufRpcEngine.class);
ProtocolMetaInfoServerSideTranslatorPB xlator =
@ -1018,7 +1015,7 @@ public class RPC {
* @return the server (for convenience)
*/
public Server addProtocol(RpcKind rpcKind, Class<?> protocolClass,
Object protocolImpl) throws IOException {
Object protocolImpl) {
registerProtocolAndImpl(rpcKind, protocolClass, protocolImpl);
return this;
}

View File

@ -909,11 +909,7 @@ public abstract class Server {
}
for(Call call : calls) {
try {
doPurge(call, now);
} catch (IOException e) {
LOG.warn("Error in purging old calls " + e);
}
doPurge(call, now);
}
} catch (OutOfMemoryError e) {
//
@ -958,7 +954,7 @@ public abstract class Server {
// Remove calls that have been pending in the responseQueue
// for a long time.
//
private void doPurge(Call call, long now) throws IOException {
private void doPurge(Call call, long now) {
LinkedList<Call> responseQueue = call.connection.responseQueue;
synchronized (responseQueue) {
Iterator<Call> iter = responseQueue.listIterator(0);
@ -1514,7 +1510,7 @@ public abstract class Server {
}
private AuthProtocol initializeAuthContext(int authType)
throws IOException, InterruptedException {
throws IOException {
AuthProtocol authProtocol = AuthProtocol.valueOf(authType);
if (authProtocol == null) {
IOException ioe = new IpcException("Unknown auth protocol:" + authType);
@ -1986,7 +1982,7 @@ public abstract class Server {
this.serviceClass = serviceClass;
}
private synchronized void close() throws IOException {
private synchronized void close() {
disposeSasl();
data = null;
dataLengthBuffer = null;
@ -2262,10 +2258,7 @@ public abstract class Server {
if (connectionList.remove(connection))
numConnections--;
}
try {
connection.close();
} catch (IOException e) {
}
connection.close();
}
/**

View File

@ -189,7 +189,7 @@ public class MiniRPCBenchmark {
MiniProtocol client = null;
try {
long start = Time.now();
client = (MiniProtocol) RPC.getProxy(MiniProtocol.class,
client = RPC.getProxy(MiniProtocol.class,
MiniProtocol.versionID, addr, conf);
long end = Time.now();
return end - start;
@ -211,7 +211,7 @@ public class MiniRPCBenchmark {
client = proxyUserUgi.doAs(new PrivilegedExceptionAction<MiniProtocol>() {
@Override
public MiniProtocol run() throws IOException {
MiniProtocol p = (MiniProtocol) RPC.getProxy(MiniProtocol.class,
MiniProtocol p = RPC.getProxy(MiniProtocol.class,
MiniProtocol.versionID, addr, conf);
Token<TestDelegationTokenIdentifier> token;
token = p.getDelegationToken(new Text(RENEWER));
@ -239,7 +239,7 @@ public class MiniRPCBenchmark {
client = currentUgi.doAs(new PrivilegedExceptionAction<MiniProtocol>() {
@Override
public MiniProtocol run() throws IOException {
return (MiniProtocol) RPC.getProxy(MiniProtocol.class,
return RPC.getProxy(MiniProtocol.class,
MiniProtocol.versionID, addr, conf);
}
});

View File

@ -31,7 +31,6 @@ import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.OptionBuilder;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.apache.hadoop.conf.Configurable;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.CommonConfigurationKeys;
import org.apache.hadoop.ipc.RPC.Server;
@ -55,7 +54,7 @@ import com.google.protobuf.BlockingService;
* Benchmark for protobuf RPC.
* Run with --help option for usage.
*/
public class RPCCallBenchmark implements Tool, Configurable {
public class RPCCallBenchmark implements Tool {
private Configuration conf;
private AtomicLong callCount = new AtomicLong(0);
private static ThreadMXBean threadBean =
@ -403,7 +402,7 @@ public class RPCCallBenchmark implements Tool, Configurable {
}
};
} else if (opts.rpcEngine == WritableRpcEngine.class) {
final TestProtocol proxy = (TestProtocol)RPC.getProxy(
final TestProtocol proxy = RPC.getProxy(
TestProtocol.class, TestProtocol.versionID, addr, conf);
return new RpcServiceWrapper() {
@Override

View File

@ -628,7 +628,7 @@ public class TestIPC {
}
@Test(timeout=30000, expected=IOException.class)
public void testIpcAfterStopping() throws IOException, InterruptedException {
public void testIpcAfterStopping() throws IOException {
// start server
Server server = new TestServer(5, false);
InetSocketAddress addr = NetUtils.getConnectAddress(server);
@ -920,7 +920,7 @@ public class TestIPC {
}
private void assertRetriesOnSocketTimeouts(Configuration conf,
int maxTimeoutRetries) throws IOException, InterruptedException {
int maxTimeoutRetries) throws IOException {
SocketFactory mockFactory = Mockito.mock(SocketFactory.class);
doThrow(new ConnectTimeoutException("fake")).when(mockFactory).createSocket();
Client client = new Client(IntWritable.class, conf, mockFactory);

View File

@ -64,7 +64,7 @@ public class TestMultipleProtocolServer {
public static final long versionID = 0L;
void hello() throws IOException;
}
interface Bar extends Mixin, VersionedProtocol {
interface Bar extends Mixin {
public static final long versionID = 0L;
int echo(int i) throws IOException;
}

View File

@ -57,7 +57,7 @@ public class TestRPCCompatibility {
void ping() throws IOException;
}
public interface TestProtocol1 extends VersionedProtocol, TestProtocol0 {
public interface TestProtocol1 extends TestProtocol0 {
String echo(String value) throws IOException;
}
@ -123,7 +123,7 @@ public class TestRPCCompatibility {
}
@After
public void tearDown() throws IOException {
public void tearDown() {
if (proxy != null) {
RPC.stopProxy(proxy.getProxy());
proxy = null;

View File

@ -334,7 +334,7 @@ public class TestSaslRPC {
TestSaslProtocol proxy = null;
try {
proxy = (TestSaslProtocol) RPC.getProxy(TestSaslProtocol.class,
proxy = RPC.getProxy(TestSaslProtocol.class,
TestSaslProtocol.versionID, addr, conf);
//QOP must be auth
Assert.assertEquals(SaslRpcServer.SASL_PROPS.get(Sasl.QOP), "auth");
@ -415,20 +415,20 @@ public class TestSaslRPC {
TestSaslProtocol proxy2 = null;
TestSaslProtocol proxy3 = null;
try {
proxy1 = (TestSaslProtocol) RPC.getProxy(TestSaslProtocol.class,
proxy1 = RPC.getProxy(TestSaslProtocol.class,
TestSaslProtocol.versionID, addr, newConf);
proxy1.getAuthMethod();
Client client = WritableRpcEngine.getClient(conf);
Set<ConnectionId> conns = client.getConnectionIds();
assertEquals("number of connections in cache is wrong", 1, conns.size());
// same conf, connection should be re-used
proxy2 = (TestSaslProtocol) RPC.getProxy(TestSaslProtocol.class,
proxy2 = RPC.getProxy(TestSaslProtocol.class,
TestSaslProtocol.versionID, addr, newConf);
proxy2.getAuthMethod();
assertEquals("number of connections in cache is wrong", 1, conns.size());
// different conf, new connection should be set up
newConf.set(SERVER_PRINCIPAL_KEY, SERVER_PRINCIPAL_2);
proxy3 = (TestSaslProtocol) RPC.getProxy(TestSaslProtocol.class,
proxy3 = RPC.getProxy(TestSaslProtocol.class,
TestSaslProtocol.versionID, addr, newConf);
proxy3.getAuthMethod();
ConnectionId[] connsArray = conns.toArray(new ConnectionId[0]);
@ -468,7 +468,7 @@ public class TestSaslRPC {
InetSocketAddress addr = NetUtils.getConnectAddress(server);
try {
proxy = (TestSaslProtocol) RPC.getProxy(TestSaslProtocol.class,
proxy = RPC.getProxy(TestSaslProtocol.class,
TestSaslProtocol.versionID, addr, newConf);
proxy.ping();
} finally {
@ -488,7 +488,7 @@ public class TestSaslRPC {
}
@Test
public void testSaslPlainServerBadPassword() throws IOException {
public void testSaslPlainServerBadPassword() {
SaslException e = null;
try {
runNegotiation(
@ -824,7 +824,7 @@ public class TestSaslRPC {
public String run() throws IOException {
TestSaslProtocol proxy = null;
try {
proxy = (TestSaslProtocol) RPC.getProxy(TestSaslProtocol.class,
proxy = RPC.getProxy(TestSaslProtocol.class,
TestSaslProtocol.versionID, addr, clientConf);
proxy.ping();

View File

@ -118,7 +118,7 @@ public class TestServer {
}
@Test
public void testExceptionsHandler() throws IOException {
public void testExceptionsHandler() {
Server.ExceptionsHandler handler = new Server.ExceptionsHandler();
handler.addTerseExceptions(IOException.class);
handler.addTerseExceptions(RpcServerException.class, IpcException.class);

View File

@ -297,9 +297,8 @@ public class NameNodeProxies {
return new ClientNamenodeProtocolTranslatorPB(proxy);
}
@SuppressWarnings("unchecked")
private static Object createNameNodeProxy(InetSocketAddress address,
Configuration conf, UserGroupInformation ugi, Class xface)
Configuration conf, UserGroupInformation ugi, Class<?> xface)
throws IOException {
RPC.setProtocolEngine(conf, xface, ProtobufRpcEngine.class);
Object proxy = RPC.getProxy(xface, RPC.getProtocolVersion(xface), address,