Search in sources :

Example 1 with Registry

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");
}
Also used : TapestryAppInitializer(org.apache.tapestry5.http.internal.TapestryAppInitializer) Registry(org.apache.tapestry5.ioc.Registry) Test(org.testng.annotations.Test)

Example 2 with Registry

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")));
}
Also used : Status(org.apache.tapestry5.ioc.services.Status) SymbolSource(org.apache.tapestry5.ioc.services.SymbolSource) Formatter(java.util.Formatter) ServiceActivityScoreboard(org.apache.tapestry5.ioc.services.ServiceActivityScoreboard) ServiceActivity(org.apache.tapestry5.ioc.services.ServiceActivity)

Example 3 with Registry

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;
}
Also used : RegistryBuilder(org.apache.tapestry5.ioc.RegistryBuilder) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 4 with 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);
}
Also used : PageTesterContext(org.apache.tapestry5.internal.test.PageTesterContext) EntityManagerManager(org.apache.tapestry5.jpa.EntityManagerManager) RegistryBuilder(org.apache.tapestry5.ioc.RegistryBuilder) ApplicationGlobals(org.apache.tapestry5.http.services.ApplicationGlobals)

Example 5 with Registry

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();
}
Also used : TapestryIOCModule(org.apache.tapestry5.ioc.modules.TapestryIOCModule)

Aggregations

RegistryBuilder (org.apache.tapestry5.ioc.RegistryBuilder)7 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 ObjectStreamException (java.io.ObjectStreamException)2 Method (java.lang.reflect.Method)2 TapestryAppInitializer (org.apache.tapestry5.http.internal.TapestryAppInitializer)2 JustInTimeObjectCreator (org.apache.tapestry5.ioc.internal.services.JustInTimeObjectCreator)2 BeforeClass (org.testng.annotations.BeforeClass)2 File (java.io.File)1 AnnotatedElement (java.lang.reflect.AnnotatedElement)1 Constructor (java.lang.reflect.Constructor)1 URL (java.net.URL)1 URLClassLoader (java.net.URLClassLoader)1 Formatter (java.util.Formatter)1 ServletContext (javax.servlet.ServletContext)1 StrategyRegistry (org.apache.tapestry5.commons.util.StrategyRegistry)1 AsyncRequestService (org.apache.tapestry5.http.internal.AsyncRequestService)1 ServletContextSymbolProvider (org.apache.tapestry5.http.internal.ServletContextSymbolProvider)1 SingleKeySymbolProvider (org.apache.tapestry5.http.internal.SingleKeySymbolProvider)1 DelegatingSymbolProvider (org.apache.tapestry5.http.internal.util.DelegatingSymbolProvider)1 ApplicationGlobals (org.apache.tapestry5.http.services.ApplicationGlobals)1