Java源码示例:net.bytebuddy.implementation.bind.annotation.SuperCall
示例1
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);
}
}
示例2
@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());
}
示例3
@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());
}
示例4
@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());
}
示例5
@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());
}
示例6
@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());
}
示例7
@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());
}
示例8
@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());
}
示例9
@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);
}
示例10
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));
}
示例11
@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));
}
}
示例12
@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 );
}
示例13
/**
* 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;
}
示例14
@SuppressWarnings("unused")
@RuntimeType
public Object invoke(@SuperCall Callable<Object> superMethod, @AllArguments @RuntimeType Object[] args) throws Throwable {
return superMethod.call();
}
示例15
public String intercept(@SuperCall Callable<String> zuper) throws Exception {
return zuper.call() + BAR;
}
示例16
public static void foo(@SuperCall Runnable runnable) {
assertThat(runnable, CoreMatchers.not(instanceOf(Serializable.class)));
runnable.run();
}
示例17
public static String bar(@SuperCall Callable<String> callable) throws Exception {
assertThat(callable, CoreMatchers.not(instanceOf(Serializable.class)));
return callable.call();
}
示例18
public static Object foo(@SuperCall Callable<?> zuper) throws Exception {
return zuper.call();
}
示例19
@RuntimeType
public static Object foo(@SuperCall Callable<?> zuper) throws Exception {
return zuper.call();
}
示例20
public static String bar(@SuperCall String value) throws Exception {
return value;
}
示例21
public static String bar(@SuperCall(serializableProxy = true) Callable<String> callable) throws Exception {
assertThat(callable, instanceOf(Serializable.class));
return callable.call();
}
示例22
@RuntimeType
public static Object foo(@SuperCall(fallbackToDefault = false) Callable<?> zuper) throws Exception {
return null;
}
示例23
public static String intercept(@SuperCall Callable<String> zuper) throws Exception {
return zuper.call() + BAR;
}