org.apache.hadoop.ipc.ProtocolTranslator Java Examples

The following examples show how to use org.apache.hadoop.ipc.ProtocolTranslator. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RetryInvocationHandler.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
static boolean isRpcInvocation(Object proxy) {
  if (proxy instanceof ProtocolTranslator) {
    proxy = ((ProtocolTranslator) proxy).getUnderlyingProxyObject();
  }
  if (!Proxy.isProxyClass(proxy.getClass())) {
    return false;
  }
  final InvocationHandler ih = Proxy.getInvocationHandler(proxy);
  return ih instanceof RpcInvocationHandler;
}
 
Example #2
Source File: TestRetryProxy.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * Test for {@link RetryInvocationHandler#isRpcInvocation(Object)}
 */
@Test
public void testRpcInvocation() throws Exception {
  // For a proxy method should return true
  final UnreliableInterface unreliable = (UnreliableInterface)
    RetryProxy.create(UnreliableInterface.class, unreliableImpl, RETRY_FOREVER);
  assertTrue(RetryInvocationHandler.isRpcInvocation(unreliable));
  
  // Embed the proxy in ProtocolTranslator
  ProtocolTranslator xlator = new ProtocolTranslator() {
    int count = 0;
    @Override
    public Object getUnderlyingProxyObject() {
      count++;
      return unreliable;
    }
    @Override
    public String toString() {
      return "" + count;
    }
  };
  
  // For a proxy wrapped in ProtocolTranslator method should return true
  assertTrue(RetryInvocationHandler.isRpcInvocation(xlator));
  // Ensure underlying proxy was looked at
  assertEquals(xlator.toString(), "1");
  
  // For non-proxy the method must return false
  assertFalse(RetryInvocationHandler.isRpcInvocation(new Object()));
}
 
Example #3
Source File: RetryInvocationHandler.java    From big-c with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
static boolean isRpcInvocation(Object proxy) {
  if (proxy instanceof ProtocolTranslator) {
    proxy = ((ProtocolTranslator) proxy).getUnderlyingProxyObject();
  }
  if (!Proxy.isProxyClass(proxy.getClass())) {
    return false;
  }
  final InvocationHandler ih = Proxy.getInvocationHandler(proxy);
  return ih instanceof RpcInvocationHandler;
}
 
Example #4
Source File: TestRetryProxy.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * Test for {@link RetryInvocationHandler#isRpcInvocation(Object)}
 */
@Test
public void testRpcInvocation() throws Exception {
  // For a proxy method should return true
  final UnreliableInterface unreliable = (UnreliableInterface)
    RetryProxy.create(UnreliableInterface.class, unreliableImpl, RETRY_FOREVER);
  assertTrue(RetryInvocationHandler.isRpcInvocation(unreliable));
  
  // Embed the proxy in ProtocolTranslator
  ProtocolTranslator xlator = new ProtocolTranslator() {
    int count = 0;
    @Override
    public Object getUnderlyingProxyObject() {
      count++;
      return unreliable;
    }
    @Override
    public String toString() {
      return "" + count;
    }
  };
  
  // For a proxy wrapped in ProtocolTranslator method should return true
  assertTrue(RetryInvocationHandler.isRpcInvocation(xlator));
  // Ensure underlying proxy was looked at
  assertEquals(xlator.toString(), "1");
  
  // For non-proxy the method must return false
  assertFalse(RetryInvocationHandler.isRpcInvocation(new Object()));
}