use of org.apache.tapestry5.ioc.Registry in project tapestry-5 by apache.
the class TapestryAppInitializerTest method testLoadAppModule.
@SuppressWarnings("unchecked")
@Test
public void testLoadAppModule() {
Registry registry = new TapestryAppInitializer(logger, "org.apache.tapestry5.integration.app0", "foo").createRegistry();
Transformer<String> s1 = registry.getService("Service1", Transformer.class);
assertEquals(s1.transform("a"), "A");
}
use of org.apache.tapestry5.ioc.Registry in project tapestry-5 by apache.
the class TapestryAppInitializer method announceStartup.
/**
* Announce application startup, by logging (at INFO level) the names of all pages,
* components, mixins and services.
*/
public void announceStartup() {
if (// if info logging is off we can stop now
!logger.isInfoEnabled()) {
return;
}
long toFinish = System.currentTimeMillis();
SymbolSource source = registry.getService("SymbolSource", SymbolSource.class);
StringBuilder buffer = new StringBuilder("Startup status:\n\nServices:\n\n");
Formatter f = new Formatter(buffer);
int unrealized = 0;
ServiceActivityScoreboard scoreboard = registry.getService(ServiceActivityScoreboard.class);
List<ServiceActivity> serviceActivity = scoreboard.getServiceActivity();
int longest = 0;
for (ServiceActivity activity : serviceActivity) {
Status status = activity.getStatus();
longest = Math.max(longest, activity.getServiceId().length());
if (status == Status.DEFINED || status == Status.VIRTUAL)
unrealized++;
}
String formatString = "%" + longest + "s: %s\n";
for (ServiceActivity activity : serviceActivity) {
f.format(formatString, activity.getServiceId(), activity.getStatus().name());
}
f.format("\n%4.2f%% unrealized services (%d/%d)\n", 100. * unrealized / serviceActivity.size(), unrealized, serviceActivity.size());
f.format("\nApplication '%s' (version %s) startup time: %,d ms to build IoC Registry, %,d ms overall.", appName, source.valueForSymbol(TapestryHttpSymbolConstants.APPLICATION_VERSION), registryCreatedTime - startTime, toFinish - startTime);
String version = source.valueForSymbol(TapestryHttpSymbolConstants.TAPESTRY_VERSION);
boolean productionMode = Boolean.parseBoolean(source.valueForSymbol(TapestryHttpSymbolConstants.PRODUCTION_MODE));
buffer.append("\n\n");
buffer.append(" ______ __ ____\n");
buffer.append("/_ __/__ ____ ___ ___ / /_______ __ / __/\n");
buffer.append(" / / / _ `/ _ \\/ -_|_-</ __/ __/ // / /__ \\ \n");
buffer.append("/_/ \\_,_/ .__/\\__/___/\\__/_/ \\_, / /____/\n");
f.format(" /_/ /___/ %s%s\n\n", version, productionMode ? "" : " (development mode)");
// log multi-line string with OS-specific line endings (TAP5-2294)
logger.info(buffer.toString().replaceAll("\\n", System.getProperty("line.separator")));
}
use of org.apache.tapestry5.ioc.Registry in project tapestry-5 by apache.
the class TestRegistryManager method getOrCreateRegistry.
/**
* Get the existing registry or create one if required.
* @return The test Registry
* @throws Exception
*/
public org.apache.tapestry5.ioc.Registry getOrCreateRegistry() throws Exception {
if (registry == null) {
RegistryBuilder builder = new RegistryBuilder();
if (annotation.modules() != null) {
builder.add(annotation.modules());
}
for (Method moduleDefFactory : moduleDefFactories) {
try {
org.apache.tapestry5.ioc.def.ModuleDef moduleDef = (org.apache.tapestry5.ioc.def.ModuleDef) moduleDefFactory.invoke(null);
builder.add(moduleDef);
} catch (InvocationTargetException e) {
if (e.getTargetException() instanceof Exception) {
throw (Exception) e.getTargetException();
}
throw e;
}
}
registry = builder.build();
registry.performRegistryStartup();
}
return registry;
}
use of org.apache.tapestry5.ioc.Registry in project tapestry-5 by apache.
the class JpaTest method setupRegistry.
// @BeforeSuite
public final void setupRegistry() {
RegistryBuilder builder = new RegistryBuilder();
builder.add(TapestryModule.class);
builder.add(JpaModule.class);
builder.add(JpaTestModule.class);
registry = builder.build();
// set PageTesterContext, otherwise T5 tries to load classpath assets
ApplicationGlobals globals = registry.getObject(ApplicationGlobals.class, null);
globals.storeContext(new PageTesterContext(""));
registry.performRegistryStartup();
entityManagerManager = registry.getService(EntityManagerManager.class);
topLevelService = registry.getService(TopLevelService.class);
}
use of org.apache.tapestry5.ioc.Registry in project tapestry-5 by apache.
the class RegistryImpl method performRegistryStartup.
/**
* It's not unreasonable for an eagerly-loaded service to decide to start a thread, at which
* point we raise issues
* about improper publishing of the Registry instance from the RegistryImpl constructor. Moving
* eager loading of
* services out to its own method should ensure thread safety.
*/
@Override
public void performRegistryStartup() {
if (JDKUtils.JDK_1_5) {
throw new RuntimeException("Your JDK version is too old." + " Tapestry requires Java 1.6 or newer since version 5.4.");
}
eagerLoadLock.lock();
List<EagerLoadServiceProxy> proxies = CollectionFactory.newList();
for (Module m : moduleToServiceDefs.keySet()) m.collectEagerLoadServices(proxies);
for (EagerLoadServiceProxy proxy : proxies) {
proxy.eagerLoadService();
}
for (Runnable startup : startups) {
startup.run();
}
startups.clear();
getService("RegistryStartup", Runnable.class).run();
cleanupThread();
}
Aggregations