Search in sources :

Example 1 with OrMatcherOperator

use of com.navercorp.pinpoint.bootstrap.instrument.matcher.operator.OrMatcherOperator in project pinpoint by naver.

the class DefaultMultiPackageBasedMatcherTest method getMatcherOperandWithMulitPackageName.

@Test
public void getMatcherOperandWithMulitPackageName() {
    DefaultMultiPackageBasedMatcher matcher = new DefaultMultiPackageBasedMatcher(Arrays.asList("java", "javax"));
    assertTrue(matcher.getBasePackageNames().contains("java"));
    assertTrue(matcher.getBasePackageNames().contains("javax"));
    MatcherOperand operand = matcher.getMatcherOperand();
    assertTrue(operand instanceof OrMatcherOperator);
    OrMatcherOperator operator = (OrMatcherOperator) operand;
    assertTrue(operator.getLeftOperand() instanceof PackageInternalNameMatcherOperand);
    PackageInternalNameMatcherOperand leftOperand = (PackageInternalNameMatcherOperand) operator.getLeftOperand();
    assertEquals("java", leftOperand.getPackageInternalName());
    assertTrue(operator.getRightOperand() instanceof PackageInternalNameMatcherOperand);
    PackageInternalNameMatcherOperand rightOperand = (PackageInternalNameMatcherOperand) operator.getRightOperand();
    assertEquals("javax", rightOperand.getPackageInternalName());
}
Also used : MatcherOperand(com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.MatcherOperand) PackageInternalNameMatcherOperand(com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.PackageInternalNameMatcherOperand) OrMatcherOperator(com.navercorp.pinpoint.bootstrap.instrument.matcher.operator.OrMatcherOperator) PackageInternalNameMatcherOperand(com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.PackageInternalNameMatcherOperand) Test(org.junit.Test)

Example 2 with OrMatcherOperator

use of com.navercorp.pinpoint.bootstrap.instrument.matcher.operator.OrMatcherOperator in project pinpoint by naver.

the class DefaultMultiClassBasedMatcherTest method getMatcherOperandWithMultiClassNameAndAdditional.

@Test
public void getMatcherOperandWithMultiClassNameAndAdditional() {
    // (class OR class) AND interface
    InterfaceInternalNameMatcherOperand additional = new InterfaceInternalNameMatcherOperand("java/lang/Runnable", false);
    DefaultMultiClassBasedMatcher matcher = new DefaultMultiClassBasedMatcher(Arrays.asList("java.lang.String", "java.lang.Thread"), additional);
    assertTrue(matcher.getBaseClassNames().contains("java.lang.String"));
    assertTrue(matcher.getBaseClassNames().contains("java.lang.Thread"));
    MatcherOperand operand = matcher.getMatcherOperand();
    assertTrue(operand instanceof AndMatcherOperator);
    AndMatcherOperator operator = (AndMatcherOperator) operand;
    // (class OR class)
    assertTrue(operator.getLeftOperand() instanceof OrMatcherOperator);
    // ... AND interface
    assertTrue(operator.getRightOperand() instanceof InterfaceInternalNameMatcherOperand);
    InterfaceInternalNameMatcherOperand rightOperand = (InterfaceInternalNameMatcherOperand) operator.getRightOperand();
    assertEquals("java/lang/Runnable", rightOperand.getInterfaceInternalName());
}
Also used : InterfaceInternalNameMatcherOperand(com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.InterfaceInternalNameMatcherOperand) MatcherOperand(com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.MatcherOperand) ClassInternalNameMatcherOperand(com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.ClassInternalNameMatcherOperand) InterfaceInternalNameMatcherOperand(com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.InterfaceInternalNameMatcherOperand) AndMatcherOperator(com.navercorp.pinpoint.bootstrap.instrument.matcher.operator.AndMatcherOperator) OrMatcherOperator(com.navercorp.pinpoint.bootstrap.instrument.matcher.operator.OrMatcherOperator) Test(org.junit.Test)

Example 3 with OrMatcherOperator

use of com.navercorp.pinpoint.bootstrap.instrument.matcher.operator.OrMatcherOperator in project pinpoint by naver.

the class AbstractMatcherOperandTest method or.

@Test
public void or() {
    MatcherOperand operand = new ClassInternalNameMatcherOperand("java/lang/String");
    operand = operand.or(new InterfaceInternalNameMatcherOperand("java/lang/Runnable", false));
    operand = operand.or(new AnnotationInternalNameMatcherOperand("javax/annotation/Resource", false));
    assertTrue(operand instanceof OrMatcherOperator);
    OrMatcherOperator operator = (OrMatcherOperator) operand;
    assertTrue(operator.getLeftOperand() instanceof OrMatcherOperator);
    assertTrue(operator.getRightOperand() instanceof AnnotationInternalNameMatcherOperand);
    operator = (OrMatcherOperator) operator.getLeftOperand();
    assertTrue(operator.getLeftOperand() instanceof ClassInternalNameMatcherOperand);
    assertTrue(operator.getRightOperand() instanceof InterfaceInternalNameMatcherOperand);
}
Also used : OrMatcherOperator(com.navercorp.pinpoint.bootstrap.instrument.matcher.operator.OrMatcherOperator) Test(org.junit.Test)

Example 4 with OrMatcherOperator

use of com.navercorp.pinpoint.bootstrap.instrument.matcher.operator.OrMatcherOperator in project pinpoint by naver.

the class TransformerMatcherExecutionPlanner method traversal.

// find indexed operands.
private boolean traversal(final MatcherOperand operand, final List<MatcherOperand> index) {
    if (!operand.isOperator()) {
        if (operand.isIndex()) {
            index.add(operand);
            return true;
        }
        return false;
    }
    if (operand instanceof NotMatcherOperator) {
        // skip NOT operator.
        return false;
    }
    MatcherOperator operator = (MatcherOperator) operand;
    final MatcherOperand leftOperand = operator.getLeftOperand();
    if (leftOperand == null) {
        throw new IllegalArgumentException("invalid left operand - left operand must not be null. operator=" + operator);
    }
    final MatcherOperand rightOperand = operator.getRightOperand();
    if (rightOperand == null) {
        throw new IllegalArgumentException("invalid right operand - right operand must not be null. operator=" + operator);
    }
    if (operand instanceof AndMatcherOperator) {
        // if find any.
        final boolean indexed = traversal(leftOperand, index);
        if (indexed) {
            return true;
        }
        return traversal(rightOperand, index);
    } else if (operand instanceof OrMatcherOperator) {
        // find all.
        final boolean indexed = traversal(leftOperand, index);
        return traversal(rightOperand, index) || indexed;
    } else {
        throw new IllegalArgumentException("unknown operator. operator=" + operand);
    }
}
Also used : MatcherOperand(com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.MatcherOperand) AndMatcherOperator(com.navercorp.pinpoint.bootstrap.instrument.matcher.operator.AndMatcherOperator) OrMatcherOperator(com.navercorp.pinpoint.bootstrap.instrument.matcher.operator.OrMatcherOperator) AndMatcherOperator(com.navercorp.pinpoint.bootstrap.instrument.matcher.operator.AndMatcherOperator) MatcherOperator(com.navercorp.pinpoint.bootstrap.instrument.matcher.operator.MatcherOperator) NotMatcherOperator(com.navercorp.pinpoint.bootstrap.instrument.matcher.operator.NotMatcherOperator) OrMatcherOperator(com.navercorp.pinpoint.bootstrap.instrument.matcher.operator.OrMatcherOperator) NotMatcherOperator(com.navercorp.pinpoint.bootstrap.instrument.matcher.operator.NotMatcherOperator)

Example 5 with OrMatcherOperator

use of com.navercorp.pinpoint.bootstrap.instrument.matcher.operator.OrMatcherOperator in project pinpoint by naver.

the class DefaultTransformerMatcher method traversal.

boolean traversal(ClassLoader classLoader, MatcherOperand operand, InternalClassMetadata classMetadata) {
    if (operand instanceof NotMatcherOperator) {
        NotMatcherOperator operator = (NotMatcherOperator) operand;
        if (operator.getRightOperand() == null) {
            throw new IllegalArgumentException("invalid operator - not found right operand. operator=" + operator);
        }
        final MatcherOperand rightOperand = operator.getRightOperand();
        // NOT
        return match(classLoader, rightOperand, classMetadata) == false;
    }
    MatcherOperator operator = (MatcherOperator) operand;
    // for binary operator.
    if (operator.getLeftOperand() == null) {
        throw new IllegalArgumentException("invalid operator - not found left operand. operator=" + operator);
    }
    final MatcherOperand leftOperand = operator.getLeftOperand();
    if (operator.getRightOperand() == null) {
        throw new IllegalArgumentException("invalid operator - not found right operand. operator=" + operator);
    }
    final MatcherOperand rightOperand = operator.getRightOperand();
    MatcherOperand firstOperand = leftOperand;
    MatcherOperand secondOperand = rightOperand;
    if (leftOperand.getExecutionCost() > rightOperand.getExecutionCost()) {
        // cost-based execution plan.
        firstOperand = rightOperand;
        secondOperand = leftOperand;
    }
    if (operand instanceof OrMatcherOperator) {
        // OR
        if (match(classLoader, firstOperand, classMetadata)) {
            return true;
        }
        return match(classLoader, secondOperand, classMetadata);
    } else if (operand instanceof AndMatcherOperator) {
        // AND
        if (match(classLoader, firstOperand, classMetadata)) {
            return match(classLoader, secondOperand, classMetadata);
        }
        return false;
    } else {
        throw new IllegalArgumentException("unknown operator. operator=" + operator);
    }
}
Also used : SuperClassInternalNameMatcherOperand(com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.SuperClassInternalNameMatcherOperand) ClassInternalNameMatcherOperand(com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.ClassInternalNameMatcherOperand) InterfaceInternalNameMatcherOperand(com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.InterfaceInternalNameMatcherOperand) MatcherOperand(com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.MatcherOperand) AnnotationInternalNameMatcherOperand(com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.AnnotationInternalNameMatcherOperand) PackageInternalNameMatcherOperand(com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.PackageInternalNameMatcherOperand) AndMatcherOperator(com.navercorp.pinpoint.bootstrap.instrument.matcher.operator.AndMatcherOperator) OrMatcherOperator(com.navercorp.pinpoint.bootstrap.instrument.matcher.operator.OrMatcherOperator) NotMatcherOperator(com.navercorp.pinpoint.bootstrap.instrument.matcher.operator.NotMatcherOperator) OrMatcherOperator(com.navercorp.pinpoint.bootstrap.instrument.matcher.operator.OrMatcherOperator) AndMatcherOperator(com.navercorp.pinpoint.bootstrap.instrument.matcher.operator.AndMatcherOperator) MatcherOperator(com.navercorp.pinpoint.bootstrap.instrument.matcher.operator.MatcherOperator) NotMatcherOperator(com.navercorp.pinpoint.bootstrap.instrument.matcher.operator.NotMatcherOperator)

Aggregations

OrMatcherOperator (com.navercorp.pinpoint.bootstrap.instrument.matcher.operator.OrMatcherOperator)6 MatcherOperand (com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.MatcherOperand)5 Test (org.junit.Test)4 ClassInternalNameMatcherOperand (com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.ClassInternalNameMatcherOperand)3 InterfaceInternalNameMatcherOperand (com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.InterfaceInternalNameMatcherOperand)3 AndMatcherOperator (com.navercorp.pinpoint.bootstrap.instrument.matcher.operator.AndMatcherOperator)3 PackageInternalNameMatcherOperand (com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.PackageInternalNameMatcherOperand)2 MatcherOperator (com.navercorp.pinpoint.bootstrap.instrument.matcher.operator.MatcherOperator)2 NotMatcherOperator (com.navercorp.pinpoint.bootstrap.instrument.matcher.operator.NotMatcherOperator)2 AnnotationInternalNameMatcherOperand (com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.AnnotationInternalNameMatcherOperand)1 SuperClassInternalNameMatcherOperand (com.navercorp.pinpoint.bootstrap.instrument.matcher.operand.SuperClassInternalNameMatcherOperand)1