POLYGENE-257 Introduce ModuleAssembly.defaultServices()
Project: http://git-wip-us.apache.org/repos/asf/polygene-java/repo Commit: http://git-wip-us.apache.org/repos/asf/polygene-java/commit/52fe1570 Tree: http://git-wip-us.apache.org/repos/asf/polygene-java/tree/52fe1570 Diff: http://git-wip-us.apache.org/repos/asf/polygene-java/diff/52fe1570 Branch: refs/heads/develop Commit: 52fe1570f5f7d26de714f12ef07df533cbbab45c Parents: 78e0873 Author: Paul Merlin <[email protected]> Authored: Sat May 27 11:43:29 2017 +0200 Committer: Paul Merlin <[email protected]> Committed: Sat May 27 11:43:29 2017 +0200 ---------------------------------------------------------------------- .../polygene/bootstrap/ModuleAssembly.java | 12 ++++ .../DefaultIdentityGeneratorAssembler.java | 39 ++++++++++++ .../DefaultMetricsProviderAssembler.java | 20 ++++++ .../defaults/DefaultSerializationAssembler.java | 52 ++++++++++++++++ .../defaults/DefaultUnitOfWorkAssembler.java | 58 ++++++++++++++++++ .../polygene/bootstrap/defaults/package.html | 24 ++++++++ .../DefaultIdentityGeneratorAssembler.java | 39 ------------ .../DefaultSerializationAssembler.java | 52 ---------------- .../unitofwork/DefaultUnitOfWorkAssembler.java | 58 ------------------ .../runtime/bootstrap/ModuleAssemblyImpl.java | 64 ++++++++++++++------ .../runtime/structure/ModuleInstance.java | 10 +-- 11 files changed, 252 insertions(+), 176 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/polygene-java/blob/52fe1570/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/ModuleAssembly.java ---------------------------------------------------------------------- diff --git a/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/ModuleAssembly.java b/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/ModuleAssembly.java index ebf59d3..9ed6402 100644 --- a/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/ModuleAssembly.java +++ b/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/ModuleAssembly.java @@ -71,6 +71,18 @@ public interface ModuleAssembly ModuleAssembly setMetaInfo( Object info ); /** + * Assemble default services for {@link org.apache.polygene.api.identity.IdentityGenerator}, + * {@link org.apache.polygene.api.serialization.Serialization} and + * {@link org.apache.polygene.api.metrics.MetricsProvider}. + * + * If one of this default services is already assembled on this module it is not added. + * The returned {@link ServiceDeclaration} only apply to effectively defaulted services. + * + * @return the declaration for assembled services + */ + ServiceDeclaration defaultServices(); + + /** * Set the module activators. Activators are executed in order around the * Module activation and passivation. * http://git-wip-us.apache.org/repos/asf/polygene-java/blob/52fe1570/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/defaults/DefaultIdentityGeneratorAssembler.java ---------------------------------------------------------------------- diff --git a/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/defaults/DefaultIdentityGeneratorAssembler.java b/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/defaults/DefaultIdentityGeneratorAssembler.java new file mode 100644 index 0000000..5462b2b --- /dev/null +++ b/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/defaults/DefaultIdentityGeneratorAssembler.java @@ -0,0 +1,39 @@ +/* + * 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.polygene.bootstrap.defaults; + +import org.apache.polygene.api.identity.IdentityGenerator; +import org.apache.polygene.api.identity.UuidGeneratorMixin; +import org.apache.polygene.bootstrap.Assembler; +import org.apache.polygene.bootstrap.ModuleAssembly; + +public class DefaultIdentityGeneratorAssembler + implements Assembler +{ + public static final String IDENTITY = "default-identity-generator"; + + @Override + public void assemble( ModuleAssembly module ) + { + module.services( IdentityGenerator.class ) + .withMixins( UuidGeneratorMixin.class ) + .identifiedBy( IDENTITY ); + } +} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/52fe1570/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/defaults/DefaultMetricsProviderAssembler.java ---------------------------------------------------------------------- diff --git a/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/defaults/DefaultMetricsProviderAssembler.java b/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/defaults/DefaultMetricsProviderAssembler.java new file mode 100644 index 0000000..715cdc4 --- /dev/null +++ b/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/defaults/DefaultMetricsProviderAssembler.java @@ -0,0 +1,20 @@ +package org.apache.polygene.bootstrap.defaults; + +import org.apache.polygene.api.metrics.MetricsProvider; +import org.apache.polygene.bootstrap.Assembler; +import org.apache.polygene.bootstrap.ModuleAssembly; +import org.apache.polygene.spi.metrics.MetricsProviderAdapter; + +public class DefaultMetricsProviderAssembler + implements Assembler +{ + public static final String IDENTITY = "default-metrics-provider"; + + @Override + public void assemble( ModuleAssembly module ) + { + module.services( MetricsProvider.class ) + .withMixins( MetricsProviderAdapter.class ) + .identifiedBy( IDENTITY ); + } +} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/52fe1570/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/defaults/DefaultSerializationAssembler.java ---------------------------------------------------------------------- diff --git a/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/defaults/DefaultSerializationAssembler.java b/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/defaults/DefaultSerializationAssembler.java new file mode 100644 index 0000000..fee17e2 --- /dev/null +++ b/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/defaults/DefaultSerializationAssembler.java @@ -0,0 +1,52 @@ +/* + * 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.polygene.bootstrap.defaults; + +import org.apache.polygene.api.serialization.Converters; +import org.apache.polygene.api.serialization.Deserializer; +import org.apache.polygene.api.serialization.Serialization; +import org.apache.polygene.api.serialization.Serializer; +import org.apache.polygene.bootstrap.Assembler; +import org.apache.polygene.bootstrap.ModuleAssembly; +import org.apache.polygene.serialization.javaxjson.JavaxJsonAdapters; +import org.apache.polygene.serialization.javaxjson.JavaxJsonFactories; +import org.apache.polygene.serialization.javaxjson.JavaxJsonSerialization; +import org.apache.polygene.spi.serialization.JsonDeserializer; +import org.apache.polygene.spi.serialization.JsonSerialization; +import org.apache.polygene.spi.serialization.JsonSerializer; + +public class DefaultSerializationAssembler + implements Assembler +{ + public static final String IDENTITY = "default-serialization"; + + @Override + public void assemble( ModuleAssembly module ) + { + module.services( JavaxJsonSerialization.class ) + .withTypes( Serialization.class, + Serializer.class, Deserializer.class, + Converters.class, + JsonSerialization.class, + JsonSerializer.class, JsonDeserializer.class, + JavaxJsonAdapters.class, + JavaxJsonFactories.class ) + .identifiedBy( IDENTITY ) + .taggedWith( Serialization.Format.JSON ); + } +} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/52fe1570/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/defaults/DefaultUnitOfWorkAssembler.java ---------------------------------------------------------------------- diff --git a/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/defaults/DefaultUnitOfWorkAssembler.java b/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/defaults/DefaultUnitOfWorkAssembler.java new file mode 100644 index 0000000..31f51ec --- /dev/null +++ b/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/defaults/DefaultUnitOfWorkAssembler.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.polygene.bootstrap.defaults; + +import org.apache.polygene.api.unitofwork.UnitOfWork; +import org.apache.polygene.api.unitofwork.UnitOfWorkFactory; +import org.apache.polygene.bootstrap.Assembler; +import org.apache.polygene.bootstrap.AssemblyException; +import org.apache.polygene.bootstrap.ModuleAssembly; + +public class DefaultUnitOfWorkAssembler + implements Assembler +{ + public static final String IDENTITY = "default-uow-factory"; + + @Override + public void assemble( ModuleAssembly module ) + { + Class factoryMixin = loadMixinClass( "org.apache.polygene.runtime.unitofwork.UnitOfWorkFactoryMixin" ); + module.services( UnitOfWorkFactory.class ) + .withMixins( factoryMixin ) + .identifiedBy( IDENTITY ); + + Class uowMixin = loadMixinClass( "org.apache.polygene.runtime.unitofwork.ModuleUnitOfWork" ); + module.transients( UnitOfWork.class ) + .withMixins( uowMixin ); + } + + private Class<?> loadMixinClass( String name ) + { + try + { + return getClass().getClassLoader().loadClass( name ); + } + catch( ClassNotFoundException e ) + { + throw new AssemblyException( "Default UnitOfWorkFactory mixin is not present in the system." ); + } + } +} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/52fe1570/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/defaults/package.html ---------------------------------------------------------------------- diff --git a/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/defaults/package.html b/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/defaults/package.html new file mode 100644 index 0000000..c4c5d09 --- /dev/null +++ b/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/defaults/package.html @@ -0,0 +1,24 @@ +<!-- + ~ 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. + ~ + ~ + --> +<html> + <body> + <h2>Assemblers for required and default services.</h2> + </body> +</html> http://git-wip-us.apache.org/repos/asf/polygene-java/blob/52fe1570/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/identity/DefaultIdentityGeneratorAssembler.java ---------------------------------------------------------------------- diff --git a/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/identity/DefaultIdentityGeneratorAssembler.java b/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/identity/DefaultIdentityGeneratorAssembler.java deleted file mode 100644 index 923f3cd..0000000 --- a/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/identity/DefaultIdentityGeneratorAssembler.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * - */ -package org.apache.polygene.bootstrap.identity; - -import org.apache.polygene.api.identity.IdentityGenerator; -import org.apache.polygene.api.identity.UuidGeneratorMixin; -import org.apache.polygene.bootstrap.Assembler; -import org.apache.polygene.bootstrap.ModuleAssembly; - -public class DefaultIdentityGeneratorAssembler - implements Assembler -{ - public static final String IDENTITY = "default-identity-generator"; - - @Override - public void assemble( ModuleAssembly module ) - { - module.services( IdentityGenerator.class ) - .withMixins( UuidGeneratorMixin.class ) - .identifiedBy( IDENTITY ); - } -} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/52fe1570/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/serialization/DefaultSerializationAssembler.java ---------------------------------------------------------------------- diff --git a/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/serialization/DefaultSerializationAssembler.java b/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/serialization/DefaultSerializationAssembler.java deleted file mode 100644 index 048764d..0000000 --- a/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/serialization/DefaultSerializationAssembler.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.polygene.bootstrap.serialization; - -import org.apache.polygene.api.serialization.Converters; -import org.apache.polygene.api.serialization.Deserializer; -import org.apache.polygene.api.serialization.Serialization; -import org.apache.polygene.api.serialization.Serializer; -import org.apache.polygene.bootstrap.Assembler; -import org.apache.polygene.bootstrap.ModuleAssembly; -import org.apache.polygene.serialization.javaxjson.JavaxJsonAdapters; -import org.apache.polygene.serialization.javaxjson.JavaxJsonFactories; -import org.apache.polygene.serialization.javaxjson.JavaxJsonSerialization; -import org.apache.polygene.spi.serialization.JsonDeserializer; -import org.apache.polygene.spi.serialization.JsonSerialization; -import org.apache.polygene.spi.serialization.JsonSerializer; - -public class DefaultSerializationAssembler - implements Assembler -{ - public static final String IDENTITY = "default-serialization"; - - @Override - public void assemble( ModuleAssembly module ) - { - module.services( JavaxJsonSerialization.class ) - .withTypes( Serialization.class, - Serializer.class, Deserializer.class, - Converters.class, - JsonSerialization.class, - JsonSerializer.class, JsonDeserializer.class, - JavaxJsonAdapters.class, - JavaxJsonFactories.class ) - .identifiedBy( IDENTITY ) - .taggedWith( Serialization.Format.JSON ); - } -} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/52fe1570/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/unitofwork/DefaultUnitOfWorkAssembler.java ---------------------------------------------------------------------- diff --git a/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/unitofwork/DefaultUnitOfWorkAssembler.java b/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/unitofwork/DefaultUnitOfWorkAssembler.java deleted file mode 100644 index 47c5839..0000000 --- a/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/unitofwork/DefaultUnitOfWorkAssembler.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * - */ - -package org.apache.polygene.bootstrap.unitofwork; - -import org.apache.polygene.api.unitofwork.UnitOfWork; -import org.apache.polygene.api.unitofwork.UnitOfWorkFactory; -import org.apache.polygene.bootstrap.Assembler; -import org.apache.polygene.bootstrap.AssemblyException; -import org.apache.polygene.bootstrap.ModuleAssembly; - -public class DefaultUnitOfWorkAssembler - implements Assembler -{ - public static final String IDENTITY = "default-uow-factory"; - - @Override - public void assemble( ModuleAssembly module ) - { - Class factoryMixin = loadMixinClass( "org.apache.polygene.runtime.unitofwork.UnitOfWorkFactoryMixin" ); - module.services( UnitOfWorkFactory.class ) - .withMixins( factoryMixin ) - .identifiedBy( IDENTITY ); - - Class uowMixin = loadMixinClass( "org.apache.polygene.runtime.unitofwork.ModuleUnitOfWork" ); - module.transients( UnitOfWork.class ) - .withMixins( uowMixin ); - } - - private Class<?> loadMixinClass( String name ) - { - try - { - return getClass().getClassLoader().loadClass( name ); - } - catch( ClassNotFoundException e ) - { - throw new AssemblyException( "Default UnitOfWorkFactory mixin is not present in the system." ); - } - } -} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/52fe1570/core/runtime/src/main/java/org/apache/polygene/runtime/bootstrap/ModuleAssemblyImpl.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/main/java/org/apache/polygene/runtime/bootstrap/ModuleAssemblyImpl.java b/core/runtime/src/main/java/org/apache/polygene/runtime/bootstrap/ModuleAssemblyImpl.java index 4cae68d..2c5b3bf 100644 --- a/core/runtime/src/main/java/org/apache/polygene/runtime/bootstrap/ModuleAssemblyImpl.java +++ b/core/runtime/src/main/java/org/apache/polygene/runtime/bootstrap/ModuleAssemblyImpl.java @@ -40,6 +40,7 @@ import org.apache.polygene.api.identity.HasIdentity; import org.apache.polygene.api.identity.Identity; import org.apache.polygene.api.identity.IdentityGenerator; import org.apache.polygene.api.identity.StringIdentity; +import org.apache.polygene.api.metrics.MetricsProvider; import org.apache.polygene.api.serialization.Serialization; import org.apache.polygene.api.service.DuplicateServiceIdentityException; import org.apache.polygene.api.structure.Module; @@ -69,9 +70,10 @@ import org.apache.polygene.bootstrap.TransientAssembly; import org.apache.polygene.bootstrap.TransientDeclaration; import org.apache.polygene.bootstrap.ValueAssembly; import org.apache.polygene.bootstrap.ValueDeclaration; -import org.apache.polygene.bootstrap.identity.DefaultIdentityGeneratorAssembler; -import org.apache.polygene.bootstrap.serialization.DefaultSerializationAssembler; -import org.apache.polygene.bootstrap.unitofwork.DefaultUnitOfWorkAssembler; +import org.apache.polygene.bootstrap.defaults.DefaultIdentityGeneratorAssembler; +import org.apache.polygene.bootstrap.defaults.DefaultMetricsProviderAssembler; +import org.apache.polygene.bootstrap.defaults.DefaultSerializationAssembler; +import org.apache.polygene.bootstrap.defaults.DefaultUnitOfWorkAssembler; import org.apache.polygene.runtime.activation.ActivatorsModel; import org.apache.polygene.runtime.composite.TransientModel; import org.apache.polygene.runtime.composite.TransientsModel; @@ -102,7 +104,26 @@ import static java.util.stream.Collectors.toList; final class ModuleAssemblyImpl implements ModuleAssembly { - private static final HashMap<Class, Assembler> DEFAULT_ASSEMBLERS; + /** + * Assemblers required on all modules, keyed by service type, assembled by {@link #addRequiredAssemblers()}. + */ + private static final Map<Class, Assembler> REQUIRED_ASSEMBLERS; + + /** + * Assemblers for default services, keyed by service type, assembled if {@link #defaultServices()} is called. + */ + private static final Map<Class, Assembler> DEFAULT_ASSEMBLERS; + + static + { + REQUIRED_ASSEMBLERS = new HashMap<>( 1 ); + REQUIRED_ASSEMBLERS.put( UnitOfWorkFactory.class, new DefaultUnitOfWorkAssembler() ); + + DEFAULT_ASSEMBLERS = new HashMap<>( 3 ); + DEFAULT_ASSEMBLERS.put( IdentityGenerator.class, new DefaultIdentityGeneratorAssembler() ); + DEFAULT_ASSEMBLERS.put( Serialization.class, new DefaultSerializationAssembler() ); + DEFAULT_ASSEMBLERS.put( MetricsProvider.class, new DefaultMetricsProviderAssembler() ); + } private final LayerAssembly layerAssembly; private String name; @@ -119,14 +140,6 @@ final class ModuleAssemblyImpl private final MetaInfoDeclaration metaInfoDeclaration = new MetaInfoDeclaration(); - static - { - DEFAULT_ASSEMBLERS = new HashMap<>( 3 ); - DEFAULT_ASSEMBLERS.put( UnitOfWorkFactory.class, new DefaultUnitOfWorkAssembler() ); - DEFAULT_ASSEMBLERS.put( IdentityGenerator.class, new DefaultIdentityGeneratorAssembler() ); - DEFAULT_ASSEMBLERS.put( Serialization.class, new DefaultSerializationAssembler() ); - } - ModuleAssemblyImpl(LayerAssembly layerAssembly, String name) { this.layerAssembly = layerAssembly; @@ -165,6 +178,21 @@ final class ModuleAssemblyImpl } @Override + public ServiceDeclaration defaultServices() + { + Class[] assembledServicesTypes = DEFAULT_ASSEMBLERS + .entrySet() + .stream() + .filter( + entry -> serviceAssemblies.stream().noneMatch( + serviceAssembly -> serviceAssembly.hasType( entry.getKey() ) ) ) + .peek( entry -> entry.getValue().assemble( this ) ) + .map( Map.Entry::getKey ) + .toArray( Class[]::new ); + return services( assembledServicesTypes ); + } + + @Override @SafeVarargs public final ModuleAssembly withActivators(Class<? extends Activator<Module>>... activators) { @@ -496,7 +524,7 @@ final class ModuleAssemblyImpl ModuleModel assembleModule(LayerModel layerModel, AssemblyHelper helper) throws AssemblyException { - addDefaultAssemblers(); + addRequiredAssemblers(); List<Throwable> exceptions = new ArrayList<>(); List<TransientModel> transientModels = new ArrayList<>(); List<ObjectModel> objectModels = new ArrayList<>(); @@ -663,14 +691,14 @@ final class ModuleAssemblyImpl throw new AssemblyReportException( exceptions ); } - private void addDefaultAssemblers() + private void addRequiredAssemblers() { - DEFAULT_ASSEMBLERS + REQUIRED_ASSEMBLERS .entrySet() .stream() - .filter( entry -> - serviceAssemblies.stream().noneMatch( serviceAssembly -> - serviceAssembly.hasType( entry.getKey() ) ) ) + .filter( + entry -> serviceAssemblies.stream().noneMatch( + serviceAssembly -> serviceAssembly.hasType( entry.getKey() ) ) ) .forEach( entry -> entry.getValue().assemble( this ) ); } http://git-wip-us.apache.org/repos/asf/polygene-java/blob/52fe1570/core/runtime/src/main/java/org/apache/polygene/runtime/structure/ModuleInstance.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/main/java/org/apache/polygene/runtime/structure/ModuleInstance.java b/core/runtime/src/main/java/org/apache/polygene/runtime/structure/ModuleInstance.java index cf684fb..20fa0f7 100644 --- a/core/runtime/src/main/java/org/apache/polygene/runtime/structure/ModuleInstance.java +++ b/core/runtime/src/main/java/org/apache/polygene/runtime/structure/ModuleInstance.java @@ -88,7 +88,6 @@ import org.apache.polygene.runtime.value.ValueBuilderWithPrototype; import org.apache.polygene.runtime.value.ValueBuilderWithState; import org.apache.polygene.runtime.value.ValueInstance; import org.apache.polygene.spi.entitystore.EntityStore; -import org.apache.polygene.spi.metrics.MetricsProviderAdapter; import org.apache.polygene.spi.module.ModuleSpi; import static java.util.Arrays.asList; @@ -581,14 +580,7 @@ public class ModuleInstance { if( metrics == null ) { - try - { - metrics = findService( MetricsProvider.class ).get(); - } - catch( NoSuchServiceException e ) - { - metrics = new MetricsProviderAdapter(); - } + metrics = findService( MetricsProvider.class ).get(); } } }
