users@glassfish.java.net

Glassfish v2.1 stateful session bean passivation not working?

From: <glassfish_at_javadesktop.org>
Date: Sun, 21 Jun 2009 18:37:53 PDT

A very simple example, but couldn't observe glassfish's passivation behavior.

[b]Interface:[/b]
package examples.session.stateful;

public interface Count {
    //Increments the counter by 1
    public int count();
    
    //Sets the counter to val
    public void set(int val);
    
    // removes the counter
    public void remove();
}

[b]Bean:[/b]
package examples.session.stateful;

import javax.ejb.Remote;
import javax.ejb.Remove;
import javax.ejb.Stateful;
import javax.interceptor.Interceptors;

@Stateful
@Remote(Count.class)
@Interceptors(CountCallbacks.class)
public class CountBean implements Count {

    /** The current counter is our conversational state. */
    private int val;

    public int count() {
        System.out.println("CountBean.count(" + val + "->" + (val + 1) + ")");
        return ++val;
    }

    public void set(int val) {
        this.val = val;
        System.out.println("CountBean.set(" + val + ")");
    }

    @Remove
    public void remove() {
        System.out.println("CountBean.remove()");
    }
}

[b]Callback interceptor:[/b]
package examples.session.stateful;

import javax.ejb.PostActivate;
import javax.ejb.PrePassivate;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.interceptor.InvocationContext;

public class CountCallbacks {
    public CountCallbacks() {}

    @PostConstruct
    public void construct(InvocationContext ctx) throws Exception {
        System.out.println("CountCallbacks.construct() ");
        ctx.proceed();
    }
    
    @PostActivate
    public void activate(InvocationContext ctx) throws Exception {
        System.out.println("CountCallbacks.activate()");
        ctx.proceed();
    }
    
    @PrePassivate
    public void passivate(InvocationContext ctx) throws Exception {
        System.out.println("CountCallbacks.passivate()");
        ctx.proceed();
    }
    
    @PreDestroy
    public void destroy(InvocationContext ctx) throws Exception {
        System.out.println("CountCallbacks.destroy()");
        ctx.proceed();
    }
}

Continue...
[Message sent by forum member 'marshalking' (marshalking)]

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