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
/**
@@ -114,18 +114,14 @@ public Object getAttribute(String name, int scope) {
114
114
if (scope == SCOPE_GLOBAL_SESSION ) {
115
115
Object value = session .getAttribute (name , PortletSession .APPLICATION_SCOPE );
116
116
if (value != null ) {
117
- synchronized (this .globalSessionAttributesToUpdate ) {
118
- this .globalSessionAttributesToUpdate .put (name , value );
119
- }
117
+ this .globalSessionAttributesToUpdate .put (name , value );
120
118
}
121
119
return value ;
122
120
}
123
121
else {
124
122
Object value = session .getAttribute (name );
125
123
if (value != null ) {
126
- synchronized (this .sessionAttributesToUpdate ) {
127
- this .sessionAttributesToUpdate .put (name , value );
128
- }
124
+ this .sessionAttributesToUpdate .put (name , value );
129
125
}
130
126
return value ;
131
127
}
@@ -148,15 +144,11 @@ public void setAttribute(String name, Object value, int scope) {
148
144
PortletSession session = getSession (true );
149
145
if (scope == SCOPE_GLOBAL_SESSION ) {
150
146
session .setAttribute (name , value , PortletSession .APPLICATION_SCOPE );
151
- synchronized (this .globalSessionAttributesToUpdate ) {
152
- this .globalSessionAttributesToUpdate .remove (name );
153
- }
147
+ this .globalSessionAttributesToUpdate .remove (name );
154
148
}
155
149
else {
156
150
session .setAttribute (name , value );
157
- synchronized (this .sessionAttributesToUpdate ) {
158
- this .sessionAttributesToUpdate .remove (name );
159
- }
151
+ this .sessionAttributesToUpdate .remove (name );
160
152
}
161
153
}
162
154
}
@@ -173,15 +165,11 @@ public void removeAttribute(String name, int scope) {
173
165
if (session != null ) {
174
166
if (scope == SCOPE_GLOBAL_SESSION ) {
175
167
session .removeAttribute (name , PortletSession .APPLICATION_SCOPE );
176
- synchronized (this .globalSessionAttributesToUpdate ) {
177
- this .globalSessionAttributesToUpdate .remove (name );
178
- }
168
+ this .globalSessionAttributesToUpdate .remove (name );
179
169
}
180
170
else {
181
171
session .removeAttribute (name );
182
- synchronized (this .sessionAttributesToUpdate ) {
183
- this .sessionAttributesToUpdate .remove (name );
184
- }
172
+ this .sessionAttributesToUpdate .remove (name );
185
173
}
186
174
}
187
175
}
@@ -248,8 +236,8 @@ public Object getSessionMutex() {
248
236
@ Override
249
237
protected void updateAccessedSessionAttributes () {
250
238
this .session = this .request .getPortletSession (false );
251
- synchronized (this .sessionAttributesToUpdate ) {
252
- if ( this . session != null ) {
239
+ if (this .session != null ) {
240
+ try {
253
241
for (Map .Entry <String , Object > entry : this .sessionAttributesToUpdate .entrySet ()) {
254
242
String name = entry .getKey ();
255
243
Object newValue = entry .getValue ();
@@ -258,11 +246,6 @@ protected void updateAccessedSessionAttributes() {
258
246
this .session .setAttribute (name , newValue );
259
247
}
260
248
}
261
- }
262
- this .sessionAttributesToUpdate .clear ();
263
- }
264
- synchronized (this .globalSessionAttributesToUpdate ) {
265
- if (this .session != null ) {
266
249
for (Map .Entry <String , Object > entry : this .globalSessionAttributesToUpdate .entrySet ()) {
267
250
String name = entry .getKey ();
268
251
Object newValue = entry .getValue ();
@@ -272,8 +255,12 @@ protected void updateAccessedSessionAttributes() {
272
255
}
273
256
}
274
257
}
275
- this .globalSessionAttributesToUpdate .clear ();
258
+ catch (IllegalStateException ex ) {
259
+ // Session invalidated - shouldn't usually happen.
260
+ }
276
261
}
262
+ this .sessionAttributesToUpdate .clear ();
263
+ this .globalSessionAttributesToUpdate .clear ();
277
264
}
278
265
279
266
/**
0 commit comments