1
1
/*
2
- * Copyright 2002-2012 the original author or authors.
2
+ * Copyright 2002-2013 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
16
16
17
17
package org .springframework .web .portlet .context ;
18
18
19
- import java .util .HashMap ;
20
19
import java .util .Map ;
20
+ import java .util .concurrent .ConcurrentHashMap ;
21
21
import javax .portlet .PortletRequest ;
22
22
import javax .portlet .PortletSession ;
23
23
@@ -59,9 +59,9 @@ public class PortletRequestAttributes extends AbstractRequestAttributes {
59
59
60
60
private volatile PortletSession session ;
61
61
62
- private final Map <String , Object > sessionAttributesToUpdate = new HashMap <String , Object >();
62
+ private final Map <String , Object > sessionAttributesToUpdate = new ConcurrentHashMap <String , Object >(1 );
63
63
64
- private final Map <String , Object > globalSessionAttributesToUpdate = new HashMap <String , Object >();
64
+ private final Map <String , Object > globalSessionAttributesToUpdate = new ConcurrentHashMap <String , Object >(1 );
65
65
66
66
67
67
/**
@@ -115,18 +115,14 @@ public Object getAttribute(String name, int scope) {
115
115
if (scope == SCOPE_GLOBAL_SESSION ) {
116
116
Object value = session .getAttribute (name , PortletSession .APPLICATION_SCOPE );
117
117
if (value != null ) {
118
- synchronized (this .globalSessionAttributesToUpdate ) {
119
- this .globalSessionAttributesToUpdate .put (name , value );
120
- }
118
+ this .globalSessionAttributesToUpdate .put (name , value );
121
119
}
122
120
return value ;
123
121
}
124
122
else {
125
123
Object value = session .getAttribute (name );
126
124
if (value != null ) {
127
- synchronized (this .sessionAttributesToUpdate ) {
128
- this .sessionAttributesToUpdate .put (name , value );
129
- }
125
+ this .sessionAttributesToUpdate .put (name , value );
130
126
}
131
127
return value ;
132
128
}
@@ -150,15 +146,11 @@ public void setAttribute(String name, Object value, int scope) {
150
146
PortletSession session = getSession (true );
151
147
if (scope == SCOPE_GLOBAL_SESSION ) {
152
148
session .setAttribute (name , value , PortletSession .APPLICATION_SCOPE );
153
- synchronized (this .globalSessionAttributesToUpdate ) {
154
- this .globalSessionAttributesToUpdate .remove (name );
155
- }
149
+ this .globalSessionAttributesToUpdate .remove (name );
156
150
}
157
151
else {
158
152
session .setAttribute (name , value );
159
- synchronized (this .sessionAttributesToUpdate ) {
160
- this .sessionAttributesToUpdate .remove (name );
161
- }
153
+ this .sessionAttributesToUpdate .remove (name );
162
154
}
163
155
}
164
156
}
@@ -176,15 +168,11 @@ public void removeAttribute(String name, int scope) {
176
168
if (session != null ) {
177
169
if (scope == SCOPE_GLOBAL_SESSION ) {
178
170
session .removeAttribute (name , PortletSession .APPLICATION_SCOPE );
179
- synchronized (this .globalSessionAttributesToUpdate ) {
180
- this .globalSessionAttributesToUpdate .remove (name );
181
- }
171
+ this .globalSessionAttributesToUpdate .remove (name );
182
172
}
183
173
else {
184
174
session .removeAttribute (name );
185
- synchronized (this .sessionAttributesToUpdate ) {
186
- this .sessionAttributesToUpdate .remove (name );
187
- }
175
+ this .sessionAttributesToUpdate .remove (name );
188
176
}
189
177
}
190
178
}
@@ -256,8 +244,8 @@ public Object getSessionMutex() {
256
244
@ Override
257
245
protected void updateAccessedSessionAttributes () {
258
246
this .session = this .request .getPortletSession (false );
259
- synchronized (this .sessionAttributesToUpdate ) {
260
- if ( this . session != null ) {
247
+ if (this .session != null ) {
248
+ try {
261
249
for (Map .Entry <String , Object > entry : this .sessionAttributesToUpdate .entrySet ()) {
262
250
String name = entry .getKey ();
263
251
Object newValue = entry .getValue ();
@@ -266,11 +254,6 @@ protected void updateAccessedSessionAttributes() {
266
254
this .session .setAttribute (name , newValue );
267
255
}
268
256
}
269
- }
270
- this .sessionAttributesToUpdate .clear ();
271
- }
272
- synchronized (this .globalSessionAttributesToUpdate ) {
273
- if (this .session != null ) {
274
257
for (Map .Entry <String , Object > entry : this .globalSessionAttributesToUpdate .entrySet ()) {
275
258
String name = entry .getKey ();
276
259
Object newValue = entry .getValue ();
@@ -280,8 +263,12 @@ protected void updateAccessedSessionAttributes() {
280
263
}
281
264
}
282
265
}
283
- this .globalSessionAttributesToUpdate .clear ();
266
+ catch (IllegalStateException ex ) {
267
+ // Session invalidated - shouldn't usually happen.
268
+ }
284
269
}
270
+ this .sessionAttributesToUpdate .clear ();
271
+ this .globalSessionAttributesToUpdate .clear ();
285
272
}
286
273
287
274
/**
0 commit comments