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);
}
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);
}
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";
}
};
}
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;
}
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;
}
Aggregations