portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tay...@apache.org
Subject cvs commit: jakarta-jetspeed-2/commons/src/java/org/apache/jetspeed/container JetspeedContainerServlet.java
Date Fri, 30 Jul 2004 17:49:52 GMT
taylor      2004/07/30 10:49:52

  Modified:    commons/src/java/org/apache/jetspeed/container
                        JetspeedContainerServlet.java
  Log:
  put registration attempts on a timer thread
  
  CVS: ----------------------------------------------------------------------
  CVS: PR:
  CVS:   If this change addresses a PR in the problem report tracking
  CVS:   database, then enter the PR number(s) here.
  CVS: Obtained from:
  CVS:   If this change has been taken from another system, such as NCSA,
  CVS:   then name the system in this line, otherwise delete it.
  CVS: Submitted by:
  CVS:   If this code has been contributed to Apache by someone else; i.e.,
  CVS:   they sent us a patch or a new module, then include their name/email
  CVS:   address here. If this is your work then delete this line.
  CVS: Reviewed by:
  CVS:   If we are doing pre-commit code reviews and someone else has
  CVS:   reviewed your changes, include their name(s) here.
  CVS:   If you have not had it reviewed then delete this line.
  
  Revision  Changes    Path
  1.12      +51 -79    jakarta-jetspeed-2/commons/src/java/org/apache/jetspeed/container/JetspeedContainerServlet.java
  
  Index: JetspeedContainerServlet.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/commons/src/java/org/apache/jetspeed/container/JetspeedContainerServlet.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- JetspeedContainerServlet.java	23 Jul 2004 00:29:00 -0000	1.11
  +++ JetspeedContainerServlet.java	30 Jul 2004 17:49:52 -0000	1.12
  @@ -19,6 +19,8 @@
   import java.io.IOException;
   import java.io.PrintWriter;
   import java.io.StringWriter;
  +import java.util.Timer;
  +import java.util.TimerTask;
   
   import javax.portlet.ActionRequest;
   import javax.portlet.ActionResponse;
  @@ -116,96 +118,65 @@
           }
       }
   
  -    
  -    private void registerPortletApplication(ServletContext context, String portletApplicationName)
  +    private void registerPortletApplication(final ServletContext context, final String
portletApplicationName)
       throws ServletException
       {
  -        final int INITIAL_WAIT = 5 * 1000; // initially wait 5 seconds
  -        final int LONGER_WAIT =  300 * 1000; // longer wait stage 5 minutes
  -        final int SLOW_DOWN_THRESHOLD = 20; // after 20 tries and 1 minute, fall back to
longer wait
  -        int tries = 0;
  -        
  -        //InputStream portletStream = null;
  -        //InputStream servletStream = null;
  -        
  -        //portletStream = context.getResourceAsStream("WEB-INF/portlet.xml");
  -        //servletStream = context.getResourceAsStream("WEB-INF/web.xml");
  -        
  -        boolean registrarNotAvailable = true;
  -        
  -        while (registrarNotAvailable)
  -        {
  -            try
  -            {
  -                PortletServices services = JetspeedPortletServices.getSingleton();
  -                if (services != null)
  -                {
  -                    DeploymentRegistration registrar =
  -                        (DeploymentRegistration)services.getService("PAM"); 
  -                
  -                    if (registrar != null)
  -                    {
  -                        FileSystemHelper webapp = new DirectoryHelper(new File(context.getRealPath("/")));
  -                        if (registrar.registerPortletApplication(webapp, portletApplicationName))
  -                        {
  -                            log.info("Portlet Application Registered at Servlet Init: "
+ portletApplicationName);
  -                        }
  -                        else
  -                        {
  -                            log.info("Portlet Application did not change. Not Registered
at Servlet Init: " + portletApplicationName);
  +
  +        log.info("Attempting to register portlet application: name=" + portletApplicationName);
  +        if (attemptRegistration(context, portletApplicationName)) {
  +            log.info("Registered portlet application: name=" + portletApplicationName);
  +        }
  +
  +        log.info("Could not registered protlet application; starting back ground thread
to register when jetspeed comes online: name=" + portletApplicationName);
  +        final Timer timer = new Timer(true);
  +        timer.schedule(
  +                new TimerTask() {
  +                    public void run() {
  +                        log.info("Attempting to register portlet application: name=" +
portletApplicationName);
  +                        if (attemptRegistration(context, portletApplicationName)) {
  +                            log.info("Registered portlet application: name=" + portletApplicationName);
  +                            timer.cancel();
  +                        } else {
  +                            log.info("Could not register portlet application; will try
again later: name=" + portletApplicationName);
                           }
  -                        break;
                       }
  -                }                
  -            }
  -            catch (Exception e)
  -            {
  -                if (tries < 3)
  -                {
  -                    e.printStackTrace();
  -                }
  -                log.error("Failed to register PA: " + portletApplicationName);
  -            }
  -            finally
  -            {
  -                //closeStream(portletStream);
  -                //closeStream(servletStream);
  -            }    
  -            log.error("*** Jetspeed Runtime Registration: Portlet Services not available
for registering PA: " + portletApplicationName);
  -            try
  -            {
  -                tries++;
  -                if (tries > SLOW_DOWN_THRESHOLD)
  -                {
  -                    Thread.sleep(LONGER_WAIT);
  -                }
  -                else
  -                {
  -                    Thread.sleep(INITIAL_WAIT);
  -                }
  -            }
  -            catch (InterruptedException e)
  -            {
  -                throw new ServletException("Servlet init interrupted for " + portletApplicationName);
  -            }
  -        }        
  +                },
  +                10000,
  +                10000);
       }
   
  -    /*
  -    private void closeStream(InputStream stream)
  +    private static boolean attemptRegistration(ServletContext context, String portletApplicationName)

       {
           try
           {
  -            if (stream != null)
  +            PortletServices services = JetspeedPortletServices.getSingleton();
  +            if (services != null)
               {
  -                stream.close();
  +                DeploymentRegistration registrar =
  +                    (DeploymentRegistration)services.getService("PAM");
  +
  +                if (registrar != null)
  +                {
  +                    FileSystemHelper webapp = new DirectoryHelper(new File(context.getRealPath("/")));
  +                    if (registrar.registerPortletApplication(webapp, portletApplicationName))
  +                    {
  +                        log.info("Portlet Application Registered at Servlet Init: " + portletApplicationName);
  +                    }
  +                    else
  +                    {
  +                        log.info("Portlet Application did not change. Not Registered at
Servlet Init: " + portletApplicationName);
  +                    }
  +                    return true;
  +                }
               }
           }
  -        catch (IOException e)
  -        {        
  +        catch (Exception e)
  +        {
  +            log.error("Failed to register PA: " + portletApplicationName);
           }
  -    }
  -    */
  +        return false;
  +    }    
  +    
       // -------------------------------------------------------------------
       // R E Q U E S T  P R O C E S S I N G
       // -------------------------------------------------------------------
  @@ -353,5 +324,6 @@
           }
   
       }
  -
  +    
  + 
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jetspeed-dev-help@jakarta.apache.org


Mime
View raw message