001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/tool/tags/sakai_2-4-1/tool-api/api/src/java/org/sakaiproject/tool/api/Session.java $
003: * $Id: Session.java 9360 2006-05-14 19:23:12Z ggolden@umich.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2005, 2006 The Sakai Foundation.
007: *
008: * Licensed under the Educational Community License, Version 1.0 (the "License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.opensource.org/licenses/ecl1.php
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: **********************************************************************************/package org.sakaiproject.tool.api;
021:
022: import java.util.Collection;
023: import java.util.Enumeration;
024:
025: /**
026: * <p>
027: * Session models an end user's Sakai-wide usage session, modeled on the HttpSession of the Servlet API.
028: * </p>
029: */
030: public interface Session {
031: /**
032: * Returns the object bound with the specified name in this session, or <code>null</code> if no object is bound under the name.
033: *
034: * @param name
035: * a string specifying the name of the object
036: * @return the object with the specified name
037: * @exception IllegalStateException
038: * if this method is called on an invalidated session
039: */
040: Object getAttribute(String name);
041:
042: /**
043: * Returns an <code>Enumeration</code> of <code>String</code> objects containing the names of all the objects bound to this session.
044: *
045: * @return an <code>Enumeration</code> of <code>String</code> objects specifying the names of all the objects bound to this session
046: * @exception IllegalStateException
047: * if this method is called on an invalidated session
048: */
049: Enumeration getAttributeNames();
050:
051: /**
052: * Returns the time when this session was created, measured in milliseconds since midnight January 1, 1970 GMT.
053: *
054: * @return a <code>long</code> specifying when this session was created, expressed in milliseconds since 1/1/1970 GMT
055: * @exception IllegalStateException
056: * if this method is called on an invalidated session
057: */
058: long getCreationTime();
059:
060: /**
061: * Returns a string containing the unique identifier assigned to this session.
062: *
063: * @return a string specifying the identifier assigned to this session
064: * @exception IllegalStateException
065: * if this method is called on an invalidated session
066: */
067: String getId();
068:
069: /**
070: * Returns the last time the client sent a request associated with this session, as the number of milliseconds since midnight January 1, 1970 GMT.
071: * <p>
072: * Actions that your application takes, such as getting or setting a value associated with the session, do not affect the access time.
073: *
074: * @return a <code>long</code> representing the last time the client sent a request associated with this session, expressed in milliseconds since 1/1/1970 GMT
075: * @exception IllegalStateException
076: * if this method is called on an invalidated session
077: */
078: long getLastAccessedTime();
079:
080: /**
081: * Returns the maximum time interval, in seconds, that Sakai will keep this session open between client accesses. After this interval, Sakai will invalidate the session. The maximum time interval can be set with the <code>setMaxInactiveInterval</code>
082: * method. A negative time indicates the session should never timeout.
083: *
084: * @return an integer specifying the number of seconds this session remains open between client requests
085: * @see #setMaxInactiveInterval
086: */
087: int getMaxInactiveInterval();
088:
089: /**
090: * Find or create a tool session for this tool placement id
091: *
092: * @param placementId
093: * The id used to identify the session.
094: * @return The ToolSession to use for this tool placement id.
095: */
096: ToolSession getToolSession(String placementId);
097:
098: /**
099: * Find or create a context session for this context id
100: *
101: * @param contextId
102: * The id used to identify the session.
103: * @return The ContextSession to use for this context id.
104: */
105: ContextSession getContextSession(String contextId);
106:
107: /**
108: * Return the enterprise id of the user associated with this session.
109: *
110: * @return The enterprise id of the user associated with this session.
111: */
112: String getUserEid();
113:
114: /**
115: * Return the authenticated user id associated with this session.
116: *
117: * @return The authenticated user id associated with this session.
118: */
119: String getUserId();
120:
121: /**
122: * Invalidates this session then unbinds any objects bound to it.
123: */
124: void invalidate();
125:
126: /**
127: * Clear this session's attributes, unbinding any objects bound, but do NOT fully invalidate - it remains the current session.
128: */
129: void clear();
130:
131: /**
132: * Clear this session's attributes, except for those named, unbinding any objects bound, but do NOT fully invalidate - it remains the current session.
133: */
134: void clearExcept(Collection names);
135:
136: /**
137: * Removes the object bound with the specified name from this session. If the session does not have an object bound with the specified name, this method does nothing.
138: * <p>
139: * After this method executes, and if the object implements <code>SessionBindingListener</code>, Sakai calls <code>SessionBindingListener.valueUnbound</code>.
140: *
141: * @param name
142: * the name of the object to remove from this session
143: * @exception IllegalStateException
144: * if this method is called on an invalidated session
145: */
146: void removeAttribute(String name);
147:
148: /**
149: * Mark the session as still active, delaying timeout by another period.
150: */
151: void setActive();
152:
153: /**
154: * Binds an object to this session, using the name specified. If an object of the same name is already bound to the session, the object is replaced.
155: * <p>
156: * After this method executes, and if the new object implements <code>SessionBindingListener</code>, Sakai calls <code>SessionBindingListener.valueBound</code>.
157: * <p>
158: * If an object was already bound to this session of this name that implements <code>SessionBindingListener</code>, its <code>SessionBindingListener.valueUnbound</code> method is called.
159: * <p>
160: * If the value passed in is null, this has the same effect as calling <code>removeAttribute()<code>.
161: *
162: * @param name the name to which the object is bound;
163: * cannot be null
164: *
165: * @param value the object to be bound
166: *
167: * @exception IllegalStateException if this method is called on an
168: * invalidated session
169: */
170: void setAttribute(String name, Object value);
171:
172: /**
173: * Specifies the time, in seconds, between client requests before the Sakai will invalidate this session. A negative time indicates the session should never timeout.
174: *
175: * @param interval
176: * An integer specifying the number of seconds
177: */
178: void setMaxInactiveInterval(int interval);
179:
180: /**
181: * Set the enterprise id of the user associated with this session.
182: *
183: * @return The enterprise id of the user associated with this session.
184: */
185: void setUserEid(String eid);
186:
187: /**
188: * Set the user id associated with this session.
189: *
190: * @param uid
191: * The user id associated with this session.
192: */
193: void setUserId(String uid);
194: }
|