• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java Advice类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中net.bytebuddy.asm.Advice的典型用法代码示例。如果您正苦于以下问题:Java Advice类的具体用法?Java Advice怎么用?Java Advice使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Advice类属于net.bytebuddy.asm包,在下文中一共展示了Advice类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: monitorStart

import net.bytebuddy.asm.Advice; //导入依赖的package包/类
@Advice.OnMethodEnter(inline = false)
public static void monitorStart(@ParameterNames String parameterNames, @Advice.AllArguments Object[] args,
								@RequestName String requestName, @Advice.Origin("#t") String className,
								@Advice.Origin("#m") String methodName, @Advice.This(optional = true) Object thiz) {
	final String[] paramNames = parameterNames.split(",");
	Map<String, Object> params = new LinkedHashMap<String, Object>();
	for (int i = 0; i < args.length; i++) {
		params.put(paramNames[i], args[i]);
	}

	final MonitoredMethodRequest monitoredRequest = new MonitoredMethodRequest(Stagemonitor.getConfiguration(), requestName, null, params);
	final TracingPlugin tracingPlugin = Stagemonitor.getPlugin(TracingPlugin.class);
	tracingPlugin.getRequestMonitor().monitorStart(monitoredRequest);
	final Span span = TracingPlugin.getCurrentSpan();
	if (requestName == null) {
		span.setOperationName(getBusinessTransationName(thiz != null ? thiz.getClass().getName() : className, methodName));
	}
	span.setTag(MetricsSpanEventListener.ENABLE_TRACKING_METRICS_TAG, true);
}
 
开发者ID:stagemonitor,项目名称:stagemonitor,代码行数:20,代码来源:AbstractTracingTransformer.java


示例2: transform

import net.bytebuddy.asm.Advice; //导入依赖的package包/类
@Override
public DynamicType.Builder<?> transform(
        final DynamicType.Builder<?> builder,
        final TypeDescription typeDescription,
        final ClassLoader classLoader,
        final JavaModule module) {

    final AsmVisitorWrapper methodsVisitor =
            Advice.to(EnterAdvice.class, ExitAdviceMethods.class)
                    .on(ElementMatchers.isAnnotatedWith(CollectMetrics.class)
                            .and(ElementMatchers.isMethod()));

    final AsmVisitorWrapper constructorsVisitor =
            Advice.to(EnterAdvice.class, ExitAdviceConstructors.class)
                    .on(ElementMatchers.isAnnotatedWith(CollectMetrics.class)
                            .and(ElementMatchers.isConstructor()));

    return builder.visit(methodsVisitor).visit(constructorsVisitor);
}
 
开发者ID:ivanyu,项目名称:java-agents-demo,代码行数:20,代码来源:MetricsCollectionByteBuddyAgent.java


示例3: install

import net.bytebuddy.asm.Advice; //导入依赖的package包/类
public static void install() {
    ByteBuddyAgent.install();

    ClassLoader targetClassLoader = File.class.getClassLoader();

    // interceptor class must be injected to the same classloader as the target class that is intercepted
    new ByteBuddy().redefine(CountFileSystemOperations.class)
            .make()
            .load(targetClassLoader,
                    ClassReloadingStrategy.fromInstalledAgent());

    new ByteBuddy().redefine(DirectoryFileTree.class)
            .visit(new AsmVisitorWrapper.ForDeclaredMethods().writerFlags(ClassWriter.COMPUTE_FRAMES)
                    .method(ElementMatchers.named("length"), Advice.to(CountFileSystemOperations.LengthMethod.class))
                    .method(ElementMatchers.named("isFile"), Advice.to(CountFileSystemOperations.IsFileMethod.class))
                    .method(ElementMatchers.named("isDirectory"), Advice.to(CountFileSystemOperations.IsDirectoryMethod.class))
                    .method(ElementMatchers.named("lastModified"), Advice.to(CountFileSystemOperations.LastModifiedMethod.class))
                    .method(ElementMatchers.named("exists"), Advice.to(CountFileSystemOperations.ExistsMethod.class))

            )
            .make()
            .load(targetClassLoader,
                    ClassReloadingStrategy.fromInstalledAgent());
}
 
开发者ID:lhotari,项目名称:gradle-profiling,代码行数:25,代码来源:FileSystemOperationsInterceptor.java


示例4: install

import net.bytebuddy.asm.Advice; //导入依赖的package包/类
public static void install() {
    ByteBuddyAgent.install();

    ClassLoader targetClassLoader = DirectoryFileTree.class.getClassLoader();

    // interceptor class must be injected to the same classloader as the target class that is intercepted
    new ByteBuddy().redefine(CountDirectoryScans.class)
            .make()
            .load(targetClassLoader,
                    ClassReloadingStrategy.fromInstalledAgent());

    new ByteBuddy().redefine(DirectoryFileTree.class)
            .visit(new AsmVisitorWrapper.ForDeclaredMethods().writerFlags(ClassWriter.COMPUTE_FRAMES).method(ElementMatchers.named("visitFrom"), Advice.to(CountDirectoryScans.class)))
            .make()
            .load(targetClassLoader,
                    ClassReloadingStrategy.fromInstalledAgent());
}
 
开发者ID:lhotari,项目名称:gradle-profiling,代码行数:18,代码来源:DirectoryScanningInterceptor.java


示例5: ForAdvice

import net.bytebuddy.asm.Advice; //导入依赖的package包/类
/**
 * Creates a new advice transformer.
 *
 * @param advice           The configured advice to use.
 * @param exceptionHandler The exception handler to use.
 * @param assigner         The assigner to use.
 * @param classFileLocator The class file locator to use.
 * @param poolStrategy     The pool strategy to use for looking up an advice.
 * @param locationStrategy The location strategy to use for class loaders when resolving advice classes.
 * @param entries          The advice entries to apply.
 */
protected ForAdvice(Advice.WithCustomMapping advice,
                    StackManipulation exceptionHandler,
                    Assigner assigner,
                    ClassFileLocator classFileLocator,
                    PoolStrategy poolStrategy,
                    LocationStrategy locationStrategy,
                    List<Entry> entries) {
    this.advice = advice;
    this.exceptionHandler = exceptionHandler;
    this.assigner = assigner;
    this.classFileLocator = classFileLocator;
    this.poolStrategy = poolStrategy;
    this.locationStrategy = locationStrategy;
    this.entries = entries;
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:27,代码来源:AgentBuilder.java


示例6: addHandlers

import net.bytebuddy.asm.Advice; //导入依赖的package包/类
/**
 * This code might be executed in the context of the bootstrap class loader. That's why we have to make sure we only
 * call code which is visible. For example, we can't use slf4j or directly reference stagemonitor classes
 */
@Advice.OnMethodEnter
private static void addHandlers(@Advice.Argument(value = 0, readOnly = false) List<Handler> handlerChain, @Advice.This Binding binding) {
	final java.util.logging.Logger logger = java.util.logging.Logger.getLogger("org.stagemonitor.tracing.soap.SoapHandlerTransformer");
	final List<Handler<?>> stagemonitorHandlers = Dispatcher.get("org.stagemonitor.tracing.soap.SoapHandlerTransformer");

	if (stagemonitorHandlers != null) {
		logger.fine("Adding SOAPHandlers " + stagemonitorHandlers + " to handlerChain for Binding " + binding);
		if (handlerChain == null) {
			handlerChain = Collections.emptyList();
		}
		// creating a new list as we don't know if handlerChain is immutable or not
		handlerChain = new ArrayList<Handler>(handlerChain);
		for (Handler<?> stagemonitorHandler : stagemonitorHandlers) {
			if (!handlerChain.contains(stagemonitorHandler) &&
					// makes sure we only add the handler to the correct application
					Dispatcher.isVisibleToCurrentContextClassLoader(stagemonitorHandler)) {
				handlerChain.add(stagemonitorHandler);
			}
		}
		logger.fine("Handler Chain: " + handlerChain);
	} else {
		logger.fine("No SOAPHandlers found in Dispatcher for Binding " + binding);
	}
}
 
开发者ID:stagemonitor,项目名称:stagemonitor,代码行数:29,代码来源:SoapHandlerTransformer.java


示例7: instrument

import net.bytebuddy.asm.Advice; //导入依赖的package包/类
/**
 * Returns a copy of {@link ParameterTypesExample} which will be instrumented and loaded from a temporary class loader.
 */
public static <T> T instrument(Class<? extends T> classToBeInstrumented, SortedSet<HookMetadata> hookMetadata) throws Exception {
    Map<String, SortedSet<HookMetadata.MethodSignature>> instruments = getInstruments(hookMetadata);
    Set<HookMetadata.MethodSignature> instrumentedMethods = instruments.get(classToBeInstrumented.getName());
    // For examples of byte buddy tests, see net.bytebuddy.asm.AdviceTest in the byte buddy source code.
    return new ByteBuddy()
            .redefine(classToBeInstrumented)
            .visit(Advice.to(PromagentAdvice.class).on(Promagent.matchAnyMethodIn(instrumentedMethods)))
            .make()
            .load(Instrumentor.class.getClassLoader(), ClassLoadingStrategy.Default.CHILD_FIRST)
            .getLoaded()
            .newInstance();
}
 
开发者ID:fstab,项目名称:promagent,代码行数:16,代码来源:Instrumentor.java


示例8: intercept

import net.bytebuddy.asm.Advice; //导入依赖的package包/类
@Advice.OnMethodEnter
public static void intercept(@Advice.BoxedArguments Object[] allArguments,
		@Advice.Origin Method method) {
	Logger logger = LoggerFactory.getLogger(method.getDeclaringClass());
	logger.info("Method {} of class {} called", method.getName(), method
			.getDeclaringClass().getSimpleName());

	for (Object argument : allArguments) {
		logger.info("Method {}, parameter type {}, value={}",
				method.getName(), argument.getClass().getSimpleName(),
				argument.toString());
	}
}
 
开发者ID:jakubhalun,项目名称:tt2016_byte_buddy_agent_demo,代码行数:14,代码来源:LoggingAdvice.java


示例9: createAgent

import net.bytebuddy.asm.Advice; //导入依赖的package包/类
private static AgentBuilder createAgent(String className, String methodName) {
	return new AgentBuilder.Default().disableClassFormatChanges()
			.with(AgentBuilder.RedefinitionStrategy.RETRANSFORMATION)
			.type(named(className))
			.transform(new AgentBuilder.Transformer() {
				@Override
				public DynamicType.Builder<?> transform(
						DynamicType.Builder<?> builder,
						TypeDescription typeDescription,
						ClassLoader classLoader) {
					return builder.visit(Advice.to(LoggingAdvice.class).on(
							named(methodName)));
				}
			});
}
 
开发者ID:jakubhalun,项目名称:tt2016_byte_buddy_agent_demo,代码行数:16,代码来源:LoggingAgent.java


示例10: create

import net.bytebuddy.asm.Advice; //导入依赖的package包/类
private static Class<? extends Page> create(Class<? extends Page> pageType) {

        String className = pageType.getCanonicalName() + "$$Impl";
        ClassLoader classLoader = pageType.getClassLoader();

        InvocationHandler identifyUsingHandler = new IdentifyUsingInvocationHandler();

        Builder<BasePage> pageTypeBuilder = new ByteBuddy()//
            .with(ClassFileVersion.JAVA_V8)
            .subclass(BasePage.class, ConstructorStrategy.Default.IMITATE_SUPER_CLASS)
            .implement(pageType)
            .name(className);

        if (ClasspathUtils.KOTLIN_MODULE_LOADED) {
            pageTypeBuilder = addKotlinImplementations(pageTypeBuilder, pageType);
        }

        pageTypeBuilder = pageTypeBuilder//
            .method(isDefaultMethod())//
            .intercept(Advice.to(ActionAdvice.class)//
                .wrap(DefaultMethodCall.prioritize(pageType)));

        pageTypeBuilder = pageTypeBuilder//
            .method(isAbstract().and(isAnnotatedWith(IdentifyUsing.class)).and(takesArguments(0)))
            .intercept(InvocationHandlerAdapter.of(identifyUsingHandler));

        return pageTypeBuilder.make().load(classLoader).getLoaded();

    }
 
开发者ID:testIT-WebTester,项目名称:webtester2-core,代码行数:30,代码来源:PageImplementation.java


示例11: action

import net.bytebuddy.asm.Advice; //导入依赖的package包/类
@Advice.OnMethodEnter
public static void action(@Advice.This OffersBrowserGetter browserGetter, @Advice.Origin Method method) {
    new ActionAdviceImpl(browserGetter, method).execute();
}
 
开发者ID:testIT-WebTester,项目名称:webtester2-core,代码行数:5,代码来源:ActionAdvice.java


示例12: onMethodExit

import net.bytebuddy.asm.Advice; //导入依赖的package包/类
@Advice.OnMethodExit
public static void onMethodExit(@Advice.This PageFragment pageFragment, @Advice.Origin Method method) {
    try {
        EventProducerImpl impl = THREAD_LOCAL.get();
        if (impl != null) {
            impl.onMethodExit();
        }
    } finally {
        THREAD_LOCAL.remove();

    }
}
 
开发者ID:testIT-WebTester,项目名称:webtester2-core,代码行数:13,代码来源:EventProducerAdvice.java


示例13: create

import net.bytebuddy.asm.Advice; //导入依赖的package包/类
private static Class<? extends PageFragment> create(Class<? extends PageFragment> pageFragmentType) {

        String className = pageFragmentType.getCanonicalName() + "$$Impl";
        ClassLoader classLoader = pageFragmentType.getClassLoader();

        InvocationHandler identifyUsingHandler = new IdentifyUsingInvocationHandler();
        InvocationHandler attributeHandler = new AttributeInvocationHandler();

        Builder<BasePageFragment> pageFragmentTypeBuilder = new ByteBuddy()//
            .with(ClassFileVersion.JAVA_V8)
            .subclass(BasePageFragment.class, ConstructorStrategy.Default.IMITATE_SUPER_CLASS)
            .implement(pageFragmentType)
            .name(className);

        if (ClasspathUtils.KOTLIN_MODULE_LOADED) {
            pageFragmentTypeBuilder = addKotlinImplementations(pageFragmentTypeBuilder, pageFragmentType);
        }

        pageFragmentTypeBuilder = pageFragmentTypeBuilder//
            .method(isDefaultMethod())//
            .intercept(Advice.to(ActionAdvice.class)//
                .wrap(Advice.to(MarkingAdvice.class)//
                    .wrap(Advice.to(EventProducerAdvice.class)//
                        .wrap(DefaultMethodCall.prioritize(pageFragmentType)))));

        pageFragmentTypeBuilder = pageFragmentTypeBuilder//
            .method(isAbstract().and(isAnnotatedWith(IdentifyUsing.class)).and(takesArguments(0)))
            .intercept(InvocationHandlerAdapter.of(identifyUsingHandler));

        pageFragmentTypeBuilder = pageFragmentTypeBuilder//
            .method(isAbstract().and(isAnnotatedWith(Attribute.class)).and(takesArguments(0)))
            .intercept(Advice.to(MarkingAdvice.class)//
                .wrap(InvocationHandlerAdapter.of(attributeHandler)));

        return pageFragmentTypeBuilder.make().load(classLoader).getLoaded();

    }
 
开发者ID:testIT-WebTester,项目名称:webtester2-core,代码行数:38,代码来源:PageFragmentImplementation.java


示例14: transform

import net.bytebuddy.asm.Advice; //导入依赖的package包/类
@Override
public DynamicType.Builder<?> transform(
    DynamicType.Builder<?> builder,
    TypeDescription typeDescription,
    ClassLoader classLoader,
    JavaModule module) {
  return builder.visit(Advice.to(GetContent.class).on(named("getContent")));
}
 
开发者ID:census-instrumentation,项目名称:opencensus-java,代码行数:9,代码来源:UrlInstrumentation.java


示例15: transform

import net.bytebuddy.asm.Advice; //导入依赖的package包/类
@Override
public DynamicType.Builder<?> transform(
    DynamicType.Builder<?> builder,
    TypeDescription typeDescription,
    ClassLoader classLoader,
    JavaModule module) {
  return builder
      .visit(Advice.to(Start.class).on(named("start")))
      .visit(Advice.to(Run.class).on(named("run")));
}
 
开发者ID:census-instrumentation,项目名称:opencensus-java,代码行数:11,代码来源:ThreadInstrumentation.java


示例16: transform

import net.bytebuddy.asm.Advice; //导入依赖的package包/类
@Override
public DynamicType.Builder<?> transform(
    DynamicType.Builder<?> builder,
    TypeDescription typeDescription,
    ClassLoader classLoader,
    JavaModule module) {
  return builder.visit(Advice.to(Execute.class).on(named("execute")));
}
 
开发者ID:census-instrumentation,项目名称:opencensus-java,代码行数:9,代码来源:ExecutorInstrumentation.java


示例17: interceptVisitFrom

import net.bytebuddy.asm.Advice; //导入依赖的package包/类
@Advice.OnMethodEnter
public synchronized static void interceptVisitFrom(@Advice.Argument(1) File fileOrDirectory) {
    File key = fileOrDirectory.getAbsoluteFile();
    Integer count = COUNTS.get(key);
    COUNTS.put(key, count != null ? count + 1 : 1);

    if (TRACK_LOCATIONS) {
        List<Exception> locations = LOCATIONS.get(key);
        if (locations == null) {
            locations = new ArrayList<Exception>();
            LOCATIONS.put(key, locations);
        }
        locations.add(new Exception());
    }
}
 
开发者ID:lhotari,项目名称:gradle-profiling,代码行数:16,代码来源:CountDirectoryScans.java


示例18: onStatusMessage

import net.bytebuddy.asm.Advice; //导入依赖的package包/类
@Advice.OnMethodEnter
public static void onStatusMessage(
    final StatusMessageFlyweight msg,
    final UnsafeBuffer buffer,
    final int length,
    final InetSocketAddress srcAddress)
{
    LOGGER.logFrameIn(buffer, 0, length, srcAddress);
}
 
开发者ID:real-logic,项目名称:aeron,代码行数:10,代码来源:ChannelEndpointInterceptor.java


示例19: onNakMessage

import net.bytebuddy.asm.Advice; //导入依赖的package包/类
@Advice.OnMethodEnter
public static void onNakMessage(
    final NakFlyweight msg,
    final UnsafeBuffer buffer,
    final int length,
    final InetSocketAddress srcAddress)
{
    LOGGER.logFrameIn(buffer, 0, length, srcAddress);
}
 
开发者ID:real-logic,项目名称:aeron,代码行数:10,代码来源:ChannelEndpointInterceptor.java


示例20: onRttMeasurement

import net.bytebuddy.asm.Advice; //导入依赖的package包/类
@Advice.OnMethodEnter
public static void onRttMeasurement(
    final RttMeasurementFlyweight msg,
    final UnsafeBuffer buffer,
    final int length,
    final InetSocketAddress srcAddress)
{
    LOGGER.logFrameIn(buffer, 0, length, srcAddress);
}
 
开发者ID:real-logic,项目名称:aeron,代码行数:10,代码来源:ChannelEndpointInterceptor.java



注:本文中的net.bytebuddy.asm.Advice类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java InvokeRequest类代码示例发布时间:2022-05-22
下一篇:
Java NotConnectedException类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap