You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ah...@apache.org on 2018/11/09 17:37:13 UTC

[isis] branch v2 updated: ISIS-2031: add 'took seconds' label to bottom of tables

This is an automated email from the ASF dual-hosted git repository.

ahuber pushed a commit to branch v2
in repository https://gitbox.apache.org/repos/asf/isis.git


The following commit(s) were added to refs/heads/v2 by this push:
     new 061d559  ISIS-2031: add 'took seconds' label to bottom of tables
061d559 is described below

commit 061d55932376a0830c71f96d5fe05d65fc255bd3
Author: Andi Huber <ah...@apache.org>
AuthorDate: Fri Nov 9 18:37:07 2018 +0100

    ISIS-2031: add 'took seconds' label to bottom of tables
    
    ... when in prototyping mode
    
    Task-Url: https://issues.apache.org/jira/browse/ISIS-2031
---
 .../apache/isis/commons/internal/base/_Timing.java | 18 +++++++++
 .../system/persistence/PersistenceSession4.java    |  2 +
 .../system/persistence/PersistenceSession5.java    |  4 ++
 .../system/persistence/PersistenceSession.java     |  2 +
 .../system/persistence/PersistenceSessionBase.java | 13 +++++-
 .../ajaxtable/IsisAjaxNavigationToolbar.html       |  1 +
 .../ajaxtable/IsisAjaxNavigationToolbar.java       | 29 +++++++++++---
 .../ajaxtable/IsisTotalRecordsToolbar.java         | 16 +++++++-
 .../ajaxtable/PrototypingMessageProvider.java      | 46 ++++++++++++++++++++++
 9 files changed, 123 insertions(+), 8 deletions(-)

diff --git a/core/commons/src/main/java/org/apache/isis/commons/internal/base/_Timing.java b/core/commons/src/main/java/org/apache/isis/commons/internal/base/_Timing.java
index e34f107..5150822 100644
--- a/core/commons/src/main/java/org/apache/isis/commons/internal/base/_Timing.java
+++ b/core/commons/src/main/java/org/apache/isis/commons/internal/base/_Timing.java
@@ -43,6 +43,16 @@ public final class _Timing {
     }
 
     /**
+     * 
+     * @param startedAtNanos
+     * @return a new {@code startedAtSystemNanos} instance of {@link StopWatch}
+     */
+    public static StopWatch atSystemNanos(long startedAtSystemNanos) {
+        return new StopWatch(startedAtSystemNanos);
+    }
+    
+    
+    /**
      * Non thread safe start/stop watch utilizing the currently running
      * JVM's high-resolution time source.
      */
@@ -52,6 +62,10 @@ public final class _Timing {
         private long t1 = 0;
         private boolean stopped;
         
+        private StopWatch(long startedAtSystemNanos) {
+            t0 = startedAtSystemNanos;
+        }
+        
         private StopWatch() {
             start();
         }
@@ -68,6 +82,10 @@ public final class _Timing {
             return this;
         }
         
+        public double getSeconds() {
+            return 0.000_000_001 * getNanos();
+        }
+        
         public double getMillis() {
             return 0.000_001 * getNanos();
         }
diff --git a/core/plugins/jdo-datanucleus-4/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSession4.java b/core/plugins/jdo-datanucleus-4/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSession4.java
index 636c6c7..e82b7a5 100644
--- a/core/plugins/jdo-datanucleus-4/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSession4.java
+++ b/core/plugins/jdo-datanucleus-4/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSession4.java
@@ -129,6 +129,8 @@ implements IsisLifecycleListener.PersistenceSessionLifecycleManagement {
     @Override
     public void open() {
         ensureNotOpened();
+        
+        openedAtSystemNanos = System.nanoTime();
 
         if (LOG.isDebugEnabled()) {
             LOG.debug("opening {}", this);
diff --git a/core/plugins/jdo-datanucleus-5/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSession5.java b/core/plugins/jdo-datanucleus-5/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSession5.java
index df79646..37e29c9 100644
--- a/core/plugins/jdo-datanucleus-5/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSession5.java
+++ b/core/plugins/jdo-datanucleus-5/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSession5.java
@@ -129,6 +129,8 @@ implements IsisLifecycleListener.PersistenceSessionLifecycleManagement {
     @Override
     public void open() {
         ensureNotOpened();
+        
+        openedAtSystemNanos = System.nanoTime();
 
         if (LOG.isDebugEnabled()) {
             LOG.debug("opening {}", this);
@@ -949,6 +951,8 @@ implements IsisLifecycleListener.PersistenceSessionLifecycleManagement {
             LOG.debug("refresh immediately; oid={}", oid.enString());
         }
     }
+
+
     
 }
 
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSession.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSession.java
index 3396626..13c2d8d 100644
--- a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSession.java
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSession.java
@@ -180,5 +180,7 @@ extends
     
     void execute(List<PersistenceCommand> persistenceCommandList);
     
+    long getLifecycleStartedAtSystemNanos();
+    
 
 }
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSessionBase.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSessionBase.java
index 81ab4a7..ee2f830 100644
--- a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSessionBase.java
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSessionBase.java
@@ -72,8 +72,12 @@ abstract class PersistenceSessionBase implements PersistenceSession {
     protected final MetricsService metricsService;
     protected final ClockService clockService;
     protected final UserService userService;
-
-
+    
+    /**
+     * Set to System.currentTimeMillis() when session opens.
+     */
+    protected long openedAtSystemNanos = -1L;
+    
     /**
      * Used to create the {@link #persistenceManager} when {@link #open()}ed.
      */
@@ -174,6 +178,11 @@ abstract class PersistenceSessionBase implements PersistenceSession {
     public IsisConfiguration getConfiguration() {
         return configuration;
     }
+    
+    @Override
+    public long getLifecycleStartedAtSystemNanos() {
+        return openedAtSystemNanos;
+    }
 
     // -- ENUMS
 
diff --git a/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/collectioncontents/ajaxtable/IsisAjaxNavigationToolbar.html b/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/collectioncontents/ajaxtable/IsisAjaxNavigationToolbar.html
index 604d8de..5390d3f 100644
--- a/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/collectioncontents/ajaxtable/IsisAjaxNavigationToolbar.html
+++ b/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/collectioncontents/ajaxtable/IsisAjaxNavigationToolbar.html
@@ -21,6 +21,7 @@
             <div class="navigatorLabel">
                 <span wicket:id="navigatorLabel">[navigator-label]</span>
                 <button wicket:id="showAll" type="button" class="btn btn-xs btn-link">Show all</button>
+                <span wicket:id="prototyping">[prototyping-message]</span>
             </div>
             <div class="navigator"><div wicket:id="navigator">[navigator]</div></div>
         </td>
diff --git a/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/collectioncontents/ajaxtable/IsisAjaxNavigationToolbar.java b/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/collectioncontents/ajaxtable/IsisAjaxNavigationToolbar.java
index 502ca5d..0e0f0a8 100644
--- a/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/collectioncontents/ajaxtable/IsisAjaxNavigationToolbar.java
+++ b/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/collectioncontents/ajaxtable/IsisAjaxNavigationToolbar.java
@@ -21,8 +21,10 @@ import org.apache.wicket.ajax.AjaxRequestTarget;
 import org.apache.wicket.ajax.markup.html.AjaxLink;
 import org.apache.wicket.extensions.ajax.markup.html.repeater.data.table.AjaxNavigationToolbar;
 import org.apache.wicket.extensions.markup.html.repeater.data.table.DataTable;
+import org.apache.wicket.markup.html.basic.Label;
 import org.apache.wicket.markup.html.navigation.paging.PagingNavigator;
 
+import org.apache.isis.core.runtime.system.context.IsisContext;
 import org.apache.isis.viewer.wicket.model.hints.UiHintContainer;
 import org.apache.isis.viewer.wicket.model.models.EntityCollectionModel;
 import org.apache.isis.viewer.wicket.model.models.EntityModel;
@@ -41,11 +43,20 @@ public class IsisAjaxNavigationToolbar extends AjaxNavigationToolbar {
         this.toggleboxColumn = toggleboxColumn;
         addShowAllButton(table);
     }
+    
+    @Override
+    protected PagingNavigator newPagingNavigator(String navigatorId, DataTable<?, ?> table) {
+        return new IsisAjaxPagingNavigator(navigatorId, table);
+    }
+    
+    // -- HELPER
 
     private void addShowAllButton(final DataTable<?, ?> table) {
         table.setOutputMarkupId(true);
 
-        ((MarkupContainer)get("span")).add(new AjaxLink<Void>(ID_SHOW_ALL) {
+        final MarkupContainer span = spanThatContainsNavigatorLabel();
+        
+        span.add(new AjaxLink<Void>(ID_SHOW_ALL) {
 
             private static final long serialVersionUID = 1L;
 
@@ -69,11 +80,19 @@ public class IsisAjaxNavigationToolbar extends AjaxNavigationToolbar {
                 target.add(table);
             }
         });
+        
+        final boolean isPrototyping = IsisContext.getEnvironment()
+                .getDeploymentCategory().isPrototyping();
+        
+        span.add(new Label("prototyping", isPrototyping 
+                ? PrototypingMessageProvider.getTookTimingMessage() 
+                        : ""));
+        
+        
     }
-
-    @Override
-    protected PagingNavigator newPagingNavigator(String navigatorId, DataTable<?, ?> table) {
-        return new IsisAjaxPagingNavigator(navigatorId, table);
+    
+    private MarkupContainer spanThatContainsNavigatorLabel() {
+        return ((MarkupContainer)get("span"));
     }
 
     void honourHints() {
diff --git a/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/collectioncontents/ajaxtable/IsisTotalRecordsToolbar.java b/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/collectioncontents/ajaxtable/IsisTotalRecordsToolbar.java
index 93ea169..d5b959b 100644
--- a/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/collectioncontents/ajaxtable/IsisTotalRecordsToolbar.java
+++ b/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/collectioncontents/ajaxtable/IsisTotalRecordsToolbar.java
@@ -27,6 +27,8 @@ import org.apache.wicket.markup.html.basic.Label;
 import org.apache.wicket.model.IModel;
 import org.apache.wicket.model.Model;
 
+import org.apache.isis.core.runtime.system.context.IsisContext;
+
 /**
  * Responsibility: Display 'Showing all of 123' at the bottom of data tables.
  * <p>
@@ -46,7 +48,19 @@ public class IsisTotalRecordsToolbar extends AbstractToolbar {
 
             @Override
             public String getObject() {
-                return String.format("Showing all of %d", table.getRowCount());
+                
+                final boolean isPrototyping = IsisContext.getEnvironment()
+                        .getDeploymentCategory().isPrototyping();
+                
+                if(!isPrototyping) {
+                    return String.format("Showing all of %d", table.getRowCount());
+                }
+
+                // when prototyping append a 'took seconds message' ...
+                
+                return String.format("Showing all of %d %s", 
+                        table.getRowCount(), 
+                        PrototypingMessageProvider.getTookTimingMessage());
             }
             
         });
diff --git a/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/collectioncontents/ajaxtable/PrototypingMessageProvider.java b/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/collectioncontents/ajaxtable/PrototypingMessageProvider.java
new file mode 100644
index 0000000..c01b6cb
--- /dev/null
+++ b/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/collectioncontents/ajaxtable/PrototypingMessageProvider.java
@@ -0,0 +1,46 @@
+/*
+ *  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.isis.viewer.wicket.ui.components.collectioncontents.ajaxtable;
+
+import java.util.Locale;
+
+import org.apache.isis.commons.internal.base._Timing;
+import org.apache.isis.commons.internal.base._Timing.StopWatch;
+import org.apache.isis.core.runtime.system.context.IsisContext;
+
+/**
+ * Responsibility: produce additional info when in prototyping mode eg. render/response timing 
+ * 
+ * @since 2.0.0-M2
+ */
+class PrototypingMessageProvider {
+
+    public static String getTookTimingMessage() {
+        
+        final StringBuilder tookTimingMessage = new StringBuilder();
+        
+        IsisContext.getPersistenceSession().ifPresent(session->{
+            StopWatch stopWatch = _Timing.atSystemNanos(session.getLifecycleStartedAtSystemNanos());    
+            tookTimingMessage.append(String.format(Locale.US, "... took %.2f seconds", stopWatch.getSeconds()));
+        });
+
+        return tookTimingMessage.toString();
+    }
+
+}