Return-Path: X-Original-To: apmail-zest-commits-archive@minotaur.apache.org Delivered-To: apmail-zest-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 3EE7F18BF4 for ; Thu, 17 Dec 2015 21:03:54 +0000 (UTC) Received: (qmail 39323 invoked by uid 500); 17 Dec 2015 21:03:54 -0000 Delivered-To: apmail-zest-commits-archive@zest.apache.org Received: (qmail 39302 invoked by uid 500); 17 Dec 2015 21:03:54 -0000 Mailing-List: contact commits-help@zest.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@zest.apache.org Delivered-To: mailing list commits@zest.apache.org Received: (qmail 39261 invoked by uid 99); 17 Dec 2015 21:03:54 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 17 Dec 2015 21:03:54 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id F34A7E6979; Thu, 17 Dec 2015 21:03:53 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: soelvsten@apache.org To: commits@zest.apache.org Date: Thu, 17 Dec 2015 21:03:54 -0000 Message-Id: <93658c93c2eb4d59a12b673f75695149@git.apache.org> In-Reply-To: <0801fa39fa8b444da17d12eee9339e46@git.apache.org> References: <0801fa39fa8b444da17d12eee9339e46@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [2/3] zest-java git commit: ZEST-134 added simple eventbus to allow user to add composites to all modules 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-132 Commit: 6304ddb60e76fe72eb40faf4670aa7b0d5bf1949 Parents: 8a6ddd2 Author: Kent Sølvsten Authored: Thu Dec 17 21:59:39 2015 +0100 Committer: Kent Sølvsten 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 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 +{ + public static class Type {} + + public abstract Type 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 extends ZestEvent +{ +} 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 void visit( AssemblyVisitor visitor ) throws ThrowableType; + + /** + * Add an applicationassembly handler, listening for events in the assembly phase + * + * @param type + * @param handler A handler of ApplicationAssemblyEvents + */ + void addApplicationEventHandler( ZestEvent.Type 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 + */ + void addUserEventHandler( ZestEvent.Type 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 extends ZestUserEvent +{ +} 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 +{ + private static final Type TYPE = new Type(); + + private final ModuleAssembly module; + + public ModuleAssembledEvent( ModuleAssembly source ) + { + this.module = source; + } + + public ModuleAssembly getModuleAssembly() + { + return module; + } + + @Override + public Type 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 void addUserEventHandler( ZestEvent.Type 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 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>> 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 void addApplicationEventHandler( ZestEvent.Type type, H handler + ) + { + eventBus.addHandler( type, handler ); + } + public Collection 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, List> map = + new HashMap<>(); + + + public void addHandler(ZestEvent.Type 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 handlers = (List) map.get( type ); + if (handlers == null) { + handlers = new ArrayList<>(); + map.put( type, handlers); + } + + handlers.add( handler ); + } + + public void emit( ZestEvent event) { + if (event == null) { + throw new NullPointerException("Cannot fire null event"); + } + List handlers = getDispatchList(event.getAssociatedType()); + + ListIterator it = handlers.listIterator(); + while (it.hasNext()) { + H handler = it.next(); + event.dispatch(handler); + } + } + + private List getDispatchList(ZestEvent.Type type) { + // safe, we control the puts. + @SuppressWarnings("unchecked") + List handlers = (List) 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 +{ + + public static final Type 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 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 extends ZestEvent +{ +} 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(); } + void addUserEventHandler( ZestEvent.Type 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. *