Hi Harald,

Try the following example, it should answer your 3 questions. The thread safety issue (I believe) comes about if the user submitted multiple requests to Tomcat, and the same user (session) tool is being used. The following example uses a ThreadLocal (calendar) attribute to store the current calendar time for that thread. This alleviates multiple thread accessing the same calendar object. Also note that the user attribute is not reset in the refresh() method, as init() is only invoked once, so the user attribute should not be reset.

----------------------------
public class DateTool
  implments ApplicationTool
{
  private User user;
  private static final ThreadLocal calendar = new ThreadLocal();

  /**
   * Must be a default constructor.
   */
  public DateTool()
  {
  }

  public void init(Object object)
  {
    if(object instanceof User)
    {
      this.user = (User)object;
      calendar.set(Calendar.getInstance());
    }
    else
    {
      Log.error("Misconfiguration for DateTool!");
    }
  }

  public void refresh()
  {
    calendar.set(Calendar.getInstance());
  }

  public Date getDate()
  {
    Calendar calendar = (Calendar)calendar.get();
    return calendar.getTime();
  }
}
----------------------------

hope it helps,
CP

Harald Schl��er wrote:

Hello dear turbine users!

I'm looking for an example implementation of a session pull tool to clear
some questions:

Which interfaces should be implemented?
How to make it threadsafe?
How does the constructor look like?

I apprechiate any hint.
Thank you in advance!

Harald Schl��er




-- R E D S H E R I F F C.P. Lim - Software Engineer [EMAIL PROTECTED]

96-98 Market St    +61 (3) 9606 4036 tel
South Melbourne    +61 (3) 9606 4001 fax
Victoria  3205     +61 (413) 781 846 cell

This message and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you are not the intended recipient, you are hereby notified that any use or dissemination of this communication is strictly prohibited. If you have received this message in error please notify us immediately by return email or telephone +61 (2) 8204 5888, then delete this message. Any views expressed in this message are those of the individual sender and many not necessarily reflect the views of Red Sheriff.


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to