static <U> U newProxyInstance( Class<U> interfaceClass, U localService, U remoteService, Future<Boolean> useLocalServiceFuture) { @SuppressWarnings("unchecked") U proxy = (U) Proxy.newProxyInstance( interfaceClass.getClassLoader(), new Class<?>[] { interfaceClass }, new LocalOrRemoteProxy<>(localService, remoteService, useLocalServiceFuture)); return proxy; }
@Override protected Object handleInvocation(Object proxy, Method method, Object[] args) throws Throwable { while (true) { try { return method.invoke(delegate(), args); } catch (InvocationTargetException e) { Throwable targetException = e.getTargetException(); if (targetException instanceof NotCurrentLeaderException) { Uninterruptibles.sleepUninterruptibly(10, TimeUnit.MILLISECONDS); continue; } throw targetException; } } }
LockService dynamicLockService = LocalOrRemoteProxy.newProxyInstance( LockService.class, localLock, remoteLock, useLocalServicesFuture); TimestampService dynamicTimeService = LocalOrRemoteProxy.newProxyInstance( TimestampService.class, localTime, remoteTime, useLocalServicesFuture); TimestampManagementService dynamicManagementService = LocalOrRemoteProxy.newProxyInstance( TimestampManagementService.class, localManagement, remoteManagement, useLocalServicesFuture); return ImmutableLockAndTimestampServices.builder()
LockService dynamicLockService = LocalOrRemoteProxy.newProxyInstance( LockService.class, localLock, remoteLock, useLocalServicesFuture); TimestampService dynamicTimeService = LocalOrRemoteProxy.newProxyInstance( TimestampService.class, localTime, remoteTime, useLocalServicesFuture); TimestampManagementService dynamicManagementService = LocalOrRemoteProxy.newProxyInstance( TimestampManagementService.class, localManagement, remoteManagement, useLocalServicesFuture); return ImmutableLockAndTimestampServices.builder()
static <U> U newProxyInstance( Class<U> interfaceClass, U localService, U remoteService, Future<Boolean> useLocalServiceFuture) { @SuppressWarnings("unchecked") U proxy = (U) Proxy.newProxyInstance( interfaceClass.getClassLoader(), new Class<?>[] { interfaceClass }, new LocalOrRemoteProxy<>(localService, remoteService, useLocalServiceFuture)); return proxy; }
@Override protected Object handleInvocation(Object proxy, Method method, Object[] args) throws Throwable { while (true) { try { return method.invoke(delegate(), args); } catch (InvocationTargetException e) { Throwable targetException = e.getTargetException(); if (targetException instanceof NotCurrentLeaderException) { Uninterruptibles.sleepUninterruptibly(10, TimeUnit.MILLISECONDS); continue; } throw targetException; } } }