You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by da...@apache.org on 2013/03/27 00:22:48 UTC
git commit: ISIS-370: init services by Reflector, not the runtime
Updated Branches:
refs/heads/master d8a4d7d94 -> 06f2b0f63
ISIS-370: init services by Reflector, not the runtime
* so that RegisterEntities service is called prior to the caching of the ObjectSpecifications by ObjectSpecId.
Project: http://git-wip-us.apache.org/repos/asf/isis/repo
Commit: http://git-wip-us.apache.org/repos/asf/isis/commit/06f2b0f6
Tree: http://git-wip-us.apache.org/repos/asf/isis/tree/06f2b0f6
Diff: http://git-wip-us.apache.org/repos/asf/isis/diff/06f2b0f6
Branch: refs/heads/master
Commit: 06f2b0f63c129eff5cdd6e1f6c39d36c7a807a6b
Parents: d8a4d7d
Author: Dan Haywood <da...@apache.org>
Authored: Tue Mar 26 23:22:04 2013 +0000
Committer: Dan Haywood <da...@apache.org>
Committed: Tue Mar 26 23:22:04 2013 +0000
----------------------------------------------------------------------
.../metamodel/spec/SpecificationLoaderSpi.java | 4 +-
.../specloader/ObjectReflectorDefault.java | 105 ++++++++++++++-
.../progmodel/facets/ProgrammableReflector.java | 2 +-
.../system/session/IsisSessionFactoryAbstract.java | 73 +----------
.../src/main/webapp/WEB-INF/isis.properties | 2 +-
5 files changed, 104 insertions(+), 82 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/isis/blob/06f2b0f6/core/metamodel/src/main/java/org/apache/isis/core/metamodel/spec/SpecificationLoaderSpi.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/spec/SpecificationLoaderSpi.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/spec/SpecificationLoaderSpi.java
index 882ea0e..2ae7a95 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/spec/SpecificationLoaderSpi.java
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/spec/SpecificationLoaderSpi.java
@@ -30,9 +30,9 @@ public interface SpecificationLoaderSpi extends ApplicationScopedComponent, Debu
/**
- * Specify the classes of the services to pro-actively prime the cache.
+ * Specify the services to pro-actively prime the cache, and to initialize them also.
*/
- void setServiceClasses(List<Class<?>> serviceClasses);
+ void setServices(List<Object> services);
/**
* Populated as a result of running {@link MetaModelValidator#validate() validation} after all specs have been loaded.
http://git-wip-us.apache.org/repos/asf/isis/blob/06f2b0f6/core/metamodel/src/main/java/org/apache/isis/core/metamodel/specloader/ObjectReflectorDefault.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/specloader/ObjectReflectorDefault.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/specloader/ObjectReflectorDefault.java
index c0c2139..1af1be5 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/specloader/ObjectReflectorDefault.java
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/specloader/ObjectReflectorDefault.java
@@ -23,6 +23,7 @@ import static org.apache.isis.core.commons.ensure.Ensure.ensureThatArg;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
+import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -30,6 +31,10 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+
+import com.google.common.base.Function;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
@@ -46,6 +51,7 @@ import org.apache.isis.core.commons.lang.JavaClassUtils;
import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
import org.apache.isis.core.metamodel.adapter.ServicesProvider;
import org.apache.isis.core.metamodel.adapter.mgr.AdapterManager;
+import org.apache.isis.core.metamodel.adapter.util.InvokeUtils;
import org.apache.isis.core.metamodel.deployment.DeploymentCategory;
import org.apache.isis.core.metamodel.facetapi.Facet;
import org.apache.isis.core.metamodel.facetdecorator.FacetDecorator;
@@ -170,9 +176,9 @@ public final class ObjectReflectorDefault implements SpecificationLoaderSpi, App
private final MemberLayoutArranger memberLayoutArranger;
/**
- * Priming cache, optionally {@link #setServiceClasses(List) injected}.
+ * Priming cache, optionally {@link #setServices(List) injected}.
*/
- private List<Class<?>> serviceClasses = Lists.newArrayList();
+ private List<Object> services = Lists.newArrayList();
private final MetaModelValidator metaModelValidator;
@@ -228,7 +234,7 @@ public final class ObjectReflectorDefault implements SpecificationLoaderSpi, App
/**
* Initializes and wires up, and primes the cache based on any service
- * classes that may have been {@link #setServiceClasses(List) injected}.
+ * classes that may have been {@link #setServices(List) injected}.
*/
@Override
public void init() {
@@ -269,6 +275,8 @@ public final class ObjectReflectorDefault implements SpecificationLoaderSpi, App
facetProcessor.init();
metaModelValidator.init();
+ initServices(configuration);
+
primeCache();
ValidationFailures validationFailures = new ValidationFailures();
@@ -295,7 +303,7 @@ public final class ObjectReflectorDefault implements SpecificationLoaderSpi, App
* referenced specifications until we can find no more.
*/
private void primeCache() {
- for (final Class<?> serviceClass : serviceClasses) {
+ for (final Class<?> serviceClass : getServiceClasses()) {
internalLoadSpecification(serviceClass);
}
loadAllSpecifications();
@@ -329,10 +337,86 @@ public final class ObjectReflectorDefault implements SpecificationLoaderSpi, App
@Override
public void shutdown() {
LOG.info("shutting down " + this);
+
+ shutdownServices();
+
getCache().clear();
facetDecoratorSet.shutdown();
}
+
+ // /////////////////////////////////////////////////////////////
+ // init services, destroy services
+ // /////////////////////////////////////////////////////////////
+
+ protected void initServices(IsisConfiguration configuration) {
+ final List<Object> services = getServices();
+ Map<String, String> props = configuration.asMap();
+ LOG.info("calling @PostConstruct on all domain services");
+ for (Object service : services) {
+ callPostConstructIfExists(service, props);
+ }
+ }
+
+ private void callPostConstructIfExists(Object service, Map<String, String> props) {
+ LOG.debug("looking for @PostConstruct methods on " + service.getClass().getName());
+ Method[] methods = service.getClass().getMethods();
+ boolean found = false;
+ for (Method method : methods) {
+ PostConstruct postConstruct = method.getAnnotation(PostConstruct.class);
+ if(postConstruct == null) {
+ continue;
+ }
+ found = true;
+ LOG.info("... calling @PostConstruct method: " + service.getClass().getName() + ": " + method.getName());
+
+ final int numParams = method.getParameterTypes().length;
+
+ // unlike shutdown, we don't swallow exceptions; would rather fail early
+ if(numParams == 0) {
+ InvokeUtils.invoke(method, service);
+ } else {
+ InvokeUtils.invoke(method, service, new Object[]{props});
+ }
+ }
+ if(!found) {
+ LOG.info("... found no @PostConstruct methods on " + service.getClass().getName());
+ }
+ }
+
+
+ protected void shutdownServices() {
+ final List<Object> services = getServices();
+ LOG.info("calling @PreDestroy on all domain services");
+ for (Object service : services) {
+ callPreDestroyIfExists(service);
+ }
+ }
+
+ private void callPreDestroyIfExists(Object service) {
+ LOG.debug("looking for @PreDestroy methods on " + service.getClass().getName());
+ final Method[] methods = service.getClass().getMethods();
+ boolean found = false;
+ for (Method method : methods) {
+ final PreDestroy preDestroy = method.getAnnotation(PreDestroy.class);
+ if(preDestroy == null) {
+ continue;
+ }
+ found = true;
+ LOG.info("... calling @PreDestroy method: " + service.getClass().getName() + ": " + method.getName());
+ try {
+ InvokeUtils.invoke(method, service);
+ } catch(Exception ex) {
+ // do nothing
+ LOG.warn("... @PreDestroy method threw exception - continuing anyway", ex);
+ }
+ }
+ if(!found) {
+ LOG.info("... found no @PreDestroy methods on " + service.getClass().getName());
+ }
+ }
+
+
// /////////////////////////////////////////////////////////////
// install, load, allSpecifications, lookup
// /////////////////////////////////////////////////////////////
@@ -611,12 +695,21 @@ public final class ObjectReflectorDefault implements SpecificationLoaderSpi, App
// ////////////////////////////////////////////////////////////////////
public List<Class<?>> getServiceClasses() {
+ List<Class<?>> serviceClasses = Lists.transform(services, new Function<Object, Class<?>>(){
+ public Class<?> apply(Object o) {
+ return o.getClass();
+ }
+ });
return Collections.unmodifiableList(serviceClasses);
}
+ private List<Object> getServices() {
+ return services;
+ }
+
@Override
- public void setServiceClasses(final List<Class<?>> serviceClasses) {
- this.serviceClasses = serviceClasses;
+ public void setServices(final List<Object> services) {
+ this.services = services;
}
// ////////////////////////////////////////////////////////////////////
http://git-wip-us.apache.org/repos/asf/isis/blob/06f2b0f6/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/ProgrammableReflector.java
----------------------------------------------------------------------
diff --git a/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/ProgrammableReflector.java b/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/ProgrammableReflector.java
index db35953..9ee2184 100644
--- a/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/ProgrammableReflector.java
+++ b/core/metamodel/src/test/java/org/apache/isis/core/progmodel/facets/ProgrammableReflector.java
@@ -127,7 +127,7 @@ public class ProgrammableReflector implements SpecificationLoaderSpi, Applicatio
}
@Override
- public void setServiceClasses(final List<Class<?>> serviceClasses) {
+ public void setServices(final List<Object> services) {
throw new NotYetImplementedException();
}
http://git-wip-us.apache.org/repos/asf/isis/blob/06f2b0f6/core/runtime/src/main/java/org/apache/isis/core/runtime/system/session/IsisSessionFactoryAbstract.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/session/IsisSessionFactoryAbstract.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/session/IsisSessionFactoryAbstract.java
index d7369d0..ee69c12 100644
--- a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/session/IsisSessionFactoryAbstract.java
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/session/IsisSessionFactoryAbstract.java
@@ -199,8 +199,7 @@ public abstract class IsisSessionFactoryAbstract implements IsisSessionFactory {
public void init() {
templateImageLoader.init();
- specificationLoaderSpi.setServiceClasses(JavaClassUtils.toClasses(serviceList));
-
+ specificationLoaderSpi.setServices(serviceList);
specificationLoaderSpi.init();
// must come after init of spec loader.
@@ -212,15 +211,12 @@ public abstract class IsisSessionFactoryAbstract implements IsisSessionFactory {
authorizationManager.init();
persistenceSessionFactory.init();
- initServices(getConfiguration());
}
@Override
public void shutdown() {
- shutdownServices();
-
persistenceSessionFactory.shutdown();
authenticationManager.shutdown();
specificationLoaderSpi.shutdown();
@@ -228,73 +224,6 @@ public abstract class IsisSessionFactoryAbstract implements IsisSessionFactory {
userProfileLoader.shutdown();
}
- protected void initServices(IsisConfiguration configuration) {
- final List<Object> services = getServices();
- Map<String, String> props = configuration.asMap();
- LOG.info("calling @PostConstruct on all domain services");
- for (Object service : services) {
- callPostConstructIfExists(service, props);
- }
- }
-
- private void callPostConstructIfExists(Object service, Map<String, String> props) {
- LOG.debug("looking for @PostConstruct methods on " + service.getClass().getName());
- Method[] methods = service.getClass().getMethods();
- boolean found = false;
- for (Method method : methods) {
- PostConstruct postConstruct = method.getAnnotation(PostConstruct.class);
- if(postConstruct == null) {
- continue;
- }
- found = true;
- LOG.info("... calling @PostConstruct method: " + service.getClass().getName() + ": " + method.getName());
-
- final int numParams = method.getParameterTypes().length;
-
- // unlike shutdown, we don't swallow exceptions; would rather fail early
- if(numParams == 0) {
- InvokeUtils.invoke(method, service);
- } else {
- InvokeUtils.invoke(method, service, new Object[]{props});
- }
- }
- if(!found) {
- LOG.info("... found no @PostConstruct methods on " + service.getClass().getName());
- }
- }
-
-
- protected void shutdownServices() {
- final List<Object> services = getServices();
- LOG.info("calling @PreDestroy on all domain services");
- for (Object service : services) {
- callPreDestroyIfExists(service);
- }
- }
-
- private void callPreDestroyIfExists(Object service) {
- LOG.debug("looking for @PreDestroy methods on " + service.getClass().getName());
- final Method[] methods = service.getClass().getMethods();
- boolean found = false;
- for (Method method : methods) {
- final PreDestroy preDestroy = method.getAnnotation(PreDestroy.class);
- if(preDestroy == null) {
- continue;
- }
- found = true;
- LOG.info("... calling @PreDestroy method: " + service.getClass().getName() + ": " + method.getName());
- try {
- InvokeUtils.invoke(method, service);
- } catch(Exception ex) {
- // do nothing
- LOG.warn("... @PreDestroy method threw exception - continuing anyway", ex);
- }
- }
- if(!found) {
- LOG.info("... found no @PreDestroy methods on " + service.getClass().getName());
- }
- }
-
@Override
public IsisSession openSession(final AuthenticationSession authenticationSession) {
http://git-wip-us.apache.org/repos/asf/isis/blob/06f2b0f6/example/application/quickstart_wicket_restful_jdo/viewer-webapp/src/main/webapp/WEB-INF/isis.properties
----------------------------------------------------------------------
diff --git a/example/application/quickstart_wicket_restful_jdo/viewer-webapp/src/main/webapp/WEB-INF/isis.properties b/example/application/quickstart_wicket_restful_jdo/viewer-webapp/src/main/webapp/WEB-INF/isis.properties
index 577dd2b..4fea83e 100644
--- a/example/application/quickstart_wicket_restful_jdo/viewer-webapp/src/main/webapp/WEB-INF/isis.properties
+++ b/example/application/quickstart_wicket_restful_jdo/viewer-webapp/src/main/webapp/WEB-INF/isis.properties
@@ -161,7 +161,7 @@ isis.user-profile-store=in-memory
#isis.services.prefix =
isis.services = objstore.jdo.todo.ToDoItemsJdo,\
fixture.todo.ToDoItemsFixturesService,\
- dom.audit.AuditServiceDemo,\
+ org.apache.isis.objectstore.jdo.service.RegisterEntities,\
org.apache.isis.objectstore.jdo.applib.service.exceprecog.ExceptionRecognizerCompositeForJdoObjectStore,\
org.apache.isis.viewer.restfulobjects.rendering.eventserializer.RestfulObjectsSpecEventSerializer,\
org.apache.isis.objectstore.jdo.applib.service.publish.PublishingServiceJdo