/** Construct a client-side proxy object that implements the named protocol, * talking to a server at the named address. */ public VersionedProtocol getProxy( Class<? extends VersionedProtocol> protocol, long clientVersion, InetSocketAddress addr, User ticket, Configuration conf, SocketFactory factory, int rpcTimeout) throws IOException { VersionedProtocol proxy = (VersionedProtocol) Proxy.newProxyInstance( protocol.getClassLoader(), new Class[] { protocol }, new Invoker(protocol, addr, ticket, conf, factory, rpcTimeout)); if (proxy instanceof VersionedProtocol) { long serverVersion = ((VersionedProtocol)proxy) .getProtocolVersion(protocol.getName(), clientVersion); if (serverVersion != clientVersion) { throw new HBaseRPC.VersionMismatch(protocol.getName(), clientVersion, serverVersion); } } return proxy; }
public Invoker(HBaseClient client, Class<? extends VersionedProtocol> protocol, InetSocketAddress address, User ticket, Configuration conf, int rpcTimeout) { this.protocol = protocol; this.address = address; this.ticket = ticket; this.client = client; this.rpcTimeout = rpcTimeout; }
/** Construct a client-side proxy object that implements the named protocol, * talking to a server at the named address. */ @Override public <T extends VersionedProtocol> T getProxy( Class<T> protocol, long clientVersion, InetSocketAddress addr, Configuration conf, int rpcTimeout) throws IOException { if (this.client == null) { throw new IOException("Client must be initialized by calling setConf(Configuration)"); } T proxy = (T) Proxy.newProxyInstance( protocol.getClassLoader(), new Class[] { protocol }, new Invoker(client, protocol, addr, userProvider.getCurrent(), conf, HBaseRPC.getRpcTimeout(rpcTimeout))); /* * TODO: checking protocol version only needs to be done once when we setup a new * HBaseClient.Connection. Doing it every time we retrieve a proxy instance is resulting * in unnecessary RPC traffic. */ long serverVersion = ((VersionedProtocol)proxy) .getProtocolVersion(protocol.getName(), clientVersion); if (serverVersion != clientVersion) { throw new HBaseRPC.VersionMismatch(protocol.getName(), clientVersion, serverVersion); } return proxy; }
/** Expert: Make multiple, parallel calls to a set of servers. */ @Override public Object[] call(Method method, Object[][] params, InetSocketAddress[] addrs, Class<? extends VersionedProtocol> protocol, User ticket, Configuration conf) throws IOException, InterruptedException { if (this.client == null) { throw new IOException("Client must be initialized by calling setConf(Configuration)"); } Invocation[] invocations = new Invocation[params.length]; for (int i = 0; i < params.length; i++) { invocations[i] = new Invocation(method, protocol, params[i]); } Writable[] wrappedValues = client.call(invocations, addrs, protocol, ticket); if (method.getReturnType() == Void.TYPE) { return null; } Object[] values = (Object[])Array.newInstance(method.getReturnType(), wrappedValues.length); for (int i = 0; i < values.length; i++) { if (wrappedValues[i] != null) { values[i] = ((HbaseObjectWritable)wrappedValues[i]).get(); } } return values; }
/** Construct a server for a protocol implementation instance listening on a * port and address. */ public Server getServer(Class<? extends VersionedProtocol> protocol, Object instance, Class<?>[] ifaces, String bindAddress, int port, int numHandlers, int metaHandlerCount, boolean verbose, Configuration conf, int highPriorityLevel) throws IOException { return new Server(instance, ifaces, conf, bindAddress, port, numHandlers, metaHandlerCount, verbose, highPriorityLevel); }
public Invoker(Class<? extends VersionedProtocol> protocol, InetSocketAddress address, User ticket, Configuration conf, SocketFactory factory, int rpcTimeout) { this.protocol = protocol; this.address = address; this.ticket = ticket; this.client = CLIENTS.getClient(conf, factory); this.rpcTimeout = rpcTimeout; }
/** Expert: Make multiple, parallel calls to a set of servers. */ public Object[] call(Method method, Object[][] params, InetSocketAddress[] addrs, Class<? extends VersionedProtocol> protocol, User ticket, Configuration conf) throws IOException, InterruptedException { Invocation[] invocations = new Invocation[params.length]; for (int i = 0; i < params.length; i++) invocations[i] = new Invocation(method, params[i]); HBaseClient client = CLIENTS.getClient(conf); try { Writable[] wrappedValues = client.call(invocations, addrs, protocol, ticket); if (method.getReturnType() == Void.TYPE) { return null; } Object[] values = (Object[])Array.newInstance(method.getReturnType(), wrappedValues.length); for (int i = 0; i < values.length; i++) if (wrappedValues[i] != null) values[i] = ((HbaseObjectWritable)wrappedValues[i]).get(); return values; } finally { CLIENTS.stopClient(client); } }
/** Construct a client-side proxy object that implements the named protocol, * talking to a server at the named address. */ @Override public <T extends VersionedProtocol> T getProxy( Class<T> protocol, long clientVersion, InetSocketAddress addr, Configuration conf, int rpcTimeout) throws IOException { if (this.client == null) { throw new IOException("Client must be initialized by calling setConf(Configuration)"); } T proxy = (T) Proxy.newProxyInstance( protocol.getClassLoader(), new Class[] { protocol }, new Invoker(client, protocol, addr, User.getCurrent(), conf, HBaseRPC.getRpcTimeout(rpcTimeout))); /* * TODO: checking protocol version only needs to be done once when we setup a new * HBaseClient.Connection. Doing it every time we retrieve a proxy instance is resulting * in unnecessary RPC traffic. */ long serverVersion = ((VersionedProtocol)proxy) .getProtocolVersion(protocol.getName(), clientVersion); if (serverVersion != clientVersion) { throw new HBaseRPC.VersionMismatch(protocol.getName(), clientVersion, serverVersion); } return proxy; }
private void initMethods(Class<? extends VersionedProtocol> protocol) { for (Method m : protocol.getDeclaredMethods()) { if (get(m.getName()) == null) create(m.getName()); } }
/** * Stop this proxy and release its invoker's resource * @param proxy the proxy to be stopped */ public void stopProxy(VersionedProtocol proxy) { if (proxy!=null) { ((Invoker)Proxy.getInvocationHandler(proxy)).close(); } }
/** Construct a client-side proxy object. */ VersionedProtocol getProxy(Class<? extends VersionedProtocol> protocol, long clientVersion, InetSocketAddress addr, User ticket, Configuration conf, SocketFactory factory, int rpcTimeout) throws IOException;
/** Stop this proxy. */ void stopProxy(VersionedProtocol proxy);
/** Expert: Make multiple, parallel calls to a set of servers. */ Object[] call(Method method, Object[][] params, InetSocketAddress[] addrs, Class<? extends VersionedProtocol> protocol, User ticket, Configuration conf) throws IOException, InterruptedException;
/** Construct a server for a protocol implementation instance. */ RpcServer getServer(Class<? extends VersionedProtocol> protocol, Object instance, Class<?>[] ifaces, String bindAddress, int port, int numHandlers, int metaHandlerCount, boolean verbose, Configuration conf, int highPriorityLevel) throws IOException;