Search in sources :

Example 1 with Invokable

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

the class TopLevelServiceImpl method createThingOneThenTwo.

@Override
@CommitAfter
public void createThingOneThenTwo(final String nameOne, final String nameTwo) {
    entityTransactionManager.invokeAfterCommit(null, new Invokable<Boolean>() {

        @Override
        public Boolean invoke() {
            nestedService.createThingTwo(nameTwo);
            return true;
        }
    });
    ThingOne thingOne = new ThingOne();
    thingOne.setName(nameOne);
    em.persist(thingOne);
}
Also used : ThingOne(org.apache.tapestry5.jpa.test.entities.ThingOne) CommitAfter(org.apache.tapestry5.jpa.annotations.CommitAfter)

Example 2 with Invokable

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

the class ModuleImpl method findOrCreate.

/**
 * Locates the service proxy for a particular service (from the service definition).
 *
 * @param def              defines the service
 * @param eagerLoadProxies collection into which proxies for eager loaded services are added (or null)
 * @return the service proxy
 */
private Object findOrCreate(final ServiceDef3 def, final Collection<EagerLoadServiceProxy> eagerLoadProxies) {
    final String key = def.getServiceId();
    final Invokable create = new Invokable() {

        @Override
        public Object invoke() {
            // In a race condition, two threads may try to create the same service simulatenously.
            // The second will block until after the first creates the service.
            Object result = services.get(key);
            if (result == null) {
                result = create(def, eagerLoadProxies);
                services.put(key, result);
            }
            return result;
        }
    };
    Invokable find = new Invokable() {

        @Override
        public Object invoke() {
            Object result = services.get(key);
            if (result == null)
                result = BARRIER.withWrite(create);
            return result;
        }
    };
    return BARRIER.withRead(find);
}
Also used : Invokable(org.apache.tapestry5.ioc.Invokable)

Example 3 with Invokable

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

the class SpringModuleDef method constructObjectCreatorForApplicationContext.

private ObjectCreator constructObjectCreatorForApplicationContext(final ServiceBuilderResources resources, @Primary ApplicationContextCustomizer customizer) {
    final CustomizingContextLoader loader = new CustomizingContextLoader(customizer);
    final Runnable shutdownListener = new Runnable() {

        @Override
        public void run() {
            loader.closeWebApplicationContext(servletContext);
        }
    };
    final RegistryShutdownHub shutdownHub = resources.getService(RegistryShutdownHub.class);
    return new ObjectCreator() {

        @Override
        public Object createObject() {
            return resources.getTracker().invoke("Creating Spring ApplicationContext via ContextLoader", new Invokable<Object>() {

                @Override
                public Object invoke() {
                    resources.getLogger().info(String.format("Starting Spring (version %s)", SpringVersion.getVersion()));
                    WebApplicationContext context = loader.initWebApplicationContext(servletContext);
                    shutdownHub.addRegistryShutdownListener(shutdownListener);
                    applicationContextCreated.set(true);
                    return context;
                }
            });
        }

        @Override
        public String toString() {
            return "ObjectCreator for Spring ApplicationContext";
        }
    };
}
Also used : RegistryShutdownHub(org.apache.tapestry5.ioc.services.RegistryShutdownHub) WebApplicationContext(org.springframework.web.context.WebApplicationContext) ConfigurableWebApplicationContext(org.springframework.web.context.ConfigurableWebApplicationContext)

Example 4 with Invokable

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

the class ComponentEventImplTest method mockResources.

private ComponentPageElementResources mockResources() {
    ComponentPageElementResources resources = newMock(ComponentPageElementResources.class);
    expect(resources.invoke(EasyMock.isA(String.class), EasyMock.isA(Invokable.class))).andAnswer(new IAnswer<Object>() {

        public Object answer() throws Throwable {
            Invokable inv = (Invokable) EasyMock.getCurrentArguments()[1];
            return inv.invoke();
        }
    });
    return resources;
}
Also used : Invokable(org.apache.tapestry5.ioc.Invokable) ComponentPageElementResources(org.apache.tapestry5.internal.structure.ComponentPageElementResources)

Example 5 with Invokable

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

the class InterceptorStackBuilder method createObject.

@Override
public Object createObject() {
    Object current = delegate.createObject();
    List<ServiceDecorator> decorators = registry.findDecoratorsForService(serviceDef);
    // We get the decorators ordered according to their dependencies. However, we want to
    // process from the last interceptor to the first, so we reverse the list.
    Collections.reverse(decorators);
    for (final ServiceDecorator decorator : decorators) {
        final Object delegate = current;
        Object interceptor = registry.invoke("Invoking " + decorator, new Invokable<Object>() {

            @Override
            public Object invoke() {
                return decorator.createInterceptor(delegate);
            }
        });
        if (interceptor != null)
            current = interceptor;
    }
    return current;
}
Also used : ServiceDecorator(org.apache.tapestry5.ioc.ServiceDecorator)

Aggregations

Invokable (org.apache.tapestry5.ioc.Invokable)4 Map (java.util.Map)2 OperationTracker (org.apache.tapestry5.ioc.OperationTracker)2 ObjectStreamException (java.io.ObjectStreamException)1 Array (java.lang.reflect.Array)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Pattern (java.util.regex.Pattern)1 EntityTransaction (javax.persistence.EntityTransaction)1 ComponentResources (org.apache.tapestry5.ComponentResources)1 EventContext (org.apache.tapestry5.EventContext)1 ValueEncoder (org.apache.tapestry5.ValueEncoder)1 DisableStrictChecks (org.apache.tapestry5.annotations.DisableStrictChecks)1 OnEvent (org.apache.tapestry5.annotations.OnEvent)1 PublishEvent (org.apache.tapestry5.annotations.PublishEvent)1 RequestBody (org.apache.tapestry5.annotations.RequestBody)1 RequestParameter (org.apache.tapestry5.annotations.RequestParameter)1