• XPages and servlet factory

    By Pieter JD Malan 1 decade ago

    I noticed that the demo library implements 'com.ibm.xsp.adapter.servletFactory' - is there a way to create a servlet via the XPages extension library that is launched when the first person access the database and that can instantiate a singleton OBJECT that could be consumed from anywhere in the backend, with some sort of application wide scope?

     

    I have successfully configured an XPage to surface data from a MySQL database via hibernate, but am experiencing memory issues:  the hibernate session factory (org.hibernate.impl.SessionFactoryImpl) is not able to dereference all objects, which will allow it to get garbage collected. My suspicion is that this is happening because of WHERE the hibernate session factory is created and am hoping that instantiating it via a servlet may help.

    • Do you have access to 853 CD5?

      By Philippe Riand 1 decade ago

      It features some new extension points that you can use within your NSF application, or globally in a plug-in, to listen to application creation/destruction events. Note that the same API also existing for session creation/destruction.

      • Yes,I have ;-)

        By Pieter JD Malan 1 decade ago

        Hello,

        I have access to CD 5. Do you have a generic example of how this API would work?

        Any help would be much appreciated,

        Pieter Malan

        • Do you have a generic example of how this API would work?

          By Pieter JD Malan 1 decade ago


          • Not really

            By Philippe Riand 1 decade ago

            I have one but part of a broader NSF with many other tests.  i need to isolate the code and better document it

            Anyway, you have 2 classes: SessionListener & ApplicationListener (package com.ibm.xsp.application.events). You can implement one of them or both, like this:

             

            public class SessionEvent implements SessionListener {
            
             
            
            public void sessionCreated(ApplicationEx arg0, HttpSessionEvent sessionEvent) {
            
            System.out.println("sessionCreated, "+sessionEvent.getSession().getId());
            
            }
            
             
            
            public void sessionDestroyed(ApplicationEx arg0, HttpSessionEvent sessionEvent) {
            
            System.out.println("sessionDestroyed, "+sessionEvent.getSession().getId());
            
            }
            
            }
            
            
                public class SessionEvent implements SessionListener {
            
                 
            
                public void sessionCreated(ApplicationEx arg0, HttpSessionEvent sessionEvent) {
            
                System.out.println("sessionCreated, "+sessionEvent.getSession().getId());
            
                }
            
                 
            
                public void sessionDestroyed(ApplicationEx arg0, HttpSessionEvent sessionEvent) {
            
                System.out.println("sessionDestroyed, "+sessionEvent.getSession().getId());
            
                }
            
                }
            
                public class SessionEvent implements SessionListener {</div>
            
                &nbsp;public void sessionCreated(ApplicationEx arg0, HttpSessionEvent sessionEvent) {<br/>
                &nbsp; System.out.println(&quot;sessionCreated, &quot;+sessionEvent.getSession().getId());<br/>
                &nbsp;}</div>
            
                &nbsp;public void sessionDestroyed(ApplicationEx arg0, HttpSessionEvent sessionEvent) {<br/>
                &nbsp; System.out.println(&quot;sessionDestroyed, &quot;+sessionEvent.getSession().getId());<br/>
                &nbsp;}<br/>
                }<br/>
                &nbsp;</div>
            <p>
                Then, the class as to be registered in a extension, using a file located in the META-INF directory of your java source directory:</p>
            <p>
                <img alt="" src="/main.nsf/xsp/.ibmmodres/persistence/DominoDoc-2245E-BodyR/dir_1308872949764.jpeg"></p>
            

  • Great! Exactly what I was looking for - thanks!

    By Pieter JD Malan 1 decade ago