polygene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From paulmer...@apache.org
Subject [1/5] zest-java git commit: bootstrap: add some assembly facilities to ApplicationBuilder
Date Tue, 06 Dec 2016 17:30:08 GMT
Repository: zest-java
Updated Branches:
  refs/heads/develop 2d6e287bc -> 994d38913


bootstrap: add some assembly facilities to ApplicationBuilder


Project: http://git-wip-us.apache.org/repos/asf/zest-java/repo
Commit: http://git-wip-us.apache.org/repos/asf/zest-java/commit/4618a2eb
Tree: http://git-wip-us.apache.org/repos/asf/zest-java/tree/4618a2eb
Diff: http://git-wip-us.apache.org/repos/asf/zest-java/diff/4618a2eb

Branch: refs/heads/develop
Commit: 4618a2eb3d439083e4292f31a43ae0481953cb52
Parents: 2d6e287
Author: Paul Merlin <paulmerlin@apache.org>
Authored: Sat Dec 3 16:24:28 2016 +0100
Committer: Paul Merlin <paulmerlin@apache.org>
Committed: Mon Dec 5 09:51:25 2016 +0100

----------------------------------------------------------------------
 .../ApplicationPassivationThread.java           |  2 -
 .../bootstrap/builder/ApplicationBuilder.java   | 58 +++++++++++++++++++-
 2 files changed, 55 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zest-java/blob/4618a2eb/core/api/src/main/java/org/apache/zest/api/activation/ApplicationPassivationThread.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/zest/api/activation/ApplicationPassivationThread.java
b/core/api/src/main/java/org/apache/zest/api/activation/ApplicationPassivationThread.java
index 78ef07c..0923e67 100644
--- a/core/api/src/main/java/org/apache/zest/api/activation/ApplicationPassivationThread.java
+++ b/core/api/src/main/java/org/apache/zest/api/activation/ApplicationPassivationThread.java
@@ -27,8 +27,6 @@ import org.apache.zest.api.structure.Application;
 /**
  * Application Passivation Thread to use as a Shutdown Hook.
  * <pre>Runtime.getRuntime().addShutdownHook( new ApplicationPassivationThread( application
) );</pre>
- * <p>Constructors to control where errors are logged are provided. They support PrintStream
(STDOUT/STDERR) and SLF4J
- * Loggers. Defaults to STDERR.</p>
  */
 public final class ApplicationPassivationThread
     extends Thread

http://git-wip-us.apache.org/repos/asf/zest-java/blob/4618a2eb/core/bootstrap/src/main/java/org/apache/zest/bootstrap/builder/ApplicationBuilder.java
----------------------------------------------------------------------
diff --git a/core/bootstrap/src/main/java/org/apache/zest/bootstrap/builder/ApplicationBuilder.java
b/core/bootstrap/src/main/java/org/apache/zest/bootstrap/builder/ApplicationBuilder.java
index bd4d9d0..7c53bea 100644
--- a/core/bootstrap/src/main/java/org/apache/zest/bootstrap/builder/ApplicationBuilder.java
+++ b/core/bootstrap/src/main/java/org/apache/zest/bootstrap/builder/ApplicationBuilder.java
@@ -48,6 +48,10 @@ public class ApplicationBuilder
     implements ActivationEventListenerRegistration
 {
     private final String applicationName;
+    private String applicationVersion;
+    private Application.Mode applicationMode;
+    private final List<Object> metaInfos = new ArrayList<>();
+    private boolean passivationShutdownHook;
     private final Map<String, LayerDeclaration> layers = new HashMap<>();
     private final List<ActivationEventListener> activationListeners = new ArrayList<>();
 
@@ -56,6 +60,40 @@ public class ApplicationBuilder
         this.applicationName = applicationName;
     }
 
+    public ApplicationBuilder version( String version )
+    {
+        applicationVersion = version;
+        return this;
+    }
+
+    public ApplicationBuilder mode( Application.Mode mode )
+    {
+        applicationMode = mode;
+        return this;
+    }
+
+    public ApplicationBuilder metaInfo( Object... metaInfos )
+    {
+        for( Object metaInfo : metaInfos )
+        {
+            this.metaInfos.add( metaInfo );
+        }
+        return this;
+    }
+
+    /**
+     * Register a JVM shutdown hook that passivate the Application.
+     *
+     * The hook is registered after activating the Application and before {@link #afterActivation()}.
+     *
+     * @return This builder
+     */
+    public ApplicationBuilder withPassivationShutdownHook()
+    {
+        this.passivationShutdownHook = true;
+        return this;
+    }
+
     /**
      * Create and activate a new Application.
      * @return Activated Application
@@ -74,6 +112,18 @@ public class ApplicationBuilder
             {
                 ApplicationAssembly assembly = factory.newApplicationAssembly();
                 assembly.setName( applicationName );
+                if( applicationVersion != null )
+                {
+                    assembly.setVersion( applicationVersion );
+                }
+                if( applicationMode != null )
+                {
+                    assembly.setMode( applicationMode );
+                }
+                for( Object metaInfo : metaInfos )
+                {
+                    assembly.setMetaInfo( metaInfo );
+                }
                 HashMap<String, LayerAssembly> createdLayers = new HashMap<>();
                 for( Map.Entry<String, LayerDeclaration> entry : layers.entrySet()
)
                 {
@@ -94,6 +144,10 @@ public class ApplicationBuilder
         }
         beforeActivation();
         application.activate();
+        if( passivationShutdownHook )
+        {
+            Runtime.getRuntime().addShutdownHook( new ApplicationPassivationThread( application
) );
+        }
         afterActivation();
         return application;
     }
@@ -244,8 +298,6 @@ public class ApplicationBuilder
     public static void main( String[] args )
         throws JSONException, ActivationException, AssemblyException
     {
-        ApplicationBuilder builder = fromJson( System.in );
-        Application application = builder.newApplication();
-        Runtime.getRuntime().addShutdownHook( new ApplicationPassivationThread( application,
System.err ) );
+        fromJson( System.in ).withPassivationShutdownHook().newApplication();
     }
 }


Mime
View raw message