net.bytebuddy.implementation.bind.annotation.SuperCall Java Examples

The following examples show how to use net.bytebuddy.implementation.bind.annotation.SuperCall. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FileSystemTracer.java    From garmadon with Apache License 2.0 6 votes vote down vote up
private static Object executeMethod(@SuperCall Callable<?> zuper, String uri, String src, String dst, String fsAction, String username) throws Exception {
    long startTime = System.nanoTime();
    DataAccessEventProtos.FsEvent.Status status = DataAccessEventProtos.FsEvent.Status.SUCCESS;
    try {
        Object result = zuper.call();
        if (Boolean.FALSE.equals(result)) {
            status = DataAccessEventProtos.FsEvent.Status.FAILURE;
        }
        return result;
    } catch (Exception e) {
        status = DataAccessEventProtos.FsEvent.Status.FAILURE;
        throw e;
    } finally {
        long elapsedTime = (System.nanoTime() - startTime) / NANOSECONDS_PER_MILLISECOND;
        sendFsEvent(uri, src, dst, fsAction, username, elapsedTime, status);
    }
}
 
Example #2
Source File: FileSystemTracer.java    From garmadon with Apache License 2.0 5 votes vote down vote up
@RuntimeType
public static Object intercept(
    @SuperCall Callable<?> zuper,
    @This Object o,
    @Argument(0) Object dst) throws Exception {
    return callDistributedFileSystem(zuper, o, null, dst.toString(), FsAction.READ.name());
}
 
Example #3
Source File: TestActivity.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
/**
 * The interception method to be applied.
 *
 * @param zuper A proxy to call the super method to validate the functioning og creating an auxiliary type.
 * @return The value to be returned by the instrumented {@link Object#toString()} method.
 * @throws Exception If an exception occurs.
 */
public static String intercept(@SuperCall Callable<String> zuper) throws Exception {
    String toString = zuper.call();
    if (toString.equals(FOO)) {
        throw new IllegalStateException("Super call proxy invocation did not derive in its value");
    }
    return FOO;
}
 
Example #4
Source File: ByteBuddyMethodInterceptor.java    From JGiven with Apache License 2.0 5 votes vote down vote up
@RuntimeType
@BindingPriority( BindingPriority.DEFAULT * 3 )
public Object interceptSuper( @SuperCall final Callable<?> zuper, @This final Object receiver, @Origin Method method,
        @AllArguments final Object[] parameters,
        @FieldProxy( INTERCEPTOR_FIELD_NAME ) StepInterceptorGetterSetter stepInterceptorGetter )
        throws Throwable{

    StepInterceptor interceptor = (StepInterceptor) stepInterceptorGetter.getValue();

    if( interceptor == null ) {
        return zuper.call();
    }

    return interceptor.intercept( receiver, method, parameters, zuper::call );
}
 
Example #5
Source File: FileSystemTracer.java    From garmadon with Apache License 2.0 5 votes vote down vote up
@RuntimeType
public static Object intercept(
    @SuperCall Callable<?> zuper,
    @This Object o,
    @Argument(0) Object dst) throws Exception {
    return callDistributedFileSystem(zuper, o, null, dst.toString(), FsAction.DELETE.name());
}
 
Example #6
Source File: TimeInterceptor.java    From spring-cloud-gray with Apache License 2.0 5 votes vote down vote up
@RuntimeType
public static Object intercept(@Origin Method method,
                               @SuperCall Callable<?> callable) throws Exception {
    long start = System.nanoTime();
    try {
        // 原有函数执行
        return callable.call();
    } finally {
        PerformanceLogger.printMethodUsedTime(method.getDeclaringClass().getName() + "#" + method.getName(), (System.nanoTime() - start));
    }
}
 
Example #7
Source File: FileSystemTracer.java    From garmadon with Apache License 2.0 5 votes vote down vote up
private static Object callDistributedFileSystem(@SuperCall Callable<?> zuper, @This Object o, String src, String dst, String fsAction) throws Exception {
    ClassLoader classLoader = o.getClass().getClassLoader();
    Field dfsField = getField(classLoader, o.getClass().getName(), "dfs");
    Object dfs = dfsField.get(o);
    Field ugiField = getField(classLoader, "org.apache.hadoop.hdfs.DFSClient", "ugi");
    Object ugi = ugiField.get(dfs);
    Method getShortUserName = getMethod(classLoader, "org.apache.hadoop.security.UserGroupInformation", "getShortUserName");
    Method getUri = getMethod(classLoader, o.getClass().getName(), "getUri");
    return executeMethod(zuper, getUri.invoke(o).toString(), src, dst, fsAction, (String) getShortUserName.invoke(ugi));
}
 
Example #8
Source File: FileSystemTracer.java    From garmadon with Apache License 2.0 5 votes vote down vote up
@RuntimeType
public static Object intercept(
    @SuperCall Callable<?> zuper,
    @This Object o,
    @Argument(0) String dst) throws Exception {

    ClassLoader classLoader = o.getClass().getClassLoader();
    Field field = getField(classLoader, "org.apache.hadoop.hdfs.protocolPB.ClientNamenodeProtocolTranslatorPB", "rpcProxy");
    Object rpcProxy = field.get(o);

    Method getServerAddress = getMethod(classLoader, "org.apache.hadoop.ipc.RPC", "getServerAddress", Object.class);
    InetSocketAddress inetSocketAddress = (InetSocketAddress) getServerAddress.invoke(o, rpcProxy);
    return executeMethod(zuper, "hdfs://" + inetSocketAddress.getHostString() + ":" + inetSocketAddress.getPort(),
        null, dst, FsAction.ADD_BLOCK.name(), null);
}
 
Example #9
Source File: FileSystemTracer.java    From garmadon with Apache License 2.0 5 votes vote down vote up
@RuntimeType
public static Object intercept(
    @SuperCall Callable<?> zuper,
    @This Object o,
    @Argument(0) Object dst) throws Exception {
    return callDistributedFileSystem(zuper, o, null, dst.toString(), FsAction.GET_CONTENT_SUMMARY.name());
}
 
Example #10
Source File: FileSystemTracer.java    From garmadon with Apache License 2.0 5 votes vote down vote up
@RuntimeType
public static Object intercept(
    @SuperCall Callable<?> zuper,
    @This Object o,
    @Argument(0) Object dst) throws Exception {
    return callDistributedFileSystem(zuper, o, null, dst.toString(), FsAction.LIST_STATUS.name());
}
 
Example #11
Source File: FileSystemTracer.java    From garmadon with Apache License 2.0 5 votes vote down vote up
@RuntimeType
public static Object intercept(
    @SuperCall Callable<?> zuper,
    @This Object o,
    @Argument(0) Object dst) throws Exception {
    return callDistributedFileSystem(zuper, o, null, dst.toString(), FsAction.APPEND.name());
}
 
Example #12
Source File: FileSystemTracer.java    From garmadon with Apache License 2.0 5 votes vote down vote up
@RuntimeType
public static Object intercept(
    @SuperCall Callable<?> zuper,
    @This Object o,
    @Argument(0) Object dst) throws Exception {
    return callDistributedFileSystem(zuper, o, null, dst.toString(), FsAction.WRITE.name());
}
 
Example #13
Source File: FileSystemTracer.java    From garmadon with Apache License 2.0 5 votes vote down vote up
@RuntimeType
public static Object intercept(
    @SuperCall Callable<?> zuper,
    @This Object o,
    @Argument(0) Object src,
    @Argument(1) Object dst) throws Exception {
    return callDistributedFileSystem(zuper, o, src.toString(), dst.toString(), FsAction.RENAME.name());
}
 
Example #14
Source File: AbstractDynamicTypeBuilderTest.java    From byte-buddy with Apache License 2.0 4 votes vote down vote up
public static String intercept(@SuperCall Callable<String> zuper) throws Exception {
    return zuper.call() + BAR;
}
 
Example #15
Source File: MethodDelegationSuperCallTest.java    From byte-buddy with Apache License 2.0 4 votes vote down vote up
@RuntimeType
public static Object foo(@SuperCall(fallbackToDefault = false) Callable<?> zuper) throws Exception {
    return null;
}
 
Example #16
Source File: MethodDelegationSuperCallTest.java    From byte-buddy with Apache License 2.0 4 votes vote down vote up
public static String bar(@SuperCall(serializableProxy = true) Callable<String> callable) throws Exception {
    assertThat(callable, instanceOf(Serializable.class));
    return callable.call();
}
 
Example #17
Source File: MethodDelegationSuperCallTest.java    From byte-buddy with Apache License 2.0 4 votes vote down vote up
public static String bar(@SuperCall String value) throws Exception {
    return value;
}
 
Example #18
Source File: MethodDelegationSuperCallTest.java    From byte-buddy with Apache License 2.0 4 votes vote down vote up
@RuntimeType
public static Object foo(@SuperCall Callable<?> zuper) throws Exception {
    return zuper.call();
}
 
Example #19
Source File: MethodDelegationSuperCallTest.java    From byte-buddy with Apache License 2.0 4 votes vote down vote up
public static Object foo(@SuperCall Callable<?> zuper) throws Exception {
    return zuper.call();
}
 
Example #20
Source File: MethodDelegationSuperCallTest.java    From byte-buddy with Apache License 2.0 4 votes vote down vote up
public static String bar(@SuperCall Callable<String> callable) throws Exception {
    assertThat(callable, CoreMatchers.not(instanceOf(Serializable.class)));
    return callable.call();
}
 
Example #21
Source File: MethodDelegationSuperCallTest.java    From byte-buddy with Apache License 2.0 4 votes vote down vote up
public static void foo(@SuperCall Runnable runnable) {
    assertThat(runnable, CoreMatchers.not(instanceOf(Serializable.class)));
    runnable.run();
}
 
Example #22
Source File: AgentBuilderDefaultApplicationTest.java    From byte-buddy with Apache License 2.0 4 votes vote down vote up
public String intercept(@SuperCall Callable<String> zuper) throws Exception {
    return zuper.call() + BAR;
}
 
Example #23
Source File: MethodInvokeBenchmark.java    From Jupiter with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unused")
@RuntimeType
public Object invoke(@SuperCall Callable<Object> superMethod, @AllArguments @RuntimeType Object[] args) throws Throwable {
    return superMethod.call();
}