Java 类org.springframework.context.support.AbstractRefreshableApplicationContext 实例源码
项目:gemini.blueprint
文件:ClassUtilsTest.java
public void testAppContextClassHierarchy() {
Class<?>[] clazz =
ClassUtils.getClassHierarchy(OsgiBundleXmlApplicationContext.class, ClassUtils.ClassSet.ALL_CLASSES);
//Closeable.class,
Class<?>[] expected =
new Class<?>[] { OsgiBundleXmlApplicationContext.class,
AbstractDelegatedExecutionApplicationContext.class, AbstractOsgiBundleApplicationContext.class,
AbstractRefreshableApplicationContext.class, AbstractApplicationContext.class,
DefaultResourceLoader.class, ResourceLoader.class,
AutoCloseable.class,
DelegatedExecutionOsgiBundleApplicationContext.class,
ConfigurableOsgiBundleApplicationContext.class, ConfigurableApplicationContext.class,
ApplicationContext.class, Lifecycle.class, Closeable.class, EnvironmentCapable.class, ListableBeanFactory.class,
HierarchicalBeanFactory.class, ApplicationEventPublisher.class, ResourcePatternResolver.class,
MessageSource.class, BeanFactory.class, DisposableBean.class };
assertTrue(compareArrays(expected, clazz));
}
项目:community-edition-old
文件:NodeWebScripTest.java
@Override
protected void setUp() throws Exception
{
super.setUp();
AbstractRefreshableApplicationContext ctx = (AbstractRefreshableApplicationContext)getServer().getApplicationContext();
this.retryingTransactionHelper = (RetryingTransactionHelper)ctx.getBean("retryingTransactionHelper");
this.authenticationService = (MutableAuthenticationService)ctx.getBean("AuthenticationService");
this.personService = (PersonService)ctx.getBean("PersonService");
this.siteService = (SiteService)ctx.getBean("SiteService");
this.nodeService = (NodeService)ctx.getBean("NodeService");
this.nodeArchiveService = (NodeArchiveService)ctx.getBean("nodeArchiveService");
// Do the setup as admin
AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser();
// Create a site
TEST_SITE = createSite(TEST_SITE_NAME);
// Create two users, one who's a site member
createUser(USER_ONE, true);
createUser(USER_TWO, false);
// Do our tests by default as the first user who is a contributor
AuthenticationUtil.setFullyAuthenticatedUser(USER_ONE);
}
项目:spring-osgi
文件:ClassUtilsTest.java
public void testAppContextClassHierarchy() {
Class[] clazz = ClassUtils.getClassHierarchy(OsgiBundleXmlApplicationContext.class,
ClassUtils.INCLUDE_ALL_CLASSES);
Class[] expected = new Class[] { OsgiBundleXmlApplicationContext.class,
AbstractDelegatedExecutionApplicationContext.class, DelegatedExecutionOsgiBundleApplicationContext.class,
ConfigurableOsgiBundleApplicationContext.class, ConfigurableApplicationContext.class, ApplicationContext.class,
Lifecycle.class, Closeable.class, EnvironmentCapable.class, ListableBeanFactory.class,
HierarchicalBeanFactory.class, MessageSource.class, ApplicationEventPublisher.class,
ResourcePatternResolver.class, BeanFactory.class, ResourceLoader.class, AutoCloseable.class,
AbstractOsgiBundleApplicationContext.class, AbstractRefreshableApplicationContext.class,
AbstractApplicationContext.class, DisposableBean.class, DefaultResourceLoader.class };
String msg = "Class: ";
for (int i=0;i<clazz.length;i++) {
msg += clazz[i].getSimpleName() + " ";
}
assertTrue(msg, compareArrays(expected, clazz));
}
项目:carewebframework-core
文件:PropertyAwareResource.java
/**
* Use the application context to resolve any embedded property values within the original
* resource.
*/
@Override
public void setApplicationContext(ApplicationContext appContext) throws BeansException {
try (InputStream is = originalResource.getInputStream();) {
ConfigurableListableBeanFactory beanFactory = ((AbstractRefreshableApplicationContext) appContext)
.getBeanFactory();
StringBuilder sb = new StringBuilder();
Iterator<String> iter = IOUtils.lineIterator(is, "UTF-8");
boolean transformed = false;
while (iter.hasNext()) {
String line = iter.next();
if (line.contains("${")) {
transformed = true;
line = beanFactory.resolveEmbeddedValue(line);
}
sb.append(line);
}
transformedResource = !transformed ? originalResource : new ByteArrayResource(sb.toString().getBytes());
} catch (IOException e) {
throw MiscUtil.toUnchecked(e);
}
}
项目:gemini.blueprint
文件:DeadlockHandlingTest.java
/**
* While it may appear that this test is doing nothing, what it is doing is
* testing what happens when the OSGi framework is shutdown while the
* Spring/OSGi extender is deadlocked. If all goes well, the test will
* gracefully end. If not, it will hang for quite a while.
*/
public void testErrorHandling() throws Exception {
Resource errorResource = getLocator().locateArtifact("org.eclipse.gemini.blueprint.iandt", "deadlock",
getSpringDMVersion());
assertNotNull("bundle resource exists", errorResource);
Bundle errorBundle = bundleContext.installBundle(errorResource.getURL().toExternalForm());
assertNotNull("bundle exists", errorBundle);
errorBundle.start();
StringBuilder filter = new StringBuilder();
filter.append("(&");
filter.append("(").append(Constants.OBJECTCLASS).append("=").append(
AbstractRefreshableApplicationContext.class.getName()).append(")");
filter.append("(").append(ConfigurableOsgiBundleApplicationContext.APPLICATION_CONTEXT_SERVICE_PROPERTY_NAME);
filter.append("=").append("org.eclipse.gemini.blueprint.iandt.deadlock").append(")");
filter.append(")");
ServiceTracker tracker = new ServiceTracker(bundleContext, bundleContext.createFilter(filter.toString()), null);
try {
tracker.open();
AbstractRefreshableApplicationContext appContext = (AbstractRefreshableApplicationContext) tracker.waitForService(3000);
assertNull("Deadlock context should not be published", appContext);
}
finally {
tracker.close();
}
}
项目:alfresco-remote-api
文件:NodeWebScripTest.java
@Override
protected void setUp() throws Exception
{
super.setUp();
AbstractRefreshableApplicationContext ctx = (AbstractRefreshableApplicationContext)getServer().getApplicationContext();
this.retryingTransactionHelper = (RetryingTransactionHelper)ctx.getBean("retryingTransactionHelper");
this.authenticationService = (MutableAuthenticationService)ctx.getBean("AuthenticationService");
this.personService = (PersonService)ctx.getBean("PersonService");
this.siteService = (SiteService)ctx.getBean("SiteService");
this.nodeService = (NodeService)ctx.getBean("NodeService");
this.nodeArchiveService = (NodeArchiveService)ctx.getBean("nodeArchiveService");
this.checkOutCheckInService = (CheckOutCheckInService)ctx.getBean("checkOutCheckInService");
this.permissionService = (PermissionService)ctx.getBean("permissionService");
// Do the setup as admin
AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser();
// Create a site
TEST_SITE = createSite(TEST_SITE_NAME);
// Create two users, one who's a site member
createUser(USER_ONE, true);
createUser(USER_TWO, false);
// Do our tests by default as the first user who is a contributor
AuthenticationUtil.setFullyAuthenticatedUser(USER_ONE);
}
项目:elastic-config
文件:SpringZookeeperElasticConfigGroup.java
/**
* 刷新容器
*/
@Synchronized("lockObject")
private void refreshConext() {
RegistryCenterFactory.clearRegistryCenterMap();
if (applicationContext.getParent() != null) {
((AbstractRefreshableApplicationContext) applicationContext.getParent()).refresh();
}
((AbstractRefreshableApplicationContext) applicationContext).refresh();
}
项目:spring-osgi
文件:DeadlockHandlingTest.java
/**
* While it may appear that this test is doing nothing, what it is doing is
* testing what happens when the OSGi framework is shutdown while the
* Spring/OSGi extender is deadlocked. If all goes well, the test will
* gracefully end. If not, it will hang for quite a while.
*/
public void testErrorHandling() throws Exception {
Resource errorResource = getLocator().locateArtifact("org.springframework.osgi.iandt", "deadlock",
getSpringDMVersion());
assertNotNull("bundle resource exists", errorResource);
Bundle errorBundle = bundleContext.installBundle(errorResource.getURL().toExternalForm());
assertNotNull("bundle exists", errorBundle);
errorBundle.start();
StringBuffer filter = new StringBuffer();
filter.append("(&");
filter.append("(").append(Constants.OBJECTCLASS).append("=").append(
AbstractRefreshableApplicationContext.class.getName()).append(")");
filter.append("(").append(ConfigurableOsgiBundleApplicationContext.APPLICATION_CONTEXT_SERVICE_PROPERTY_NAME);
filter.append("=").append("org.springframework.osgi.iandt.deadlock").append(")");
filter.append(")");
ServiceTracker tracker = new ServiceTracker(bundleContext, bundleContext.createFilter(filter.toString()), null);
try {
tracker.open();
AbstractRefreshableApplicationContext appContext = (AbstractRefreshableApplicationContext) tracker.waitForService(3000);
assertNull("Deadlock context should not be published", appContext);
}
finally {
tracker.close();
}
}
项目:MaduraConfiguration
文件:ReloadListener.java
public void configurationChanged(ConfigurationEvent event)
{
if (!event.isBeforeUpdate() && event.getType() == AbstractFileConfiguration.EVENT_RELOAD)
{
if (m_applicationContext instanceof AbstractRefreshableApplicationContext)
{
((AbstractRefreshableApplicationContext)m_applicationContext).refresh();
}
}
}
项目:gemini.blueprint
文件:LifecycleTest.java
public void testLifecycle() throws Exception {
assertNotSame("Guinea pig has already been shutdown", "true",
System.getProperty("org.eclipse.gemini.blueprint.iandt.lifecycle.GuineaPig.close"));
assertEquals("Guinea pig didn't startup", "true",
System.getProperty("org.eclipse.gemini.blueprint.iandt.lifecycle.GuineaPig.startUp"));
Bundle[] bundles = bundleContext.getBundles();
Bundle testBundle = null;
for (int i = 0; i < bundles.length; i++) {
if ("org.eclipse.gemini.blueprint.iandt.lifecycle".equals(bundles[i].getSymbolicName())) {
testBundle = bundles[i];
break;
}
}
assertNotNull("Could not find the test bundle", testBundle);
StringBuilder filter = new StringBuilder();
filter.append("(&");
filter.append("(").append(Constants.OBJECTCLASS).append("=").append(ApplicationContext.class.getName()).append(")");
filter.append("(").append(ConfigurableOsgiBundleApplicationContext.APPLICATION_CONTEXT_SERVICE_PROPERTY_NAME);
filter.append("=").append(testBundle.getSymbolicName()).append(")");
filter.append(")");
logger.info("Creating filter = " + filter);
/*
[org.springframework.beans.factory.DisposableBean,
org.eclipse.gemini.blueprint.context.DelegatedExecutionOsgiBundleApplicationContext,
org.eclipse.gemini.blueprint.context.ConfigurableOsgiBundleApplicationContext,
org.springframework.context.ConfigurableApplicationContext,
org.springframework.context.ApplicationContext,
org.springframework.context.Lifecycle,
org.springframework.beans.factory.ListableBeanFactory,
org.springframework.beans.factory.HierarchicalBeanFactory,
org.springframework.context.MessageSource,
org.springframework.context.ApplicationEventPublisher,
org.springframework.core.io.support.ResourcePatternResolver,
org.springframework.beans.factory.BeanFactory,
org.springframework.core.io.ResourceLoader]
*/
// ServiceTracker tracker = new ServiceTracker(bundleContext, bundleContext.createFilter(filter.toString()), null);
// ServiceTracker tracker = new ServiceTracker(testBundle.getBundleContext(), testBundle.getBundleContext().createFilter(filter.toString()), null);
// tracker.open();
try {
// logger.info("All Services");
// ServiceReference[] refs = bundleContext.getAllServiceReferences(ApplicationContext.class.getName(), null);
// printServiceRefs(refs);
// logger.info("Visible Services from local context");
// refs = bundleContext.getServiceReferences(null, filter.toString());
// printServiceRefs(refs);
// logger.info("Visible Services from test client context");
// refs = testBundle.getBundleContext().getServiceReferences(null, filter.toString());
// printServiceRefs(refs);
//
// logger.info("tracking count = " + tracker.getTrackingCount());
// AbstractRefreshableApplicationContext appContext = (AbstractRefreshableApplicationContext) tracker.waitForService(50000);
// logger.info("tracking count = " + tracker.getTrackingCount());
// AbstractRefreshableApplicationContext appContext = (AbstractRefreshableApplicationContext) tracker.getService();
ServiceReference[] refs = bundleContext.getServiceReferences((String)null, filter.toString());
assertEquals("Should have a single service matched", 1, refs.length);
AbstractRefreshableApplicationContext appContext = (AbstractRefreshableApplicationContext)bundleContext.getService(refs[0]);
assertNotNull("test application context", appContext);
assertTrue("application context is active", appContext.isActive());
testBundle.stop();
while (testBundle.getState() == Bundle.STOPPING) {
Thread.sleep(10);
}
assertEquals("Guinea pig didn't shutdown", "true",
System.getProperty("org.eclipse.gemini.blueprint.iandt.lifecycle.GuineaPig.close"));
assertFalse("application context is inactive", appContext.isActive());
} finally {
// tracker.close();
}
}
项目:spring-osgi
文件:LifecycleTest.java
public void testLifecycle() throws Exception {
assertNotSame("Guinea pig has already been shutdown", "true",
System.getProperty("org.springframework.osgi.iandt.lifecycle.GuineaPig.close"));
assertEquals("Guinea pig didn't startup", "true",
System.getProperty("org.springframework.osgi.iandt.lifecycle.GuineaPig.startUp"));
Bundle[] bundles = bundleContext.getBundles();
Bundle testBundle = null;
for (int i = 0; i < bundles.length; i++) {
if ("org.springframework.osgi.iandt.lifecycle".equals(bundles[i].getSymbolicName())) {
testBundle = bundles[i];
break;
}
}
assertNotNull("Could not find the test bundle", testBundle);
StringBuffer filter = new StringBuffer();
filter.append("(&");
filter.append("(").append(Constants.OBJECTCLASS).append("=").append(ApplicationContext.class.getName()).append(
")");
filter.append("(").append(ConfigurableOsgiBundleApplicationContext.APPLICATION_CONTEXT_SERVICE_PROPERTY_NAME);
filter.append("=").append(testBundle.getSymbolicName()).append(")");
filter.append(")");
ServiceTracker tracker = new ServiceTracker(bundleContext, bundleContext.createFilter(filter.toString()), null);
try {
tracker.open();
AbstractRefreshableApplicationContext appContext = (AbstractRefreshableApplicationContext) tracker.waitForService(30000);
assertNotNull("test application context", appContext);
assertTrue("application context is active", appContext.isActive());
testBundle.stop();
while (testBundle.getState() == Bundle.STOPPING) {
Thread.sleep(10);
}
assertEquals("Guinea pig didn't shutdown", "true",
System.getProperty("org.springframework.osgi.iandt.lifecycle.GuineaPig.close"));
assertFalse("application context is inactive", appContext.isActive());
}
finally {
tracker.close();
}
}