You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by "Howard W. Smith, Jr." <sm...@gmail.com> on 2012/12/30 17:30:30 UTC

Is TomEE 1.5.2 SNAPSHOT persistence across restarts working as designed?

Is TomEE 1.5.2 SNAPSHOT persistence across restarts working as designed? I
know this is a Tomcat7 feature, but maybe I'm missing something in my code.
My CDI @ApplicationScoped bean references @Stateful EJB in @PostConstruct
and @Predestroy to read and write data. The @PreDestroy code works as
designed, but the @PostConstruct code never executes or shows up in the
log. What am I missing? Please see below.

Below is code in CDI @ApplicationScoped @PostConstruct and @PreDestroy

    @PostConstruct
    public void init() {
        tripDatesInQueueForGoogleCalendarUpdate = null;
        if
(applicationStatefulSessionBean.getTripDatesInQueueForGoogleCalendarUpdate()
!= null &&

!applicationStatefulSessionBean.getTripDatesInQueueForGoogleCalendarUpdate().isEmpty())
{

            tripDatesInQueueForGoogleCalendarUpdate =
applicationStatefulSessionBean.

getTripDatesInQueueForGoogleCalendarUpdate();
            log("ApplicationScopeBean.init():
tripDatesInQueueForGoogleCalendarUpdate = " +

"applicationStatefulSessionBean.getTripDatesInQueueForGoogleCalendarUpdate()
completed; " +
                "tripDatesInQueueForGoogleCalendarUpdate.size() = " +
                tripDatesInQueueForGoogleCalendarUpdate.size());
        }

    }

    @PreDestroy
    private void destroy() {
        log("ApplicationScopeBean.destroy() invoked");
        if (tripDatesInQueueForGoogleCalendarUpdate != null &&
            !tripDatesInQueueForGoogleCalendarUpdate.isEmpty()) {
            String queue = "";
            for (Date d : tripDatesInQueueForGoogleCalendarUpdate) {
                if (queue.length() > 0) {
                    queue += ", ";
                }
                queue += new DateTime(d).toString("MM/dd/yyyy");
            }
            log("ApplicationScopeBean.destroy():
tripDatesInQueueForGoogleCalendarUpdate include " + queue);

            applicationStatefulSessionBean.

setTripDatesInQueueForGoogleCalendarUpdate(tripDatesInQueueForGoogleCalendarUpdate);

            log("ApplicationScopeBean.destroy():
applicationStatefulSessionBean." +

"setTripDatesInQueueForGoogleCalendarUpdate(tripDatesInQueueForGoogleCalendarUpdate)
" +
                "completed; tripDatesInQueueForGoogleCalendarUpdate.size()
= " +
                tripDatesInQueueForGoogleCalendarUpdate.size());
        }
    }



Below is the @Stateful bean

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pf;

import java.io.Serializable;

import java.util.Date;
import java.util.List;

import javax.ejb.Stateful;

/**
 *
 * @author Administrator
 *
 *
http://stackoverflow.com/questions/5387267/persisting-session-of-tomcat-server-application-between-re-deploymets-from-myecl
 *
http://tomcat.apache.org/tomcat-7.0-doc/config/manager.html#Persistence_Across_Restarts
 */
@Stateful
public class ApplicationStatefulSessionBean implements Serializable {

    private List<Date> tripDatesInQueueForGoogleCalendarUpdate;

    public List<Date> getTripDatesInQueueForGoogleCalendarUpdate() {
        return tripDatesInQueueForGoogleCalendarUpdate;
    }

    public void setTripDatesInQueueForGoogleCalendarUpdate(List<Date>
tripDatesInQueueForGoogleCalendarUpdate) {
        this.tripDatesInQueueForGoogleCalendarUpdate =
tripDatesInQueueForGoogleCalendarUpdate;
    }

}

Re: Is TomEE 1.5.2 SNAPSHOT persistence across restarts working as designed?

Posted by "Howard W. Smith, Jr." <sm...@gmail.com>.
okay, thanks Romain.

On Sun, Dec 30, 2012 at 5:12 PM, Romain Manni-Bucau
<rm...@gmail.com>wrote:

> Oh got it
>
> Depend on the conf but AFAIK thats not linked to start stop but more to
> time (see passivation)
>

Re: Is TomEE 1.5.2 SNAPSHOT persistence across restarts working as designed?

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Oh got it

Depend on the conf but AFAIK thats not linked to start stop but more to
time (see passivation)
Le 30 déc. 2012 22:03, "Howard W. Smith, Jr." <sm...@gmail.com> a
écrit :

> Interesting, okay, thanks for the clarification.
>
> I attempted to use @Stateful in this manner, because i remember, a while
> ago, while using 1.5.1 SNAPSHOT, @Stateful bean would persist across
> restarts, as it was the first time I attempted to use @Stateful, but I
> think I don't see that same behavior in 1.5.2 SNAPSHOT, so I can change my
> implementation and not rely on @Stateful.
>
> Thanks. :)
>
>
> On Sun, Dec 30, 2012 at 4:59 PM, Romain Manni-Bucau
> <rm...@gmail.com>wrote:
>
> > No more =no more than that (dont expect more)
> >
> > @sessionscoped. Stateful are different and can even be requestscoped so
> why
> > saving them by default?
> >
>

Re: Is TomEE 1.5.2 SNAPSHOT persistence across restarts working as designed?

Posted by "Howard W. Smith, Jr." <sm...@gmail.com>.
Interesting, okay, thanks for the clarification.

I attempted to use @Stateful in this manner, because i remember, a while
ago, while using 1.5.1 SNAPSHOT, @Stateful bean would persist across
restarts, as it was the first time I attempted to use @Stateful, but I
think I don't see that same behavior in 1.5.2 SNAPSHOT, so I can change my
implementation and not rely on @Stateful.

Thanks. :)


On Sun, Dec 30, 2012 at 4:59 PM, Romain Manni-Bucau
<rm...@gmail.com>wrote:

> No more =no more than that (dont expect more)
>
> @sessionscoped. Stateful are different and can even be requestscoped so why
> saving them by default?
>

Re: Is TomEE 1.5.2 SNAPSHOT persistence across restarts working as designed?

Posted by Romain Manni-Bucau <rm...@gmail.com>.
No more =no more than that (dont expect more)

@sessionscoped. Stateful are different and can even be requestscoped so why
saving them by default?
Le 30 déc. 2012 21:57, "Howard W. Smith, Jr." <sm...@gmail.com> a
écrit :

> but no more = no longer a feature of TomEE
>
> sessionscoped beans = @SessionScoped or @Stateful, or both?
>
> On Sun, Dec 30, 2012 at 4:49 PM, Romain Manni-Bucau
> <rm...@gmail.com>wrote:
>
> > Basically only tomcat session is persisted. Now sessionscoped beans
> should
> > be too when existing but no more
> >
>

Re: Is TomEE 1.5.2 SNAPSHOT persistence across restarts working as designed?

Posted by "Howard W. Smith, Jr." <sm...@gmail.com>.
but no more = no longer a feature of TomEE

sessionscoped beans = @SessionScoped or @Stateful, or both?

On Sun, Dec 30, 2012 at 4:49 PM, Romain Manni-Bucau
<rm...@gmail.com>wrote:

> Basically only tomcat session is persisted. Now sessionscoped beans should
> be too when existing but no more
>

Re: Is TomEE 1.5.2 SNAPSHOT persistence across restarts working as designed?

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Basically only tomcat session is persisted. Now sessionscoped beans should
be too when existing but no more
Le 30 déc. 2012 16:30, "Howard W. Smith, Jr." <sm...@gmail.com> a
écrit :

> Is TomEE 1.5.2 SNAPSHOT persistence across restarts working as designed? I
> know this is a Tomcat7 feature, but maybe I'm missing something in my code.
> My CDI @ApplicationScoped bean references @Stateful EJB in @PostConstruct
> and @Predestroy to read and write data. The @PreDestroy code works as
> designed, but the @PostConstruct code never executes or shows up in the
> log. What am I missing? Please see below.
>
> Below is code in CDI @ApplicationScoped @PostConstruct and @PreDestroy
>
>     @PostConstruct
>     public void init() {
>         tripDatesInQueueForGoogleCalendarUpdate = null;
>         if
>
> (applicationStatefulSessionBean.getTripDatesInQueueForGoogleCalendarUpdate()
> != null &&
>
>
> !applicationStatefulSessionBean.getTripDatesInQueueForGoogleCalendarUpdate().isEmpty())
> {
>
>             tripDatesInQueueForGoogleCalendarUpdate =
> applicationStatefulSessionBean.
>
> getTripDatesInQueueForGoogleCalendarUpdate();
>             log("ApplicationScopeBean.init():
> tripDatesInQueueForGoogleCalendarUpdate = " +
>
>
> "applicationStatefulSessionBean.getTripDatesInQueueForGoogleCalendarUpdate()
> completed; " +
>                 "tripDatesInQueueForGoogleCalendarUpdate.size() = " +
>                 tripDatesInQueueForGoogleCalendarUpdate.size());
>         }
>
>     }
>
>     @PreDestroy
>     private void destroy() {
>         log("ApplicationScopeBean.destroy() invoked");
>         if (tripDatesInQueueForGoogleCalendarUpdate != null &&
>             !tripDatesInQueueForGoogleCalendarUpdate.isEmpty()) {
>             String queue = "";
>             for (Date d : tripDatesInQueueForGoogleCalendarUpdate) {
>                 if (queue.length() > 0) {
>                     queue += ", ";
>                 }
>                 queue += new DateTime(d).toString("MM/dd/yyyy");
>             }
>             log("ApplicationScopeBean.destroy():
> tripDatesInQueueForGoogleCalendarUpdate include " + queue);
>
>             applicationStatefulSessionBean.
>
>
> setTripDatesInQueueForGoogleCalendarUpdate(tripDatesInQueueForGoogleCalendarUpdate);
>
>             log("ApplicationScopeBean.destroy():
> applicationStatefulSessionBean." +
>
>
> "setTripDatesInQueueForGoogleCalendarUpdate(tripDatesInQueueForGoogleCalendarUpdate)
> " +
>                 "completed; tripDatesInQueueForGoogleCalendarUpdate.size()
> = " +
>                 tripDatesInQueueForGoogleCalendarUpdate.size());
>         }
>     }
>
>
>
> Below is the @Stateful bean
>
> /*
>  * To change this template, choose Tools | Templates
>  * and open the template in the editor.
>  */
> package pf;
>
> import java.io.Serializable;
>
> import java.util.Date;
> import java.util.List;
>
> import javax.ejb.Stateful;
>
> /**
>  *
>  * @author Administrator
>  *
>  *
>
> http://stackoverflow.com/questions/5387267/persisting-session-of-tomcat-server-application-between-re-deploymets-from-myecl
>  *
>
> http://tomcat.apache.org/tomcat-7.0-doc/config/manager.html#Persistence_Across_Restarts
>  */
> @Stateful
> public class ApplicationStatefulSessionBean implements Serializable {
>
>     private List<Date> tripDatesInQueueForGoogleCalendarUpdate;
>
>     public List<Date> getTripDatesInQueueForGoogleCalendarUpdate() {
>         return tripDatesInQueueForGoogleCalendarUpdate;
>     }
>
>     public void setTripDatesInQueueForGoogleCalendarUpdate(List<Date>
> tripDatesInQueueForGoogleCalendarUpdate) {
>         this.tripDatesInQueueForGoogleCalendarUpdate =
> tripDatesInQueueForGoogleCalendarUpdate;
>     }
>
> }
>