Skip to content

Commit 1635024

Browse files
committed
抄了apache tomcat的源代码里关于Session, StandardSession, Manager, StandardManager中关于Session管理部分的代码。
1 parent 8c80ca2 commit 1635024

File tree

11 files changed

+1178
-0
lines changed

11 files changed

+1178
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package me.chanjar.weixin.common.session;
19+
20+
/**
21+
* Manifest constants for the <code>org.apache.catalina.session</code>
22+
* package.
23+
*
24+
* @author Craig R. McClanahan
25+
*/
26+
27+
public class Constants {
28+
29+
public static final String Package = "me.chanjar.weixin.common.session";
30+
31+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package me.chanjar.weixin.common.session;
2+
3+
/**
4+
* Created by qianjia on 15/1/21.
5+
*/
6+
public interface InternalSession {
7+
8+
/**
9+
* Return the <code>HttpSession</code> for which this object
10+
* is the facade.
11+
*/
12+
WxSession getSession();
13+
14+
/**
15+
* Set the <code>isValid</code> flag for this session.
16+
*
17+
* @param isValid The new value for the <code>isValid</code> flag
18+
*/
19+
public void setValid(boolean isValid);
20+
21+
/**
22+
* Return the <code>isValid</code> flag for this session.
23+
*/
24+
boolean isValid();
25+
26+
/**
27+
* Return the session identifier for this session.
28+
*/
29+
String getIdInternal();
30+
31+
/**
32+
* Perform the internal processing required to invalidate this session,
33+
* without triggering an exception if the session has already expired.
34+
*/
35+
void expire();
36+
37+
/**
38+
* Update the accessed time information for this session. This method
39+
* should be called by the context when a request comes in for a particular
40+
* session, even if the application does not reference it.
41+
*/
42+
void access();
43+
44+
/**
45+
* Set the <code>isNew</code> flag for this session.
46+
*
47+
* @param isNew The new value for the <code>isNew</code> flag
48+
*/
49+
void setNew(boolean isNew);
50+
51+
/**
52+
* Set the creation time for this session. This method is called by the
53+
* Manager when an existing Session instance is reused.
54+
*
55+
* @param time The new creation time
56+
*/
57+
void setCreationTime(long time);
58+
59+
/**
60+
* Set the default maximum inactive interval (in seconds)
61+
* for Sessions created by this Manager.
62+
*
63+
* @param interval The new default value
64+
*/
65+
void setMaxInactiveInterval(int interval);
66+
67+
/**
68+
* Set the session identifier for this session.
69+
*
70+
* @param id The new session identifier
71+
*/
72+
void setId(String id);
73+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package me.chanjar.weixin.common.session;
2+
3+
import java.util.Enumeration;
4+
5+
/**
6+
* Created by qianjia on 15/1/21.
7+
*/
8+
public class InternalSessionFacade implements WxSession {
9+
10+
/**
11+
* Wrapped session object.
12+
*/
13+
private WxSession session = null;
14+
15+
public InternalSessionFacade(WxSession session) {
16+
session = session;
17+
}
18+
19+
@Override
20+
public Object getAttribute(String name) {
21+
return session.getAttribute(name);
22+
}
23+
24+
@Override
25+
public Enumeration<String> getAttributeNames() {
26+
return session.getAttributeNames();
27+
}
28+
29+
@Override
30+
public void setAttribute(String name, Object value) {
31+
session.setAttribute(name, value);
32+
}
33+
34+
@Override
35+
public void removeAttribute(String name) {
36+
session.removeAttribute(name);
37+
}
38+
39+
@Override
40+
public void invalidate() {
41+
session.invalidate();
42+
}
43+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package me.chanjar.weixin.common.session;
2+
3+
/**
4+
* Created by qianjia on 15/1/21.
5+
*/
6+
public interface InternalSessionManager {
7+
8+
/**
9+
* Construct and return a new session object, based on the default
10+
* settings specified by this Manager's properties. The session
11+
* id specified will be used as the session id.
12+
* If a new session cannot be created for any reason, return
13+
* <code>null</code>.
14+
*
15+
* @param sessionId The session id which should be used to create the
16+
* new session; if <code>null</code>, a new session id will be
17+
* generated
18+
* @exception IllegalStateException if a new session cannot be
19+
* instantiated for any reason
20+
*/
21+
public InternalSession createSession(String sessionId);
22+
23+
/**
24+
* Remove this Session from the active Sessions for this Manager.
25+
*
26+
* @param session Session to be removed
27+
*/
28+
public void remove(InternalSession session);
29+
30+
/**
31+
* Remove this Session from the active Sessions for this Manager.
32+
*
33+
* @param session Session to be removed
34+
* @param update Should the expiration statistics be updated
35+
*/
36+
public void remove(InternalSession session, boolean update);
37+
38+
/**
39+
* Add this Session to the set of active Sessions for this Manager.
40+
*
41+
* @param session Session to be added
42+
*/
43+
void add(InternalSession session);
44+
45+
46+
/**
47+
* Returns the number of active sessions
48+
*
49+
* @return number of sessions active
50+
*/
51+
int getActiveSessions();
52+
/**
53+
* Get a session from the recycled ones or create a new empty one.
54+
* The PersistentManager manager does not need to create session data
55+
* because it reads it from the Store.
56+
*/
57+
InternalSession createEmptySession();
58+
59+
InternalSession[] findSessions();
60+
61+
/**
62+
* Implements the Manager interface, direct call to processExpires
63+
*/
64+
public void backgroundProcess();
65+
66+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one or more
2+
# contributor license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright ownership.
4+
# The ASF licenses this file to You under the Apache License, Version 2.0
5+
# (the "License"); you may not use this file except in compliance with
6+
# the License. You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
applicationSession.session.ise=invalid session state
17+
applicationSession.value.iae=null value
18+
fileStore.saving=Saving Session {0} to file {1}
19+
fileStore.loading=Loading Session {0} from file {1}
20+
fileStore.removing=Removing Session {0} at file {1}
21+
fileStore.deleteFailed=Unable to delete file [{0}] which is preventing the creation of the session storage location
22+
fileStore.createFailed=Unable to create directory [{0}] for the storage of session data
23+
JDBCStore.close=Exception closing database connection {0}
24+
JDBCStore.saving=Saving Session {0} to database {1}
25+
JDBCStore.loading=Loading Session {0} from database {1}
26+
JDBCStore.removing=Removing Session {0} at database {1}
27+
JDBCStore.SQLException=SQL Error {0}
28+
serverSession.value.iae=null value
29+
sessionManagerImpl.createRandom=Created random number generator for session ID generation in {0}ms.
30+
sessionManagerImpl.createSession.tmase=createSession: Too many active sessions
31+
sessionManagerImpl.sessionTimeout=Invalid session timeout setting {0}
32+
sessionManagerImpl.getSession.ise=getSession: Session id cannot be null
33+
sessionManagerImpl.expireException=processsExpire: Exception during session expiration
34+
sessionManagerImpl.loading=Loading persisted sessions from {0}
35+
sessionManagerImpl.loading.cnfe=ClassNotFoundException while loading persisted sessions: {0}
36+
sessionManagerImpl.loading.ioe=IOException while loading persisted sessions: {0}
37+
sessionManagerImpl.unloading=Saving persisted sessions to {0}
38+
sessionManagerImpl.unloading.debug=Unloading persisted sessions
39+
sessionManagerImpl.unloading.ioe=IOException while saving persisted sessions: {0}
40+
sessionManagerImpl.unloading.nosessions=No persisted sessions to unload
41+
sessionManagerImpl.managerLoad=Exception loading sessions from persistent storage
42+
sessionManagerImpl.managerUnload=Exception unloading sessions to persistent storage
43+
sessionManagerImpl.createSession.ise=createSession: Session id cannot be null
44+
sessionImpl.attributeEvent=Session attribute event listener threw exception
45+
sessionImpl.bindingEvent=Session binding event listener threw exception
46+
sessionImpl.invalidate.ise=invalidate: Session already invalidated
47+
sessionImpl.isNew.ise=isNew: Session already invalidated
48+
sessionImpl.getAttribute.ise=getAttribute: Session already invalidated
49+
sessionImpl.getAttributeNames.ise=getAttributeNames: Session already invalidated
50+
sessionImpl.getCreationTime.ise=getCreationTime: Session already invalidated
51+
sessionImpl.getThisAccessedTime.ise=getThisAccessedTime: Session already invalidated
52+
sessionImpl.getLastAccessedTime.ise=getLastAccessedTime: Session already invalidated
53+
sessionImpl.getId.ise=getId: Session already invalidated
54+
sessionImpl.getMaxInactiveInterval.ise=getMaxInactiveInterval: Session already invalidated
55+
sessionImpl.getValueNames.ise=getValueNames: Session already invalidated
56+
sessionImpl.logoutfail=Exception logging out user when expiring session
57+
sessionImpl.notSerializable=Cannot serialize session attribute {0} for session {1}
58+
sessionImpl.removeAttribute.ise=removeAttribute: Session already invalidated
59+
sessionImpl.sessionEvent=Session event listener threw exception
60+
sessionImpl.setAttribute.iae=setAttribute: Non-serializable attribute {0}
61+
sessionImpl.setAttribute.ise=setAttribute: Session [{0}] has already been invalidated
62+
sessionImpl.setAttribute.namenull=setAttribute: name parameter cannot be null
63+
sessionImpl.sessionCreated=Created Session id = {0}
64+
persistentManager.loading=Loading {0} persisted sessions
65+
persistentManager.unloading=Saving {0} persisted sessions
66+
persistentManager.expiring=Expiring {0} sessions before saving them
67+
persistentManager.deserializeError=Error deserializing Session {0}: {1}
68+
persistentManager.serializeError=Error serializing Session {0}: {1}
69+
persistentManager.swapMaxIdle=Swapping session {0} to Store, idle for {1} seconds
70+
persistentManager.backupMaxIdle=Backing up session {0} to Store, idle for {1} seconds
71+
persistentManager.backupException=Exception occurred when backing up Session {0}: {1}
72+
persistentManager.tooManyActive=Too many active sessions, {0}, looking for idle sessions to swap out
73+
persistentManager.swapTooManyActive=Swapping out session {0}, idle for {1} seconds too many sessions active
74+
persistentManager.processSwaps=Checking for sessions to swap out, {0} active sessions in memory
75+
persistentManager.activeSession=Session {0} has been idle for {1} seconds
76+
persistentManager.swapIn=Swapping session {0} in from Store
77+
persistentManager.swapInException=Exception in the Store during swapIn: {0}
78+
persistentManager.swapInInvalid=Swapped session {0} is invalid
79+
persistentManager.storeKeysException=Unable to determine the list of session IDs for sessions in the session store, assuming that the store is empty
80+
persistentManager.storeSizeException=Unable to determine the number of sessions in the session store, assuming that the store is empty

0 commit comments

Comments
 (0)