Search in sources :

Example 1 with Scope

use of org.apache.tapestry5.ioc.annotations.Scope in project tapestry-5 by apache.

the class ServiceBinderImpl method flush.

protected void flush() {
    if (serviceInterface == null)
        return;
    if (source == null)
        source = createObjectCreatorSourceFromImplementationClass();
    // Combine service-specific markers with those inherited form the module.
    Set<Class> markers = CollectionFactory.newSet(defaultMarkers);
    markers.addAll(this.markers);
    ServiceDef serviceDef = new ServiceDefImpl(serviceInterface, serviceImplementation, serviceId, markers, scope, eagerLoad, preventDecoration, source);
    accumulator.addServiceDef(serviceDef);
    clear();
}
Also used : ServiceDef(org.apache.tapestry5.ioc.def.ServiceDef)

Example 2 with Scope

use of org.apache.tapestry5.ioc.annotations.Scope in project tapestry-5 by apache.

the class MongodbModule method buildMongoDB.

@Scope(ScopeConstants.PERTHREAD)
public static MongoDB buildMongoDB(Logger logger, final MongoDBSource mongoDBSource, PerthreadManager perthreadManager, @Symbol(MongoDBSymbols.DEFAULT_DB_NAME) String defaultDbName, @Symbol(MongoDBSymbols.CONSISTENT_REQUEST) boolean consistentRequest, @Symbol(MongoDBSymbols.SECURE_MODE) boolean secureMode, @Symbol(MongoDBSymbols.DB_USERNAME) String dbUsername, @Symbol(MongoDBSymbols.DB_PASSWORD) String dbPassword) {
    final MongoDBImpl mongoDB = new MongoDBImpl(logger, mongoDBSource, defaultDbName, consistentRequest, secureMode, dbUsername, dbPassword);
    perthreadManager.addThreadCleanupListener(mongoDB);
    return mongoDB;
}
Also used : MongoDBImpl(org.apache.tapestry5.internal.mongodb.MongoDBImpl) Scope(org.apache.tapestry5.ioc.annotations.Scope)

Example 3 with Scope

use of org.apache.tapestry5.ioc.annotations.Scope in project tapestry-5 by apache.

the class GeneratorAdapter method catchException.

/**
 * Marks the start of an exception handler.
 *
 * @param start beginning of the exception handler's scope (inclusive).
 * @param end end of the exception handler's scope (exclusive).
 * @param exception internal name of the type of exceptions handled by the handler.
 */
public void catchException(final Label start, final Label end, final Type exception) {
    Label catchLabel = new Label();
    if (exception == null) {
        mv.visitTryCatchBlock(start, end, catchLabel, null);
    } else {
        mv.visitTryCatchBlock(start, end, catchLabel, exception.getInternalName());
    }
    mark(catchLabel);
}
Also used : Label(org.apache.tapestry5.internal.plastic.asm.Label)

Example 4 with Scope

use of org.apache.tapestry5.ioc.annotations.Scope in project tapestry-5 by apache.

the class RegistryImpl method getServiceLifecycle.

@Override
public ServiceLifecycle2 getServiceLifecycle(String scope) {
    lock.check();
    ServiceLifecycle result = lifecycles.get(scope);
    if (result == null) {
        ServiceLifecycleSource source = getService("ServiceLifecycleSource", ServiceLifecycleSource.class);
        result = source.get(scope);
    }
    if (result == null)
        throw new RuntimeException(IOCMessages.unknownScope(scope));
    return InternalUtils.toServiceLifecycle2(result);
}
Also used : ServiceLifecycleSource(org.apache.tapestry5.ioc.services.ServiceLifecycleSource) ServiceLifecycle(org.apache.tapestry5.ioc.ServiceLifecycle)

Example 5 with Scope

use of org.apache.tapestry5.ioc.annotations.Scope in project tapestry-5 by apache.

the class ModuleImpl method create.

/**
 * Creates the service and updates the cache of created services.
 *
 * @param eagerLoadProxies a list into which any eager loaded proxies should be added
 */
private Object create(final ServiceDef3 def, final Collection<EagerLoadServiceProxy> eagerLoadProxies) {
    final String serviceId = def.getServiceId();
    final Logger logger = registry.getServiceLogger(serviceId);
    final Class serviceInterface = def.getServiceInterface();
    final boolean canBeProxied = canBeProxiedPredicate.test(serviceInterface);
    String description = String.format("Creating %s service %s", canBeProxied ? "proxy for" : "non-proxied instance of", serviceId);
    if (logger.isDebugEnabled())
        logger.debug(description);
    final Module module = this;
    Invokable operation = new Invokable() {

        @Override
        public Object invoke() {
            try {
                ServiceBuilderResources resources = new ServiceResourcesImpl(registry, module, def, proxyFactory, logger);
                // Build up a stack of operations that will be needed to realize the service
                // (by the proxy, at a later date).
                ObjectCreator creator = def.createServiceCreator(resources);
                // For non-proxyable services, we immediately create the service implementation
                // and return it. There's no interface to proxy, which throws out the possibility of
                // deferred instantiation, service lifecycles, and decorators.
                ServiceLifecycle2 lifecycle = registry.getServiceLifecycle(def.getServiceScope());
                if (!canBeProxied) {
                    if (lifecycle.requiresProxy())
                        throw new IllegalArgumentException(String.format("Service scope '%s' requires a proxy, but the service does not have a service interface (necessary to create a proxy). Provide a service interface or select a different service scope.", def.getServiceScope()));
                    return creator.createObject();
                }
                creator = new OperationTrackingObjectCreator(registry, String.format("Instantiating service %s implementation via %s", serviceId, creator), creator);
                creator = new LifecycleWrappedServiceCreator(lifecycle, resources, creator);
                // Marked services (or services inside marked modules) are not decorated.
                // TapestryIOCModule prevents decoration of its services. Note that all decorators will decorate
                // around the aspect interceptor, which wraps around the core service implementation.
                boolean allowDecoration = !def.isPreventDecoration();
                if (allowDecoration) {
                    creator = new AdvisorStackBuilder(def, creator, getAspectDecorator(), registry);
                    creator = new InterceptorStackBuilder(def, creator, registry);
                }
                // Add a wrapper that checks for recursion.
                creator = new RecursiveServiceCreationCheckWrapper(def, creator, logger);
                creator = new OperationTrackingObjectCreator(registry, "Realizing service " + serviceId, creator);
                JustInTimeObjectCreator delegate = new JustInTimeObjectCreator(tracker, creator, serviceId);
                Object proxy = createProxy(resources, delegate, def.isPreventDecoration());
                registry.addRegistryShutdownListener(delegate);
                if (def.isEagerLoad() && eagerLoadProxies != null)
                    eagerLoadProxies.add(delegate);
                tracker.setStatus(serviceId, Status.VIRTUAL);
                return proxy;
            } catch (Exception ex) {
                ex.printStackTrace();
                throw new RuntimeException(IOCMessages.errorBuildingService(serviceId, def, ex), ex);
            }
        }
    };
    return registry.invoke(description, operation);
}
Also used : JustInTimeObjectCreator(org.apache.tapestry5.ioc.internal.services.JustInTimeObjectCreator) Logger(org.slf4j.Logger) ServiceBuilderResources(org.apache.tapestry5.ioc.ServiceBuilderResources) InvocationTargetException(java.lang.reflect.InvocationTargetException) ObjectStreamException(java.io.ObjectStreamException) JustInTimeObjectCreator(org.apache.tapestry5.ioc.internal.services.JustInTimeObjectCreator) ServiceLifecycle2(org.apache.tapestry5.ioc.ServiceLifecycle2) Invokable(org.apache.tapestry5.ioc.Invokable)

Aggregations

Scope (org.apache.tapestry5.ioc.annotations.Scope)3 ObjectStreamException (java.io.ObjectStreamException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 EntityManagerManagerImpl (org.apache.tapestry5.internal.jpa.EntityManagerManagerImpl)1 MongoDBImpl (org.apache.tapestry5.internal.mongodb.MongoDBImpl)1 Label (org.apache.tapestry5.internal.plastic.asm.Label)1 Invokable (org.apache.tapestry5.ioc.Invokable)1 ServiceBuilderResources (org.apache.tapestry5.ioc.ServiceBuilderResources)1 ServiceLifecycle (org.apache.tapestry5.ioc.ServiceLifecycle)1 ServiceLifecycle2 (org.apache.tapestry5.ioc.ServiceLifecycle2)1 Marker (org.apache.tapestry5.ioc.annotations.Marker)1 ServiceDef (org.apache.tapestry5.ioc.def.ServiceDef)1 JustInTimeObjectCreator (org.apache.tapestry5.ioc.internal.services.JustInTimeObjectCreator)1 ServiceLifecycleSource (org.apache.tapestry5.ioc.services.ServiceLifecycleSource)1 Logger (org.slf4j.Logger)1