users@glassfish.java.net

Re: Glassfish v2.1 stateful session bean passivation not working?

From: <glassfish_at_javadesktop.org>
Date: Sun, 21 Jun 2009 18:42:30 PDT

[b]Simple client:[/b]
package examples.session.stateful;

import javax.naming.Context;
import javax.naming.InitialContext;

public class CountClient {

    public static final int noOfClients = 3;

    public static void main(String[] args) {
        try {
            /* Get a reference to the bean */
            Context ctx = new InitialContext(System.getProperties());

            /* An array to hold the Count beans */
            Count count[] = new Count[noOfClients];
            int countVal = 0;

            /* Create and count() on each member of array */
            System.out.println("Instantiating beans...");
            for (int i = 0; i < noOfClients; i++) {
                count[i] = (Count) ctx.lookup(Count.class.getName());

                /* initialize each bean to the current count value */
                count[i].set(countVal);

                /* Add 1 and print */
                countVal = count[i].count();
                System.out.println(countVal);

                /* Sleep for 1/2 second */
                Thread.sleep(500);
            }

            /*
             * Let's call count() on each bean to make sure the
             * beans were passivated and activated properly.
             */
            System.out.println("Calling count() on beans...");
            for (int i = 0; i < noOfClients; i++) {

                /* Add 1 and print */
                countVal = count[i].count();
                System.out.println(countVal);

                /* call remove to let the container dispose of the bean */
                count[i].remove();

                /* Sleep for 1/2 second */
                Thread.sleep(500);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

[b]Glassfish config (domain.xml):[/b]
<ejb-container cache-idle-timeout-in-seconds="600" cache-resize-quantity="1" commit-option="B" [b]max-cache-size="1" [/b]max-pool-size="1" pool-idle-timeout-in-seconds="600" pool-resize-quantity="8" removal-timeout-in-seconds="5400" session-store="${com.sun.aas.instanceRoot}/session-store" steady-pool-size="0" victim-selection-policy="fifo">...

Note here I changed the max-cache-size to 1, so that theoretically the 2nd client call will create another stateful session bean, and get the first passivated. However, the output was:

INFO: CountCallbacks.construct()
INFO: CountBean.set(0)
INFO: CountBean.count(0->1)

INFO: CountCallbacks.construct()
INFO: CountBean.set(1)
INFO: CountBean.count(1->2)

INFO: CountCallbacks.construct()
INFO: CountBean.set(2)
INFO: CountBean.count(2->3)

INFO: CountBean.count(1->2)
INFO: CountBean.remove()
INFO: CountCallbacks.destroy()

INFO: CountBean.count(2->3)
INFO: CountBean.remove()
INFO: CountCallbacks.destroy()

INFO: CountBean.count(3->4)
INFO: CountBean.remove()
INFO: CountCallbacks.destroy()

None of the PrePassivate or PostActivate invoked. Is this a bug in Glassfish v2.1 b60e?
[Message sent by forum member 'marshalking' (marshalking)]

http://forums.java.net/jive/thread.jspa?messageID=352283