Subversion Repository Public Repository

litesoft

Diff Revisions 947 vs 948 for /trunk/Java/core/Server/src/org/litesoft/core/ServerContext.java

Diff revisions: vs.
  @@ -6,8 +6,7 @@
6 6 import java.util.*;
7 7
8 8 @SuppressWarnings({"UnusedDeclaration"})
9 - public class ServerContext
10 - {
9 + public class ServerContext {
11 10 private static final ThreadLocal<ServerContext> DATA = new ThreadLocal<ServerContext>();
12 11
13 12 /**
  @@ -17,11 +16,9 @@
17 16 *
18 17 * @throws IllegalStateException if 'set' has not been called on this Thread.
19 18 */
20 - public static ServerContext get()
21 - {
19 + public static ServerContext get() {
22 20 ServerContext zContext = DATA.get();
23 - if ( zContext == null )
24 - {
21 + if ( zContext == null ) {
25 22 throw new IllegalStateException( "No Server Context for current Thread" );
26 23 }
27 24 return zContext;
  @@ -30,71 +27,58 @@
30 27 /**
31 28 * Clear (or remove) the current Thread's (ThreadLocal) Server Context.
32 29 */
33 - public static void clear()
34 - {
30 + public static void clear() {
35 31 DATA.remove();
36 32 }
37 33
38 34 /**
39 35 * Set the current Thread's (ThreadLocal) Server Context to 'this'.
40 36 */
41 - public void set()
42 - {
37 + public void set() {
43 38 DATA.set( this );
44 39 }
45 40
46 41 private ContextID mContextID;
47 42 private ServerSession mServerSession;
48 43
49 - public ServerContext( ContextID pContextID, ServerSession pServerSession )
50 - {
44 + public ServerContext( ContextID pContextID, ServerSession pServerSession ) {
51 45 Objects.assertNotNull( "ContextID", mContextID = pContextID );
52 46 Objects.assertNotNull( "ServerSession", mServerSession = pServerSession );
53 47 }
54 48
55 - public ContextID getContextID()
56 - {
49 + public ContextID getContextID() {
57 50 return mContextID;
58 51 }
59 52
60 - public ServerSession getServerSession()
61 - {
53 + public ServerSession getServerSession() {
62 54 return mServerSession;
63 55 }
64 56
65 57 private static final ServerStore TEMPLATE_ServerStore = new ServerStore();
66 58
67 - public static ServerStore getTemplateServerStore()
68 - {
59 + public static ServerStore getTemplateServerStore() {
69 60 return TEMPLATE_ServerStore;
70 61 }
71 62
72 63 private static final ServerStore MASTER_ServerStore = new ServerStore();
73 64
74 - public static ServerStore getMasterServerStore()
75 - {
65 + public static ServerStore getMasterServerStore() {
76 66 return MASTER_ServerStore;
77 67 }
78 68
79 - public ServerStore getServerStore()
80 - {
81 - synchronized ( SERVER_STORES )
82 - {
69 + public ServerStore getServerStore() {
70 + synchronized ( SERVER_STORES ) {
83 71 ServerStore zServerStore = SERVER_STORES.get( mContextID );
84 - if ( zServerStore == null )
85 - {
72 + if ( zServerStore == null ) {
86 73 SERVER_STORES.put( mContextID, zServerStore = new ServerStore( TEMPLATE_ServerStore ) );
87 74 }
88 75 return zServerStore;
89 76 }
90 77 }
91 78
92 - public static void clearServerStore( ContextID pContextID )
93 - {
94 - if ( pContextID != null )
95 - {
96 - synchronized ( SERVER_STORES )
97 - {
79 + public static void clearServerStore( ContextID pContextID ) {
80 + if ( pContextID != null ) {
81 + synchronized ( SERVER_STORES ) {
98 82 LLremoveServerStore( pContextID );
99 83 }
100 84 }
  @@ -102,22 +86,17 @@
102 86
103 87 private static final Map<ContextID, ServerStore> SERVER_STORES = new HashMap<ContextID, ServerStore>();
104 88
105 - public static void clearAllServerStores()
106 - {
107 - synchronized ( SERVER_STORES )
108 - {
109 - for ( ContextID zContextID : SERVER_STORES.keySet() )
110 - {
89 + public static void clearAllServerStores() {
90 + synchronized ( SERVER_STORES ) {
91 + for ( ContextID zContextID : SERVER_STORES.keySet() ) {
111 92 LLremoveServerStore( zContextID );
112 93 }
113 94 }
114 95 }
115 96
116 - private static void LLremoveServerStore( ContextID pContextID )
117 - {
97 + private static void LLremoveServerStore( ContextID pContextID ) {
118 98 ServerStore zServerStore = SERVER_STORES.remove( pContextID );
119 - if ( zServerStore != null )
120 - {
99 + if ( zServerStore != null ) {
121 100 zServerStore.dispose();
122 101 }
123 102 }