/** * Declare Layer. * @param layerName Name of the Layer * @return Layer declaration for the given name, new if did not already exists */ public LayerDeclaration withLayer( String layerName ) { LayerDeclaration layerDeclaration = layers.get( layerName ); if( layerDeclaration != null ) { return layerDeclaration; } layerDeclaration = new LayerDeclaration( layerName ); layers.put( layerName, layerDeclaration ); return layerDeclaration; }
@Test public void givenBuilderUseWhenBuildingApplicationExpectSuccess() throws AssemblyException, ActivationException { ApplicationBuilder builder = new ApplicationBuilder( "Build from API test." ); builder.withLayer( "layer1" ).using( "layer2" ).using( "layer3" ); builder.withLayer( "layer2" ); builder.withLayer( "layer3" ) .withModule( "test module" ) .withAssemblers( findClasses( getClass() ).filter( matches( ".*ServiceAssembler" ) ) .collect( toList() ) ); Application application = builder.newApplication(); Module module = application.findModule( "layer3", "test module" ); TestService service = module.findService( TestService.class ).get(); assertThat( service.sayHello(), equalTo( "Hello Polygene!" ) ); }
for( Map.Entry<String, LayerDeclaration> entry : layers.entrySet() ) LayerAssembly layer = entry.getValue().createLayer( assembly ); createdLayers.put( entry.getKey(), layer ); layer.initialize( createdLayers );
appBuilder.withLayer( "Layer 1" ).withModule( "Module A" ).withAssembler( module -> module.services( TestService.class ) .identifiedBy( "TestService_Module.A" ) .withActivators( FailBeforePassivationServiceActivator.class ) .instantiateOnStartup() ); appBuilder.withLayer( "Layer 2" ).withModule( "Module B" ).withAssembler( module -> module.services( TestService.class ) .identifiedBy( "TestService_Module.B" )
for( int j = 0; j < using.size(); j++ ) layerDeclaration.using( using.getString( j ) ); ModuleDeclaration moduleDeclaration = layerDeclaration.withModule( moduleName ); JsonValue optAssemblers = moduleObject.get( "assemblers" ); if( optAssemblers != null && optAssemblers.getValueType() == JsonValue.ValueType.ARRAY )
for( Map.Entry<String, LayerDeclaration> entry : layers.entrySet() ) LayerAssembly layer = entry.getValue().createLayer( assembly ); createdLayers.put( entry.getKey(), layer ); layer.initialize( createdLayers );
for( int j = 0; j < using.size(); j++ ) layerDeclaration.using( using.getString( j ) ); ModuleDeclaration moduleDeclaration = layerDeclaration.withModule( moduleName ); JsonValue optAssemblers = moduleObject.get( "assemblers" ); if( optAssemblers != null && optAssemblers.getValueType() == JsonValue.ValueType.ARRAY )
/** * Declare Layer. * @param layerName Name of the Layer * @return Layer declaration for the given name, new if did not already exists */ public LayerDeclaration withLayer( String layerName ) { LayerDeclaration layerDeclaration = layers.get( layerName ); if( layerDeclaration != null ) { return layerDeclaration; } layerDeclaration = new LayerDeclaration( layerName ); layers.put( layerName, layerDeclaration ); return layerDeclaration; }