cancel
Showing results for 
Search instead for 
Did you mean: 

Connection hangs after all work is done

webworks2000
Champ in-the-making
Champ in-the-making
I've noticed on all of the examples in the SDK, the programs are ended by a [size=117]System.exit(0)[/size] call.  I've tried to write some code without the exit call and it simply hangs at the end as if it's waiting for more to do.  I realize this can be by design to reduce connection times, etc…. but is there a way to actually kill the connection so the program can end?

For example… Here is the code from "org.alfresco.sample.jcr.SimpleExample":


        // Setup Spring and Transaction Service
        ApplicationContext context = new ClassPathXmlApplicationContext("classpath:alfresco/application-context.xml");
       
        // Retrieve Repository
        Repository repository = (Repository)context.getBean("JCR.Repository");

        // Login to workspace
        // Note: Default workspace is the one used by Alfresco Web Client which contains all the Spaces
        //       and their documents
        Session session = repository.login(new SimpleCredentials("admin", "admin".toCharArray()));

        try
        {
            // Retrieve Company Home
            Node root = session.getRootNode();
            Node companyHome = root.getNode("app:company_home");
           
            // Iterator through children of Company Home
            NodeIterator iterator = companyHome.getNodes();
            while(iterator.hasNext())
            {
                Node child = iterator.nextNode();
                System.out.println(child.getName());

                PropertyIterator propIterator = child.getProperties();
                while(propIterator.hasNext())
                {
                    Property prop = propIterator.nextProperty();
                    if (!prop.getDefinition().isMultiple())
                    {
                        System.out.println(" " + prop.getName() + " = " + prop.getString());
                    }
                }
            }
        }
        finally
        {
            session.logout();
            System.exit(0);  //////////////////  This kills the program
        }

Is there anyway to break the connection and allow the program to exit on it's own?  This is essential for my application.  :?
Thanks!
4 REPLIES 4

webworks2000
Champ in-the-making
Champ in-the-making
After looking into this more, it seems the following line is the one that causes the hang - even if it is the only line that deals with Alfresco


// either
ctx = ApplicationContextHelper.getApplicationContext();
// Or
ctx = new ClassPathXmlApplicationContext("alfresco/application-context.xml");

derek
Star Contributor
Star Contributor
Hi,
    public static void main(String … args)
    {
        ClassPathXmlApplicationContext ctx = (ClassPathXmlApplicationContext) getApplicationContext();
        synchronized (ctx)
        {
            try { ctx.wait(10000L); } catch (Throwable e) {}
        }
        ctx.close();
    }
Alfresco doesn't control the lifecycle but responds to lifecycle callbacks provided by Spring.  If the code above doesn't work (and I've just checked that it does) then a component has been added that isn't listening to the lifecycle callbacks.

Regards

derek
Star Contributor
Star Contributor
Another thing is that you are starting the entire Alfresco server-level application context and then shutting it down.  You should consider JCR-RMI and connect to an instance of the server that remains alive.

nikkijuk
Champ in-the-making
Champ in-the-making
Another thing is that you are starting the entire Alfresco server-level application context and then shutting it down.  You should consider JCR-RMI and connect to an instance of the server that remains alive.

I am quite confused what would be your recommended way of embedding Alfresco inside own application (Tomcat + Liferay at development, JBoss + Liferay at production) using JCR.

After trying JNDI-JCR from Jira I have come to conclusion that it doesn't currently work with JBoss and after reading about RMI-JCR it seems that it's not yet fit to production. Now, as I have understood, there's left only embedding using JCR.Repository object which is got thru Sping from alfresco/application-context.xml.

Using Alfresco SDK means in our environment that we need to build maven2 script for SDK:s server and hope that classes of Liferay and Alfresco somehow manage together (differents spring versions, 1.x & 2.x, etc.). For that I'd like to find examples of pom.xml and detailed list of Alfrescos libraries and their versions, but don't know where to go for them.

- Jukkis