org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver Java Examples

The following examples show how to use org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DefaultContextLoadTimeWeaver.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Override
public void setBeanClassLoader(ClassLoader classLoader) {
	LoadTimeWeaver serverSpecificLoadTimeWeaver = createServerSpecificLoadTimeWeaver(classLoader);
	if (serverSpecificLoadTimeWeaver != null) {
		if (logger.isInfoEnabled()) {
			logger.info("Determined server-specific load-time weaver: " +
					serverSpecificLoadTimeWeaver.getClass().getName());
		}
		this.loadTimeWeaver = serverSpecificLoadTimeWeaver;
	}
	else if (InstrumentationLoadTimeWeaver.isInstrumentationAvailable()) {
		logger.info("Found Spring's JVM agent for instrumentation");
		this.loadTimeWeaver = new InstrumentationLoadTimeWeaver(classLoader);
	}
	else {
		try {
			this.loadTimeWeaver = new ReflectiveLoadTimeWeaver(classLoader);
			logger.info("Using a reflective load-time weaver for class loader: " +
					this.loadTimeWeaver.getInstrumentableClassLoader().getClass().getName());
		}
		catch (IllegalStateException ex) {
			throw new IllegalStateException(ex.getMessage() + " Specify a custom LoadTimeWeaver or start your " +
					"Java virtual machine with Spring's agent: -javaagent:org.springframework.instrument.jar");
		}
	}
}
 
Example #2
Source File: DefaultContextLoadTimeWeaver.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void setBeanClassLoader(ClassLoader classLoader) {
	LoadTimeWeaver serverSpecificLoadTimeWeaver = createServerSpecificLoadTimeWeaver(classLoader);
	if (serverSpecificLoadTimeWeaver != null) {
		if (logger.isInfoEnabled()) {
			logger.info("Determined server-specific load-time weaver: " +
					serverSpecificLoadTimeWeaver.getClass().getName());
		}
		this.loadTimeWeaver = serverSpecificLoadTimeWeaver;
	}
	else if (InstrumentationLoadTimeWeaver.isInstrumentationAvailable()) {
		logger.info("Found Spring's JVM agent for instrumentation");
		this.loadTimeWeaver = new InstrumentationLoadTimeWeaver(classLoader);
	}
	else {
		try {
			this.loadTimeWeaver = new ReflectiveLoadTimeWeaver(classLoader);
			logger.info("Using a reflective load-time weaver for class loader: " +
					this.loadTimeWeaver.getInstrumentableClassLoader().getClass().getName());
		}
		catch (IllegalStateException ex) {
			throw new IllegalStateException(ex.getMessage() + " Specify a custom LoadTimeWeaver or start your " +
					"Java virtual machine with Spring's agent: -javaagent:org.springframework.instrument.jar");
		}
	}
}
 
Example #3
Source File: DefaultContextLoadTimeWeaver.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public void destroy() {
	if (this.loadTimeWeaver instanceof InstrumentationLoadTimeWeaver) {
		if (logger.isDebugEnabled()) {
			logger.debug("Removing all registered transformers for class loader: " +
					this.loadTimeWeaver.getInstrumentableClassLoader().getClass().getName());
		}
		((InstrumentationLoadTimeWeaver) this.loadTimeWeaver).removeTransformers();
	}
}
 
Example #4
Source File: Main.java    From invesdwin-instrument with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void main(String[] args) {
	DynamicInstrumentationLoader.waitForInitialized();
	DynamicInstrumentationLoader.initLoadTimeWeavingContext();
	if (!InstrumentationLoadTimeWeaver.isInstrumentationAvailable()) {
		throw new IllegalStateException("Instrumentation not available!");
	} else {
		System.out.println("Instrumentation available!");
	}
}
 
Example #5
Source File: AgentInstrumentationInitializer.java    From invesdwin-instrument with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void initialize(final String args, final Instrumentation inst) {
    if (InstrumentationLoadTimeWeaver.isInstrumentationAvailable()) {
        throw new IllegalStateException(
                "Instrumentation is already available, the agent should have been loaded already!");
    }

    InstrumentationSavingAgent.premain(args, inst);
}
 
Example #6
Source File: LocalContainerEntityManagerFactoryBeanTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
protected LocalContainerEntityManagerFactoryBean createEntityManagerFactoryBean(
		String persistenceXml, Properties props, String entityManagerName) throws Exception {

	// This will be set by DummyPersistenceProvider
	actualPui = null;
	actualProps = null;

	LocalContainerEntityManagerFactoryBean containerEmfb = new LocalContainerEntityManagerFactoryBean();

	containerEmfb.setPersistenceUnitName(entityManagerName);
	containerEmfb.setPersistenceProviderClass(DummyContainerPersistenceProvider.class);
	if (props != null) {
		containerEmfb.setJpaProperties(props);
	}
	containerEmfb.setLoadTimeWeaver(new InstrumentationLoadTimeWeaver());
	containerEmfb.setPersistenceXmlLocation(persistenceXml);
	containerEmfb.afterPropertiesSet();

	assertEquals(entityManagerName, actualPui.getPersistenceUnitName());
	if (props != null) {
		assertEquals(props, actualProps);
	}
	//checkInvariants(containerEmfb);

	return containerEmfb;

	//containerEmfb.destroy();
	//emfMc.verify();
}
 
Example #7
Source File: DefaultPersistenceUnitManager.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public void afterPropertiesSet() {
	if (this.loadTimeWeaver == null && InstrumentationLoadTimeWeaver.isInstrumentationAvailable()) {
		this.loadTimeWeaver = new InstrumentationLoadTimeWeaver(this.resourcePatternResolver.getClassLoader());
	}
	preparePersistenceUnitInfos();
}
 
Example #8
Source File: DefaultContextLoadTimeWeaver.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public void destroy() {
	if (this.loadTimeWeaver instanceof InstrumentationLoadTimeWeaver) {
		logger.info("Removing all registered transformers for class loader: " +
				this.loadTimeWeaver.getInstrumentableClassLoader().getClass().getName());
		((InstrumentationLoadTimeWeaver) this.loadTimeWeaver).removeTransformers();
	}
}
 
Example #9
Source File: DefaultPersistenceUnitManager.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void afterPropertiesSet() {
	if (this.loadTimeWeaver == null && InstrumentationLoadTimeWeaver.isInstrumentationAvailable()) {
		this.loadTimeWeaver = new InstrumentationLoadTimeWeaver(this.resourcePatternResolver.getClassLoader());
	}
	preparePersistenceUnitInfos();
}
 
Example #10
Source File: DefaultContextLoadTimeWeaver.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void destroy() {
	if (this.loadTimeWeaver instanceof InstrumentationLoadTimeWeaver) {
		logger.info("Removing all registered transformers for class loader: " +
				this.loadTimeWeaver.getInstrumentableClassLoader().getClass().getName());
		((InstrumentationLoadTimeWeaver) this.loadTimeWeaver).removeTransformers();
	}
}
 
Example #11
Source File: PersistenceConfig.java    From Spring with Apache License 2.0 5 votes vote down vote up
@Bean
public EntityManagerFactory entityManagerFactory() {
	LocalContainerEntityManagerFactoryBean factoryBean = new LocalContainerEntityManagerFactoryBean();
	factoryBean.setPersistenceUnitManager(persistenceUnitManager());
	factoryBean.setJpaVendorAdapter(new HibernateJpaVendorAdapter());
	factoryBean.setJpaProperties(dataConfig.hibernateProperties());
	factoryBean.afterPropertiesSet();
	factoryBean.setLoadTimeWeaver(new InstrumentationLoadTimeWeaver());
	return factoryBean.getNativeEntityManagerFactory();
}
 
Example #12
Source File: ServiceConfig.java    From Spring with Apache License 2.0 5 votes vote down vote up
@Bean
public EntityManagerFactory entityManagerFactory() {
    final LocalContainerEntityManagerFactoryBean factoryBean = new LocalContainerEntityManagerFactoryBean();
    factoryBean.setPersistenceUnitManager(persistenceUnitManager());
    factoryBean.setJpaVendorAdapter(new HibernateJpaVendorAdapter());
    factoryBean.setJpaProperties(dataConfig.hibernateProperties());
    factoryBean.afterPropertiesSet();
    factoryBean.setLoadTimeWeaver(new InstrumentationLoadTimeWeaver());
    return factoryBean.getNativeEntityManagerFactory();
}
 
Example #13
Source File: PersistenceConfig.java    From Spring with Apache License 2.0 5 votes vote down vote up
@Bean
public EntityManagerFactory entityManagerFactory(){
    final LocalContainerEntityManagerFactoryBean factoryBean = new LocalContainerEntityManagerFactoryBean();
    factoryBean.setPersistenceUnitManager(persistenceUnitManager());
    factoryBean.setJpaVendorAdapter(new HibernateJpaVendorAdapter());
    factoryBean.setJpaProperties(dataConfig.hibernateProperties());
    factoryBean.afterPropertiesSet();
    factoryBean.setLoadTimeWeaver(new InstrumentationLoadTimeWeaver());
    return factoryBean.getNativeEntityManagerFactory();
}
 
Example #14
Source File: LocalContainerEntityManagerFactoryBeanTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
protected LocalContainerEntityManagerFactoryBean createEntityManagerFactoryBean(
		String persistenceXml, Properties props, String entityManagerName) throws Exception {

	// This will be set by DummyPersistenceProvider
	actualPui = null;
	actualProps = null;

	LocalContainerEntityManagerFactoryBean containerEmfb = new LocalContainerEntityManagerFactoryBean();

	containerEmfb.setPersistenceUnitName(entityManagerName);
	containerEmfb.setPersistenceProviderClass(DummyContainerPersistenceProvider.class);
	if (props != null) {
		containerEmfb.setJpaProperties(props);
	}
	containerEmfb.setLoadTimeWeaver(new InstrumentationLoadTimeWeaver());
	containerEmfb.setPersistenceXmlLocation(persistenceXml);
	containerEmfb.afterPropertiesSet();

	assertEquals(entityManagerName, actualPui.getPersistenceUnitName());
	if (props != null) {
		assertEquals(props, actualProps);
	}
	//checkInvariants(containerEmfb);

	return containerEmfb;

	//containerEmfb.destroy();
	//emfMc.verify();
}
 
Example #15
Source File: DefaultPersistenceUnitManager.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public void afterPropertiesSet() {
	if (this.loadTimeWeaver == null && InstrumentationLoadTimeWeaver.isInstrumentationAvailable()) {
		this.loadTimeWeaver = new InstrumentationLoadTimeWeaver(this.resourcePatternResolver.getClassLoader());
	}
	preparePersistenceUnitInfos();
}
 
Example #16
Source File: DefaultContextLoadTimeWeaver.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public void destroy() {
	if (this.loadTimeWeaver instanceof InstrumentationLoadTimeWeaver) {
		if (logger.isDebugEnabled()) {
			logger.debug("Removing all registered transformers for class loader: " +
					this.loadTimeWeaver.getInstrumentableClassLoader().getClass().getName());
		}
		((InstrumentationLoadTimeWeaver) this.loadTimeWeaver).removeTransformers();
	}
}
 
Example #17
Source File: DefaultContextLoadTimeWeaver.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public void setBeanClassLoader(ClassLoader classLoader) {
	LoadTimeWeaver serverSpecificLoadTimeWeaver = createServerSpecificLoadTimeWeaver(classLoader);
	if (serverSpecificLoadTimeWeaver != null) {
		if (logger.isDebugEnabled()) {
			logger.debug("Determined server-specific load-time weaver: " +
					serverSpecificLoadTimeWeaver.getClass().getName());
		}
		this.loadTimeWeaver = serverSpecificLoadTimeWeaver;
	}
	else if (InstrumentationLoadTimeWeaver.isInstrumentationAvailable()) {
		logger.debug("Found Spring's JVM agent for instrumentation");
		this.loadTimeWeaver = new InstrumentationLoadTimeWeaver(classLoader);
	}
	else {
		try {
			this.loadTimeWeaver = new ReflectiveLoadTimeWeaver(classLoader);
			if (logger.isDebugEnabled()) {
				logger.debug("Using reflective load-time weaver for class loader: " +
						this.loadTimeWeaver.getInstrumentableClassLoader().getClass().getName());
			}
		}
		catch (IllegalStateException ex) {
			throw new IllegalStateException(ex.getMessage() + " Specify a custom LoadTimeWeaver or start your " +
					"Java virtual machine with Spring's agent: -javaagent:org.springframework.instrument.jar");
		}
	}
}
 
Example #18
Source File: LocalContainerEntityManagerFactoryBeanTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
protected LocalContainerEntityManagerFactoryBean createEntityManagerFactoryBean(
		String persistenceXml, Properties props, String entityManagerName) throws Exception {

	// This will be set by DummyPersistenceProvider
	actualPui = null;
	actualProps = null;

	LocalContainerEntityManagerFactoryBean containerEmfb = new LocalContainerEntityManagerFactoryBean();

	containerEmfb.setPersistenceUnitName(entityManagerName);
	containerEmfb.setPersistenceProviderClass(DummyContainerPersistenceProvider.class);
	if (props != null) {
		containerEmfb.setJpaProperties(props);
	}
	containerEmfb.setLoadTimeWeaver(new InstrumentationLoadTimeWeaver());
	containerEmfb.setPersistenceXmlLocation(persistenceXml);
	containerEmfb.afterPropertiesSet();

	assertEquals(entityManagerName, actualPui.getPersistenceUnitName());
	if (props != null) {
		assertEquals(props, actualProps);
	}
	//checkInvariants(containerEmfb);

	return containerEmfb;

	//containerEmfb.destroy();
	//emfMc.verify();
}
 
Example #19
Source File: DefaultPersistenceUnitManager.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public void afterPropertiesSet() {
	if (this.loadTimeWeaver == null && InstrumentationLoadTimeWeaver.isInstrumentationAvailable()) {
		this.loadTimeWeaver = new InstrumentationLoadTimeWeaver(this.resourcePatternResolver.getClassLoader());
	}
	preparePersistenceUnitInfos();
}
 
Example #20
Source File: DefaultContextLoadTimeWeaver.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public void setBeanClassLoader(ClassLoader classLoader) {
	LoadTimeWeaver serverSpecificLoadTimeWeaver = createServerSpecificLoadTimeWeaver(classLoader);
	if (serverSpecificLoadTimeWeaver != null) {
		if (logger.isDebugEnabled()) {
			logger.debug("Determined server-specific load-time weaver: " +
					serverSpecificLoadTimeWeaver.getClass().getName());
		}
		this.loadTimeWeaver = serverSpecificLoadTimeWeaver;
	}
	else if (InstrumentationLoadTimeWeaver.isInstrumentationAvailable()) {
		logger.debug("Found Spring's JVM agent for instrumentation");
		this.loadTimeWeaver = new InstrumentationLoadTimeWeaver(classLoader);
	}
	else {
		try {
			this.loadTimeWeaver = new ReflectiveLoadTimeWeaver(classLoader);
			if (logger.isDebugEnabled()) {
				logger.debug("Using reflective load-time weaver for class loader: " +
						this.loadTimeWeaver.getInstrumentableClassLoader().getClass().getName());
			}
		}
		catch (IllegalStateException ex) {
			throw new IllegalStateException(ex.getMessage() + " Specify a custom LoadTimeWeaver or start your " +
					"Java virtual machine with Spring's agent: -javaagent:spring-instrument-{version}.jar");
		}
	}
}
 
Example #21
Source File: DynamicInstrumentationLoader.java    From invesdwin-instrument with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static boolean isInitialized() {
    return InstrumentationLoadTimeWeaver.isInstrumentationAvailable();
}
 
Example #22
Source File: JpaConfiguration.java    From tutorials with MIT License 4 votes vote down vote up
private String detectWeavingMode() {
    return InstrumentationLoadTimeWeaver.isInstrumentationAvailable() ? "true" : "static";
}
 
Example #23
Source File: EspmJpaConfig.java    From cloud-espm-cloud-native with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the weaving mode.
 * 
 * @return string
 */
private String getWeavingMode() {
    return InstrumentationLoadTimeWeaver.isInstrumentationAvailable() ? "true" : "static";
}
 
Example #24
Source File: AbstractJpaTests.java    From spring4-understanding with Apache License 2.0 2 votes vote down vote up
/**
 * Subclasses should override this method if they wish to disable shadow class loading.
 * <p>The default implementation deactivates shadow class loading if Spring's
 * InstrumentationSavingAgent has been configured on VM startup.
 */
protected boolean shouldUseShadowLoader() {
	return !InstrumentationLoadTimeWeaver.isInstrumentationAvailable();
}