/** * Creates a {@link ZKClientService} from the given {@link ZKClient} if the given {@link ZKClient} is an instance of * {@link ZKClientService} or is a {@link ForwardingZKClient} that eventually trace back to a delegate of type * {@link ZKClientService}. If such a {@link ZKClientService} instance is found, this method returns * an instance by invoking {@link #delegate(ZKClient, ZKClientService)} with the given {@link ZKClient} and * the {@link ZKClientService} found respectively. * * @param client The {@link ZKClient}. * @return A {@link ZKClientService}. * @throws IllegalArgumentException If no {@link ZKClientService} is found. */ public static ZKClientService delegate(ZKClient client) { ZKClient zkClient = client; while (!(zkClient instanceof ZKClientService) && zkClient instanceof ForwardingZKClient) { zkClient = ((ForwardingZKClient) zkClient).getDelegate(); } if (zkClient instanceof ZKClientService) { return delegate(client, (ZKClientService) zkClient); } throw new IllegalArgumentException("No ZKClientService found from the delegation hierarchy"); }
/** * Creates a {@link ZKClientService} from the given {@link ZKClient} if the given {@link ZKClient} is an instance of * {@link ZKClientService} or is a {@link ForwardingZKClient} that eventually trace back to a delegate of type * {@link ZKClientService}. If such a {@link ZKClientService} instance is found, this method returns * an instance by invoking {@link #delegate(ZKClient, ZKClientService)} with the given {@link ZKClient} and * the {@link ZKClientService} found respectively. * * @param client The {@link ZKClient}. * @return A {@link ZKClientService}. * @throws IllegalArgumentException If no {@link ZKClientService} is found. */ public static ZKClientService delegate(ZKClient client) { ZKClient zkClient = client; while (!(zkClient instanceof ZKClientService) && zkClient instanceof ForwardingZKClient) { zkClient = ((ForwardingZKClient) zkClient).getDelegate(); } if (zkClient instanceof ZKClientService) { return delegate(client, (ZKClientService) zkClient); } throw new IllegalArgumentException("No ZKClientService found from the delegation hierarchy"); }