コード例 #1
0
  public byte[] modify(
      ClassLoader classLoader,
      String javassistClassName,
      ProtectionDomain protectedDomain,
      byte[] classFileBuffer) {
    if (logger.isInfoEnabled()) {
      logger.info("Modifying. {}", javassistClassName);
    }

    try {
      InstrumentClass statementClass =
          byteCodeInstrumentor.getClass(classLoader, javassistClassName, classFileBuffer);

      Interceptor interceptor = new StatementExecuteQueryInterceptor();
      statementClass.addGroupInterceptor(
          "executeQuery", new String[] {"java.lang.String"}, interceptor, MYSQLScope.SCOPE_NAME);

      // FIXME
      Interceptor executeUpdateInterceptor1 = new StatementExecuteUpdateInterceptor();
      statementClass.addGroupInterceptor(
          "executeUpdate",
          new String[] {"java.lang.String"},
          executeUpdateInterceptor1,
          MYSQLScope.SCOPE_NAME);

      Interceptor executeUpdateInterceptor2 = new StatementExecuteUpdateInterceptor();
      statementClass.addGroupInterceptor(
          "executeUpdate",
          new String[] {"java.lang.String", "int"},
          executeUpdateInterceptor2,
          MYSQLScope.SCOPE_NAME);

      Interceptor executeUpdateInterceptor3 = new StatementExecuteUpdateInterceptor();
      statementClass.addGroupInterceptor(
          "execute",
          new String[] {"java.lang.String"},
          executeUpdateInterceptor3,
          MYSQLScope.SCOPE_NAME);

      Interceptor executeUpdateInterceptor4 = new StatementExecuteUpdateInterceptor();
      statementClass.addGroupInterceptor(
          "execute",
          new String[] {"java.lang.String", "int"},
          executeUpdateInterceptor4,
          MYSQLScope.SCOPE_NAME);

      statementClass.addTraceValue(DatabaseInfoTraceValue.class);
      return statementClass.toBytecode();
    } catch (InstrumentException e) {
      if (logger.isWarnEnabled()) {
        logger.warn("{} modify fail. Cause:{}", this.getClass().getSimpleName(), e.getMessage(), e);
      }
      return null;
    }
  }
コード例 #2
0
 @Override
 public byte[] transform(
     ClassLoader classLoader,
     String className,
     Class<?> classBeingRedefined,
     ProtectionDomain protectionDomain,
     byte[] classfileBuffer)
     throws IllegalClassFormatException {
   try {
     InstrumentClass target = context.getInstrumentClass(classLoader, className, classfileBuffer);
     recipe.edit(classLoader, target);
     return target.toBytecode();
   } catch (PinpointException e) {
     throw e;
   } catch (Throwable e) {
     String msg = "Fail to invoke plugin class recipe: " + toString();
     throw new PinpointException(msg, e);
   }
 }
コード例 #3
0
  /* (non-Javadoc)
   * @see com.navercorp.pinpoint.bootstrap.plugin.transformer.PinpointClassFileTransformer#transform(com.navercorp.pinpoint.bootstrap.plugin.PinpointInstrument, java.lang.ClassLoader, java.lang.String, java.lang.Class, java.security.ProtectionDomain, byte[])
   */
  @Override
  public byte[] transform(
      Instrumentor instrumentContext,
      ClassLoader loader,
      String className,
      Class<?> classBeingRedefined,
      ProtectionDomain protectionDomain,
      byte[] classfileBuffer)
      throws InstrumentException {
    if (logger.isInfoEnabled()) {
      logger.info("Modify {}", className);
    }

    try {
      InstrumentClass target =
          instrumentContext.getInstrumentClass(loader, className, classfileBuffer);

      if (!target.isInterceptable()) {
        return null;
      }

      List<InstrumentMethod> methodList = target.getDeclaredMethods(METHOD_FILTER);
      for (InstrumentMethod method : methodList) {
        if (logger.isTraceEnabled()) {
          logger.trace(
              "### c={}, m={}, params={}",
              new Object[] {
                className, method.getName(), Arrays.toString(method.getParameterTypes())
              });
        }

        method.addInterceptor(
            BasicMethodInterceptor.class.getName(), va(SpringBeansConstants.SERVICE_TYPE));
      }

      return target.toBytecode();
    } catch (Exception e) {
      logger.warn("modify fail. Cause:{}", e.getMessage(), e);
      return null;
    }
  }
コード例 #4
0
  @Override
  public byte[] doInTransform(
      Instrumentor instrumentor,
      ClassLoader classLoader,
      String className,
      Class<?> classBeingRedefined,
      ProtectionDomain protectionDomain,
      byte[] classfileBuffer)
      throws InstrumentException {
    InstrumentClass target =
        instrumentor.getInstrumentClass(classLoader, className, classfileBuffer);

    target.addGetter(
        "com.navercorp.pinpoint.plugin.sample._13_RPC_Client.ServerAddressGetter", "serverAddress");
    target.addGetter(
        "com.navercorp.pinpoint.plugin.sample._13_RPC_Client.ServerPortGetter", "serverPort");
    target
        .getDeclaredMethod(
            "sendRequest", "com.navercorp.plugin.sample.target.TargetClass13_Request")
        .addInterceptor(
            "com.navercorp.pinpoint.plugin.sample._13_RPC_Client.SendRequestInterceptor");

    return target.toBytecode();
  }