polygene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From soelvs...@apache.org
Subject zest-java git commit: ZEST-134 added simple eventbus to allow user to add composites to all modules
Date Thu, 17 Dec 2015 21:00:09 GMT
Repository: zest-java
Updated Branches:
  refs/heads/ZEST-135 [created] 6304ddb60


ZEST-134 added simple eventbus to allow user to add composites to all modules


Project: http://git-wip-us.apache.org/repos/asf/zest-java/repo
Commit: http://git-wip-us.apache.org/repos/asf/zest-java/commit/6304ddb6
Tree: http://git-wip-us.apache.org/repos/asf/zest-java/tree/6304ddb6
Diff: http://git-wip-us.apache.org/repos/asf/zest-java/diff/6304ddb6

Branch: refs/heads/ZEST-135
Commit: 6304ddb60e76fe72eb40faf4670aa7b0d5bf1949
Parents: 8a6ddd2
Author: Kent Sølvsten <soelvsten@apache.org>
Authored: Thu Dec 17 21:59:39 2015 +0100
Committer: Kent Sølvsten <soelvsten@apache.org>
Committed: Thu Dec 17 21:59:39 2015 +0100

----------------------------------------------------------------------
 .../zest/api/event/ZestApplicationEvent.java    | 23 ++++++
 .../api/event/ZestApplicationEventHandler.java  | 23 ++++++
 .../org/apache/zest/api/event/ZestEvent.java    | 28 +++++++
 .../apache/zest/api/event/ZestEventHandler.java | 23 ++++++
 .../apache/zest/api/event/ZestUserEvent.java    | 23 ++++++
 .../zest/api/event/ZestUserEventHandler.java    | 23 ++++++
 .../zest/bootstrap/ApplicationAssembly.java     | 11 +++
 .../bootstrap/ApplicationAssemblyFactory.java   | 11 +++
 .../org/apache/zest/bootstrap/Energy4Java.java  |  4 +
 .../zest/bootstrap/ZestAssemblyEvent.java       | 25 ++++++
 .../bootstrap/ZestAssemblyEventHandler.java     | 26 ++++++
 .../bootstrap/handler/ModuleAssembledEvent.java | 57 +++++++++++++
 .../apache/zest/runtime/ZestRuntimeImpl.java    |  6 +-
 .../ApplicationAssemblyFactoryImpl.java         | 18 +++-
 .../bootstrap/ApplicationAssemblyImpl.java      | 14 +++-
 .../bootstrap/ApplicationModelFactoryImpl.java  | 10 +++
 .../org/apache/zest/runtime/event/EventBus.java | 87 ++++++++++++++++++++
 .../event/ModuleAssembledRuntimeEvent.java      | 66 +++++++++++++++
 .../zest/runtime/event/ZestRuntimeEvent.java    | 25 ++++++
 .../runtime/event/ZestRuntimeEventHandler.java  | 25 ++++++
 .../apache/zest/test/AbstractZestBaseTest.java  | 10 ++-
 21 files changed, 532 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zest-java/blob/6304ddb6/core/api/src/main/java/org/apache/zest/api/event/ZestApplicationEvent.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/zest/api/event/ZestApplicationEvent.java b/core/api/src/main/java/org/apache/zest/api/event/ZestApplicationEvent.java
new file mode 100755
index 0000000..9bb8e20
--- /dev/null
+++ b/core/api/src/main/java/org/apache/zest/api/event/ZestApplicationEvent.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.zest.api.event;
+
+public abstract class ZestApplicationEvent<H extends ZestApplicationEventHandler> extends
ZestUserEvent
+{
+}

http://git-wip-us.apache.org/repos/asf/zest-java/blob/6304ddb6/core/api/src/main/java/org/apache/zest/api/event/ZestApplicationEventHandler.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/zest/api/event/ZestApplicationEventHandler.java
b/core/api/src/main/java/org/apache/zest/api/event/ZestApplicationEventHandler.java
new file mode 100755
index 0000000..9298a4c
--- /dev/null
+++ b/core/api/src/main/java/org/apache/zest/api/event/ZestApplicationEventHandler.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.zest.api.event;
+
+public interface ZestApplicationEventHandler extends ZestUserEventHandler
+{
+}

http://git-wip-us.apache.org/repos/asf/zest-java/blob/6304ddb6/core/api/src/main/java/org/apache/zest/api/event/ZestEvent.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/zest/api/event/ZestEvent.java b/core/api/src/main/java/org/apache/zest/api/event/ZestEvent.java
new file mode 100755
index 0000000..fe621e4
--- /dev/null
+++ b/core/api/src/main/java/org/apache/zest/api/event/ZestEvent.java
@@ -0,0 +1,28 @@
+/*
+ * 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.zest.api.event;
+
+public abstract class ZestEvent<H extends ZestEventHandler>
+{
+    public static class Type<H> {}
+
+    public abstract Type<H> getAssociatedType();
+
+    public abstract void dispatch(H handler);
+}

http://git-wip-us.apache.org/repos/asf/zest-java/blob/6304ddb6/core/api/src/main/java/org/apache/zest/api/event/ZestEventHandler.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/zest/api/event/ZestEventHandler.java b/core/api/src/main/java/org/apache/zest/api/event/ZestEventHandler.java
new file mode 100755
index 0000000..d3ea81f
--- /dev/null
+++ b/core/api/src/main/java/org/apache/zest/api/event/ZestEventHandler.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.zest.api.event;
+
+public interface ZestEventHandler
+{
+}

http://git-wip-us.apache.org/repos/asf/zest-java/blob/6304ddb6/core/api/src/main/java/org/apache/zest/api/event/ZestUserEvent.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/zest/api/event/ZestUserEvent.java b/core/api/src/main/java/org/apache/zest/api/event/ZestUserEvent.java
new file mode 100755
index 0000000..b41179d
--- /dev/null
+++ b/core/api/src/main/java/org/apache/zest/api/event/ZestUserEvent.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.zest.api.event;
+
+public abstract class ZestUserEvent<H extends ZestUserEventHandler> extends ZestEvent<H>
+{
+}

http://git-wip-us.apache.org/repos/asf/zest-java/blob/6304ddb6/core/api/src/main/java/org/apache/zest/api/event/ZestUserEventHandler.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/zest/api/event/ZestUserEventHandler.java b/core/api/src/main/java/org/apache/zest/api/event/ZestUserEventHandler.java
new file mode 100755
index 0000000..c585ca6
--- /dev/null
+++ b/core/api/src/main/java/org/apache/zest/api/event/ZestUserEventHandler.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.zest.api.event;
+
+public interface ZestUserEventHandler extends ZestEventHandler
+{
+}

http://git-wip-us.apache.org/repos/asf/zest-java/blob/6304ddb6/core/bootstrap/src/main/java/org/apache/zest/bootstrap/ApplicationAssembly.java
----------------------------------------------------------------------
diff --git a/core/bootstrap/src/main/java/org/apache/zest/bootstrap/ApplicationAssembly.java
b/core/bootstrap/src/main/java/org/apache/zest/bootstrap/ApplicationAssembly.java
old mode 100644
new mode 100755
index 849f397..f76515d
--- a/core/bootstrap/src/main/java/org/apache/zest/bootstrap/ApplicationAssembly.java
+++ b/core/bootstrap/src/main/java/org/apache/zest/bootstrap/ApplicationAssembly.java
@@ -20,6 +20,8 @@
 package org.apache.zest.bootstrap;
 
 import org.apache.zest.api.activation.Activator;
+import org.apache.zest.api.event.ZestApplicationEventHandler;
+import org.apache.zest.api.event.ZestEvent;
 import org.apache.zest.api.structure.Application;
 
 /**
@@ -107,4 +109,13 @@ public interface ApplicationAssembly
 
     <ThrowableType extends Throwable> void visit( AssemblyVisitor<ThrowableType>
visitor )
         throws ThrowableType;
+
+    /**
+     * Add an applicationassembly handler, listening for events in the assembly phase
+     *
+     * @param type
+     * @param handler A handler of ApplicationAssemblyEvents
+     */
+    <H extends ZestApplicationEventHandler> void addApplicationEventHandler( ZestEvent.Type<H>
type, H handler );
+
 }

http://git-wip-us.apache.org/repos/asf/zest-java/blob/6304ddb6/core/bootstrap/src/main/java/org/apache/zest/bootstrap/ApplicationAssemblyFactory.java
----------------------------------------------------------------------
diff --git a/core/bootstrap/src/main/java/org/apache/zest/bootstrap/ApplicationAssemblyFactory.java
b/core/bootstrap/src/main/java/org/apache/zest/bootstrap/ApplicationAssemblyFactory.java
old mode 100644
new mode 100755
index 264fa65..5f0c3a3
--- a/core/bootstrap/src/main/java/org/apache/zest/bootstrap/ApplicationAssemblyFactory.java
+++ b/core/bootstrap/src/main/java/org/apache/zest/bootstrap/ApplicationAssemblyFactory.java
@@ -18,6 +18,9 @@
 
 package org.apache.zest.bootstrap;
 
+import org.apache.zest.api.event.ZestEvent;
+import org.apache.zest.api.event.ZestUserEventHandler;
+
 /**
  * Factory for creating new Zest application assemblies. Typically
  * you will implement one or more Assemblers, wrap them in an ApplicationAssembler,
@@ -26,6 +29,14 @@ package org.apache.zest.bootstrap;
 public interface ApplicationAssemblyFactory
 {
     /**
+     * Add an applicationassembly handler, listening for events in the assembly phase
+     *
+     * @param type
+     * @param handler A handler of ApplicationAssemblyEvents
+     */
+    <H extends ZestUserEventHandler> void addUserEventHandler( ZestEvent.Type<H>
type, H handler );
+
+    /**
      * Create a new application with one layer and one module.
      *
      * @param assembler the assembler for the single module

http://git-wip-us.apache.org/repos/asf/zest-java/blob/6304ddb6/core/bootstrap/src/main/java/org/apache/zest/bootstrap/Energy4Java.java
----------------------------------------------------------------------
diff --git a/core/bootstrap/src/main/java/org/apache/zest/bootstrap/Energy4Java.java b/core/bootstrap/src/main/java/org/apache/zest/bootstrap/Energy4Java.java
old mode 100644
new mode 100755
index f7b61c2..9cf003f
--- a/core/bootstrap/src/main/java/org/apache/zest/bootstrap/Energy4Java.java
+++ b/core/bootstrap/src/main/java/org/apache/zest/bootstrap/Energy4Java.java
@@ -84,6 +84,10 @@ public final class Energy4Java
         return model.newInstance( runtime.spi(), importedServiceInstances );
     }
 
+    public ApplicationAssemblyFactory  applicationAssemblyFactory() {
+        return runtime.applicationAssemblyFactory();
+    }
+
     public ZestSPI spi()
     {
         return runtime.spi();

http://git-wip-us.apache.org/repos/asf/zest-java/blob/6304ddb6/core/bootstrap/src/main/java/org/apache/zest/bootstrap/ZestAssemblyEvent.java
----------------------------------------------------------------------
diff --git a/core/bootstrap/src/main/java/org/apache/zest/bootstrap/ZestAssemblyEvent.java
b/core/bootstrap/src/main/java/org/apache/zest/bootstrap/ZestAssemblyEvent.java
new file mode 100755
index 0000000..cf34295
--- /dev/null
+++ b/core/bootstrap/src/main/java/org/apache/zest/bootstrap/ZestAssemblyEvent.java
@@ -0,0 +1,25 @@
+/*
+ * 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.zest.bootstrap;
+
+import org.apache.zest.api.event.ZestUserEvent;
+
+public abstract class ZestAssemblyEvent<H extends ZestAssemblyEventHandler> extends
ZestUserEvent<H>
+{
+}

http://git-wip-us.apache.org/repos/asf/zest-java/blob/6304ddb6/core/bootstrap/src/main/java/org/apache/zest/bootstrap/ZestAssemblyEventHandler.java
----------------------------------------------------------------------
diff --git a/core/bootstrap/src/main/java/org/apache/zest/bootstrap/ZestAssemblyEventHandler.java
b/core/bootstrap/src/main/java/org/apache/zest/bootstrap/ZestAssemblyEventHandler.java
new file mode 100755
index 0000000..b04557d
--- /dev/null
+++ b/core/bootstrap/src/main/java/org/apache/zest/bootstrap/ZestAssemblyEventHandler.java
@@ -0,0 +1,26 @@
+/*
+ * 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.zest.bootstrap;
+
+import org.apache.zest.api.event.ZestUserEventHandler;
+
+public interface ZestAssemblyEventHandler
+    extends ZestUserEventHandler
+{
+}

http://git-wip-us.apache.org/repos/asf/zest-java/blob/6304ddb6/core/bootstrap/src/main/java/org/apache/zest/bootstrap/handler/ModuleAssembledEvent.java
----------------------------------------------------------------------
diff --git a/core/bootstrap/src/main/java/org/apache/zest/bootstrap/handler/ModuleAssembledEvent.java
b/core/bootstrap/src/main/java/org/apache/zest/bootstrap/handler/ModuleAssembledEvent.java
new file mode 100755
index 0000000..a7b63e3
--- /dev/null
+++ b/core/bootstrap/src/main/java/org/apache/zest/bootstrap/handler/ModuleAssembledEvent.java
@@ -0,0 +1,57 @@
+/*
+ * 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.zest.bootstrap.handler;
+
+import org.apache.zest.bootstrap.ZestAssemblyEvent;
+import org.apache.zest.bootstrap.ZestAssemblyEventHandler;
+import org.apache.zest.bootstrap.ModuleAssembly;
+
+public class ModuleAssembledEvent extends ZestAssemblyEvent<ModuleAssembledEvent.Handler>
+{
+    private static final Type<Handler> TYPE = new Type();
+
+    private final ModuleAssembly module;
+
+    public ModuleAssembledEvent( ModuleAssembly source )
+    {
+        this.module = source;
+    }
+
+    public ModuleAssembly getModuleAssembly()
+    {
+        return module;
+    }
+
+    @Override
+    public Type<Handler> getAssociatedType()
+    {
+        return TYPE;
+    }
+
+    @Override
+    public void dispatch( Handler handler )
+    {
+        handler.onModuleAssembled( this );
+    }
+
+    public interface Handler extends ZestAssemblyEventHandler
+    {
+        void onModuleAssembled(ModuleAssembledEvent event);
+    }
+}

http://git-wip-us.apache.org/repos/asf/zest-java/blob/6304ddb6/core/runtime/src/main/java/org/apache/zest/runtime/ZestRuntimeImpl.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/ZestRuntimeImpl.java b/core/runtime/src/main/java/org/apache/zest/runtime/ZestRuntimeImpl.java
old mode 100644
new mode 100755
index ac931fa..d7f1ff3
--- a/core/runtime/src/main/java/org/apache/zest/runtime/ZestRuntimeImpl.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/ZestRuntimeImpl.java
@@ -58,6 +58,7 @@ import org.apache.zest.runtime.bootstrap.ApplicationModelFactoryImpl;
 import org.apache.zest.runtime.composite.ProxyReferenceInvocationHandler;
 import org.apache.zest.runtime.composite.TransientInstance;
 import org.apache.zest.runtime.entity.EntityInstance;
+import org.apache.zest.runtime.event.EventBus;
 import org.apache.zest.runtime.property.PropertyInstance;
 import org.apache.zest.runtime.service.ImportedServiceReferenceInstance;
 import org.apache.zest.runtime.service.ServiceInstance;
@@ -78,11 +79,12 @@ public final class ZestRuntimeImpl
 {
     private final ApplicationAssemblyFactory applicationAssemblyFactory;
     private final ApplicationModelFactory applicationModelFactory;
+    private final EventBus eventBus = new EventBus();
 
     public ZestRuntimeImpl()
     {
-        applicationAssemblyFactory = new ApplicationAssemblyFactoryImpl();
-        applicationModelFactory = new ApplicationModelFactoryImpl();
+        applicationAssemblyFactory = new ApplicationAssemblyFactoryImpl(eventBus);
+        applicationModelFactory = new ApplicationModelFactoryImpl(eventBus);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/zest-java/blob/6304ddb6/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ApplicationAssemblyFactoryImpl.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ApplicationAssemblyFactoryImpl.java
b/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ApplicationAssemblyFactoryImpl.java
old mode 100644
new mode 100755
index 7b1c7a4..b8e43c1
--- a/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ApplicationAssemblyFactoryImpl.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ApplicationAssemblyFactoryImpl.java
@@ -14,12 +14,15 @@
 
 package org.apache.zest.runtime.bootstrap;
 
+import org.apache.zest.api.event.ZestEvent;
+import org.apache.zest.api.event.ZestUserEventHandler;
 import org.apache.zest.bootstrap.ApplicationAssembly;
 import org.apache.zest.bootstrap.ApplicationAssemblyFactory;
 import org.apache.zest.bootstrap.Assembler;
 import org.apache.zest.bootstrap.AssemblyException;
 import org.apache.zest.bootstrap.LayerAssembly;
 import org.apache.zest.bootstrap.ModuleAssembly;
+import org.apache.zest.runtime.event.EventBus;
 
 /**
  * Factory for ApplicationAssembly.
@@ -27,6 +30,19 @@ import org.apache.zest.bootstrap.ModuleAssembly;
 public final class ApplicationAssemblyFactoryImpl
     implements ApplicationAssemblyFactory
 {
+    private final EventBus eventBus;
+
+    public ApplicationAssemblyFactoryImpl( EventBus eventBus )
+    {
+        this.eventBus = eventBus;
+    }
+
+    @Override
+    public <H extends ZestUserEventHandler> void addUserEventHandler( ZestEvent.Type<H>
type, H handler )
+    {
+        eventBus.addHandler( type, handler );
+    }
+
     @Override
     public ApplicationAssembly newApplicationAssembly( Assembler assembler )
         throws AssemblyException
@@ -68,6 +84,6 @@ public final class ApplicationAssemblyFactoryImpl
     @Override
     public ApplicationAssembly newApplicationAssembly()
     {
-        return new ApplicationAssemblyImpl();
+        return new ApplicationAssemblyImpl( this.eventBus );
     }
 }

http://git-wip-us.apache.org/repos/asf/zest-java/blob/6304ddb6/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ApplicationAssemblyImpl.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ApplicationAssemblyImpl.java
b/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ApplicationAssemblyImpl.java
old mode 100644
new mode 100755
index 8fe7f7d..034bb77
--- a/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ApplicationAssemblyImpl.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ApplicationAssemblyImpl.java
@@ -23,11 +23,14 @@ import java.util.List;
 import java.util.Map;
 import org.apache.zest.api.activation.Activator;
 import org.apache.zest.api.common.MetaInfo;
+import org.apache.zest.api.event.ZestApplicationEventHandler;
+import org.apache.zest.api.event.ZestEvent;
 import org.apache.zest.api.structure.Application;
 import org.apache.zest.bootstrap.ApplicationAssembly;
 import org.apache.zest.bootstrap.AssemblyVisitor;
 import org.apache.zest.bootstrap.LayerAssembly;
 import org.apache.zest.bootstrap.ModuleAssembly;
+import org.apache.zest.runtime.event.EventBus;
 
 /**
  * The representation of an entire application. From
@@ -38,15 +41,17 @@ public final class ApplicationAssemblyImpl
     implements ApplicationAssembly
 {
     private final Map<String, LayerAssemblyImpl> layerAssemblies = new LinkedHashMap<>();
+    private final EventBus eventBus;
     private String name = "Application";
     private String version = "1.0"; // Default version
     private Application.Mode mode;
     private final MetaInfo metaInfo = new MetaInfo();
     private final List<Class<? extends Activator<Application>>> activators
= new ArrayList<>();
 
-    public ApplicationAssemblyImpl()
+    public ApplicationAssemblyImpl( EventBus eventBus )
     {
         mode = Application.Mode.valueOf( System.getProperty( "mode", "production" ) );
+        this.eventBus = eventBus;
     }
 
     @Override
@@ -118,6 +123,13 @@ public final class ApplicationAssemblyImpl
         }
     }
 
+    @Override
+    public <H extends ZestApplicationEventHandler> void addApplicationEventHandler(
ZestEvent.Type<H> type, H handler
+    )
+    {
+        eventBus.addHandler( type, handler );
+    }
+
     public Collection<LayerAssemblyImpl> layerAssemblies()
     {
         return layerAssemblies.values();

http://git-wip-us.apache.org/repos/asf/zest-java/blob/6304ddb6/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ApplicationModelFactoryImpl.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ApplicationModelFactoryImpl.java
b/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ApplicationModelFactoryImpl.java
old mode 100644
new mode 100755
index d1eb738..6f1bc79
--- a/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ApplicationModelFactoryImpl.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ApplicationModelFactoryImpl.java
@@ -29,9 +29,11 @@ import org.apache.zest.bootstrap.ApplicationModelFactory;
 import org.apache.zest.bootstrap.AssemblyException;
 import org.apache.zest.bootstrap.BindingException;
 import org.apache.zest.bootstrap.LayerAssembly;
+import org.apache.zest.bootstrap.handler.ModuleAssembledEvent;
 import org.apache.zest.functional.HierarchicalVisitor;
 import org.apache.zest.runtime.activation.ActivatorsModel;
 import org.apache.zest.runtime.composite.CompositeMethodModel;
+import org.apache.zest.runtime.event.EventBus;
 import org.apache.zest.runtime.injection.InjectedFieldModel;
 import org.apache.zest.runtime.model.Binder;
 import org.apache.zest.runtime.model.Resolution;
@@ -46,6 +48,13 @@ import org.apache.zest.runtime.structure.UsedLayersModel;
 public final class ApplicationModelFactoryImpl
     implements ApplicationModelFactory
 {
+
+    private final EventBus eventBus;
+
+    public ApplicationModelFactoryImpl( EventBus eventBus) {
+        this.eventBus = eventBus;
+    }
+
     @Override
     public ApplicationDescriptor newApplicationModel( ApplicationAssembly assembly )
         throws AssemblyException
@@ -83,6 +92,7 @@ public final class ApplicationModelFactoryImpl
 
             for( ModuleAssemblyImpl moduleAssembly : layerAssembly.moduleAssemblies() )
             {
+                eventBus.emit( new ModuleAssembledEvent( moduleAssembly ) );
                 moduleModels.add( moduleAssembly.assembleModule( helper ) );
             }
             mapAssemblyModel.put( layerAssembly, layerModel );

http://git-wip-us.apache.org/repos/asf/zest-java/blob/6304ddb6/core/runtime/src/main/java/org/apache/zest/runtime/event/EventBus.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/event/EventBus.java b/core/runtime/src/main/java/org/apache/zest/runtime/event/EventBus.java
new file mode 100755
index 0000000..59b8c73
--- /dev/null
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/event/EventBus.java
@@ -0,0 +1,87 @@
+/*
+ * 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.zest.runtime.event;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.Map;
+import org.apache.zest.api.event.ZestEvent;
+import org.apache.zest.api.event.ZestEventHandler;
+import org.apache.zest.bootstrap.handler.ModuleAssembledEvent;
+
+public class EventBus
+{
+    public EventBus() {
+        ModuleAssembledRuntimeEvent.Handler handler = event -> EventBus.this.emit( new
ModuleAssembledEvent( event.getModuleAssembly() ) );
+        addHandler( ModuleAssembledRuntimeEvent.TYPE, handler );
+    }
+
+    /**
+     * Map of event type to map of event source to list of their handlers.
+     */
+    private final Map<ZestEvent.Type<?>, List<?>> map =
+        new HashMap<>();
+
+
+    public <H extends ZestEventHandler> void addHandler(ZestEvent.Type<H> type,
H handler) {
+        if (type == null) {
+            throw new NullPointerException("Cannot add a handler with a null type");
+        }
+        if (handler == null) {
+            throw new NullPointerException("Cannot add a null handler");
+        }
+
+        // safe, we control the puts.
+        @SuppressWarnings("unchecked")
+        List<H> handlers = (List<H>) map.get( type );
+        if (handlers == null) {
+            handlers = new ArrayList<>();
+            map.put( type, handlers);
+        }
+
+        handlers.add( handler );
+    }
+
+    public <H extends ZestEventHandler> void emit( ZestEvent<H> event) {
+        if (event == null) {
+            throw new NullPointerException("Cannot fire null event");
+        }
+        List<H> handlers = getDispatchList(event.getAssociatedType());
+
+        ListIterator<H> it = handlers.listIterator();
+        while (it.hasNext()) {
+            H handler = it.next();
+            event.dispatch(handler);
+        }
+    }
+
+    private <H extends ZestEventHandler> List<H> getDispatchList(ZestEvent.Type<H>
type) {
+        // safe, we control the puts.
+        @SuppressWarnings("unchecked")
+        List<H> handlers = (List<H>) map.get( type );
+        if (handlers == null) {
+            return Collections.emptyList();
+        }
+
+        return handlers;
+    }
+}

http://git-wip-us.apache.org/repos/asf/zest-java/blob/6304ddb6/core/runtime/src/main/java/org/apache/zest/runtime/event/ModuleAssembledRuntimeEvent.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/event/ModuleAssembledRuntimeEvent.java
b/core/runtime/src/main/java/org/apache/zest/runtime/event/ModuleAssembledRuntimeEvent.java
new file mode 100755
index 0000000..3994552
--- /dev/null
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/event/ModuleAssembledRuntimeEvent.java
@@ -0,0 +1,66 @@
+/*
+ * 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.zest.runtime.event;
+
+import org.apache.zest.api.event.ZestEvent;
+import org.apache.zest.bootstrap.ModuleAssembly;
+
+public class ModuleAssembledRuntimeEvent
+    extends ZestRuntimeEvent<ModuleAssembledRuntimeEvent.Handler>
+{
+
+    public static final Type<Handler> TYPE = new Type();
+
+    private final ModuleAssembly module;
+
+    /**
+     * Constructs a prototypical Event.
+     *
+     * @param source The object on which the Event initially occurred.
+     *
+     * @throws IllegalArgumentException if source is null.
+     */
+    public ModuleAssembledRuntimeEvent( ModuleAssembly source )
+    {
+        this.module = source;
+    }
+
+    public ModuleAssembly getModuleAssembly()
+    {
+        return module;
+    }
+
+    @Override
+    public ZestEvent.Type<Handler> getAssociatedType()
+    {
+        return TYPE;
+    }
+
+    @Override
+    public void dispatch( Handler handler )
+    {
+        handler.onModuleAssembled( this );
+    }
+
+    public interface Handler extends ZestRuntimeEventHandler
+    {
+        void onModuleAssembled(ModuleAssembledRuntimeEvent event);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/zest-java/blob/6304ddb6/core/runtime/src/main/java/org/apache/zest/runtime/event/ZestRuntimeEvent.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/event/ZestRuntimeEvent.java
b/core/runtime/src/main/java/org/apache/zest/runtime/event/ZestRuntimeEvent.java
new file mode 100755
index 0000000..c3a7a14
--- /dev/null
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/event/ZestRuntimeEvent.java
@@ -0,0 +1,25 @@
+/*
+ * 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.zest.runtime.event;
+
+import org.apache.zest.api.event.ZestEvent;
+
+public abstract class ZestRuntimeEvent<H extends ZestRuntimeEventHandler> extends ZestEvent<H>
+{
+}

http://git-wip-us.apache.org/repos/asf/zest-java/blob/6304ddb6/core/runtime/src/main/java/org/apache/zest/runtime/event/ZestRuntimeEventHandler.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/event/ZestRuntimeEventHandler.java
b/core/runtime/src/main/java/org/apache/zest/runtime/event/ZestRuntimeEventHandler.java
new file mode 100755
index 0000000..41448ba
--- /dev/null
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/event/ZestRuntimeEventHandler.java
@@ -0,0 +1,25 @@
+/*
+ * 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.zest.runtime.event;
+
+import org.apache.zest.api.event.ZestEventHandler;
+
+public interface ZestRuntimeEventHandler extends ZestEventHandler
+{
+}

http://git-wip-us.apache.org/repos/asf/zest-java/blob/6304ddb6/core/testsupport/src/main/java/org/apache/zest/test/AbstractZestBaseTest.java
----------------------------------------------------------------------
diff --git a/core/testsupport/src/main/java/org/apache/zest/test/AbstractZestBaseTest.java
b/core/testsupport/src/main/java/org/apache/zest/test/AbstractZestBaseTest.java
old mode 100644
new mode 100755
index 47484b8..ec1ca26
--- a/core/testsupport/src/main/java/org/apache/zest/test/AbstractZestBaseTest.java
+++ b/core/testsupport/src/main/java/org/apache/zest/test/AbstractZestBaseTest.java
@@ -18,9 +18,9 @@
  */
 package org.apache.zest.test;
 
-import org.junit.After;
-import org.junit.Before;
 import org.apache.zest.api.ZestAPI;
+import org.apache.zest.api.event.ZestEvent;
+import org.apache.zest.api.event.ZestUserEventHandler;
 import org.apache.zest.api.structure.Application;
 import org.apache.zest.api.structure.ApplicationDescriptor;
 import org.apache.zest.bootstrap.ApplicationAssembler;
@@ -29,6 +29,8 @@ import org.apache.zest.bootstrap.ApplicationAssemblyFactory;
 import org.apache.zest.bootstrap.AssemblyException;
 import org.apache.zest.bootstrap.Energy4Java;
 import org.apache.zest.spi.ZestSPI;
+import org.junit.After;
+import org.junit.Before;
 
 public abstract class AbstractZestBaseTest
 {
@@ -56,6 +58,10 @@ public abstract class AbstractZestBaseTest
         application.activate();
     }
 
+    <H extends ZestUserEventHandler> void addUserEventHandler( ZestEvent.Type<H>
type, H handler ) {
+        zest.applicationAssemblyFactory().addUserEventHandler( type, handler );
+    };
+
     /** Called by the superclass for the test to define the entire application, every layer,
every module and all
      * the contents of each module.
      *


Mime
View raw message