/** * Load an ApplicationBuilder from a JSONObject. * @param root JSON object * @return Application Builder loaded from JSON * @throws AssemblyException if unable to declare the assembly */ public static ApplicationBuilder fromJson( JsonObject root ) throws AssemblyException { String applicationName = root.getString( "name" ); ApplicationBuilder builder = new ApplicationBuilder( applicationName ); builder.configureWithJson( root ); return builder; }
/** * {@literal main} method that read JSON from STDIN. * <p>Passivation exceptions are written to STDERR if any.</p> * @param args Unused * @throws AssemblyException if the assembly failed * @throws ActivationException if the activation failed */ public static void main( String[] args ) throws ActivationException, AssemblyException { fromJson( System.in ).withPassivationShutdownHook().newApplication(); } }
@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!" ) ); }
throws AssemblyException, ActivationException ApplicationBuilder appBuilder = new ApplicationBuilder( "TestApplication" ); 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" ) .withActivators( FailAfterPassivationServiceActivator.class ) .instantiateOnStartup() ); appBuilder.registerActivationEventListener( new TestActivationEventListener() ); Application app = appBuilder.newApplication();
@Test public void givenJsonInputStreamWhenBuildingApplicationExpectSuccess() throws IOException, ActivationException, AssemblyException { InputStream input = new ByteArrayInputStream( APPLICATION.getBytes( "UTF-8" ) ); ApplicationBuilder builder = ApplicationBuilder.fromJson( input ); Application application = builder.newApplication(); Module module = application.findModule( "layer3", "test module" ); TestService service = module.findService( TestService.class ).get(); assertThat( service.sayHello(), equalTo( "Hello Polygene!" ) ); }
/** * Load an ApplicationBuilder from a JSON String. * @param json JSON String * @return Application Builder loaded from JSON * @throws AssemblyException if unable to declare the assembly */ public static ApplicationBuilder fromJson( String json ) { JsonObject root = Json.createReader( new StringReader( json ) ).readObject(); return fromJson( root ); }
beforeActivation(); application.activate(); if( passivationShutdownHook ) afterActivation(); return application;
LayerDeclaration layerDeclaration = withLayer( layerName ); JsonValue optUsing = layerObject.get( "uses" ); if( optUsing != null && optUsing.getValueType() == JsonValue.ValueType.ARRAY )
@Test public void givenJsonWhenBuildingApplicationExpectSuccess() throws ActivationException, AssemblyException { ApplicationBuilder builder = ApplicationBuilder.fromJson( APPLICATION ); Application application = builder.newApplication(); Module module = application.findModule( "layer3", "test module" ); TestService service = module.findService( TestService.class ).get(); assertThat( service.sayHello(), equalTo( "Hello Polygene!" ) ); }
/** * Load an ApplicationBuilder from a JSON String. * @param json JSON String * @return Application Builder loaded from JSON * @throws AssemblyException if unable to declare the assembly */ public static ApplicationBuilder fromJson( String json ) { JsonObject root = Json.createReader( new StringReader( json ) ).readObject(); return fromJson( root ); }
beforeActivation(); application.activate(); if( passivationShutdownHook ) afterActivation(); return application;
LayerDeclaration layerDeclaration = withLayer( layerName ); JsonValue optUsing = layerObject.get( "uses" ); if( optUsing != null && optUsing.getValueType() == JsonValue.ValueType.ARRAY )
/** * {@literal main} method that read JSON from STDIN. * <p>Passivation exceptions are written to STDERR if any.</p> * @param args Unused * @throws AssemblyException if the assembly failed * @throws ActivationException if the activation failed */ public static void main( String[] args ) throws ActivationException, AssemblyException { fromJson( System.in ).withPassivationShutdownHook().newApplication(); } }
/** * Load an ApplicationBuilder from a JSONObject. * @param root JSON object * @return Application Builder loaded from JSON * @throws AssemblyException if unable to declare the assembly */ public static ApplicationBuilder fromJson( JsonObject root ) throws AssemblyException { String applicationName = root.getString( "name" ); ApplicationBuilder builder = new ApplicationBuilder( applicationName ); builder.configureWithJson( root ); return builder; }
/** * Load an ApplicationBuilder from a JSON InputStream. * @param json JSON input * @return Application Builder loaded from JSON * @throws AssemblyException if unable to declare the assembly */ public static ApplicationBuilder fromJson( InputStream json ) throws AssemblyException { JsonObject root = Json.createReader( json ).readObject(); return fromJson( root ); }
/** * Load an ApplicationBuilder from a JSON InputStream. * @param json JSON input * @return Application Builder loaded from JSON * @throws AssemblyException if unable to declare the assembly */ public static ApplicationBuilder fromJson( InputStream json ) throws AssemblyException { JsonObject root = Json.createReader( json ).readObject(); return fromJson( root ); }