1 2 Previous Next 26 Replies Latest reply on Aug 11, 2009 5:17 AM by m.a.knapp Go to original post
      • 15. Re: Ajax queues concurrency woes
        nbelaevski

        I guess this:

        <managed-bean>
         <managed-bean-name>test</managed-bean-name>
         <managed-bean-class>test.TestBean</managed-bean-class>
         <managed-bean-scope>request</managed-bean-scope>
         </managed-bean>
        should have session scope instead of request?

        • 16. Re: Ajax queues concurrency woes
          m.a.knapp

          with scope set to 'session' it seems to work without any problems now

          I was using scope set to 'request' and a4j:keepAlive ( <a4j:keepAlive beanName="test" /> ) ... which seems to be the reason for that erratic behavior

          is there a difference between both types 'request with keepAlive' and 'session' in such situations ?

          Thanks for Help. I hope, things turn out well now ...

          • 17. Re: Ajax queues concurrency woes
            nbelaevski

            Yes, a4j:keepAlive stores data in view state. View states are stored per each view id (page name) and view version (int counter). The last handles "back" button.

            Maximum number of stated saved in session is limited to the particular number to limit memory consumption. Each time view is rendered, view version is increased and new version of the view is stored, optionally purging the oldest one. But for AJAX that's not true, because if it was done that way, AJAX requests would quickly fill all the allowed space. E.g. a4j:poll. So, for AJAX requests view version is not increased, but stays constant; and that's the source of the erratic behavior with a4j:keepAlive you observe.

            You can use a4j:queue for all requests to solve this.

            • 18. Re: Ajax queues concurrency woes
              m.a.knapp

              Story goes on ... with org.ajax4jsf.SERIALIZE_SERVER_STATE=true

              I tried to apply the while thing on my real application, but I came across
              a java.lang.ClassNotFoundException occurring when
              the "rendered" attribute of a component contains a function of a facelts tag library.

              I have created a litte test example again

              when the "Rerender" button is pressed the exception occurs

              The exception

              13:02:26,843 ERROR [STDERR] java.lang.ClassNotFoundException: No ClassLoaders found for: test.TestTags
              13:02:26,843 ERROR [STDERR] at org.jboss.mx.loading.LoadMgr3.beginLoadTask(LoadMgr3.java:212)
              13:02:26,843 ERROR [STDERR] at org.jboss.mx.loading.RepositoryClassLoader.loadClassImpl(RepositoryClassLoader.java:521)
              13:02:26,843 ERROR [STDERR] at org.jboss.mx.loading.RepositoryClassLoader.loadClass(RepositoryClassLoader.java:415)
              13:02:26,843 ERROR [STDERR] at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
              13:02:26,843 ERROR [STDERR] at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
              13:02:26,843 ERROR [STDERR] at java.lang.Class.forName0(Native Method)
              13:02:26,843 ERROR [STDERR] at java.lang.Class.forName(Class.java:169)
              13:02:26,843 ERROR [STDERR] at org.apache.el.lang.FunctionMapperImpl$Function.getMethod(FunctionMapperImpl.java:147)
              13:02:26,843 ERROR [STDERR] at org.apache.el.lang.FunctionMapperImpl.resolveFunction(FunctionMapperImpl.java:53)
              13:02:26,843 ERROR [STDERR] at org.apache.el.parser.AstFunction.getValue(AstFunction.java:71)
              13:02:26,859 ERROR [STDERR] at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
              13:02:26,859 ERROR [STDERR] at com.sun.facelets.el.TagValueExpression.getValue(TagValueExpression.java:71)
              13:02:26,859 ERROR [STDERR] at javax.faces.component.UIComponentBase.isRendered(UIComponentBase.java:390)
              13:02:26,859 ERROR [STDERR] at javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1018)
              13:02:26,859 ERROR [STDERR] at org.ajax4jsf.component.UIAjaxForm.processDecodes(UIAjaxForm.java:63)
              13:02:26,859 ERROR [STDERR] at org.ajax4jsf.component.AjaxViewRoot$1.invokeContextCallback(AjaxViewRoot.java:392)
              13:02:26,859 ERROR [STDERR] at org.ajax4jsf.component.AjaxViewRoot.processPhase(AjaxViewRoot.java:238)
              13:02:26,859 ERROR [STDERR] at org.ajax4jsf.component.AjaxViewRoot.processDecodes(AjaxViewRoot.java:409)
              13:02:26,859 ERROR [STDERR] at com.sun.faces.lifecycle.ApplyRequestValuesPhase.execute(ApplyRequestValuesPhase.java:78)
              13:02:26,859 ERROR [STDERR] at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
              13:02:26,859 ERROR [STDERR] at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
              13:02:26,859 ERROR [STDERR] at javax.faces.webapp.FacesServlet.service(FacesServlet.java:265)
              13:02:26,859 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
              13:02:26,859 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
              13:02:26,859 ERROR [STDERR] at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:510)
              13:02:26,859 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
              13:02:26,859 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
              13:02:26,859 ERROR [STDERR] at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178)
              13:02:26,859 ERROR [STDERR] at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
              13:02:26,859 ERROR [STDERR] at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:368)
              13:02:26,859 ERROR [STDERR] at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:495)
              13:02:26,859 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
              13:02:26,859 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
              13:02:26,859 ERROR [STDERR] at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
              13:02:26,859 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
              13:02:26,859 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
              13:02:26,859 ERROR [STDERR] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
              13:02:26,859 ERROR [STDERR] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
              13:02:26,859 ERROR [STDERR] at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:182)
              13:02:26,859 ERROR [STDERR] at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:524)
              13:02:26,859 ERROR [STDERR] at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
              13:02:26,859 ERROR [STDERR] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
              13:02:26,859 ERROR [STDERR] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
              13:02:26,859 ERROR [STDERR] at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
              13:02:26,859 ERROR [STDERR] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
              13:02:26,859 ERROR [STDERR] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
              13:02:26,859 ERROR [STDERR] at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
              13:02:26,859 ERROR [STDERR] at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
              13:02:26,859 ERROR [STDERR] at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
              13:02:26,859 ERROR [STDERR] at java.lang.Thread.run(Thread.java:619)

              JSF code

              <?xml version="1.0" encoding="ISO-8859-1" ?>
              <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
               "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
              <html
               xmlns = "http://www.w3.org/1999/xhtml"
               xmlns:a4j = "http://richfaces.org/a4j"
               xmlns:rich = "http://richfaces.org/rich"
               xmlns:ui = "http://java.sun.com/jsf/facelets"
               xmlns:h = "http://java.sun.com/jsf/html"
               xmlns:f = "http://java.sun.com/jsf/core"
               xmlns:test = "http://test/test"
              >
              <head>
               <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
               <title>QueueTest</title>
              </head>
              <body>
               <div style="position:absolute; top:2px; left:2px; bottom:2px; right:2px; background-color:#ffffaf;" >
               <f:view>
               <h1>Page 1</h1>
               <a4j:form>
               <h:outputText value="This is a Test" rendered="#{test:isReallyTrue()}" />
               <br />
               <a4j:commandButton value="Rerender" reRender="panel" limitToList="true" />
               </a4j:form>
               </f:view>
               </div>
              </body>
              </html>
              




              facelets tag lib xml - test.taglib.xml

              <?xml version="1.0" encoding="UTF-8"?>
              <!DOCTYPE facelet-taglib PUBLIC
               "-//Sun Microsystems, Inc.//DTD Facelet Taglib 1.0//EN"
               "http://java.sun.com/dtd/facelet-taglib_1_0.dtd">
              <facelet-taglib xmlns="http://java.sun.com/JSF/Facelet">
               <namespace>http://test/test</namespace>
               <function>
               <function-name>isReallyTrue</function-name>
               <function-class>test.TestTags</function-class>
               <function-signature>boolean isReallyTrue()</function-signature>
               </function>
              </facelet-taglib>
              



              facelets tag lib class

              package test;
              
              public class TestTags
              {
               public static boolean isReallyTrue()
               {
               return true;
               }
              }
              



              entry for web.xml
               <context-param>
               <param-name>facelets.LIBRARIES</param-name>
               <param-value>
               /WEB-INF/test.taglib.xml
               </param-value>
               </context-param>
              





              • 19. Re: Ajax queues concurrency woes
                nbelaevski
                • 20. Re: Ajax queues concurrency woes
                  m.a.knapp

                  On Tomcat 6.0.26 it is ok.

                  • 21. Re: Ajax queues concurrency woes
                    m.a.knapp

                    Thanks, that helped much. A Thousand thanks for you help, Nick :-)

                    • 22. Re: Ajax queues concurrency woes
                      m.a.knapp

                      Everything sems to work know, but as I noticed in jprofiler, the state serialization consumes quite a lot of time ... actually a bit too much.
                      Is there a faster method or an alternative ?

                      • 23. Re: Ajax queues concurrency woes
                        nbelaevski

                        Only making requests to come serially using a4j:queue.

                        • 24. Re: Ajax queues concurrency woes
                          m.a.knapp

                          That means one queue for all events within a view ?
                          Is it possible to invoke a4j:jsFunction, which does not change the current state without serializing the whole state again ?

                          • 25. Re: Ajax queues concurrency woes
                            nbelaevski

                            Yes, one queue. In this case serialization is not necessary. For requests initiated by a4j:jsFunction full view processing is done, so the problem can happen again without making requests happen serially.

                            • 26. Re: Ajax queues concurrency woes
                              m.a.knapp

                              We solved the problem this way for as

                              we have extended the class org.ajax4jsf.Filter with a synchronizatzion method in that way, that only one session at a time is invoking the handleRequest Method and it works for as ... fast and no unexpected behavior anymore.


                               @Override
                               protected void handleRequest(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException {
                               HttpSession session = request.getSession();
                               if(session == null) {
                               log.debug("No session, no lock");
                               super.handleRequest(request, response, chain);
                               return;
                               }
                              
                               String sessionId = session.getId();
                               if(sessionId == null) {
                               log.debug("No session id, no lock");
                               super.handleRequest(request, response, chain);
                               return;
                               }
                              
                               RichfacesFilterLock lock = acquireLock(sessionId);
                               try {
                               log.trace("acquired lock on {}", lock);
                               super.handleRequest(request, response, chain);
                               } finally {
                               lock.unlock();
                               log.trace("released lock on {}", lock);
                               }
                               }
                              


                              1 2 Previous Next