当前位置: 首页>>代码示例>>Java>>正文


Java AgentBuilder类代码示例

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


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

示例1: createAgentBuilder

import net.bytebuddy.agent.builder.AgentBuilder; //导入依赖的package包/类
/**
 * Creates the AgentBuilder that will redefine the System class.
 * @param inst instrumentation instance.
 * @return an agent builder.
 */
private static AgentBuilder createAgentBuilder(Instrumentation inst) {

    // Find me a class called "java.lang.System"
    final ElementMatcher.Junction<NamedElement> systemType = ElementMatchers.named("java.lang.System");

    // And then find a method called setSecurityManager and tell MySystemInterceptor to
    // intercept it (the method binding is smart enough to take it from there)
    final AgentBuilder.Transformer transformer =
            (b, typeDescription) -> b.method(ElementMatchers.named("setSecurityManager"))
                    .intercept(MethodDelegation.to(MySystemInterceptor.class));

    // Disable a bunch of stuff and turn on redefine as the only option
    final ByteBuddy byteBuddy = new ByteBuddy().with(Implementation.Context.Disabled.Factory.INSTANCE);
    final AgentBuilder agentBuilder = new AgentBuilder.Default()
            .withByteBuddy(byteBuddy)
            .withInitializationStrategy(AgentBuilder.InitializationStrategy.NoOp.INSTANCE)
            .withRedefinitionStrategy(AgentBuilder.RedefinitionStrategy.REDEFINITION)
            .withTypeStrategy(AgentBuilder.TypeStrategy.Default.REDEFINE)
            .type(systemType)
            .transform(transformer);

    return agentBuilder;
}
 
开发者ID:wsargent,项目名称:securityfixer,代码行数:29,代码来源:SecurityFixerAgent.java

示例2: transformClasses

import net.bytebuddy.agent.builder.AgentBuilder; //导入依赖的package包/类
private static void transformClasses(Instrumentation instrumentation) {

		new AgentBuilder.Default().withListener(new AgentListener()).type(geTypeMatchers())
				.transform(new Transformer() {

					@Override
					public Builder<?> transform(Builder<?> builder, TypeDescription typeDescription) {

						return builder
								.invokable(isAnnotatedWith(named(INJECT_ANNOTATION))
										.or(isAnnotatedWith(named(AUTOWIRED_ANNOTATION))))
								.intercept(SuperMethodCall.INSTANCE
										.andThen(MethodDelegation.to(InjectionInterceptor.class)));
					}

				}).installOn(instrumentation);
	}
 
开发者ID:YoannBuch,项目名称:DependencyInjectionAgent,代码行数:18,代码来源:DIAgent.java

示例3: removeTransformer

import net.bytebuddy.agent.builder.AgentBuilder; //导入依赖的package包/类
public static void removeTransformer()
{
    if (logTransformer != null)
    {
        readerAgentRunner.close();
        instrumentation.removeTransformer(logTransformer);

        final ElementMatcher.Junction<TypeDescription> orClause = nameEndsWith("DriverConductor")
            .or(nameEndsWith("ClientProxy"))
            .or(nameEndsWith("ClientCommandAdapter"))
            .or(nameEndsWith("SenderProxy"))
            .or(nameEndsWith("ReceiverProxy"))
            .or(inheritsAnnotation(EventLog.class));

        final ResettableClassFileTransformer transformer = new AgentBuilder.Default()
            .type(orClause)
            .transform(AgentBuilder.Transformer.NoOp.INSTANCE)
            .installOn(instrumentation);

        instrumentation.removeTransformer(transformer);

        readerAgentRunner = null;
        instrumentation = null;
        logTransformer = null;
    }
}
 
开发者ID:real-logic,项目名称:aeron,代码行数:27,代码来源:EventLogAgent.java

示例4: agent

import net.bytebuddy.agent.builder.AgentBuilder; //导入依赖的package包/类
private static synchronized void agent(final boolean shouldRedefine, final Instrumentation instrumentation)
{
    BufferAlignmentAgent.instrumentation = instrumentation;
    // all Int methods, and all String method other than
    // XXXStringWithoutLengthXXX or getStringXXX(int, int)
    final Junction<MethodDescription> intVerifierMatcher = nameContains("Int")
        .or(nameMatches(".*String[^W].*").and(not(ElementMatchers.takesArguments(int.class, int.class))));

    alignmentTransformer = new AgentBuilder.Default(new ByteBuddy().with(TypeValidation.DISABLED))
        .with(LISTENER)
        .disableClassFormatChanges()
        .with(shouldRedefine ?
            AgentBuilder.RedefinitionStrategy.RETRANSFORMATION :
            AgentBuilder.RedefinitionStrategy.DISABLED)
        .type(isSubTypeOf(DirectBuffer.class).and(not(isInterface())))
        .transform((builder, typeDescription, classLoader, module) -> builder
            .visit(to(LongVerifier.class).on(nameContains("Long")))
            .visit(to(DoubleVerifier.class).on(nameContains("Double")))
            .visit(to(IntVerifier.class).on(intVerifierMatcher))
            .visit(to(FloatVerifier.class).on(nameContains("Float")))
            .visit(to(ShortVerifier.class).on(nameContains("Short")))
            .visit(to(CharVerifier.class).on(nameContains("Char"))))
        .installOn(instrumentation);
}
 
开发者ID:real-logic,项目名称:agrona,代码行数:25,代码来源:BufferAlignmentAgent.java

示例5: initByteBuddyClassFileTransformer

import net.bytebuddy.agent.builder.AgentBuilder; //导入依赖的package包/类
private static ClassFileTransformer initByteBuddyClassFileTransformer(AutoEvictingCachingBinaryLocator binaryLocator) {
	AgentBuilder agentBuilder = createAgentBuilder(binaryLocator);
	for (StagemonitorByteBuddyTransformer transformer : getStagemonitorByteBuddyTransformers()) {
		agentBuilder = agentBuilder
				.type(transformer.getMatcher())
				.transform(transformer.getTransformer())
				.asDecorator();
	}

	final long start = System.currentTimeMillis();
	try {
		return agentBuilder.installOn(instrumentation);
	} finally {
		if (corePlugin.isDebugInstrumentation()) {
			logger.info("Installed agent in {} ms", System.currentTimeMillis() - start);
		}
	}
}
 
开发者ID:stagemonitor,项目名称:stagemonitor,代码行数:19,代码来源:AgentAttacher.java

示例6: createAgentBuilder

import net.bytebuddy.agent.builder.AgentBuilder; //导入依赖的package包/类
private static AgentBuilder createAgentBuilder(AutoEvictingCachingBinaryLocator binaryLocator) {
	final ByteBuddy byteBuddy = new ByteBuddy()
			.with(TypeValidation.of(corePlugin.isDebugInstrumentation()))
			.with(MethodGraph.Compiler.ForDeclaredMethods.INSTANCE);
	return new AgentBuilder.Default(byteBuddy)
			.with(AgentBuilder.RedefinitionStrategy.RETRANSFORMATION)
			.with(getListener())
			.with(binaryLocator)
			.ignore(any(), timed("classloader", "reflection", isReflectionClassLoader()))
			.or(any(), timed("classloader", "groovy-call-site", classLoaderWithName("org.codehaus.groovy.runtime.callsite.CallSiteClassLoader")))
			.or(any(), new IsIgnoredClassLoaderElementMatcher())
			.or(timed("type", "global-exclude", nameStartsWith("org.aspectj.")
					.or(nameStartsWith("org.groovy."))
					.or(nameStartsWith("com.p6spy."))
					.or(nameStartsWith("net.bytebuddy."))
					.or(nameStartsWith("org.slf4j.").and(not(nameStartsWith("org.slf4j.impl."))))
					.or(nameContains("javassist"))
					.or(nameContains(".asm."))
					.or(nameStartsWith("org.stagemonitor")
							.and(not(nameContains("Test")
									.or(nameContains("benchmark"))
									.or(nameStartsWith("org.stagemonitor.demo")))))
			))
			.disableClassFormatChanges();
}
 
开发者ID:stagemonitor,项目名称:stagemonitor,代码行数:26,代码来源:AgentAttacher.java

示例7: premain

import net.bytebuddy.agent.builder.AgentBuilder; //导入依赖的package包/类
public static void premain(final String agentArgs,
                               final Instrumentation inst) throws Exception {
        System.out.printf("Starting %s\n",
                MetricsCollectionByteBuddyAgent.class.getSimpleName());

        new AgentBuilder.Default()
                .type(ElementMatchers.any())
                .transform(new MetricsTransformer())
//        .with(AgentBuilder.Listener.StreamWriting.toSystemOut())
                .with(AgentBuilder.TypeStrategy.Default.REDEFINE)
                .installOn(inst);
    }
 
开发者ID:ivanyu,项目名称:java-agents-demo,代码行数:13,代码来源:MetricsCollectionByteBuddyAgent.java

示例8: premain

import net.bytebuddy.agent.builder.AgentBuilder; //导入依赖的package包/类
public static void premain(String agentArgs, Instrumentation inst) {
        try {
            PromagentCollectorRegistry registry = new PromagentCollectorRegistry();
            ManagementFactory.getPlatformMBeanServer().registerMBean(new Exporter(registry), new ObjectName("io.promagent:type=exporter"));
            Map<String, String> args = parseCmdline(agentArgs);
            if (args.containsKey("port")) {
                BuiltInServer.run(args.get("host"), args.get("port"), registry);
            }
            ClassLoaderCache classLoaderCache = ClassLoaderCache.getInstance();
            List<Path> hookJars = classLoaderCache.getPerDeploymentJars();
            SortedSet<HookMetadata> hookMetadata = new HookMetadataParser(hookJars).parse();
            MetricsStore metricsStore = new MetricsStore(registry);
            Delegator.init(hookMetadata, metricsStore, classLoaderCache);
            printHookMetadata(hookMetadata);

            AgentBuilder agentBuilder = new AgentBuilder.Default()
                    .with(AgentBuilder.RedefinitionStrategy.REDEFINITION)
                    .with(AgentBuilder.TypeStrategy.Default.REDEFINE);
                    // .with(AgentBuilder.Listener.StreamWriting.toSystemError()); // use this to see exceptions thrown in instrumented code
            agentBuilder = applyHooks(agentBuilder, hookMetadata, classLoaderCache);
            agentBuilder.installOn(inst);

            // TODO -- the following is an experiment supporting collectors directly (in addition to hooks)
//            io.prometheus.client.Collector jmxCollector = (io.prometheus.client.Collector) classLoaderCache.currentClassLoader().loadClass("io.promagent.collectors.JmxCollector").newInstance();
//            registry.registerNoJmx(jmxCollector);

        } catch (Throwable t) {
            t.printStackTrace();
        }
    }
 
开发者ID:fstab,项目名称:promagent,代码行数:31,代码来源:Promagent.java

示例9: applyHooks

import net.bytebuddy.agent.builder.AgentBuilder; //导入依赖的package包/类
/**
 * Add {@link ElementMatcher} for the hooks.
 */
private static AgentBuilder applyHooks(AgentBuilder agentBuilder, SortedSet<HookMetadata> hookMetadata, ClassLoaderCache classLoaderCache) {
    Map<String, SortedSet<MethodSignature>> instruments = getInstruments(hookMetadata);
    for (Map.Entry<String, SortedSet<MethodSignature>> entry : instruments.entrySet()) {
        String instrumentedClassName = entry.getKey();
        Set<MethodSignature> instrumentedMethods = entry.getValue();
        agentBuilder = agentBuilder
                .type(ElementMatchers.hasSuperType(named(instrumentedClassName)))
                .transform(new AgentBuilder.Transformer.ForAdvice()
                        .include(classLoaderCache.currentClassLoader()) // must be able to load PromagentAdvice
                        .advice(matchAnyMethodIn(instrumentedMethods), PromagentAdvice.class.getName())
                );
    }
    return agentBuilder;
}
 
开发者ID:fstab,项目名称:promagent,代码行数:18,代码来源:Promagent.java

示例10: start

import net.bytebuddy.agent.builder.AgentBuilder; //导入依赖的package包/类
/**
 * 启动入口
 * @param instrumentation
 * @return
 */
public Agent start(Instrumentation instrumentation) {
    new AgentBuilder.Default()
        .type(
            inPlugins().and(not(isInterface()))
        )
        .transform(((builder, typeDescription, classLoader, javaModule) -> {
            ClassDataSource dataSource = pluginManager.find(typeDescription.getName());
            //TODO 大有可为
            return DataSourceMonitorRegister.register(dataSource, builder); //注册监听代码(拦截器)
        }))
        .with(listener())
        .installOn(instrumentation);
    return this;
}
 
开发者ID:superbiger,项目名称:sbiger-apm,代码行数:20,代码来源:AgentBoot.java

示例11: createAgent

import net.bytebuddy.agent.builder.AgentBuilder; //导入依赖的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

示例12: premain

import net.bytebuddy.agent.builder.AgentBuilder; //导入依赖的package包/类
/**
 * Initializes the OpenCensus Agent for Java.
 *
 * @param agentArgs agent options, passed as a single string by the JVM
 * @param instrumentation the {@link Instrumentation} object provided by the JVM for instrumenting
 *     Java programming language code
 * @throws Exception if initialization of the agent fails
 * @see java.lang.instrument
 */
public static void premain(String agentArgs, Instrumentation instrumentation) throws Exception {
  checkNotNull(instrumentation, "instrumentation");

  logger.fine("Initializing.");

  // The classes in bootstrap.jar, such as ContextManger and ContextStrategy, will be referenced
  // from classes loaded by the bootstrap classloader. Thus, these classes have to be loaded by
  // the bootstrap classloader, too.
  instrumentation.appendToBootstrapClassLoaderSearch(
      new JarFile(Resources.getResourceAsTempFile("bootstrap.jar")));

  checkLoadedByBootstrapClassloader(ContextTrampoline.class);
  checkLoadedByBootstrapClassloader(ContextStrategy.class);

  Settings settings = Settings.load();
  AgentBuilder agentBuilder =
      new AgentBuilder.Default()
          .disableClassFormatChanges()
          .with(AgentBuilder.RedefinitionStrategy.RETRANSFORMATION)
          .with(new AgentBuilderListener())
          .ignore(none());
  for (Instrumenter instrumenter : ServiceLoader.load(Instrumenter.class)) {
    agentBuilder = instrumenter.instrument(agentBuilder, settings);
  }
  agentBuilder.installOn(instrumentation);

  logger.fine("Initialized.");
}
 
开发者ID:census-instrumentation,项目名称:opencensus-java,代码行数:38,代码来源:AgentMain.java

示例13: instrument

import net.bytebuddy.agent.builder.AgentBuilder; //导入依赖的package包/类
@Override
public AgentBuilder instrument(AgentBuilder agentBuilder, Settings settings) {
  checkNotNull(agentBuilder, "agentBuilder");
  checkNotNull(settings, "settings");

  if (!settings.isEnabled("trace.java.net.URL.getContent")) {
    return agentBuilder;
  }

  return agentBuilder.type(named("java.net.URL")).transform(new Transformer());
}
 
开发者ID:census-instrumentation,项目名称:opencensus-java,代码行数:12,代码来源:UrlInstrumentation.java

示例14: instrument

import net.bytebuddy.agent.builder.AgentBuilder; //导入依赖的package包/类
@Override
public AgentBuilder instrument(AgentBuilder agentBuilder, Settings settings) {
  checkNotNull(agentBuilder, "agentBuilder");
  checkNotNull(settings, "settings");

  if (!settings.isEnabled("context-propagation.thread")) {
    return agentBuilder;
  }

  return agentBuilder.type(isSubTypeOf(Thread.class)).transform(new Transformer());
}
 
开发者ID:census-instrumentation,项目名称:opencensus-java,代码行数:12,代码来源:ThreadInstrumentation.java

示例15: instrument

import net.bytebuddy.agent.builder.AgentBuilder; //导入依赖的package包/类
@Override
public AgentBuilder instrument(AgentBuilder agentBuilder, Settings settings) {
  checkNotNull(agentBuilder, "agentBuilder");
  checkNotNull(settings, "settings");

  if (!settings.isEnabled("context-propagation.executor")) {
    return agentBuilder;
  }

  return agentBuilder.type(createMatcher()).transform(new Transformer());
}
 
开发者ID:census-instrumentation,项目名称:opencensus-java,代码行数:12,代码来源:ExecutorInstrumentation.java


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