/** * {@inheritDoc} */ @Override protected void applyAssignment(AgentConfig agentConfiguration, MethodType methodType, MethodInstrumentationConfig methodInstrumentationConfig) { SensorInstrumentationPoint sensorInstrumentationPoint = getOrCreateSensorInstrumentationPoint(agentConfiguration, methodType, methodInstrumentationConfig); applyAssignment(agentConfiguration, sensorInstrumentationPoint); }
/** * {@inheritDoc} */ @Override protected void applyAssignment(AgentConfig agentConfiguration, MethodType methodType, MethodInstrumentationConfig methodInstrumentationConfig) { SensorInstrumentationPoint sensorInstrumentationPoint = getOrCreateSensorInstrumentationPoint(agentConfiguration, methodType, methodInstrumentationConfig); applyAssignment(agentConfiguration, sensorInstrumentationPoint); }
@Override public InstrumentationDefinition call() throws Exception { ClassType classType = (ClassType) type; boolean added = false; for (IInstrumentationApplier applier : appliers) { added |= applier.addInstrumentationPoints(agentConfiguration, classType); } if (added) { return createInstrumentationResult(type); } else { return null; } } });
/** * Returns the {@link IInstrumentationApplier} for the given sensor assignment and the * {@link Environment} it's being used in. * * @param sensorAssignment * {@link ISensorAssignment} * @param environment * Environment being used. * @return {@link IInstrumentationApplier} * @throws IllegalArgumentException * If supplied assignment is not of known type. */ public IInstrumentationApplier getInstrumentationApplier(ISensorAssignment<?> sensorAssignment, Environment environment) throws IllegalArgumentException { // switch based on the class Class<?> sensorAssigmentClass = sensorAssignment.getClass(); if (TimerMethodSensorAssignment.class.isAssignableFrom(sensorAssigmentClass)) { return new TimerMethodSensorInstrumentationApplier((TimerMethodSensorAssignment) sensorAssignment, environment, registrationService); } else if (InvocationStartMethodSensorAssignment.class.isAssignableFrom(sensorAssigmentClass)) { return new InvocationStartMethodSensorInstrumentationApplier((InvocationStartMethodSensorAssignment) sensorAssignment, environment, registrationService); } else if (ExceptionSensorAssignment.class.isAssignableFrom(sensorAssigmentClass)) { return new ExceptionSensorInstrumentationApplier((ExceptionSensorAssignment) sensorAssignment, environment, registrationService); } else if (SpecialMethodSensorAssignment.class.isAssignableFrom(sensorAssigmentClass)) { return new SpecialInstrumentationApplier((SpecialMethodSensorAssignment) sensorAssignment, environment, registrationService); } else if (MethodSensorAssignment.class.isAssignableFrom(sensorAssigmentClass)) { return new MethodSensorInstrumentationApplier((MethodSensorAssignment) sensorAssignment, environment, registrationService); } throw new IllegalArgumentException("Instrumentation applier can be created. Assignment " + sensorAssignment + " is of unknow type."); }
/** * {@inheritDoc} */ @Override public boolean addInstrumentationPoints(AgentConfig agentConfiguration, ClassType classType) { boolean added = false; if (matches(classType)) { for (MethodType methodType : classType.getMethods()) { if (matches(methodType)) { MethodInstrumentationConfig methodInstrumentationConfig = getOrCreateMethodInstrumentationConfig(methodType); applyAssignment(agentConfiguration, methodType, methodInstrumentationConfig); added = true; } } } return added; }
/** * Removes all instrumentation point from the given types. * * @param types * to remove instrumentation points * @return types from which instrumentation points have been removed */ public Collection<? extends ImmutableClassType> removeInstrumentationPoints(final Collection<? extends ImmutableType> types) { return removeInstrumentationPoints(types, Collections.<IInstrumentationApplier> singleton(RemoveAllInstrumentationApplier.getInstance())); }
@Override protected void applyAssignment(AgentConfig agentConfiguration, MethodType methodType, MethodInstrumentationConfig methodInstrumentationConfig) { // test both getOrCreateSensorInstrumentationPoint(agentConfiguration, methodType, methodInstrumentationConfig); getOrCreateSpecialInstrumentationPoint(agentConfiguration, methodType, methodInstrumentationConfig); }
/** * {@inheritDoc} */ @Override protected void applyAssignment(AgentConfig agentConfiguration, MethodType methodType, MethodInstrumentationConfig methodInstrumentationConfig) { SpecialInstrumentationPoint specialInstrumentationPoint = getOrCreateSpecialInstrumentationPoint(agentConfiguration, methodType, methodInstrumentationConfig); MethodSensorTypeConfig methodSensorTypeConfig = getSensorTypeConfigFromConfiguration(agentConfiguration); long sensorId = methodSensorTypeConfig.getId(); specialInstrumentationPoint.setSensorId(sensorId); specialInstrumentationPoint.setSubstitutionDescriptor(functionalAssignment.getSpecialMethodSensorConfig().getSubstitutionDescriptor()); }
/** * {@inheritDoc} */ @Override protected boolean matches(ClassType classType) { return getClassSensorAssignmentFilter().matches(methodSensorAssignment, classType, false); }
/** * {@inheritDoc} */ @Override protected boolean matches(MethodType methodType) { return getMethodSensorAssignmentFilter().matches(methodSensorAssignment, methodType); }
/** * If the assignment matches the {@link JmxAttributeDescriptor}. * <p> * By default uses filter provided by {@link #getJmxSensorAssignmentFilter()}. * * @param jmxAttributeDescriptor * Descriptor to check. * @return True if the assignment matches the descriptor. */ protected boolean matches(JmxAttributeDescriptor jmxAttributeDescriptor) { return getJmxSensorAssignmentFilter().matches(jmxSensorAssignment, jmxAttributeDescriptor); }
/** * {@inheritDoc} */ @Override protected boolean matches(ClassType classType) { return getClassSensorAssignmentFilter().matches(functionalAssignment, classType, false); }
/** * {@inheritDoc} */ @Override protected boolean matches(ClassType classType) { return classType.isException() && getClassSensorAssignmentFilter().matches(exceptionSensorAssignment, classType); }
/** * {@inheritDoc} */ @Override public boolean removeInstrumentationPoints(ClassType classType) { if (!classType.hasInstrumentationPoints()) { return false; } boolean removed = false; if (matches(classType)) { for (MethodType methodType : classType.getMethods()) { if (matches(methodType)) { methodType.setMethodInstrumentationConfig(null); removed = true; } } } return removed; }
@Test public void returnNull() { AbstractClassSensorAssignment<?> result = applier.getSensorAssignment(); assertThat(result, is(nullValue())); } }
@Test public void returnFalse() { boolean result = applier.addInstrumentationPoints(agentConfiguration, classType); assertThat(result, is(false)); verifyZeroInteractions(agentConfiguration, classType); } }
/** * {@inheritDoc} * <p> * We only support method instrumentation with special assignments for now. No constructors of * any kind. */ @Override protected boolean matches(MethodType methodType) { return MethodType.Character.METHOD.equals(methodType.getMethodCharacter()) && getMethodSensorAssignmentFilter().matches(functionalAssignment, methodType); }
@Test(expectedExceptions = NullPointerException.class) public void nullClass() { try { when(classType.hasInstrumentationPoints()).thenReturn(false); applier.removeInstrumentationPoints(null); } finally { verifyZeroInteractions(classType, methodType); } } }
/** * {@inheritDoc} */ protected void applyAssignment(AgentConfig agentConfiguration, SensorInstrumentationPoint sensorInstrumentationPoint) { // first deal with sensor id MethodSensorTypeConfig methodSensorTypeConfig = getSensorTypeConfigFromConfiguration(agentConfiguration, environment, methodSensorAssignment); long sensorId = methodSensorTypeConfig.getId(); // set to rsc sensorInstrumentationPoint.addSensorId(sensorId, methodSensorTypeConfig.getPriority()); // add all settings sensorInstrumentationPoint.addSettings(methodSensorAssignment.getSettings()); }
@Test public void notNull() { RemoveAllInstrumentationApplier instance = RemoveAllInstrumentationApplier.getInstance(); assertThat(instance, is(not(nullValue()))); } }