/** * {@inheritDoc} */ @Override public void run() { Collection<ImmutableType> changedClassTypes = execute(); createInstrumentationChangedEvent(changedClassTypes); }
/** * @return Returns environment based on the {@link ConfigurationHolder}. */ protected Environment getEnvironment() { return getConfigurationHolder().getEnvironment(); }
/** * Process the removed assignments. All instrumentation points affected by the any of these * assignments are first completely removed. All classes that have any point removed will be * re-analyzed against complete configuration in order to reset the possible points coming not * from removed assignments. * * @param classSensorAssignments * Collection of removed {@link AbstractClassSensorAssignment}s. * @return Returns a {@link Collection} of {@link ImmutableClassType} which have been removed. */ protected Collection<ImmutableClassType> processRemovedAssignments(Collection<? extends AbstractClassSensorAssignment<?>> classSensorAssignments) { Collection<ImmutableClassType> changedClassTypes = new ArrayList<>(); // process all class sensor assignments for removal for (AbstractClassSensorAssignment<?> assignment : classSensorAssignments) { // narrow the search Collection<? extends ImmutableClassType> classTypes = classCacheSearchNarrower.narrowByClassSensorAssignment(getClassCache(), assignment); // get the applier IInstrumentationApplier instrumentationApplier = configurationResolver.getInstrumentationApplier(assignment, getEnvironment()); changedClassTypes.addAll(getClassCache().getInstrumentationService().removeInstrumentationPoints(classTypes, Collections.singleton(instrumentationApplier))); } // if no class was affected just return if (CollectionUtils.isNotEmpty(changedClassTypes)) { // if any class was affected re-check those classes against complete configuration // because we removed all instrumentation points Collection<IInstrumentationApplier> instrumentationAppliers = getConfigurationHolder().getInstrumentationAppliers(); getClassCache().getInstrumentationService().addInstrumentationPoints(changedClassTypes, getAgentConfiguration(), instrumentationAppliers); } return changedClassTypes; }
/** * Process the added assignments. New instrumentation points will be added to all the classes in * the class cache that fit to the given assignments. * * @param classSensorAssignments * Collection of added {@link AbstractClassSensorAssignment}s. * @return Returns a {@link Collection} of {@link ImmutableClassType} which have been added. */ protected Collection<ImmutableClassType> processAddedAssignments(Collection<? extends AbstractClassSensorAssignment<?>> classSensorAssignments) { Collection<ImmutableClassType> changedClassTypes = new ArrayList<>(); // process all class sensor assignments for adding for (AbstractClassSensorAssignment<?> assignment : classSensorAssignments) { // narrow the search Collection<? extends ImmutableClassType> classTypes = classCacheSearchNarrower.narrowByClassSensorAssignment(getClassCache(), assignment); // get the applier IInstrumentationApplier instrumentationApplier = configurationResolver.getInstrumentationApplier(assignment, getEnvironment()); // execute Collection<? extends ImmutableClassType> instrumentedClassTypes = getClassCache().getInstrumentationService().addInstrumentationPoints(classTypes, getAgentConfiguration(), Collections.singleton(instrumentationApplier)); changedClassTypes.addAll(instrumentedClassTypes); } return changedClassTypes; }
/** * {@inheritDoc} */ @Override protected Collection<ImmutableType> execute() { // always update with new Environment getConfigurationHolder().update(environmentUpdateEvent.getAfter(), getAgentId()); Collection<ImmutableType> changedClassTypes = new HashSet<>(); // then process removed and added assignments changedClassTypes.addAll(super.processRemovedAssignments(environmentUpdateEvent.getRemovedSensorAssignments(functionalAssignmentFactory))); changedClassTypes.addAll(super.processAddedAssignments(environmentUpdateEvent.getAddedSensorAssignments(functionalAssignmentFactory))); return changedClassTypes; }
if (CollectionUtils.isNotEmpty(changedTypes)) { if (log.isInfoEnabled()) { log.info("Updated instrumentation definition of {} class(es) for the agent [ID: {}]", changedTypes.size(), getAgentId()); List<InstrumentationDefinition> instrumentationDefinitions = new ArrayList<>(getClassCache().getInstrumentationService().getInstrumentationResults(changedTypes)); ClassInstrumentationChangedEvent event = new ClassInstrumentationChangedEvent(this, getAgentId(), instrumentationDefinitions); eventPublisher.publishEvent(event);
/** * {@inheritDoc} */ @Override protected Collection<ImmutableType> execute() { // always update configuration getConfigurationHolder().update(getEnvironment(), getAgentId()); Collection<ImmutableType> changedClassTypes = new HashSet<>(); // first process all removed and added assignments changedClassTypes.addAll(super.processRemovedAssignments(profileUpdateEvent.getRemovedSensorAssignments())); changedClassTypes.addAll(super.processAddedAssignments(profileUpdateEvent.getAddedSensorAssignments())); return changedClassTypes; }
/** * @return Returns agent configuration based on the {@link ConfigurationHolder}. */ protected AgentConfig getAgentConfiguration() { return getConfigurationHolder().getAgentConfiguration(); }