boolean idempotentOrAtMostOnce(Method method) throws NoSuchMethodException { final Method m = fpp.getInterface() .getMethod(method.getName(), method.getParameterTypes()); return m.isAnnotationPresent(Idempotent.class) || m.isAnnotationPresent(AtMostOnce.class); }
/** * Create a proxy for an interface of implementations of that interface using * the given {@link FailoverProxyProvider} and the same retry policy for each * method in the interface. * * @param iface the interface that the retry will implement * @param proxyProvider provides implementation instances whose methods should be retried * @param retryPolicy the policy for retrying or failing over method call failures * @return the retry proxy */ public static <T> Object create(Class<T> iface, FailoverProxyProvider<T> proxyProvider, RetryPolicy retryPolicy) { return Proxy.newProxyInstance( proxyProvider.getInterface().getClassLoader(), new Class<?>[] { iface }, new RetryInvocationHandler<T>(proxyProvider, retryPolicy) ); }
/** * Create a proxy for an interface of implementations of that interface using * the given {@link FailoverProxyProvider} and the a set of retry policies * specified by method name. If no retry policy is defined for a method then a * default of {@link RetryPolicies#TRY_ONCE_THEN_FAIL} is used. * * @param iface the interface that the retry will implement * @param proxyProvider provides implementation instances whose methods should be retried * @param methodNameToPolicyMapa map of method names to retry policies * @return the retry proxy */ public static <T> Object create(Class<T> iface, FailoverProxyProvider<T> proxyProvider, Map<String,RetryPolicy> methodNameToPolicyMap, RetryPolicy defaultPolicy) { return Proxy.newProxyInstance( proxyProvider.getInterface().getClassLoader(), new Class<?>[] { iface }, new RetryInvocationHandler<T>(proxyProvider, defaultPolicy, methodNameToPolicyMap) ); } }
@Override public Class<T> getInterface() { return proxyProvider.getInterface(); }
@Override public Class<T> getInterface() { return proxyProvider.getInterface(); }
@Override public Class<T> getInterface() { return proxyProvider.getInterface(); }
boolean idempotentOrAtMostOnce(Method method) throws NoSuchMethodException { final Method m = fpp.getInterface() .getMethod(method.getName(), method.getParameterTypes()); return m.isAnnotationPresent(Idempotent.class) || m.isAnnotationPresent(AtMostOnce.class); }
/** * Create a proxy for an interface of implementations of that interface using * the given {@link FailoverProxyProvider} and the same retry policy for each * method in the interface. * * @param iface the interface that the retry will implement * @param proxyProvider provides implementation instances whose methods should be retried * @param retryPolicy the policy for retrying or failing over method call failures * @return the retry proxy */ public static <T> Object create(Class<T> iface, FailoverProxyProvider<T> proxyProvider, RetryPolicy retryPolicy) { return Proxy.newProxyInstance( proxyProvider.getInterface().getClassLoader(), new Class<?>[] { iface }, new RetryInvocationHandler<T>(proxyProvider, retryPolicy) ); }
/** * Create a proxy for an interface of implementations of that interface using * the given {@link FailoverProxyProvider} and the same retry policy for each * method in the interface. * * @param iface the interface that the retry will implement * @param proxyProvider provides implementation instances whose methods should be retried * @param retryPolicy the policy for retrying or failing over method call failures * @return the retry proxy */ public static <T> Object create(Class<T> iface, FailoverProxyProvider<T> proxyProvider, RetryPolicy retryPolicy) { return Proxy.newProxyInstance( proxyProvider.getInterface().getClassLoader(), new Class<?>[] { iface }, new RetryInvocationHandler<T>(proxyProvider, retryPolicy) ); }
/** * Create a proxy for an interface of implementations of that interface using * the given {@link FailoverProxyProvider} and the same retry policy for each * method in the interface. * * @param iface the interface that the retry will implement * @param proxyProvider provides implementation instances whose methods should be retried * @param retryPolicy the policy for retrying or failing over method call failures * @return the retry proxy */ public static <T> Object create(Class<T> iface, FailoverProxyProvider<T> proxyProvider, RetryPolicy retryPolicy) { return Proxy.newProxyInstance( proxyProvider.getInterface().getClassLoader(), new Class<?>[] { iface }, new RetryInvocationHandler<T>(proxyProvider, retryPolicy) ); }
/** * Create a proxy for an interface of implementations of that interface using * the given {@link FailoverProxyProvider} and the same retry policy for each * method in the interface. * * @param iface the interface that the retry will implement * @param proxyProvider provides implementation instances whose methods should be retried * @param retryPolicy the policy for retrying or failing over method call failures * @return the retry proxy */ public static <T> Object create(Class<T> iface, FailoverProxyProvider<T> proxyProvider, RetryPolicy retryPolicy) { return Proxy.newProxyInstance( proxyProvider.getInterface().getClassLoader(), new Class<?>[] { iface }, new RetryInvocationHandler<T>(proxyProvider, retryPolicy) ); }
/** * Create a proxy for an interface of implementations of that interface using * the given {@link FailoverProxyProvider} and the a set of retry policies * specified by method name. If no retry policy is defined for a method then a * default of {@link RetryPolicies#TRY_ONCE_THEN_FAIL} is used. * * @param iface the interface that the retry will implement * @param proxyProvider provides implementation instances whose methods should be retried * @param methodNameToPolicyMapa map of method names to retry policies * @return the retry proxy */ public static <T> Object create(Class<T> iface, FailoverProxyProvider<T> proxyProvider, Map<String,RetryPolicy> methodNameToPolicyMap, RetryPolicy defaultPolicy) { return Proxy.newProxyInstance( proxyProvider.getInterface().getClassLoader(), new Class<?>[] { iface }, new RetryInvocationHandler<T>(proxyProvider, defaultPolicy, methodNameToPolicyMap) ); } }
/** * Create a proxy for an interface of implementations of that interface using * the given {@link FailoverProxyProvider} and the a set of retry policies * specified by method name. If no retry policy is defined for a method then a * default of {@link RetryPolicies#TRY_ONCE_THEN_FAIL} is used. * * @param iface the interface that the retry will implement * @param proxyProvider provides implementation instances whose methods should be retried * @param methodNameToPolicyMapa map of method names to retry policies * @return the retry proxy */ public static <T> Object create(Class<T> iface, FailoverProxyProvider<T> proxyProvider, Map<String,RetryPolicy> methodNameToPolicyMap, RetryPolicy defaultPolicy) { return Proxy.newProxyInstance( proxyProvider.getInterface().getClassLoader(), new Class<?>[] { iface }, new RetryInvocationHandler<T>(proxyProvider, defaultPolicy, methodNameToPolicyMap) ); } }
/** * Create a proxy for an interface of implementations of that interface using * the given {@link FailoverProxyProvider} and the a set of retry policies * specified by method name. If no retry policy is defined for a method then a * default of {@link RetryPolicies#TRY_ONCE_THEN_FAIL} is used. * * @param iface the interface that the retry will implement * @param proxyProvider provides implementation instances whose methods should be retried * @param methodNameToPolicyMapa map of method names to retry policies * @return the retry proxy */ public static <T> Object create(Class<T> iface, FailoverProxyProvider<T> proxyProvider, Map<String,RetryPolicy> methodNameToPolicyMap, RetryPolicy defaultPolicy) { return Proxy.newProxyInstance( proxyProvider.getInterface().getClassLoader(), new Class<?>[] { iface }, new RetryInvocationHandler<T>(proxyProvider, defaultPolicy, methodNameToPolicyMap) ); } }
/** * Create a proxy for an interface of implementations of that interface using * the given {@link FailoverProxyProvider} and the a set of retry policies * specified by method name. If no retry policy is defined for a method then a * default of {@link RetryPolicies#TRY_ONCE_THEN_FAIL} is used. * * @param iface the interface that the retry will implement * @param proxyProvider provides implementation instances whose methods should be retried * @param methodNameToPolicyMapa map of method names to retry policies * @return the retry proxy */ public static <T> Object create(Class<T> iface, FailoverProxyProvider<T> proxyProvider, Map<String,RetryPolicy> methodNameToPolicyMap, RetryPolicy defaultPolicy) { return Proxy.newProxyInstance( proxyProvider.getInterface().getClassLoader(), new Class<?>[] { iface }, new RetryInvocationHandler<T>(proxyProvider, defaultPolicy, methodNameToPolicyMap) ); } }
boolean isIdempotentOrAtMostOnce = proxyProvider.getInterface() .getMethod(method.getName(), method.getParameterTypes()) .isAnnotationPresent(Idempotent.class); if (!isIdempotentOrAtMostOnce) { isIdempotentOrAtMostOnce = proxyProvider.getInterface() .getMethod(method.getName(), method.getParameterTypes()) .isAnnotationPresent(AtMostOnce.class);
boolean isIdempotentOrAtMostOnce = proxyProvider.getInterface() .getMethod(method.getName(), method.getParameterTypes()) .isAnnotationPresent(Idempotent.class); if (!isIdempotentOrAtMostOnce) { isIdempotentOrAtMostOnce = proxyProvider.getInterface() .getMethod(method.getName(), method.getParameterTypes()) .isAnnotationPresent(AtMostOnce.class);
boolean isIdempotentOrAtMostOnce = proxyProvider.getInterface() .getMethod(method.getName(), method.getParameterTypes()) .isAnnotationPresent(Idempotent.class); if (!isIdempotentOrAtMostOnce) { isIdempotentOrAtMostOnce = proxyProvider.getInterface() .getMethod(method.getName(), method.getParameterTypes()) .isAnnotationPresent(AtMostOnce.class);
private DFSClient genClientWithDummyHandler() throws IOException { URI nnUri = dfs.getUri(); FailoverProxyProvider<ClientProtocol> failoverProxyProvider = NameNodeProxies.createFailoverProxyProvider(conf, nnUri, ClientProtocol.class, true, null); InvocationHandler dummyHandler = new DummyRetryInvocationHandler( failoverProxyProvider, RetryPolicies .failoverOnNetworkException(RetryPolicies.TRY_ONCE_THEN_FAIL, Integer.MAX_VALUE, DFSConfigKeys.DFS_CLIENT_FAILOVER_SLEEPTIME_BASE_DEFAULT, DFSConfigKeys.DFS_CLIENT_FAILOVER_SLEEPTIME_MAX_DEFAULT)); ClientProtocol proxy = (ClientProtocol) Proxy.newProxyInstance( failoverProxyProvider.getInterface().getClassLoader(), new Class[] { ClientProtocol.class }, dummyHandler); DFSClient client = new DFSClient(null, proxy, conf, null); return client; }