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 2015/03/25 02:04:16 UTC
[5/9] isis git commit: ISIS-1028: simplifying some design
ISIS-1028: simplifying some design
Project: http://git-wip-us.apache.org/repos/asf/isis/repo
Commit: http://git-wip-us.apache.org/repos/asf/isis/commit/a62594b4
Tree: http://git-wip-us.apache.org/repos/asf/isis/tree/a62594b4
Diff: http://git-wip-us.apache.org/repos/asf/isis/diff/a62594b4
Branch: refs/heads/master
Commit: a62594b47bf85cc54e60261640635390debcf9d4
Parents: 43e8693
Author: Dan Haywood <da...@haywood-associates.co.uk>
Authored: Tue Mar 24 23:28:32 2015 +0000
Committer: Dan Haywood <da...@haywood-associates.co.uk>
Committed: Tue Mar 24 23:28:32 2015 +0000
----------------------------------------------------------------------
.../eventbus/AxonEventListenerAdapter.java | 41 ---------
.../eventbus/AxonSimpleEventBusAdapter.java | 69 --------------
.../eventbus/AxonSimpleEventBusService.java | 31 -------
.../services/eventbus/EventBusAdapter.java | 23 -----
.../eventbus/EventBusServiceDefault.java | 95 +++++++++++++++-----
.../services/eventbus/GuavaEventBusAdapter.java | 58 ------------
.../eventbus/RuntimeEventBusService.java | 65 --------------
.../eventbus/adapter/EventBusAdapter.java | 23 +++++
.../adapter/EventBusAdapterForAxonSimple.java | 95 ++++++++++++++++++++
.../adapter/EventBusAdapterForGuava.java | 59 ++++++++++++
.../jdo/datanucleus/JDOStateManagerForIsis.java | 4 +-
.../eventbus/AxonSimpleEventBusServiceJdo.java | 51 -----------
.../service/eventbus/EventBusServiceJdo.java | 6 +-
13 files changed, 256 insertions(+), 364 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/isis/blob/a62594b4/core/runtime/src/main/java/org/apache/isis/core/runtime/services/eventbus/AxonEventListenerAdapter.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/services/eventbus/AxonEventListenerAdapter.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/services/eventbus/AxonEventListenerAdapter.java
deleted file mode 100644
index e7cedc0..0000000
--- a/core/runtime/src/main/java/org/apache/isis/core/runtime/services/eventbus/AxonEventListenerAdapter.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.isis.core.runtime.services.eventbus;
-
-import org.axonframework.domain.EventMessage;
-import org.axonframework.eventhandling.annotation.AnnotationEventListenerAdapter;
-
-public class AxonEventListenerAdapter extends AnnotationEventListenerAdapter {
-
- public AxonEventListenerAdapter(Object annotatedEventListener) {
- super(annotatedEventListener);
- }
-
- /**
- * {@inheritDoc}
- * <p>
- * Adds
- */
- @Override
- public void handle(@SuppressWarnings("rawtypes") EventMessage event) {
- try {
- super.handle(event);
- } catch (Exception exception) {
- DefaultSubscriberExceptionHandler.processException(exception, event);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/a62594b4/core/runtime/src/main/java/org/apache/isis/core/runtime/services/eventbus/AxonSimpleEventBusAdapter.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/services/eventbus/AxonSimpleEventBusAdapter.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/services/eventbus/AxonSimpleEventBusAdapter.java
deleted file mode 100644
index 68c7044..0000000
--- a/core/runtime/src/main/java/org/apache/isis/core/runtime/services/eventbus/AxonSimpleEventBusAdapter.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.isis.core.runtime.services.eventbus;
-
-import java.util.Map;
-
-import com.google.common.collect.Maps;
-
-import org.axonframework.domain.GenericEventMessage;
-import org.axonframework.eventhandling.SimpleEventBus;
-
-/**
- * A wrapper for an Axon {@link org.axonframework.eventhandling.SimpleEventBus},
- * allowing arbitrary events to be posted and subscribed to.
- */
-public class AxonSimpleEventBusAdapter extends EventBusAdapter {
-
- private static SimpleEventBus simpleEventBus = new SimpleEventBus();
-
- private static Map<Object, AxonEventListenerAdapter> adapters = Maps.newConcurrentMap();
-
- private static AxonEventListenerAdapter adapterFor(final Object domainService) {
- AxonEventListenerAdapter annotationEventListenerAdapter = adapters.get(domainService);
- if (annotationEventListenerAdapter == null) {
- annotationEventListenerAdapter = new AxonEventListenerAdapter(domainService);
- adapters.put(domainService, annotationEventListenerAdapter);
- }
- return annotationEventListenerAdapter;
- }
-
- @Override
- public void register(final Object domainService) {
- AxonSimpleEventBusAdapter.simpleEventBus.subscribe(AxonSimpleEventBusAdapter.adapterFor(domainService));
-
- }
-
- @Override
- public void unregister(final Object domainService) {
- // Seems it's needed to be a no-op (See EventBusService).
- // AxonSimpleEventBusAdapter.simpleEventBus.unsubscribe(AxonSimpleEventBusAdapter.adapterFor(domainService));
-
- }
-
- /*
- * {@inheritDoc}
- * <p>
- * Logic equivalent to Guava Event Bus. Despite that,
- * event processing cannot be followed after an Exception is thrown.
- */
- @Override
- public void post(final Object event) {
- AxonSimpleEventBusAdapter.simpleEventBus.publish(GenericEventMessage.asEventMessage(event));
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/isis/blob/a62594b4/core/runtime/src/main/java/org/apache/isis/core/runtime/services/eventbus/AxonSimpleEventBusService.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/services/eventbus/AxonSimpleEventBusService.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/services/eventbus/AxonSimpleEventBusService.java
deleted file mode 100644
index 6fb8a2b..0000000
--- a/core/runtime/src/main/java/org/apache/isis/core/runtime/services/eventbus/AxonSimpleEventBusService.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.isis.core.runtime.services.eventbus;
-
-import org.apache.isis.applib.services.eventbus.EventBus;
-
-/**
- * An Event Bus Service based on Axon.
- */
-public class AxonSimpleEventBusService extends RuntimeEventBusService {
-
- @Override
- protected EventBus newEventBus() {
- return new AxonSimpleEventBusAdapter();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/a62594b4/core/runtime/src/main/java/org/apache/isis/core/runtime/services/eventbus/EventBusAdapter.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/services/eventbus/EventBusAdapter.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/services/eventbus/EventBusAdapter.java
deleted file mode 100644
index 5d45588..0000000
--- a/core/runtime/src/main/java/org/apache/isis/core/runtime/services/eventbus/EventBusAdapter.java
+++ /dev/null
@@ -1,23 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.isis.core.runtime.services.eventbus;
-
-import org.apache.isis.applib.services.eventbus.EventBus;
-
-public abstract class EventBusAdapter implements EventBus {
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/a62594b4/core/runtime/src/main/java/org/apache/isis/core/runtime/services/eventbus/EventBusServiceDefault.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/services/eventbus/EventBusServiceDefault.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/services/eventbus/EventBusServiceDefault.java
index 36c21f1..88d0342 100644
--- a/core/runtime/src/main/java/org/apache/isis/core/runtime/services/eventbus/EventBusServiceDefault.java
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/services/eventbus/EventBusServiceDefault.java
@@ -16,38 +16,91 @@
*/
package org.apache.isis.core.runtime.services.eventbus;
+import java.util.Map;
+import javax.annotation.PostConstruct;
import javax.enterprise.context.RequestScoped;
-import com.google.common.eventbus.EventBus;
-import com.google.common.eventbus.SubscriberExceptionContext;
-import com.google.common.eventbus.SubscriberExceptionHandler;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.apache.isis.applib.annotation.Programmatic;
import org.apache.isis.applib.services.eventbus.EventBus;
-import org.apache.isis.applib.services.eventbus.AbstractDomainEvent;
import org.apache.isis.applib.services.eventbus.EventBusService;
-import org.apache.isis.core.commons.exceptions.IsisApplicationException;
import org.apache.isis.core.metamodel.facets.Annotations;
import org.apache.isis.core.runtime.services.RequestScopedService;
-import org.apache.isis.core.runtime.system.context.IsisContext;
-import org.apache.isis.core.runtime.system.transaction.IsisTransactionManager;
+import org.apache.isis.core.runtime.services.eventbus.adapter.EventBusAdapterForAxonSimple;
+import org.apache.isis.core.runtime.services.eventbus.adapter.EventBusAdapterForGuava;
/**
- * An Event Bus Service based on Guava.
- * <p>
- * @deprecated - but only because {@link org.apache.isis.objectstore.jdo.datanucleus.service.eventbus.EventBusServiceJdo}
- * is annotated (with <code>@DomainService</code>) as the default implementation. The functionality in this implementation
- * is still required.
+ * Holds common runtime logic for EventBusService implementations.
*/
-@Deprecated
-public class EventBusServiceDefault extends RuntimeEventBusService {
-
+public abstract class EventBusServiceDefault extends EventBusService {
+
+ //region > register
+ /**
+ * {@inheritDoc}
+ *
+ * This service overrides the method to perform additional validation that (a) request-scoped services register
+ * their proxies, not themselves, and (b) that singleton services are never registered after the event bus has
+ * been created.
+ *
+ * <p>
+ * Note that we <i>do</i> allow for request-scoped services to register (their proxies) multiple times, ie at
+ * the beginning of each transaction. Because the subscribers are stored in a set, these additional
+ * registrations are in effect ignored.
+ * </p>
+ */
@Override
- // //////////////////////////////////////
+ public void register(final Object domainService) {
+ if(domainService instanceof RequestScopedService) {
+ // ok; allow to be registered multiple times (each xactn) since stored in a set.
+ } else {
+ if (Annotations.getAnnotation(domainService.getClass(), RequestScoped.class) != null) {
+ throw new IllegalArgumentException("Request-scoped services must register their proxy, not themselves");
+ }
+ // a singleton
+ if(this.eventBus != null) {
+ // ... coming too late to the party.
+ throw new IllegalStateException("Event bus has already been created; too late to register any further (singleton) subscribers");
+ }
+ }
+ super.register(domainService);
+ }
+
+ //endregion
+
+ //region > init, shutdown
+ @Programmatic
+ @PostConstruct
+ public void init(final Map<String, String> properties) {
+ final String implementation = properties.get("org.apache.isis.eventbus.implementation");
- protected EventBus newEventBus() {
- return new GuavaEventBusAdapter();
+ this.implementation =
+ "axon".equalsIgnoreCase(implementation)
+ ? EventBusImplementation.AXON
+ : EventBusImplementation.GUAVA;
}
+ //endregion
-}
+ //region > newEventBus
+ enum EventBusImplementation {
+ GUAVA {
+ @Override
+ public EventBus create() {
+ return new EventBusAdapterForGuava();
+ }
+ },
+ AXON {
+ @Override
+ public EventBus create() {
+ return new EventBusAdapterForAxonSimple();
+ }
+ };
+
+ public abstract EventBus create();
+ }
+ private EventBusImplementation implementation;
+ @Override
+ protected org.apache.isis.applib.services.eventbus.EventBus newEventBus() {
+ return implementation.create();
+ }
+ //endregion
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/a62594b4/core/runtime/src/main/java/org/apache/isis/core/runtime/services/eventbus/GuavaEventBusAdapter.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/services/eventbus/GuavaEventBusAdapter.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/services/eventbus/GuavaEventBusAdapter.java
deleted file mode 100644
index 12fbf9e..0000000
--- a/core/runtime/src/main/java/org/apache/isis/core/runtime/services/eventbus/GuavaEventBusAdapter.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.isis.core.runtime.services.eventbus;
-
-import com.google.common.eventbus.SubscriberExceptionContext;
-import com.google.common.eventbus.SubscriberExceptionHandler;
-
-/**
- * A wrapper for a Guava {@link com.google.common.eventbus.EventBus},
- * allowing arbitrary events to be posted and subscribed to.
- */
-public class GuavaEventBusAdapter extends EventBusAdapter {
-
- private static final com.google.common.eventbus.EventBus eventBus = new com.google.common.eventbus.EventBus(newEventBusSubscriberExceptionHandler());
-
- protected static SubscriberExceptionHandler newEventBusSubscriberExceptionHandler() {
- return new SubscriberExceptionHandler() {
- @Override
- public void handleException(Throwable exception,
- SubscriberExceptionContext context) {
- Object event = context.getEvent();
- DefaultSubscriberExceptionHandler.processException(exception, event);
- }
-
- };
- }
-
- @Override
- public void register(final Object domainService) {
- this.eventBus.register(domainService);
- }
-
- @Override
- public void unregister(final Object domainService) {
- // Intentionally no-op.
- // this.eventBus.unregister(domainService);
- }
-
- @Override
- public void post(final Object event) {
- GuavaEventBusAdapter.eventBus.post(event);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/a62594b4/core/runtime/src/main/java/org/apache/isis/core/runtime/services/eventbus/RuntimeEventBusService.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/services/eventbus/RuntimeEventBusService.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/services/eventbus/RuntimeEventBusService.java
deleted file mode 100644
index fd47781..0000000
--- a/core/runtime/src/main/java/org/apache/isis/core/runtime/services/eventbus/RuntimeEventBusService.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.isis.core.runtime.services.eventbus;
-
-import javax.enterprise.context.RequestScoped;
-
-import org.apache.isis.applib.services.eventbus.EventBusService;
-import org.apache.isis.core.metamodel.facets.Annotations;
-import org.apache.isis.core.runtime.services.RequestScopedService;
-
-/**
- * Holds common runtime logic for EventBusService implementations.
- *
- * @version $Rev$ $Date$
- */
-public abstract class RuntimeEventBusService extends EventBusService {
-
- //region > register
- /**
- * {@inheritDoc}
- *
- * This service overrides the method to perform additional validation that (a) request-scoped services register
- * their proxies, not themselves, and (b) that singleton services are never registered after the event bus has
- * been created.
- *
- * <p>
- * Note that we <i>do</i> allow for request-scoped services to register (their proxies) multiple times, ie at
- * the beginning of each transaction. Because the subscribers are stored in a set, these additional
- * registrations are in effect ignored.
- * </p>
- */
- @Override
- public void register(final Object domainService) {
- if(domainService instanceof RequestScopedService) {
- // ok; allow to be registered multiple times (each xactn) since stored in a set.
- } else {
- if (Annotations.getAnnotation(domainService.getClass(), RequestScoped.class) != null) {
- throw new IllegalArgumentException("Request-scoped services must register their proxy, not themselves");
- }
- // a singleton
- if(this.eventBus != null) {
- // ... coming too late to the party.
- throw new IllegalStateException("Event bus has already been created; too late to register any further (singleton) subscribers");
- }
- }
- super.register(domainService);
- }
-
- //endregion
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/a62594b4/core/runtime/src/main/java/org/apache/isis/core/runtime/services/eventbus/adapter/EventBusAdapter.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/services/eventbus/adapter/EventBusAdapter.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/services/eventbus/adapter/EventBusAdapter.java
new file mode 100644
index 0000000..a29e2dd
--- /dev/null
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/services/eventbus/adapter/EventBusAdapter.java
@@ -0,0 +1,23 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.isis.core.runtime.services.eventbus.adapter;
+
+import org.apache.isis.applib.services.eventbus.EventBus;
+
+public abstract class EventBusAdapter implements EventBus {
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/a62594b4/core/runtime/src/main/java/org/apache/isis/core/runtime/services/eventbus/adapter/EventBusAdapterForAxonSimple.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/services/eventbus/adapter/EventBusAdapterForAxonSimple.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/services/eventbus/adapter/EventBusAdapterForAxonSimple.java
new file mode 100644
index 0000000..b8403f7
--- /dev/null
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/services/eventbus/adapter/EventBusAdapterForAxonSimple.java
@@ -0,0 +1,95 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.isis.core.runtime.services.eventbus.adapter;
+
+import java.util.Map;
+
+import com.google.common.collect.Maps;
+
+import org.axonframework.domain.EventMessage;
+import org.axonframework.domain.GenericEventMessage;
+import org.axonframework.eventhandling.SimpleEventBus;
+import org.axonframework.eventhandling.annotation.AnnotationEventListenerAdapter;
+import org.apache.isis.applib.annotation.Programmatic;
+import org.apache.isis.core.runtime.services.eventbus.DefaultSubscriberExceptionHandler;
+
+/**
+ * A wrapper for an Axon {@link org.axonframework.eventhandling.SimpleEventBus},
+ * allowing arbitrary events to be posted and subscribed to.
+ */
+public class EventBusAdapterForAxonSimple extends EventBusAdapter {
+
+ private static SimpleEventBus simpleEventBus = new SimpleEventBus();
+
+ private static Map<Object, AxonEventListenerAdapter> adapters = Maps.newConcurrentMap();
+
+ private static AxonEventListenerAdapter adapterFor(final Object domainService) {
+ AxonEventListenerAdapter annotationEventListenerAdapter = adapters.get(domainService);
+ if (annotationEventListenerAdapter == null) {
+ annotationEventListenerAdapter = new AxonEventListenerAdapter(domainService);
+ adapters.put(domainService, annotationEventListenerAdapter);
+ }
+ return annotationEventListenerAdapter;
+ }
+
+ @Override
+ public void register(final Object domainService) {
+ EventBusAdapterForAxonSimple.simpleEventBus.subscribe(EventBusAdapterForAxonSimple.adapterFor(domainService));
+
+ }
+
+ @Override
+ public void unregister(final Object domainService) {
+ // Seems it's needed to be a no-op (See EventBusService).
+ // AxonSimpleEventBusAdapter.simpleEventBus.unsubscribe(AxonSimpleEventBusAdapter.adapterFor(domainService));
+
+ }
+
+ /*
+ * Logic equivalent to Guava Event Bus.
+ *
+ * <p>
+ * Despite that, event processing cannot be followed after an Exception is thrown.
+ * </p>
+ */
+ @Override
+ @Programmatic
+ public void post(final Object event) {
+ EventBusAdapterForAxonSimple.simpleEventBus.publish(GenericEventMessage.asEventMessage(event));
+ }
+
+
+ static class AxonEventListenerAdapter extends AnnotationEventListenerAdapter {
+
+ public AxonEventListenerAdapter(final Object annotatedEventListener) {
+ super(annotatedEventListener);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void handle(@SuppressWarnings("rawtypes") final EventMessage event) {
+ try {
+ super.handle(event);
+ } catch (final Exception exception) {
+ DefaultSubscriberExceptionHandler.processException(exception, event);
+ }
+ }
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/isis/blob/a62594b4/core/runtime/src/main/java/org/apache/isis/core/runtime/services/eventbus/adapter/EventBusAdapterForGuava.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/services/eventbus/adapter/EventBusAdapterForGuava.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/services/eventbus/adapter/EventBusAdapterForGuava.java
new file mode 100644
index 0000000..f8e97c9
--- /dev/null
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/services/eventbus/adapter/EventBusAdapterForGuava.java
@@ -0,0 +1,59 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.isis.core.runtime.services.eventbus.adapter;
+
+import com.google.common.eventbus.SubscriberExceptionContext;
+import com.google.common.eventbus.SubscriberExceptionHandler;
+import org.apache.isis.core.runtime.services.eventbus.DefaultSubscriberExceptionHandler;
+
+/**
+ * A wrapper for a Guava {@link com.google.common.eventbus.EventBus},
+ * allowing arbitrary events to be posted and subscribed to.
+ */
+public class EventBusAdapterForGuava extends EventBusAdapter {
+
+ private static final com.google.common.eventbus.EventBus eventBus = new com.google.common.eventbus.EventBus(newEventBusSubscriberExceptionHandler());
+
+ protected static SubscriberExceptionHandler newEventBusSubscriberExceptionHandler() {
+ return new SubscriberExceptionHandler() {
+ @Override
+ public void handleException(final Throwable exception,
+ final SubscriberExceptionContext context) {
+ final Object event = context.getEvent();
+ DefaultSubscriberExceptionHandler.processException(exception, event);
+ }
+
+ };
+ }
+
+ @Override
+ public void register(final Object domainService) {
+ eventBus.register(domainService);
+ }
+
+ @Override
+ public void unregister(final Object domainService) {
+ // Intentionally no-op.
+ // this.eventBus.unregister(domainService);
+ }
+
+ @Override
+ public void post(final Object event) {
+ EventBusAdapterForGuava.eventBus.post(event);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/a62594b4/core/runtime/src/main/java/org/apache/isis/objectstore/jdo/datanucleus/JDOStateManagerForIsis.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/isis/objectstore/jdo/datanucleus/JDOStateManagerForIsis.java b/core/runtime/src/main/java/org/apache/isis/objectstore/jdo/datanucleus/JDOStateManagerForIsis.java
index e1c660a..21e6882 100644
--- a/core/runtime/src/main/java/org/apache/isis/objectstore/jdo/datanucleus/JDOStateManagerForIsis.java
+++ b/core/runtime/src/main/java/org/apache/isis/objectstore/jdo/datanucleus/JDOStateManagerForIsis.java
@@ -25,7 +25,6 @@ import javax.jdo.spi.StateManager;
import org.datanucleus.ExecutionContext;
import org.datanucleus.cache.CachedPC;
import org.datanucleus.metadata.AbstractClassMetaData;
-import org.datanucleus.state.JDOStateManager;
import org.datanucleus.state.ObjectProvider;
import org.datanucleus.state.ReferentialJDOStateManager;
import org.datanucleus.store.FieldValues;
@@ -33,7 +32,6 @@ import org.datanucleus.store.fieldmanager.FieldManager;
import org.apache.isis.core.metamodel.services.ServicesInjectorSpi;
import org.apache.isis.core.runtime.system.context.IsisContext;
-import org.apache.isis.objectstore.jdo.datanucleus.service.eventbus.EventBusServiceJdo;
public class JDOStateManagerForIsis extends ReferentialJDOStateManager implements StateManager, ObjectProvider {
@@ -48,7 +46,7 @@ public class JDOStateManagerForIsis extends ReferentialJDOStateManager implement
}
/**
- * Tunnel down the thread stack as a hint to the {@link EventBusServiceJdo}.
+ * Tunnel down the thread stack as a hint to the {@link org.apache.isis.objectstore.jdo.datanucleus.service.eventbus.EventBusServiceJdo}.
*/
public final static ThreadLocal<Hint> hint = new ThreadLocal<JDOStateManagerForIsis.Hint>() {
protected Hint initialValue() {
http://git-wip-us.apache.org/repos/asf/isis/blob/a62594b4/core/runtime/src/main/java/org/apache/isis/objectstore/jdo/datanucleus/service/eventbus/AxonSimpleEventBusServiceJdo.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/isis/objectstore/jdo/datanucleus/service/eventbus/AxonSimpleEventBusServiceJdo.java b/core/runtime/src/main/java/org/apache/isis/objectstore/jdo/datanucleus/service/eventbus/AxonSimpleEventBusServiceJdo.java
deleted file mode 100644
index dbfb744..0000000
--- a/core/runtime/src/main/java/org/apache/isis/objectstore/jdo/datanucleus/service/eventbus/AxonSimpleEventBusServiceJdo.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.isis.objectstore.jdo.datanucleus.service.eventbus;
-
-import org.apache.isis.core.runtime.services.eventbus.AxonSimpleEventBusService;
-import org.apache.isis.objectstore.jdo.datanucleus.JDOStateManagerForIsis;
-import org.apache.isis.objectstore.jdo.datanucleus.JDOStateManagerForIsis.Hint;
-
-/**
- * This domain service that enables both the framework and application code to
- * publish events through an Axon
- * {@link org.axonframework.eventhandling.SimpleEventBus} instance.
- *
- * <p>
- * In addition, this implementation is "JDO-aware" meaning that it
- * allows events to be {@link #post(Object) posted} from the setters of
- * entities, automatically ignoring any calls to those setters that occur as a
- * side-effect of the JDO load/detach lifecycle.
- *
- * <p>
- * This implementation has no UI.
- */
-public class AxonSimpleEventBusServiceJdo extends AxonSimpleEventBusService {
-
- /**
- * skip if called in any way by way of the {@link JDOStateManagerForIsis}.
- *
- * <p>
- * The {@link JDOStateManagerForIsis} sets a
- * {@link JDOStateManagerForIsis#hint threadlocal} if it has been called.
- */
- @Override
- public boolean skip(final Object event) {
- return JDOStateManagerForIsis.hint.get() != Hint.NONE;
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/isis/blob/a62594b4/core/runtime/src/main/java/org/apache/isis/objectstore/jdo/datanucleus/service/eventbus/EventBusServiceJdo.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/isis/objectstore/jdo/datanucleus/service/eventbus/EventBusServiceJdo.java b/core/runtime/src/main/java/org/apache/isis/objectstore/jdo/datanucleus/service/eventbus/EventBusServiceJdo.java
index 2df75cf..505fceb 100644
--- a/core/runtime/src/main/java/org/apache/isis/objectstore/jdo/datanucleus/service/eventbus/EventBusServiceJdo.java
+++ b/core/runtime/src/main/java/org/apache/isis/objectstore/jdo/datanucleus/service/eventbus/EventBusServiceJdo.java
@@ -24,8 +24,10 @@ import org.apache.isis.objectstore.jdo.datanucleus.JDOStateManagerForIsis;
import org.apache.isis.objectstore.jdo.datanucleus.JDOStateManagerForIsis.Hint;
/**
- * This domain service that enables both the framework and application code to publish events through a Guava
- * {@link com.google.common.eventbus.EventBus} instance.
+ * This domain service that enables both the framework and application code to publish events through either a
+ * Guava {@link com.google.common.eventbus.EventBus} instance or through an Axon
+ * {@link org.axonframework.eventhandling.SimpleEventBus} instance.
+
*
* <p>
* In addition, this implementation is "JDO-aware" meaning that it allows events to be