//----------------------------BEGIN LICENSE----------------------------
/* 
 * Willow : the Open Source WorkFlow Project
 * Distributable under GNU LGPL license by gun.org
 *
 * Copyright (C) 2004-2010  huihoo.org 
 * Copyright (C) 2004-2010  ZosaTapo <dertyang@hotmail.com> 
 * 
 * ====================================================================
 * Project Homepage : http://www.huihoo.org/willow
 * Source Forge     : http://sourceforge.net/projects/huihoo
 * Mailing list     : willow@lists.sourceforge.net 
 */
//----------------------------END  LICENSE----------------------------
package org.huihoo.willow;

import java.beans.PropertyChangeListener;
import java.io.IOException;

import org.huihoo.willow.session.AbstractSession;


public interface Manager
{

	// ------------------------------------------------------------- Properties

	/**
	 * Return the Service with which this Manager is associated.
	 */
	public Service getService();

	/**
	 * Set the Service with which this Manager is associated.
	 *
	 * @param engine The newly associated Service
	 */
	public void setService(Service engine);

	/**
	 * Return descriptive information about this Manager implementation and
	 * the corresponding version number, in the format
	 * <code>&lt;description&gt;/&lt;version&gt;</code>.
	 */
	public String getInfo();

	/**
	 * Return the default maximum inactive interval (in seconds)
	 * for Sessions created by this Manager.
	 */
	public int getMaxInactiveInterval();

	/**
	 * Set the default maximum inactive interval (in seconds)
	 * for Sessions created by this Manager.
	 *
	 * @param interval The new default value
	 */
	public void setMaxInactiveInterval(int interval);

	// --------------------------------------------------------- Public Methods

	/**
	 * Add this AbstractSession to the set of active Sessions for this Manager.
	 *
	 * @param session AbstractSession to be added
	 */
	public void add(AbstractSession session);

	/**
	 * Add a property change listener to this component.
	 *
	 * @param listener The listener to add
	 */
	public void addPropertyChangeListener(PropertyChangeListener listener);

	/**
	 * Get a session from the recycled ones or create a new empty one.
	 * The PersistentManager manager does not need to create session data
	 * because it reads it from the Store.
	 */
	public AbstractSession createEmptySession();

	/**
	 * Construct and return a new session object, based on the default
	 * settings specified by this Manager's properties.  The session
	 * id will be assigned by this method, and available via the getId()
	 * method of the returned session.  If a new session cannot be created
	 * for any reason, return <code>null</code>.
	 *
	 * @exception IllegalStateException if a new session cannot be
	 *  instantiated for any reason
	 */
	public AbstractSession createSession();

	/**
	 * Return the active AbstractSession, associated with this Manager, with the
	 * specified session id (if any); otherwise return <code>null</code>.
	 *
	 * @param id The session id for the session to be returned
	 *
	 * @exception IllegalStateException if a new session cannot be
	 *  instantiated for any reason
	 */
	public AbstractSession findSession(String id);

	/**
	 * Return the set of active Sessions associated with this Manager.
	 * If this Manager has no active Sessions, a zero-length array is returned.
	 */
	public AbstractSession[] findSessions();

	/**
	 * Remove this AbstractSession from the active Sessions for this Manager.
	 *
	 * @param session AbstractSession to be removed
	 */
	public void remove(AbstractSession session);

	/**
	 * Remove a property change listener from this component.
	 *
	 * @param listener The listener to remove
	 */
	public void removePropertyChangeListener(PropertyChangeListener listener);

	/**
	 * Load any currently active sessions that were previously unloaded
	 * to the appropriate persistence mechanism, if any.  If persistence is not
	 * supported, this method returns without doing anything.
	 *
	 * @exception ClassNotFoundException if a serialized class cannot be
	 *  found during the reload
	 * @exception IOException if an input/output error occurs
	 */
	public void load() throws ClassNotFoundException, IOException;
	
	/**
	 * Save any currently active sessions in the appropriate persistence
	 * mechanism, if any.  If persistence is not supported, this method
	 * returns without doing anything.
	 *
	 * @exception IOException if an input/output error occurs
	 */
	public void unload() throws IOException;

}