Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 278258
Collapse All | Expand All

(-)src/org/eclipse/rwt/service/ISessionStore.java (-22 / +20 lines)
Lines 53-64 Link Here
53
   *             cannot be null
53
   *             cannot be null
54
   *            
54
   *            
55
   * @param value the object to be bound
55
   * @param value the object to be bound
56
   *
56
   * @return <code>true</code> if the attribute was set or <code>false</code>
57
   * @exception IllegalStateException If this method is called on an
57
   *         if the attribute could not be set because the session was 
58
   *                                  invalidated session
58
   *         invalidated.
59
   *
60
   */
59
   */
61
  void setAttribute( String name, Object value );
60
  boolean setAttribute( String name, Object value );
62
61
63
  /**
62
  /**
64
   * Returns the object bound with the specified name in this
63
   * Returns the object bound with the specified name in this
Lines 66-74 Link Here
66
   * under the name.
65
   * under the name.
67
   * 
66
   * 
68
   * @param name a string specifying the name of the object
67
   * @param name a string specifying the name of the object
69
   * @return the object with the specified name
68
   * @return the object with the specified name or <code>null</code> if the
70
   * @exception IllegalStateException If this method is called on an invalidated
69
   *         underlying session was invalidated.
71
   *                                  session.
72
   */
70
   */
73
  Object getAttribute( String name );
71
  Object getAttribute( String name );
74
72
Lines 83-92 Link Here
83
   * 
81
   * 
84
   * @param name The name of the object to remove from this 
82
   * @param name The name of the object to remove from this 
85
   *             <code>ISessionStore</code>.
83
   *             <code>ISessionStore</code>.
86
   * @exception IllegalStateException If this method is called on an invalidated
84
   * @return <code>true</code> if the attribute was removed or 
87
   *                                  session.
85
   *         <code>false</code> if the attribute could not be removed because 
86
   *         the session was invalidated.
88
   */
87
   */
89
  void removeAttribute( String name );
88
  boolean removeAttribute( String name );
90
89
91
  /**
90
  /**
92
   * Returns an <code>Enumeration</code> of <code>String</code> objects
91
   * Returns an <code>Enumeration</code> of <code>String</code> objects
Lines 95-103 Link Here
95
   * 
94
   * 
96
   * @return An <code>Enumeration</code> of <code>String</code> objects
95
   * @return An <code>Enumeration</code> of <code>String</code> objects
97
   *         specifying the names of all the objects bound to this
96
   *         specifying the names of all the objects bound to this
98
   *         <code>ISessionStore</code>.
97
   *         <code>ISessionStore</code> or <code>null</code> if the underlying
99
   * @exception IllegalStateException If this method is called on an invalidated
98
   *         session was invalidated.
100
   *                                  session.
101
   */
99
   */
102
  Enumeration getAttributeNames();
100
  Enumeration getAttributeNames();
103
101
Lines 109-116 Link Here
109
   * 
107
   * 
110
   * @return A string specifying the identifier assigned to the
108
   * @return A string specifying the identifier assigned to the
111
   *         underlying <code>HttpSession</code>.
109
   *         underlying <code>HttpSession</code>.
112
   * @exception IllegalStateException If this method is called on an invalidated
113
   *                                  session.
114
   */
110
   */
115
  String getId();
111
  String getId();
116
112
Lines 121-130 Link Here
121
   * If the given listenern is already added the method has no effect.
117
   * If the given listenern is already added the method has no effect.
122
   *  
118
   *  
123
   * @param listener the SessionStoreListener to be added
119
   * @param listener the SessionStoreListener to be added
124
   * @exception IllegalStateException If this method is called on an invalidated
120
   * @return <code>true</code> if the listener was added or <code>false</code>
125
   *                                  session.
121
   *         if the listener could not be added because the session was 
122
   *         invalidated.
126
   */
123
   */
127
  void addSessionStoreListener( SessionStoreListener listener );
124
  boolean addSessionStoreListener( SessionStoreListener listener );
128
  
125
  
129
  /**
126
  /**
130
   * Removes an instance of <code>SessionStoreListener</code> to this
127
   * Removes an instance of <code>SessionStoreListener</code> to this
Lines 134-143 Link Here
134
   * has no effect.
131
   * has no effect.
135
   * 
132
   * 
136
   * @param listener the SessionStoreListener to be removed
133
   * @param listener the SessionStoreListener to be removed
137
   * @exception IllegalStateException If this method is called on an invalidated
134
   * @return <code>true</code> if the listener was removed or <code>false</code>
138
   *                                  session.
135
   *         if the listener could not be removed because the session was 
136
   *         invalidated.
139
   */
137
   */
140
  void removeSessionStoreListener( SessionStoreListener listener );
138
  boolean removeSessionStoreListener( SessionStoreListener listener );
141
139
142
  /**
140
  /**
143
   * Returns the underlying HttpSession instance.
141
   * Returns the underlying HttpSession instance.
(-)src/org/eclipse/rwt/internal/lifecycle/UICallBackManager.java (-8 / +1 lines)
Lines 211-224 Link Here
211
      } finally {
211
      } finally {
212
        locked.remove( currentThread );
212
        locked.remove( currentThread );
213
        if( !result ) {
213
        if( !result ) {
214
          // TODO [rh] remove the try/catch block once this bug 278258 is fixed
214
          ContextProvider.getSession().removeSessionStoreListener( listener );
215
          //      (Rework ISessionStore#add/removeSessionStoreListener)
216
          try {
217
            ContextProvider.getSession().removeSessionStoreListener( listener );
218
          } catch( IllegalStateException e ) {
219
            // ignore - the session store is (about to be) unbound, this means
220
            // the listener is/will be removed anyway
221
          }
222
        }
215
        }
223
      }
216
      }
224
      waitForUIThread = true;
217
      waitForUIThread = true;
(-)src/org/eclipse/rwt/internal/service/SessionStoreImpl.java (-58 / +71 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2002, 2008 Innoopract Informationssysteme GmbH.
2
 * Copyright (c) 2002, 2009 Innoopract Informationssysteme GmbH.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     Innoopract Informationssysteme GmbH - initial API and implementation
9
 *     Innoopract Informationssysteme GmbH - initial API and implementation
10
 *     EclipseSource - ongoing development
10
 ******************************************************************************/
11
 ******************************************************************************/
11
package org.eclipse.rwt.internal.service;
12
package org.eclipse.rwt.internal.service;
12
13
Lines 26-34 Link Here
26
  public static final String ID_SESSION_STORE
27
  public static final String ID_SESSION_STORE
27
    = SessionStoreImpl.class.getName();
28
    = SessionStoreImpl.class.getName();
28
  
29
  
29
  private final Map attributes = new HashMap();
30
  private final Map attributes;
30
  private final Set listeners = new HashSet();
31
  private final Set listeners;
31
  private final HttpSession session;
32
  private final HttpSession session;
33
  private final String id;
32
  private boolean bound;
34
  private boolean bound;
33
  private boolean aboutUnbound;
35
  private boolean aboutUnbound;
34
  private ISessionShutdownAdapter shutdownAdapter;
36
  private ISessionShutdownAdapter shutdownAdapter;
Lines 36-41 Link Here
36
  
38
  
37
  public SessionStoreImpl( final HttpSession session ) {
39
  public SessionStoreImpl( final HttpSession session ) {
38
    ParamCheck.notNull( session, "session" );
40
    ParamCheck.notNull( session, "session" );
41
    attributes = new HashMap();
42
    listeners = new HashSet();
43
    this.id = session.getId();
39
    this.session = session;
44
    this.session = session;
40
    this.session.setAttribute( ID_SESSION_STORE, this );
45
    this.session.setAttribute( ID_SESSION_STORE, this );
41
    bound = true;
46
    bound = true;
Lines 52-108 Link Here
52
      } );
57
      } );
53
    }
58
    }
54
  }
59
  }
55
56
  
60
  
57
  //////////////////////////
61
  //////////////////////////
58
  // interface ISessionStore
62
  // interface ISessionStore
59
  
63
  
60
  public Object getAttribute( final String name ) {
64
  public Object getAttribute( final String name ) {
61
    checkBound();
65
    Object result = null;
62
    synchronized( attributes ) {
66
    if( bound ) {
63
      return attributes.get( name );
67
      synchronized( attributes ) {
68
        result = attributes.get( name );
69
      }
64
    }
70
    }
71
    return result;
65
  }
72
  }
66
73
67
  public void setAttribute( final String name, final Object value ) {
74
  public boolean setAttribute( final String name, final Object value ) {
68
    checkBound();
75
    boolean result = false;
69
    if( value == null ) {
76
    if( bound ) {
70
      removeAttribute( name );
77
      result = true;
71
    } else {
78
      if( value == null ) {
72
      Object removed = null;
79
        removeAttribute( name );
73
      synchronized( attributes ) {
80
      } else {
74
        if( attributes.containsKey( name ) ) {
81
        Object removed = null;
75
          removed = removeAttributeInternal( name );
82
        synchronized( attributes ) {
83
          if( attributes.containsKey( name ) ) {
84
            removed = removeAttributeInternal( name );
85
          }
86
          attributes.put( name, value );
76
        }
87
        }
77
        attributes.put( name, value );        
88
        if( removed != null ) {
78
      }
89
          fireValueUnbound( name, removed );
79
      if( removed != null ) {
90
        }
80
        fireValueUnbound( name, removed );
91
        fireValueBound( name, value );
81
      }
92
      }
82
      fireValueBound( name, value );
83
    }
93
    }
94
    return result;
84
  }
95
  }
85
  
96
  
86
  public void removeAttribute( final String name ) {
97
  public boolean removeAttribute( final String name ) {
87
    checkBound();
98
    boolean result = false;
88
    fireValueUnbound( name, removeAttributeInternal( name ) );
99
    if( bound ) {
100
      result = true;
101
      fireValueUnbound( name, removeAttributeInternal( name ) );
102
    }
103
    return result;
89
  }
104
  }
90
105
91
  public Enumeration getAttributeNames() {
106
  public Enumeration getAttributeNames() {
92
    checkBound();
107
    Enumeration result = null;
93
    final Iterator iterator = attributes.keySet().iterator();
108
    if( bound ) {
94
    return new Enumeration() {
109
      final Iterator iterator = attributes.keySet().iterator();
95
      public boolean hasMoreElements() {
110
      result = new Enumeration() {
96
        return iterator.hasNext();
111
97
      }
112
        public boolean hasMoreElements() {
98
      public Object nextElement() {
113
          return iterator.hasNext();
99
        return iterator.next();
114
        }
100
      }
115
101
    };
116
        public Object nextElement() {
117
          return iterator.next();
118
        }
119
      };
120
    }
121
    return result;
102
  }
122
  }
103
  
123
  
104
  public String getId() {
124
  public String getId() {
105
    return session.getId();
125
    return id;
106
  }
126
  }
107
  
127
  
108
  public HttpSession getHttpSession() {
128
  public HttpSession getHttpSession() {
Lines 113-132 Link Here
113
    return bound;
133
    return bound;
114
  }
134
  }
115
135
116
  public void addSessionStoreListener( final SessionStoreListener lsnr ) {
136
  public boolean addSessionStoreListener( final SessionStoreListener lsnr ) {
117
    checkAboutUnbound();
137
    boolean result = false;
118
    checkBound();
138
    if( bound && !aboutUnbound ) {
119
    synchronized( listeners ) {
139
      result = true;
120
      listeners.add( lsnr );
140
      synchronized( listeners ) {
141
        listeners.add( lsnr );
142
      }
121
    }
143
    }
144
    return result;
122
  }
145
  }
123
146
124
  public void removeSessionStoreListener( final SessionStoreListener lsnr ) {
147
  public boolean removeSessionStoreListener( final SessionStoreListener lsnr ) {
125
    checkAboutUnbound();
148
    boolean result = false;
126
    checkBound();
149
    if( bound && !aboutUnbound ) {
127
    synchronized( listeners ) {
150
      result = true;
128
      listeners.remove( lsnr );
151
      synchronized( listeners ) {
152
        listeners.remove( lsnr );
153
      }
129
    }
154
    }
155
    return result;
130
  }
156
  }
131
157
132
  
158
  
Lines 239-257 Link Here
239
    return result;
265
    return result;
240
  }
266
  }
241
  
267
  
242
  private void checkBound() {
243
    if( !bound ) {
244
      throw new IllegalStateException( "The session store has been unbound." );
245
    }
246
  }
247
  
248
  private void checkAboutUnbound() {
249
    if( aboutUnbound ) {
250
      String msg = "The session store is about to be unbound.";
251
      throw new IllegalStateException( msg );
252
    }
253
  }
254
    
255
  private void fireValueBound( final String name, final Object value ) {
268
  private void fireValueBound( final String name, final Object value ) {
256
    if( value instanceof HttpSessionBindingListener ) {
269
    if( value instanceof HttpSessionBindingListener ) {
257
      HttpSessionBindingListener listener
270
      HttpSessionBindingListener listener
(-)src/org/eclipse/rwt/service/SessionStore_Test.java (-44 / +20 lines)
Lines 104-163 Link Here
104
    assertSame( httpSession, sessionLog[ 0 ] );
104
    assertSame( httpSession, sessionLog[ 0 ] );
105
    assertSame( attr2, valueLog[ 0 ] );
105
    assertSame( attr2, valueLog[ 0 ] );
106
    assertSame( session, storeLog[ 0 ] );
106
    assertSame( session, storeLog[ 0 ] );
107
    try {
107
    // check method calls for unbound session store
108
      session.setAttribute( ATTR1, null );
108
    boolean setAttribute = session.setAttribute( ATTR1, null );
109
      fail();
109
    assertFalse( setAttribute );
110
    } catch( final IllegalStateException ise ) {
110
    Object attribute = session.getAttribute( ATTR1 );
111
    }
111
    assertNull( attribute );
112
    try {
112
    boolean removeAttribute = session.removeAttribute( ATTR1 );
113
      session.getAttribute( ATTR1 );
113
    assertFalse( removeAttribute );
114
      fail();
114
    attributeNames = session.getAttributeNames();
115
    } catch( final IllegalStateException ise ) {
115
    assertNull( attributeNames );
116
    }
116
    boolean addSessionStoreListener = session.addSessionStoreListener( null );
117
    try {
117
    assertFalse( addSessionStoreListener );
118
      session.removeAttribute( ATTR1 );
118
    boolean removeSessionStoreListener = session.removeSessionStoreListener( null );
119
      fail();
119
    assertFalse( removeSessionStoreListener );
120
    } catch( final IllegalStateException ise ) {
120
    // check that listener cannot be added when about to be unbound
121
    }
121
    final boolean[] aboutUnboundListener = { true };
122
    try {
123
      session.getAttributeNames();
124
      fail();
125
    } catch( final IllegalStateException ise ) {
126
    }
127
    try {
128
      session.addSessionStoreListener( null );
129
      fail();
130
    } catch( final IllegalStateException ise ) {
131
    }
132
    try {
133
      session.removeSessionStoreListener( null );
134
      fail();
135
    } catch( final IllegalStateException ise ) {
136
    }
137
138
139
    TestSession checkAboutUnboundHttpSession = new TestSession();
122
    TestSession checkAboutUnboundHttpSession = new TestSession();
140
    final SessionStoreImpl checkAboutUnbound
123
    final SessionStoreImpl checkAboutUnbound
141
      = new SessionStoreImpl( checkAboutUnboundHttpSession );
124
      = new SessionStoreImpl( checkAboutUnboundHttpSession );
142
    checkAboutUnbound.addSessionStoreListener( new SessionStoreListener() {
125
    checkAboutUnbound.addSessionStoreListener( new SessionStoreListener() {
143
      public void beforeDestroy( final SessionStoreEvent event ) {
126
      public void beforeDestroy( final SessionStoreEvent event ) {
144
        checkAboutUnbound.addSessionStoreListener( new SessionStoreListener() {
127
        SessionStoreListener lsnr = new SessionStoreListener() {
145
          public void beforeDestroy( final SessionStoreEvent event ) {
128
          public void beforeDestroy( final SessionStoreEvent event ) {
146
          }
129
          }
147
        } );
130
        };
148
      }
131
        aboutUnboundListener[ 0 ]
149
    } );
132
          = checkAboutUnbound.addSessionStoreListener( lsnr );
150
    TestServletContext servletContext
151
      = ( TestServletContext )checkAboutUnboundHttpSession.getServletContext();
152
    final Set problems = new HashSet();
153
    servletContext.setLogger( new TestLogger() {
154
      public void log( final String message, final Throwable throwable ) {
155
        problems.add( throwable );
156
      }
133
      }
157
    } );
134
    } );
158
    checkAboutUnbound.getHttpSession().invalidate();
135
    checkAboutUnbound.getHttpSession().invalidate();
159
    assertEquals( 1, problems.size() );
136
    assertFalse( aboutUnboundListener[ 0 ] );
160
    servletContext.setLogger( null );
161
137
162
    final boolean[] hasContext = { false };
138
    final boolean[] hasContext = { false };
163
    SessionStoreImpl checkContext = new SessionStoreImpl( new TestSession() );
139
    SessionStoreImpl checkContext = new SessionStoreImpl( new TestSession() );

Return to bug 278258