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 AB520183E1 for ; Thu, 17 Dec 2015 23:10:05 +0000 (UTC) Received: (qmail 47834 invoked by uid 500); 17 Dec 2015 23:10:05 -0000 Delivered-To: apmail-zest-commits-archive@zest.apache.org Received: (qmail 47814 invoked by uid 500); 17 Dec 2015 23:10:05 -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 47805 invoked by uid 99); 17 Dec 2015 23:10:05 -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 23:10:05 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 4F822E6967; Thu, 17 Dec 2015 23:10:05 +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 Message-Id: <4043975731d9421faf44613d63a35613@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: zest-java git commit: ZEST-132 added extra event for completeness sake Date: Thu, 17 Dec 2015 23:10:05 +0000 (UTC) Repository: zest-java Updated Branches: refs/heads/ZEST-132 86cbd80f8 -> 986652af3 ZEST-132 added extra event for completeness sake Project: http://git-wip-us.apache.org/repos/asf/zest-java/repo Commit: http://git-wip-us.apache.org/repos/asf/zest-java/commit/986652af Tree: http://git-wip-us.apache.org/repos/asf/zest-java/tree/986652af Diff: http://git-wip-us.apache.org/repos/asf/zest-java/diff/986652af Branch: refs/heads/ZEST-132 Commit: 986652af37f09b3c6fa373c86d90f799241c2943 Parents: 86cbd80 Author: Kent Sølvsten Authored: Fri Dec 18 00:10:07 2015 +0100 Committer: Kent Sølvsten Committed: Fri Dec 18 00:10:07 2015 +0100 ---------------------------------------------------------------------- .../handler/ModuleAssemblingEvent.java | 58 +++++++++++++++ .../unitofwork/DefaultUnitOfWorkAssembler.java | 1 + .../bootstrap/ApplicationAssemblyImpl.java | 2 +- .../runtime/bootstrap/LayerAssemblyImpl.java | 7 +- .../org/apache/zest/runtime/event/EventBus.java | 76 +++++++++++--------- .../event/ModuleAssemblingRuntimeEvent.java | 63 ++++++++++++++++ .../org/apache/zest/test/AbstractZestTest.java | 8 +-- .../org/apache/zest/index/rdf/RdfQueryTest.java | 2 - 8 files changed, 175 insertions(+), 42 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/zest-java/blob/986652af/core/bootstrap/src/main/java/org/apache/zest/bootstrap/handler/ModuleAssemblingEvent.java ---------------------------------------------------------------------- diff --git a/core/bootstrap/src/main/java/org/apache/zest/bootstrap/handler/ModuleAssemblingEvent.java b/core/bootstrap/src/main/java/org/apache/zest/bootstrap/handler/ModuleAssemblingEvent.java new file mode 100755 index 0000000..6a71f34 --- /dev/null +++ b/core/bootstrap/src/main/java/org/apache/zest/bootstrap/handler/ModuleAssemblingEvent.java @@ -0,0 +1,58 @@ +/* + * 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.ModuleAssembly; +import org.apache.zest.bootstrap.ZestAssemblyEvent; +import org.apache.zest.bootstrap.ZestAssemblyEventHandler; + +public class ModuleAssemblingEvent + extends ZestAssemblyEvent +{ + public static final Type TYPE = new Type(); + + private final ModuleAssembly module; + + public ModuleAssemblingEvent( ModuleAssembly source ) + { + this.module = source; + } + + public ModuleAssembly getModuleAssembly() + { + return module; + } + + @Override + public Type getAssociatedType() + { + return TYPE; + } + + @Override + public void dispatch( Handler handler ) + { + handler.onModuleAssembling( this ); + } + + public interface Handler extends ZestAssemblyEventHandler + { + void onModuleAssembling( ModuleAssemblingEvent event ); + } +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/986652af/core/bootstrap/src/main/java/org/apache/zest/bootstrap/unitofwork/DefaultUnitOfWorkAssembler.java ---------------------------------------------------------------------- diff --git a/core/bootstrap/src/main/java/org/apache/zest/bootstrap/unitofwork/DefaultUnitOfWorkAssembler.java b/core/bootstrap/src/main/java/org/apache/zest/bootstrap/unitofwork/DefaultUnitOfWorkAssembler.java index 3ef541d..568de0f 100755 --- a/core/bootstrap/src/main/java/org/apache/zest/bootstrap/unitofwork/DefaultUnitOfWorkAssembler.java +++ b/core/bootstrap/src/main/java/org/apache/zest/bootstrap/unitofwork/DefaultUnitOfWorkAssembler.java @@ -24,6 +24,7 @@ import org.apache.zest.bootstrap.Assembler; import org.apache.zest.bootstrap.AssemblyException; import org.apache.zest.bootstrap.ModuleAssembly; +@Deprecated public class DefaultUnitOfWorkAssembler implements Assembler { http://git-wip-us.apache.org/repos/asf/zest-java/blob/986652af/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 index 034bb77..2654e48 100755 --- 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 @@ -65,7 +65,7 @@ public final class ApplicationAssemblyImpl return existing; } } - LayerAssemblyImpl layerAssembly = new LayerAssemblyImpl( this, name ); + LayerAssemblyImpl layerAssembly = new LayerAssemblyImpl( this, name, eventBus ); layerAssemblies.put( name, layerAssembly ); return layerAssembly; } http://git-wip-us.apache.org/repos/asf/zest-java/blob/986652af/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/LayerAssemblyImpl.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/LayerAssemblyImpl.java b/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/LayerAssemblyImpl.java old mode 100644 new mode 100755 index d029800..6d74d1f --- a/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/LayerAssemblyImpl.java +++ b/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/LayerAssemblyImpl.java @@ -45,6 +45,8 @@ import org.apache.zest.bootstrap.TransientAssembly; import org.apache.zest.bootstrap.TransientDeclaration; import org.apache.zest.bootstrap.ValueAssembly; import org.apache.zest.bootstrap.ValueDeclaration; +import org.apache.zest.runtime.event.EventBus; +import org.apache.zest.runtime.event.ModuleAssemblingRuntimeEvent; /** * Assembly of a Layer. From here you can create more ModuleAssemblies for @@ -57,15 +59,17 @@ public final class LayerAssemblyImpl private final ApplicationAssembly applicationAssembly; private final HashMap moduleAssemblies; private final Set uses; + private final EventBus eventBus; private String name; private final MetaInfo metaInfo = new MetaInfo(); private final List>> activators = new ArrayList<>(); - public LayerAssemblyImpl( ApplicationAssembly applicationAssembly, String name ) + public LayerAssemblyImpl( ApplicationAssembly applicationAssembly, String name, EventBus eventBus ) { this.applicationAssembly = applicationAssembly; this.name = name; + this.eventBus = eventBus; moduleAssemblies = new LinkedHashMap<>(); uses = new LinkedHashSet<>(); @@ -83,6 +87,7 @@ public final class LayerAssemblyImpl } } ModuleAssemblyImpl moduleAssembly = new ModuleAssemblyImpl( this, name ); + eventBus.emit( new ModuleAssemblingRuntimeEvent( moduleAssembly ) ); moduleAssemblies.put( name, moduleAssembly ); return moduleAssembly; } http://git-wip-us.apache.org/repos/asf/zest-java/blob/986652af/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 index 74dd346..1989d53 100755 --- 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 @@ -30,27 +30,29 @@ import org.apache.zest.api.unitofwork.UnitOfWork; import org.apache.zest.api.unitofwork.UnitOfWorkFactory; import org.apache.zest.bootstrap.ModuleAssembly; import org.apache.zest.bootstrap.handler.ModuleAssembledEvent; +import org.apache.zest.bootstrap.handler.ModuleAssemblingEvent; import org.apache.zest.runtime.unitofwork.ModuleUnitOfWork; import org.apache.zest.runtime.unitofwork.UnitOfWorkFactoryMixin; public class EventBus { - public EventBus() { + public EventBus() + { + // add default UnitOfWork to all modules (may be customized by user afterwards) + addHandler( ModuleAssemblingRuntimeEvent.TYPE, event -> { + ModuleAssembly moduleAssembly = event.getModuleAssembly(); + moduleAssembly.services( UnitOfWorkFactory.class ).withMixins( UnitOfWorkFactoryMixin.class ); + moduleAssembly.transients( UnitOfWork.class ).withMixins( ModuleUnitOfWork.class ); + } ); + // emit ModuleAssemblingEvent to interested users + addHandler( ModuleAssemblingRuntimeEvent.TYPE, event -> + this.emit( new ModuleAssemblingEvent( event.getModuleAssembly() ) ) + ); + // emit ModuleAssembledEvent to interested users - ModuleAssembledRuntimeEvent.Handler handler = event -> EventBus.this.emit( new ModuleAssembledEvent( event.getModuleAssembly() ) ); - addHandler( ModuleAssembledRuntimeEvent.TYPE, handler ); - // add default UnitOfWork to all modules (of not already added by user) - addHandler( ModuleAssembledRuntimeEvent.TYPE, new ModuleAssembledRuntimeEvent.Handler( ) { - @Override - public void onModuleAssembled( ModuleAssembledRuntimeEvent event ) - { - ModuleAssembly moduleAssembly = event.getModuleAssembly(); - // mixin will not be used, if user have already added a matching mixin - // @TODO make it possible to ask if service is already there (more robust) - moduleAssembly.services( UnitOfWorkFactory.class ).withMixins( UnitOfWorkFactoryMixin.class ); - moduleAssembly.transients( UnitOfWork.class ).withMixins( ModuleUnitOfWork.class ); - } - }); + addHandler( ModuleAssembledRuntimeEvent.TYPE, event -> + this.emit( new ModuleAssembledEvent( event.getModuleAssembly() ) ) + ); } /** @@ -59,44 +61,52 @@ public class EventBus 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"); + 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"); + if( handler == null ) + { + throw new NullPointerException( "Cannot add a null handler" ); } // safe, we control the puts. - @SuppressWarnings("unchecked") + @SuppressWarnings( "unchecked" ) List handlers = (List) map.get( type ); - if (handlers == null) { + if( handlers == null ) + { handlers = new ArrayList<>(); - map.put( type, handlers); + map.put( type, handlers ); } handlers.add( handler ); } - public void emit( ZestEvent event) { - if (event == null) { - throw new NullPointerException("Cannot fire null event"); + public void emit( ZestEvent event ) + { + if( event == null ) + { + throw new NullPointerException( "Cannot fire null event" ); } - List handlers = getDispatchList(event.getAssociatedType()); + List handlers = getDispatchList( event.getAssociatedType() ); ListIterator it = handlers.listIterator(); - while (it.hasNext()) { + while( it.hasNext() ) + { H handler = it.next(); - event.dispatch(handler); + event.dispatch( handler ); } } - private List getDispatchList(ZestEvent.Type type) { + private List getDispatchList( ZestEvent.Type type ) + { // safe, we control the puts. - @SuppressWarnings("unchecked") + @SuppressWarnings( "unchecked" ) List handlers = (List) map.get( type ); - if (handlers == null) { + if( handlers == null ) + { return Collections.emptyList(); } http://git-wip-us.apache.org/repos/asf/zest-java/blob/986652af/core/runtime/src/main/java/org/apache/zest/runtime/event/ModuleAssemblingRuntimeEvent.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/event/ModuleAssemblingRuntimeEvent.java b/core/runtime/src/main/java/org/apache/zest/runtime/event/ModuleAssemblingRuntimeEvent.java new file mode 100755 index 0000000..42e4092 --- /dev/null +++ b/core/runtime/src/main/java/org/apache/zest/runtime/event/ModuleAssemblingRuntimeEvent.java @@ -0,0 +1,63 @@ +/* + * 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 ModuleAssemblingRuntimeEvent 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 ModuleAssemblingRuntimeEvent( ModuleAssembly source ) + { + this.module = source; + } + + public ModuleAssembly getModuleAssembly() + { + return module; + } + + @Override + public ZestEvent.Type getAssociatedType() + { + return TYPE; + } + + @Override + public void dispatch( Handler handler ) + { + handler.onModuleAssembling( this ); + } + + public interface Handler extends ZestRuntimeEventHandler + { + void onModuleAssembling(ModuleAssemblingRuntimeEvent event); + } +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/986652af/core/testsupport/src/main/java/org/apache/zest/test/AbstractZestTest.java ---------------------------------------------------------------------- diff --git a/core/testsupport/src/main/java/org/apache/zest/test/AbstractZestTest.java b/core/testsupport/src/main/java/org/apache/zest/test/AbstractZestTest.java old mode 100644 new mode 100755 index 29c27aa..3039982 --- a/core/testsupport/src/main/java/org/apache/zest/test/AbstractZestTest.java +++ b/core/testsupport/src/main/java/org/apache/zest/test/AbstractZestTest.java @@ -15,17 +15,16 @@ package org.apache.zest.test; import org.apache.zest.api.injection.scope.Structure; -import org.apache.zest.api.unitofwork.UnitOfWorkFactory; -import org.apache.zest.bootstrap.unitofwork.DefaultUnitOfWorkAssembler; -import org.junit.After; -import org.junit.Before; import org.apache.zest.api.unitofwork.UnitOfWork; +import org.apache.zest.api.unitofwork.UnitOfWorkFactory; import org.apache.zest.bootstrap.ApplicationAssembly; 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.spi.module.ModuleSpi; +import org.junit.After; +import org.junit.Before; /** * Base class for Composite tests. @@ -58,7 +57,6 @@ public abstract class AbstractZestTest extends AbstractZestBaseTest { LayerAssembly layer = applicationAssembly.layer( "Layer 1" ); ModuleAssembly module = layer.module( "Module 1" ); - new DefaultUnitOfWorkAssembler().assemble( module ); module.objects( AbstractZestTest.this.getClass() ); assemble( module ); } http://git-wip-us.apache.org/repos/asf/zest-java/blob/986652af/extensions/indexing-rdf/src/test/java/org/apache/zest/index/rdf/RdfQueryTest.java ---------------------------------------------------------------------- diff --git a/extensions/indexing-rdf/src/test/java/org/apache/zest/index/rdf/RdfQueryTest.java b/extensions/indexing-rdf/src/test/java/org/apache/zest/index/rdf/RdfQueryTest.java index 4469b75..867a3a4 100755 --- a/extensions/indexing-rdf/src/test/java/org/apache/zest/index/rdf/RdfQueryTest.java +++ b/extensions/indexing-rdf/src/test/java/org/apache/zest/index/rdf/RdfQueryTest.java @@ -22,7 +22,6 @@ import java.io.File; import org.apache.zest.api.common.Visibility; import org.apache.zest.bootstrap.AssemblyException; import org.apache.zest.bootstrap.ModuleAssembly; -import org.apache.zest.bootstrap.unitofwork.DefaultUnitOfWorkAssembler; import org.apache.zest.index.rdf.assembly.RdfNativeSesameStoreAssembler; import org.apache.zest.library.rdf.repository.NativeConfiguration; import org.apache.zest.spi.query.EntityFinderException; @@ -52,7 +51,6 @@ public class RdfQueryTest config.entities( NativeConfiguration.class ).visibleIn( Visibility.layer ); config.forMixin( NativeConfiguration.class ).declareDefaults().dataDirectory().set( DATA_DIR.getAbsolutePath() ); new EntityTestAssembler().assemble( config ); - new DefaultUnitOfWorkAssembler().assemble( config ); } @Test