@Override public <T extends CoprocessorProtocol> boolean registerProtocol( Class<T> protocol, T handler) { /* No stacking of protocol handlers is currently allowed. The * first to claim wins! */ if (protocolHandlers.containsKey(protocol)) { LOG.error("Protocol "+protocol.getName()+ " already registered, rejecting request from "+ handler ); return false; } protocolHandlers.putInstance(protocol, handler); protocolHandlerNames.put(protocol.getName(), protocol); if (LOG.isDebugEnabled()) { LOG.debug("Registered master protocol handler: protocol="+protocol.getName()); } return true; }
/** * Registers a new CoprocessorProtocol subclass and instance to be available for handling * {@link HRegion#exec(Exec)} calls. * <p> * Only a single protocol type/handler combination may be registered per region. After the first * registration, subsequent calls with the same protocol type will fail with a return value of * {@code false}. * </p> * @param protocol a {@code CoprocessorProtocol} subinterface defining the protocol methods * @param handler an instance implementing the interface * @param <T> the protocol type * @return {@code true} if the registration was successful, {@code false} otherwise */ public <T extends CoprocessorProtocol> boolean registerProtocol(Class<T> protocol, T handler) { /* * No stacking of protocol handlers is currently allowed. The first to claim wins! */ if (protocolHandlers.containsKey(protocol)) { LOG.error("Protocol " + protocol.getName() + " already registered, rejecting request from " + handler); return false; } protocolHandlers.putInstance(protocol, handler); protocolHandlerNames.put(protocol.getName(), protocol); if (LOG.isDebugEnabled()) { LOG.debug("Registered protocol handler: region=" + Bytes.toStringBinary(getRegionName()) + " protocol=" + protocol.getName()); } return true; }
/** * {@inheritDoc} */ @Override public <T extends CoprocessorProtocol, R> Map<byte[],R> coprocessorExec( Class<T> protocol, byte[] startKey, byte[] endKey, Batch.Call<T,R> callable) throws IOException, Throwable { final Map<byte[],R> results = Collections.synchronizedMap(new TreeMap<byte[],R>( Bytes.BYTES_COMPARATOR)); coprocessorExec(protocol, startKey, endKey, callable, new Batch.Callback<R>(){ public void update(byte[] region, byte[] row, R value) { results.put(region, value); } }); return results; }
/** * Registers a new CoprocessorProtocol subclass and instance to * be available for handling {@link HRegion#exec(Exec)} calls. * * <p> * Only a single protocol type/handler combination may be registered per * region. * After the first registration, subsequent calls with the same protocol type * will fail with a return value of {@code false}. * </p> * @param protocol a {@code CoprocessorProtocol} subinterface defining the * protocol methods * @param handler an instance implementing the interface * @param <T> the protocol type * @return {@code true} if the registration was successful, {@code false} * otherwise */ public <T extends CoprocessorProtocol> boolean registerProtocol( Class<T> protocol, T handler) { /* No stacking of protocol handlers is currently allowed. The * first to claim wins! */ if (protocolHandlers.containsKey(protocol)) { LOG.error("Protocol "+protocol.getName()+ " already registered, rejecting request from "+ handler ); return false; } protocolHandlers.putInstance(protocol, handler); protocolHandlerNames.put(protocol.getName(), protocol); if (LOG.isDebugEnabled()) { LOG.debug("Registered protocol handler: region="+ Bytes.toStringBinary(getRegionName())+" protocol="+protocol.getName()); } return true; }
/** * {@inheritDoc} */ @Override public <T extends CoprocessorProtocol, R> Map<byte[],R> coprocessorExec( Class<T> protocol, byte[] startKey, byte[] endKey, Batch.Call<T,R> callable) throws IOException, Throwable { final Map<byte[],R> results = new TreeMap<byte[],R>( Bytes.BYTES_COMPARATOR); coprocessorExec(protocol, startKey, endKey, callable, new Batch.Callback<R>(){ public void update(byte[] region, byte[] row, R value) { results.put(region, value); } }); return results; }
@Override public RegionEnvironment createEnvironment(Class<?> implClass, Coprocessor instance, int priority, int seq, Configuration conf) { // Check if it's an Endpoint. // Due to current dynamic protocol design, Endpoint // uses a different way to be registered and executed. // It uses a visitor pattern to invoke registered Endpoint // method. for (Class c : implClass.getInterfaces()) { if (CoprocessorProtocol.class.isAssignableFrom(c)) { region.registerProtocol(c, (CoprocessorProtocol)instance); break; } } return new RegionEnvironment(instance, priority, seq, conf, region, rsServices); }
/** * {@inheritDoc} */ @Override public <T extends CoprocessorProtocol, R> Map<byte[], R> coprocessorExec(Class<T> protocol, byte[] startKey, byte[] endKey, Batch.Call<T, R> callable) throws IOException, Throwable { final Map<byte[], R> results = Collections.synchronizedMap(new TreeMap<byte[], R>(Bytes.BYTES_COMPARATOR)); coprocessorExec(protocol, startKey, endKey, callable, new Batch.Callback<R>() { public void update(byte[] region, byte[] row, R value) { results.put(region, value); } }); return results; }
/** * {@inheritDoc} */ @Override public <T extends CoprocessorProtocol, R> void coprocessorExec(Class<T> protocol, byte[] startKey, byte[] endKey, Batch.Call<T, R> callable, Batch.Callback<R> callback) throws IOException, Throwable { // get regions covered by the row range List<byte[]> keys = getStartKeysInRange(startKey, endKey); connection.processExecs(protocol, keys, tableName, pool, callable, callback); }
@Override public <T extends CoprocessorProtocol, R> void coprocessorExec( Class<T> protocol, byte[] startKey, byte[] endKey, Batch.Call<T, R> callable, Batch.Callback<R> callback) throws IOException, Throwable { table.coprocessorExec(protocol, startKey, endKey, callable, callback); }
/** * Creates a new {@link Batch.Call} instance that invokes a method * with the given parameters and returns the result. * * @param method the method reference to invoke * @param args zero or more arguments to be passed to the method * @param <T> the class type of the protocol implementation being invoked * @param <R> the return type for the method call * @return a {@code Callable} instance that will invoke the given method and * return the results * @see org.apache.hadoop.hbase.client.HTable#coprocessorExec(Class, byte[], byte[], org.apache.hadoop.hbase.client.coprocessor.Batch.Call, org.apache.hadoop.hbase.client.coprocessor.Batch.Callback) */ public static <T extends CoprocessorProtocol,R> Call<T,R> forMethod( final Method method, final Object... args) { return new Call<T,R>() { public R call(T instance) throws IOException { try { if (Proxy.isProxyClass(instance.getClass())) { InvocationHandler invoker = Proxy.getInvocationHandler(instance); return (R)invoker.invoke(instance, method, args); } else { LOG.warn("Non proxied invocation of method '"+method.getName()+"'!"); return (R)method.invoke(instance, args); } } catch (IllegalAccessException iae) { throw new IOException("Unable to invoke method '"+ method.getName()+"'", iae); } catch (InvocationTargetException ite) { throw new IOException(ite.toString(), ite); } catch (Throwable t) { throw new IOException(t.toString(), t); } } }; }
public Exec(Configuration configuration, byte[] row, Class<? extends CoprocessorProtocol> protocol, Method method, Object[] parameters) { super(method, protocol, parameters); this.conf = configuration; this.referenceRow = row; this.protocol = protocol; this.protocolName = protocol.getName(); }
@Override public <T extends CoprocessorProtocol, R> Map<byte[], R> coprocessorExec( Class<T> protocol, byte[] startKey, byte[] endKey, Batch.Call<T, R> callable) throws IOException, Throwable { throw new UnsupportedOperationException("coprocessorExec not implemented"); }
@Override public <T extends CoprocessorProtocol, R> void coprocessorExec( Class<T> protocol, byte[] startKey, byte[] endKey, Batch.Call<T, R> callable, Batch.Callback<R> callback) throws IOException, Throwable { throw new UnsupportedOperationException("coprocessorExec not implemented"); }
@Override public MasterEnvironment createEnvironment(final Class<?> implClass, final Coprocessor instance, final int priority, final int seq, final Configuration conf) { for (Class c : implClass.getInterfaces()) { if (CoprocessorProtocol.class.isAssignableFrom(c)) { masterServices.registerProtocol(c, (CoprocessorProtocol)instance); break; } } return new MasterEnvironment(implClass, instance, priority, seq, conf, masterServices); }
@Override public RegionEnvironment createEnvironment(Class<?> implClass, Coprocessor instance, int priority, int seq, Configuration conf) { // Check if it's an Endpoint. // Due to current dynamic protocol design, Endpoint // uses a different way to be registered and executed. // It uses a visitor pattern to invoke registered Endpoint // method. for (Class c : implClass.getInterfaces()) { if (CoprocessorProtocol.class.isAssignableFrom(c)) { region.registerProtocol(c, (CoprocessorProtocol)instance); break; } } ConcurrentMap<String, Object> classData; // make sure only one thread can add maps synchronized (sharedDataMap) { // as long as at least one RegionEnvironment holds on to its classData it will // remain in this map classData = (ConcurrentMap<String, Object>)sharedDataMap.get(implClass.getName()); if (classData == null) { classData = new ConcurrentHashMap<String, Object>(); sharedDataMap.put(implClass.getName(), classData); } } return new RegionEnvironment(instance, priority, seq, conf, region, rsServices, classData); }
@Override public <T extends CoprocessorProtocol, R> Map<byte[], R> coprocessorExec( Class<T> protocol, byte[] startKey, byte[] endKey, Call<T, R> callable) throws IOException, Throwable { // TODO Auto-generated method stub return null; }
@Override public <T extends CoprocessorProtocol, R> void coprocessorExec( Class<T> protocol, byte[] startKey, byte[] endKey, Call<T, R> callable, Callback<R> callback) throws IOException, Throwable { // TODO Auto-generated method stub }
public <T extends CoprocessorProtocol, R> Map<byte[], R> coprocessorExec( String tableName, Class<T> paramClass, byte[] paramArrayOfByte1, byte[] paramArrayOfByte2, Call<T, R> paramCall) throws IOException, Throwable { return poolableHConnection.coprocessorExec(tableName, paramClass, paramArrayOfByte1, paramArrayOfByte2, paramCall); }
public <T extends CoprocessorProtocol, R> void coprocessorExec( String tableName, Class<T> paramClass, byte[] paramArrayOfByte1, byte[] paramArrayOfByte2, Call<T, R> paramCall, Callback<R> paramCallback) throws IOException, Throwable { poolableHConnection.coprocessorExec(tableName, paramClass, paramArrayOfByte1, paramArrayOfByte2, paramCall, paramCallback); }
public <T extends CoprocessorProtocol, R> void coprocessorExec( Class<T> protocol, byte[] startKey, byte[] endKey, Batch.Call<T, R> callable, Batch.Callback<R> callback) throws IOException, Throwable { this.delegate.coprocessorExec(protocol, startKey, endKey, callable, callback); }
public <T extends CoprocessorProtocol> T coprocessorProxy(String tableName, Class<T> paramClass, byte[] paramArrayOfByte) { try { checkOpen(); HTableInterface table = getTable(tableName); return table.coprocessorProxy(paramClass, paramArrayOfByte); } catch (Exception e) { throw new RuntimeException(e); } }
public <T extends CoprocessorProtocol> T coprocessorProxy(String tableName, Class<T> paramClass, byte[] paramArrayOfByte) { try { return hzTemplate.coprocessorProxy(tableName, paramClass, paramArrayOfByte); } catch (Exception ex) { throw new HzBaoException(ex); } }
public <T extends CoprocessorProtocol, R> Map<byte[], R> coprocessorExec(String tableName, Class<T> paramClass, byte[] paramArrayOfByte1, byte[] paramArrayOfByte2, Call<T, R> paramCall) { try { return hzTemplate.coprocessorExec(tableName, paramClass, paramArrayOfByte1, paramArrayOfByte2, paramCall); } catch (Throwable ex) { throw new HzBaoException(ex); } }
public <T extends CoprocessorProtocol, R> void coprocessorExec(String tableName, Class<T> paramClass, byte[] paramArrayOfByte1, byte[] paramArrayOfByte2, Call<T, R> paramCall, Callback<R> paramCallback) { try { hzTemplate.coprocessorExec(tableName, paramClass, paramArrayOfByte1, paramArrayOfByte2, paramCall, paramCallback); } catch (Throwable ex) { throw new HzBaoException(ex); } }
public <T extends CoprocessorProtocol> T coprocessorProxy(String tableName, final Class<T> paramClass, final byte[] paramArrayOfByte) { return execute(tableName, new HzTableCallback<T>() { public T doInAction(HTableInterface table) throws HzTemplateException { try { return table.coprocessorProxy(paramClass, paramArrayOfByte); } catch (Exception ex) { throw new HzTemplateException(ex); } } }); }
@Override public <T extends CoprocessorProtocol, R> Map<byte[], R> coprocessorExec(String tableName, final Class<T> paramClass, final byte[] paramArrayOfByte1, final byte[] paramArrayOfByte2, final Call<T, R> paramCall) throws IOException, Throwable { return execute(tableName, new HzTableCallback<Map<byte[], R>>() { public Map<byte[], R> doInAction(HTableInterface table) throws HzTemplateException { try { return table.coprocessorExec(paramClass, paramArrayOfByte1, paramArrayOfByte2, paramCall); } catch (Throwable ex) { throw new HzTemplateException(ex); } } }); }
public <T extends CoprocessorProtocol, R> void coprocessorExec(String tableName, final Class<T> paramClass, final byte[] paramArrayOfByte1, final byte[] paramArrayOfByte2, final Call<T, R> paramCall, final Callback<R> paramCallback) throws IOException, Throwable { execute(tableName, new HzTableCallback<Object>() { public Object doInAction(HTableInterface table) throws HzTemplateException { try { table.coprocessorExec(paramClass, paramArrayOfByte1, paramArrayOfByte2, paramCall, paramCallback); return null; } catch (Throwable ex) { throw new HzTemplateException(ex); } } }); }