Search in sources :

Example 96 with Method

use of java.lang.reflect.Method in project hbase by apache.

the class FanOutOneBlockAsyncDFSOutputHelper method createStorageTypeSetter.

private static StorageTypeSetter createStorageTypeSetter() throws NoSuchMethodException {
    Method setStorageTypeMethod = OpWriteBlockProto.Builder.class.getMethod("setStorageType", StorageTypeProto.class);
    ImmutableMap.Builder<String, StorageTypeProto> builder = ImmutableMap.builder();
    for (StorageTypeProto storageTypeProto : StorageTypeProto.values()) {
        builder.put(storageTypeProto.name(), storageTypeProto);
    }
    ImmutableMap<String, StorageTypeProto> name2ProtoEnum = builder.build();
    return new StorageTypeSetter() {

        @Override
        public OpWriteBlockProto.Builder set(OpWriteBlockProto.Builder builder, Enum<?> storageType) {
            Object protoEnum = name2ProtoEnum.get(storageType.name());
            try {
                setStorageTypeMethod.invoke(builder, protoEnum);
            } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
                throw new RuntimeException(e);
            }
            return builder;
        }
    };
}
Also used : StorageTypeProto(org.apache.hadoop.hdfs.protocol.proto.HdfsProtos.StorageTypeProto) Method(java.lang.reflect.Method) OpWriteBlockProto(org.apache.hadoop.hdfs.protocol.proto.DataTransferProtos.OpWriteBlockProto) ImmutableMap(com.google.common.collect.ImmutableMap) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 97 with Method

use of java.lang.reflect.Method in project hbase by apache.

the class AnnotationReadingPriorityFunction method getBasePriority.

/**
   * Get the priority for a given request from the header and the param
   * This doesn't consider which user is sending the request at all.
   * This doesn't consider annotations
   */
protected int getBasePriority(RequestHeader header, Message param) {
    if (param == null) {
        return HConstants.NORMAL_QOS;
    }
    // Trust the client-set priorities if set
    if (header.hasPriority()) {
        return header.getPriority();
    }
    String cls = param.getClass().getName();
    Class<? extends Message> rpcArgClass = argumentToClassMap.get(cls);
    RegionSpecifier regionSpecifier = null;
    //check whether the request has reference to meta region or now.
    try {
        // Check if the param has a region specifier; the pb methods are hasRegion and getRegion if
        // hasRegion returns true.  Not all listed methods have region specifier each time.  For
        // example, the ScanRequest has it on setup but thereafter relies on the scannerid rather than
        // send the region over every time.
        Method hasRegion = methodMap.get("hasRegion").get(rpcArgClass);
        if (hasRegion != null && (Boolean) hasRegion.invoke(param, (Object[]) null)) {
            Method getRegion = methodMap.get("getRegion").get(rpcArgClass);
            regionSpecifier = (RegionSpecifier) getRegion.invoke(param, (Object[]) null);
            Region region = rpcServices.getRegion(regionSpecifier);
            if (region.getRegionInfo().isSystemTable()) {
                if (LOG.isTraceEnabled()) {
                    LOG.trace("High priority because region=" + region.getRegionInfo().getRegionNameAsString());
                }
                return HConstants.SYSTEMTABLE_QOS;
            }
        }
    } catch (Exception ex) {
        // server and have it throw the exception if still an issue.  Just mark it normal priority.
        if (LOG.isTraceEnabled())
            LOG.trace("Marking normal priority after getting exception=" + ex);
        return HConstants.NORMAL_QOS;
    }
    if (param instanceof ScanRequest) {
        // scanner methods...
        ScanRequest request = (ScanRequest) param;
        if (!request.hasScannerId()) {
            return HConstants.NORMAL_QOS;
        }
        RegionScanner scanner = rpcServices.getScanner(request.getScannerId());
        if (scanner != null && scanner.getRegionInfo().isSystemTable()) {
            if (LOG.isTraceEnabled()) {
                // Scanner requests are small in size so TextFormat version should not overwhelm log.
                LOG.trace("High priority scanner request " + TextFormat.shortDebugString(request));
            }
            return HConstants.SYSTEMTABLE_QOS;
        }
    }
    return HConstants.NORMAL_QOS;
}
Also used : ScanRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.ScanRequest) Method(java.lang.reflect.Method) RegionSpecifier(org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.RegionSpecifier)

Example 98 with Method

use of java.lang.reflect.Method in project hbase by apache.

the class DirectMemoryUtils method destroyDirectByteBuffer.

/**
   * DirectByteBuffers are garbage collected by using a phantom reference and a
   * reference queue. Every once a while, the JVM checks the reference queue and
   * cleans the DirectByteBuffers. However, as this doesn't happen
   * immediately after discarding all references to a DirectByteBuffer, it's
   * easy to OutOfMemoryError yourself using DirectByteBuffers. This function
   * explicitly calls the Cleaner method of a DirectByteBuffer.
   * 
   * @param toBeDestroyed
   *          The DirectByteBuffer that will be "cleaned". Utilizes reflection.
   *          
   */
public static void destroyDirectByteBuffer(ByteBuffer toBeDestroyed) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, SecurityException, NoSuchMethodException {
    Preconditions.checkArgument(toBeDestroyed.isDirect(), "toBeDestroyed isn't direct!");
    Method cleanerMethod = toBeDestroyed.getClass().getMethod("cleaner");
    cleanerMethod.setAccessible(true);
    Object cleaner = cleanerMethod.invoke(toBeDestroyed);
    Method cleanMethod = cleaner.getClass().getMethod("clean");
    cleanMethod.setAccessible(true);
    cleanMethod.invoke(cleaner);
}
Also used : Method(java.lang.reflect.Method)

Example 99 with Method

use of java.lang.reflect.Method in project hbase by apache.

the class ProtobufUtil method toFilter.

/**
   * Convert a protocol buffer Filter to a client Filter
   *
   * @param proto the protocol buffer Filter to convert
   * @return the converted Filter
   */
@SuppressWarnings("unchecked")
public static Filter toFilter(FilterProtos.Filter proto) throws IOException {
    String type = proto.getName();
    final byte[] value = proto.getSerializedFilter().toByteArray();
    String funcName = "parseFrom";
    try {
        Class<? extends Filter> c = (Class<? extends Filter>) Class.forName(type, true, CLASS_LOADER);
        Method parseFrom = c.getMethod(funcName, byte[].class);
        if (parseFrom == null) {
            throw new IOException("Unable to locate function: " + funcName + " in type: " + type);
        }
        return (Filter) parseFrom.invoke(c, value);
    } catch (Exception e) {
        // In either case, let's not retry.
        throw new DoNotRetryIOException(e);
    }
}
Also used : Filter(org.apache.hadoop.hbase.filter.Filter) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) ByteString(com.google.protobuf.ByteString) Method(java.lang.reflect.Method) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) HBaseIOException(org.apache.hadoop.hbase.HBaseIOException) IOException(java.io.IOException) ServiceException(com.google.protobuf.ServiceException) DeserializationException(org.apache.hadoop.hbase.exceptions.DeserializationException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) HBaseIOException(org.apache.hadoop.hbase.HBaseIOException) IOException(java.io.IOException) RemoteException(org.apache.hadoop.ipc.RemoteException)

Example 100 with Method

use of java.lang.reflect.Method in project hbase by apache.

the class ParseFilter method parseSimpleFilterExpression.

/**
 * Constructs a filter object given a simple filter expression
 * <p>
 * @param filterStringAsByteArray filter string given by the user
 * @return filter object we constructed
 */
public Filter parseSimpleFilterExpression(byte[] filterStringAsByteArray) throws CharacterCodingException {
    String filterName = Bytes.toString(getFilterName(filterStringAsByteArray));
    ArrayList<byte[]> filterArguments = getFilterArguments(filterStringAsByteArray);
    if (!filterHashMap.containsKey(filterName)) {
        throw new IllegalArgumentException("Filter Name " + filterName + " not supported");
    }
    try {
        filterName = filterHashMap.get(filterName);
        Class<?> c = Class.forName(filterName);
        Class<?>[] argTypes = new Class[] { ArrayList.class };
        Method m = c.getDeclaredMethod("createFilterFromArguments", argTypes);
        return (Filter) m.invoke(null, filterArguments);
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    } catch (NoSuchMethodException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    }
    throw new IllegalArgumentException("Incorrect filter string " + new String(filterStringAsByteArray));
}
Also used : ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

Method (java.lang.reflect.Method)7234 Test (org.junit.Test)1402 InvocationTargetException (java.lang.reflect.InvocationTargetException)935 ArrayList (java.util.ArrayList)557 Field (java.lang.reflect.Field)498 IOException (java.io.IOException)463 HashMap (java.util.HashMap)279 Map (java.util.Map)232 PropertyDescriptor (java.beans.PropertyDescriptor)230 List (java.util.List)221 Annotation (java.lang.annotation.Annotation)174 Type (java.lang.reflect.Type)174 IndexedPropertyDescriptor (java.beans.IndexedPropertyDescriptor)168 BeanInfo (java.beans.BeanInfo)155 HashSet (java.util.HashSet)147 File (java.io.File)138 SimpleBeanInfo (java.beans.SimpleBeanInfo)128 FakeFox01BeanInfo (org.apache.harmony.beans.tests.support.mock.FakeFox01BeanInfo)128 URL (java.net.URL)114 ParameterizedType (java.lang.reflect.ParameterizedType)113