|
@@ -1,101 +1,101 @@ |
1 |
|
- |
// This Source Code is in the Public Domain per: http://unlicense.org |
2 |
|
- |
package org.litesoft.GWT.server; |
3 |
|
- |
|
4 |
|
- |
import org.litesoft.bo.views.caching.*; |
5 |
|
- |
import org.litesoft.core.*; |
6 |
|
- |
|
7 |
|
- |
import javax.servlet.http.*; |
8 |
|
- |
import java.io.*; |
9 |
|
- |
|
10 |
|
- |
public class ServletSessionHelper { |
11 |
|
- |
public static ContextID callInit( HttpSession pHttpSession ) { |
12 |
|
- |
ContextID zContextID = getContextID( pHttpSession ); |
13 |
|
- |
new ServerContext( zContextID, new OurServerSession( pHttpSession ) ).set(); |
14 |
|
- |
return zContextID; |
15 |
|
- |
} |
16 |
|
- |
|
17 |
|
- |
public static void callFini() { |
18 |
|
- |
ServerContext.clear(); |
19 |
|
- |
} |
20 |
|
- |
|
21 |
|
- |
public static void chkInitialized() { |
22 |
|
- |
if ( sCacheManager == null ) { |
23 |
|
- |
throw new IllegalStateException( "App Not Initialized" ); |
24 |
|
- |
} |
25 |
|
- |
} |
26 |
|
- |
|
27 |
|
- |
public static void initialize( VoCacheManager pCacheManager ) { |
28 |
|
- |
sCacheManager = (pCacheManager != null) ? pCacheManager : VoCacheManager.NULL; |
29 |
|
- |
} |
30 |
|
- |
|
31 |
|
- |
private static volatile VoCacheManager sCacheManager = null; // In Theory this should be non-static, but the UserID needs to access it! |
32 |
|
- |
|
33 |
|
- |
public static VoCacheManager getCacheManager() { |
34 |
|
- |
return sCacheManager; |
35 |
|
- |
} |
36 |
|
- |
|
37 |
|
- |
@SuppressWarnings({"SynchronizationOnLocalVariableOrMethodParameter"}) |
38 |
|
- |
private static ContextID getContextID( HttpSession pHttpSession ) { |
39 |
|
- |
WrapperForContextID zWrapper; |
40 |
|
- |
synchronized ( pHttpSession ) { |
41 |
|
- |
if ( null == (zWrapper = (WrapperForContextID) pHttpSession.getAttribute( WrapperForContextID.SESSION_KEY )) ) { |
42 |
|
- |
pHttpSession.setAttribute( WrapperForContextID.SESSION_KEY, // |
43 |
|
- |
zWrapper = new WrapperForContextID( new ContextID( "HttpSession", pHttpSession.getId() ) ) ); |
44 |
|
- |
} |
45 |
|
- |
} |
46 |
|
- |
return zWrapper.getContextID(); |
47 |
|
- |
} |
48 |
|
- |
|
49 |
|
- |
private static final class WrapperForContextID implements Serializable, |
50 |
|
- |
HttpSessionBindingListener { |
51 |
|
- |
private static final long serialVersionUID = 1L; |
52 |
|
- |
|
53 |
|
- |
public static final String SESSION_KEY = WrapperForContextID.class.getName(); |
54 |
|
- |
|
55 |
|
- |
private ContextID mContextID; |
56 |
|
- |
|
57 |
|
- |
private WrapperForContextID( ContextID pContextID ) { |
58 |
|
- |
mContextID = pContextID; |
59 |
|
- |
} |
60 |
|
- |
|
61 |
|
- |
public ContextID getContextID() { |
62 |
|
- |
return mContextID; |
63 |
|
- |
} |
64 |
|
- |
|
65 |
|
- |
@Override |
66 |
|
- |
public void valueBound( HttpSessionBindingEvent event ) { |
67 |
|
- |
} |
68 |
|
- |
|
69 |
|
- |
@Override |
70 |
|
- |
public void valueUnbound( HttpSessionBindingEvent event ) { |
71 |
|
- |
ServerContext.clearServerStore( mContextID ); |
72 |
|
- |
VoCacheManager zCacheManager = sCacheManager; |
73 |
|
- |
if ( zCacheManager != null ) { |
74 |
|
- |
zCacheManager.drop( mContextID ); |
75 |
|
- |
} |
76 |
|
- |
} |
77 |
|
- |
} |
78 |
|
- |
|
79 |
|
- |
private static class OurServerSession extends ServerSession { |
80 |
|
- |
private HttpSession mSession; |
81 |
|
- |
|
82 |
|
- |
private OurServerSession( HttpSession pSession ) { |
83 |
|
- |
mSession = pSession; |
84 |
|
- |
} |
85 |
|
- |
|
86 |
|
- |
@Override |
87 |
|
- |
protected Serializable LLgetAttribute( String pName ) { |
88 |
|
- |
return (Serializable) mSession.getAttribute( pName ); |
89 |
|
- |
} |
90 |
|
- |
|
91 |
|
- |
@Override |
92 |
|
- |
protected void LLsetAttribute( String pName, Serializable pInstance ) { |
93 |
|
- |
mSession.setAttribute( pName, pInstance ); |
94 |
|
- |
} |
95 |
|
- |
|
96 |
|
- |
@Override |
97 |
|
- |
protected void LLremoveAttribute( String pName ) { |
98 |
|
- |
mSession.removeAttribute( pName ); |
99 |
|
- |
} |
100 |
|
- |
} |
101 |
|
- |
} |
|
1 |
+ |
// This Source Code is in the Public Domain per: http://unlicense.org |
|
2 |
+ |
package org.litesoft.GWT.server; |
|
3 |
+ |
|
|
4 |
+ |
import org.litesoft.bo.views.caching.*; |
|
5 |
+ |
import org.litesoft.core.*; |
|
6 |
+ |
|
|
7 |
+ |
import javax.servlet.http.*; |
|
8 |
+ |
import java.io.*; |
|
9 |
+ |
|
|
10 |
+ |
public class ServletSessionHelper { |
|
11 |
+ |
public static ContextID callInit( HttpSession pHttpSession ) { |
|
12 |
+ |
ContextID zContextID = getContextID( pHttpSession ); |
|
13 |
+ |
new ServerContext( zContextID, new OurServerSession( pHttpSession ) ).set(); |
|
14 |
+ |
return zContextID; |
|
15 |
+ |
} |
|
16 |
+ |
|
|
17 |
+ |
public static void callFini() { |
|
18 |
+ |
ServerContext.clear(); |
|
19 |
+ |
} |
|
20 |
+ |
|
|
21 |
+ |
public static void chkInitialized() { |
|
22 |
+ |
if ( sCacheManager == null ) { |
|
23 |
+ |
throw new IllegalStateException( "App Not Initialized" ); |
|
24 |
+ |
} |
|
25 |
+ |
} |
|
26 |
+ |
|
|
27 |
+ |
public static void initialize( VoCacheManager pCacheManager ) { |
|
28 |
+ |
sCacheManager = (pCacheManager != null) ? pCacheManager : VoCacheManager.NULL; |
|
29 |
+ |
} |
|
30 |
+ |
|
|
31 |
+ |
private static volatile VoCacheManager sCacheManager = null; // In Theory this should be non-static, but the UserID needs to access it! |
|
32 |
+ |
|
|
33 |
+ |
public static VoCacheManager getCacheManager() { |
|
34 |
+ |
return sCacheManager; |
|
35 |
+ |
} |
|
36 |
+ |
|
|
37 |
+ |
@SuppressWarnings({"SynchronizationOnLocalVariableOrMethodParameter"}) |
|
38 |
+ |
private static ContextID getContextID( HttpSession pHttpSession ) { |
|
39 |
+ |
WrapperForContextID zWrapper; |
|
40 |
+ |
synchronized ( pHttpSession ) { |
|
41 |
+ |
if ( null == (zWrapper = (WrapperForContextID) pHttpSession.getAttribute( WrapperForContextID.SESSION_KEY )) ) { |
|
42 |
+ |
pHttpSession.setAttribute( WrapperForContextID.SESSION_KEY, // |
|
43 |
+ |
zWrapper = new WrapperForContextID( new ContextID( "HttpSession", pHttpSession.getId() ) ) ); |
|
44 |
+ |
} |
|
45 |
+ |
} |
|
46 |
+ |
return zWrapper.getContextID(); |
|
47 |
+ |
} |
|
48 |
+ |
|
|
49 |
+ |
private static final class WrapperForContextID implements Serializable, |
|
50 |
+ |
HttpSessionBindingListener { |
|
51 |
+ |
private static final long serialVersionUID = 1L; |
|
52 |
+ |
|
|
53 |
+ |
public static final String SESSION_KEY = WrapperForContextID.class.getName(); |
|
54 |
+ |
|
|
55 |
+ |
private ContextID mContextID; |
|
56 |
+ |
|
|
57 |
+ |
private WrapperForContextID( ContextID pContextID ) { |
|
58 |
+ |
mContextID = pContextID; |
|
59 |
+ |
} |
|
60 |
+ |
|
|
61 |
+ |
public ContextID getContextID() { |
|
62 |
+ |
return mContextID; |
|
63 |
+ |
} |
|
64 |
+ |
|
|
65 |
+ |
@Override |
|
66 |
+ |
public void valueBound( HttpSessionBindingEvent event ) { |
|
67 |
+ |
} |
|
68 |
+ |
|
|
69 |
+ |
@Override |
|
70 |
+ |
public void valueUnbound( HttpSessionBindingEvent event ) { |
|
71 |
+ |
ServerContext.clearServerStore( mContextID ); |
|
72 |
+ |
VoCacheManager zCacheManager = sCacheManager; |
|
73 |
+ |
if ( zCacheManager != null ) { |
|
74 |
+ |
zCacheManager.drop( mContextID ); |
|
75 |
+ |
} |
|
76 |
+ |
} |
|
77 |
+ |
} |
|
78 |
+ |
|
|
79 |
+ |
private static class OurServerSession extends ServerSession { |
|
80 |
+ |
private HttpSession mSession; |
|
81 |
+ |
|
|
82 |
+ |
private OurServerSession( HttpSession pSession ) { |
|
83 |
+ |
mSession = pSession; |
|
84 |
+ |
} |
|
85 |
+ |
|
|
86 |
+ |
@Override |
|
87 |
+ |
protected Serializable LLgetAttribute( String pName ) { |
|
88 |
+ |
return (Serializable) mSession.getAttribute( pName ); |
|
89 |
+ |
} |
|
90 |
+ |
|
|
91 |
+ |
@Override |
|
92 |
+ |
protected void LLsetAttribute( String pName, Serializable pInstance ) { |
|
93 |
+ |
mSession.setAttribute( pName, pInstance ); |
|
94 |
+ |
} |
|
95 |
+ |
|
|
96 |
+ |
@Override |
|
97 |
+ |
protected void LLremoveAttribute( String pName ) { |
|
98 |
+ |
mSession.removeAttribute( pName ); |
|
99 |
+ |
} |
|
100 |
+ |
} |
|
101 |
+ |
} |