You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jspwiki.apache.org by ju...@apache.org on 2020/01/28 20:34:09 UTC

[jspwiki] 08/32: rename + extract interface from ProgressManager, instantiate it through classmappings.xml on WikiEngine

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

juanpablo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jspwiki.git

commit 5eb41ff79eece279d2e116f5a0e15d2f02395540
Author: juanpablo <ju...@apache.org>
AuthorDate: Sat Jan 18 15:36:10 2020 +0100

    rename + extract interface from ProgressManager, instantiate it through classmappings.xml on WikiEngine
---
 .../src/main/java/org/apache/wiki/WikiEngine.java  |  10 +-
 ...essManager.java => DefaultProgressManager.java} |  11 +--
 .../apache/wiki/ui/progress/ProgressManager.java   | 101 ++-------------------
 .../src/main/resources/ini/classmappings.xml       |   4 +
 4 files changed, 17 insertions(+), 109 deletions(-)

diff --git a/jspwiki-main/src/main/java/org/apache/wiki/WikiEngine.java b/jspwiki-main/src/main/java/org/apache/wiki/WikiEngine.java
index 5014218..b261745 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/WikiEngine.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/WikiEngine.java
@@ -473,12 +473,9 @@ public class WikiEngine  {
         m_frontPage      = TextUtil.getStringProperty( props, PROP_FRONTPAGE,   "Main" );
 
         //
-        //  Initialize the important modules.  Any exception thrown by the
-        //  managers means that we will not start up.
+        //  Initialize the important modules.  Any exception thrown by the managers means that we will not start up.
         //
-
-        // FIXME: This part of the code is getting unwieldy.  We must think
-        //        of a better way to do the startup-sequence.
+        // FIXME: This part of the code is getting unwieldy.  We must think of a better way to do the startup-sequence.
         try {
             final Class< ? > urlclass = ClassUtil.findClass( "org.apache.wiki.url",
                                                              TextUtil.getStringProperty( props, PROP_URLCONSTRUCTOR, "DefaultURLConstructor" ) );
@@ -497,10 +494,9 @@ public class WikiEngine  {
             m_userManager           = ClassUtil.getMappedObject( UserManager.class.getName() );
             m_groupManager          = ClassUtil.getMappedObject( GroupManager.class.getName() );
             m_editorManager         = ClassUtil.getMappedObject( EditorManager.class.getName(), this );
+            m_progressManager       = ClassUtil.getMappedObject( ProgressManager.class.getName(), this );
             m_editorManager.initialize( props );
 
-            m_progressManager   = new ProgressManager();
-
             // Initialize the authentication, authorization, user and acl managers
             m_authenticationManager.initialize( this, props );
             m_authorizationManager.initialize( this, props );
diff --git a/jspwiki-main/src/main/java/org/apache/wiki/ui/progress/ProgressManager.java b/jspwiki-main/src/main/java/org/apache/wiki/ui/progress/DefaultProgressManager.java
similarity index 93%
copy from jspwiki-main/src/main/java/org/apache/wiki/ui/progress/ProgressManager.java
copy to jspwiki-main/src/main/java/org/apache/wiki/ui/progress/DefaultProgressManager.java
index 6ce37ce..f363385 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/ui/progress/ProgressManager.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/ui/progress/DefaultProgressManager.java
@@ -38,19 +38,16 @@ import java.util.concurrent.ConcurrentHashMap;
  *
  *  @since  2.6
  */
-public class ProgressManager {
+public class DefaultProgressManager implements ProgressManager {
 
     private final Map< String,ProgressItem > m_progressingTasks = new ConcurrentHashMap<>();
 
-    /** The name of the progress tracker JSON object.  The current value is "{@value}", */
-    public static final String JSON_PROGRESSTRACKER = "progressTracker";
-
-    private static final Logger log = Logger.getLogger( ProgressManager.class );
+    private static final Logger log = Logger.getLogger( DefaultProgressManager.class );
 
     /**
      *  Creates a new ProgressManager.
      */
-    public ProgressManager() {
+    public DefaultProgressManager() {
     	// TODO: Replace with custom annotations. See JSPWIKI-566
         WikiAjaxDispatcherServlet.registerServlet( JSON_PROGRESSTRACKER, new JSONTracker() );
     }
@@ -120,7 +117,7 @@ public class ProgressManager {
          */
         public int getProgress( final String progressId )
         {
-            return ProgressManager.this.getProgress( progressId );
+            return DefaultProgressManager.this.getProgress( progressId );
         }
         
         public String getServletMapping() {
diff --git a/jspwiki-main/src/main/java/org/apache/wiki/ui/progress/ProgressManager.java b/jspwiki-main/src/main/java/org/apache/wiki/ui/progress/ProgressManager.java
index 6ce37ce..4f818f5 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/ui/progress/ProgressManager.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/ui/progress/ProgressManager.java
@@ -18,19 +18,6 @@
  */
 package org.apache.wiki.ui.progress;
 
-import org.apache.log4j.Logger;
-import org.apache.wiki.ajax.WikiAjaxDispatcherServlet;
-import org.apache.wiki.ajax.WikiAjaxServlet;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
-import java.util.concurrent.ConcurrentHashMap;
-
-
 /**
  *  Manages progressing items.  In general this class is used whenever JSPWiki is doing something which may require a long time.
  *  In addition, this manager provides a JSON interface for finding remotely what the progress is.  The JSON object name is
@@ -38,32 +25,16 @@ import java.util.concurrent.ConcurrentHashMap;
  *
  *  @since  2.6
  */
-public class ProgressManager {
-
-    private final Map< String,ProgressItem > m_progressingTasks = new ConcurrentHashMap<>();
+public interface ProgressManager {
 
-    /** The name of the progress tracker JSON object.  The current value is "{@value}", */
-    public static final String JSON_PROGRESSTRACKER = "progressTracker";
-
-    private static final Logger log = Logger.getLogger( ProgressManager.class );
-
-    /**
-     *  Creates a new ProgressManager.
-     */
-    public ProgressManager() {
-    	// TODO: Replace with custom annotations. See JSPWIKI-566
-        WikiAjaxDispatcherServlet.registerServlet( JSON_PROGRESSTRACKER, new JSONTracker() );
-    }
+    String JSON_PROGRESSTRACKER = "progressTracker";
 
     /**
      *  You can use this to get an unique process identifier.
      *
      *  @return A new random value
      */
-    public String getNewProgressIdentifier()
-    {
-        return UUID.randomUUID().toString();
-    }
+    String getNewProgressIdentifier();
 
     /**
      *  Call this method to get your ProgressItem into the ProgressManager queue. The ProgressItem will be moved to state STARTED.
@@ -71,11 +42,7 @@ public class ProgressManager {
      *  @param pi ProgressItem to start
      *  @param id The progress identifier
      */
-    public void startProgress( final ProgressItem pi, final String id ) {
-        log.debug( "Adding " + id + " to progress queue" );
-        m_progressingTasks.put( id, pi );
-        pi.setState( ProgressItem.STARTED );
-    }
+    void startProgress( ProgressItem pi, String id );
 
     /**
      *  Call this method to remove your ProgressItem from the queue (after which getProgress() will no longer find it.
@@ -83,13 +50,7 @@ public class ProgressManager {
      *
      *  @param id The progress identifier
      */
-    public void stopProgress( final String id ) {
-        log.debug( "Removed " + id + " from progress queue" );
-        final ProgressItem pi = m_progressingTasks.remove( id );
-        if( pi != null ) {
-            pi.setState( ProgressItem.STOPPED );
-        }
-    }
+    void stopProgress( String id );
 
     /**
      *  Get the progress in percents.
@@ -98,56 +59,6 @@ public class ProgressManager {
      *  @return a value between 0 to 100 indicating the progress
      *  @throws IllegalArgumentException If no such progress item exists.
      */
-    public int getProgress( final String id ) throws IllegalArgumentException {
-        final ProgressItem pi = m_progressingTasks.get( id );
-        if( pi != null ) {
-            return pi.getProgress();
-        }
-
-        throw new IllegalArgumentException( "No such id was found" );
-    }
-
-    /**
-     *  Provides access to a progress indicator, assuming you know the ID. Progress of zero (0) means that the progress has just started,
-     *  and a progress of 100 means that it is complete.
-     */
-    public class JSONTracker implements WikiAjaxServlet {
-        /**
-         *  Returns upload progress in percents so far.
-         *
-         *  @param progressId The string representation of the progress ID that you want to know the progress of.
-         *  @return a value between 0 to 100 indicating the progress
-         */
-        public int getProgress( final String progressId )
-        {
-            return ProgressManager.this.getProgress( progressId );
-        }
-        
-        public String getServletMapping() {
-        	return JSON_PROGRESSTRACKER;
-        }
-        
-        public void service( final HttpServletRequest req,
-                             final HttpServletResponse resp,
-                             final String actionName,
-                             final List< String > params ) throws IOException {
-        	log.debug( "ProgressManager.doGet() START" );
-        	if( params.size() < 1 ) {
-        		return;
-        	}
-        	final String progressId = params.get(0);
-        	log.debug( "progressId=" + progressId );
-        	String progressString = "";
-        	try {
-        		progressString = Integer.toString( getProgress( progressId ) );
-        	} catch( final IllegalArgumentException e ) { // ignore
-        		log.debug( "progressId " + progressId + " is no longer valid" );
-        	}
-        	log.debug( "progressString=" + progressString );
-        	resp.getWriter().write( progressString );
-        	log.debug( "ProgressManager.doGet() DONE" );
-        }
-
-    }
+    int getProgress( String id ) throws IllegalArgumentException;
 
 }
diff --git a/jspwiki-main/src/main/resources/ini/classmappings.xml b/jspwiki-main/src/main/resources/ini/classmappings.xml
index bc6f1e0..3f5bd1f 100644
--- a/jspwiki-main/src/main/resources/ini/classmappings.xml
+++ b/jspwiki-main/src/main/resources/ini/classmappings.xml
@@ -124,6 +124,10 @@
     <mappedClass>org.apache.wiki.ui.TemplateManager</mappedClass>
   </mapping>
   <mapping>
+    <requestedClass>org.apache.wiki.ui.progress.ProgressManager</requestedClass>
+    <mappedClass>org.apache.wiki.ui.progress.DefaultProgressManager</mappedClass>
+  </mapping>
+  <mapping>
     <requestedClass>org.apache.wiki.variables.VariableManager</requestedClass>
     <mappedClass>org.apache.wiki.variables.DefaultVariableManager</mappedClass>
   </mapping>