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 353891 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/rwt/internal/uicallback/UICallBackManager.java (-7 / +16 lines)
Lines 68-81 Link Here
68
  public void wakeClient() {
68
  public void wakeClient() {
69
    synchronized( lock ) {
69
    synchronized( lock ) {
70
      if( !uiThreadRunning ) {
70
      if( !uiThreadRunning ) {
71
        wakeCalled = true;
71
        releaseBlockedRequest();
72
        releaseBlockedRequest();
72
      }
73
      }
73
    }
74
    }
74
  }
75
  }
76
  
77
  public void forceWakeClient() {
78
    synchronized( lock ) {
79
      wakeCalled = true;
80
      releaseBlockedRequest();
81
    }
82
  }
75
83
76
  public void releaseBlockedRequest() {
84
  public void releaseBlockedRequest() {
77
    synchronized( lock ) {
85
    synchronized( lock ) {
78
      wakeCalled = true;
79
      lock.notifyAll();
86
      lock.notifyAll();
80
    }
87
    }
81
  }
88
  }
Lines 125-130 Link Here
125
      return hasRunnables;
132
      return hasRunnables;
126
    }
133
    }
127
  }
134
  }
135
  
136
  boolean wasWakeCalled() {
137
    return wakeCalled;
138
  }
128
139
129
  boolean processRequest( HttpServletResponse response ) {
140
  boolean processRequest( HttpServletResponse response ) {
130
    boolean result = true;
141
    boolean result = true;
Lines 132-144 Link Here
132
      if( isCallBackRequestBlocked() ) {
143
      if( isCallBackRequestBlocked() ) {
133
        releaseBlockedRequest();
144
        releaseBlockedRequest();
134
      }
145
      }
135
      if( mustBlockCallBackRequest() ) {
146
      if( wakeCalled || mustBlockCallBackRequest() ) {
136
        long requestStartTime = System.currentTimeMillis();
147
        long requestStartTime = System.currentTimeMillis();
137
        callBackRequestTracker.activate( Thread.currentThread() );
148
        callBackRequestTracker.activate( Thread.currentThread() );
138
        SessionTerminationListener listener = attachSessionTerminationListener();
149
        SessionTerminationListener listener = attachSessionTerminationListener();
139
        try {
150
        try {
140
          boolean canRelease = false;
151
          boolean canRelease = false;
141
          wakeCalled = false;
142
          while( !wakeCalled && !canRelease ) {
152
          while( !wakeCalled && !canRelease ) {
143
            lock.wait( requestCheckInterval );
153
            lock.wait( requestCheckInterval );
144
            canRelease = canReleaseBlockedRequest( response, requestStartTime );
154
            canRelease = canReleaseBlockedRequest( response, requestStartTime );
Lines 153-167 Link Here
153
        } finally {
163
        } finally {
154
          listener.detach();
164
          listener.detach();
155
          callBackRequestTracker.deactivate( Thread.currentThread() );
165
          callBackRequestTracker.deactivate( Thread.currentThread() );
166
          wakeCalled = false;
156
        }
167
        }
157
      }
168
      }
158
    }
169
    }
159
    return result;
170
    return result;
160
  }
171
  }
161
172
162
  private boolean canReleaseBlockedRequest( HttpServletResponse response, 
173
  private boolean canReleaseBlockedRequest( HttpServletResponse response, long requestStartTime ) {
163
                                            long requestStartTime ) 
164
  {
165
    boolean result = false;
174
    boolean result = false;
166
    if( !mustBlockCallBackRequest() ) {
175
    if( !mustBlockCallBackRequest() ) {
167
      result = true;
176
      result = true;
Lines 199-205 Link Here
199
    return result;
208
    return result;
200
  }
209
  }
201
210
202
  private boolean isSessionExpired( long requestStartTime ) {
211
  private static boolean isSessionExpired( long requestStartTime ) {
203
    return isSessionExpired( requestStartTime, System.currentTimeMillis() );
212
    return isSessionExpired( requestStartTime, System.currentTimeMillis() );
204
  }
213
  }
205
214
(-)src/org/eclipse/rwt/internal/uicallback/UICallBackServiceHandler.java (-1 / +2 lines)
Lines 58-64 Link Here
58
  }
58
  }
59
59
60
  static void writeUIRequestNeeded( JavaScriptResponseWriter writer ) {
60
  static void writeUIRequestNeeded( JavaScriptResponseWriter writer ) {
61
    if( UICallBackManager.getInstance().hasRunnables() ) {
61
    UICallBackManager uiCallBackManager = UICallBackManager.getInstance();
62
    if( uiCallBackManager.hasRunnables() || uiCallBackManager.wasWakeCalled() ) {
62
      writer.write( JS_SEND_UI_REQUEST );
63
      writer.write( JS_SEND_UI_REQUEST );
63
    }
64
    }
64
  }
65
  }
(-)src/org/eclipse/swt/widgets/Display.java (-1 / +1 lines)
Lines 1196-1202 Link Here
1196
      if( thread != Thread.currentThread() ) {
1196
      if( thread != Thread.currentThread() ) {
1197
        UICallBack.runNonUIThreadWithFakeContext( this, new Runnable() {
1197
        UICallBack.runNonUIThreadWithFakeContext( this, new Runnable() {
1198
          public void run() {
1198
          public void run() {
1199
            UICallBackManager.getInstance().releaseBlockedRequest();
1199
            UICallBackManager.getInstance().forceWakeClient();
1200
          }
1200
          }
1201
        } );
1201
        } );
1202
      }
1202
      }
(-)src/org/eclipse/rwt/internal/uicallback/UICallBackManager_Test.java (-11 / +22 lines)
Lines 110-120 Link Here
110
    assertFalse( manager.isCallBackRequestBlocked() );
110
    assertFalse( manager.isCallBackRequestBlocked() );
111
    assertFalse( thread.isAlive() );
111
    assertFalse( thread.isAlive() );
112
  }
112
  }
113
  
114
  public void testWakeWithoutPendingUICallbackReleasesNextUICallback() throws Exception {
115
    Throwable[] uiCallBackServiceHandlerThrowable = { null };
116
    ServiceContext context = ContextProvider.getContext();
113
117
118
    manager.forceWakeClient();
119
    simulateUiCallBackRequest( uiCallBackServiceHandlerThrowable, context );
120
    
121
    assertNull( uiCallBackServiceHandlerThrowable[ 0 ] );
122
    assertFalse( manager.isCallBackRequestBlocked() );
123
  }
124
  
114
  public void testWaitOnUIThread() throws Exception {
125
  public void testWaitOnUIThread() throws Exception {
115
    final Throwable[] uiCallBackServiceHandlerThrowable = { null };
126
    final Throwable[] uiCallBackServiceHandlerThrowable = { null };
116
    ServiceContext context = ContextProvider.getContext();
127
    ServiceContext context = ContextProvider.getContext();
117
    simulateUiCallBackThread( uiCallBackServiceHandlerThrowable, context );
128
    simulateUiCallBackRequest( uiCallBackServiceHandlerThrowable, context );
118
    assertNull( uiCallBackServiceHandlerThrowable[ 0 ] );
129
    assertNull( uiCallBackServiceHandlerThrowable[ 0 ] );
119
    display.wake();
130
    display.wake();
120
    assertTrue( manager.isCallBackRequestBlocked() );
131
    assertTrue( manager.isCallBackRequestBlocked() );
Lines 124-130 Link Here
124
  public void testWaitOnBackgroundThread() throws Throwable {
135
  public void testWaitOnBackgroundThread() throws Throwable {
125
    final Throwable[] uiCallBackServiceHandlerThrowable = { null };
136
    final Throwable[] uiCallBackServiceHandlerThrowable = { null };
126
    ServiceContext context = ContextProvider.getContext();
137
    ServiceContext context = ContextProvider.getContext();
127
    simulateUiCallBackThread( uiCallBackServiceHandlerThrowable, context );
138
    simulateUiCallBackRequest( uiCallBackServiceHandlerThrowable, context );
128
    assertNull( uiCallBackServiceHandlerThrowable[ 0 ] );
139
    assertNull( uiCallBackServiceHandlerThrowable[ 0 ] );
129
    assertTrue( manager.isCallBackRequestBlocked() );
140
    assertTrue( manager.isCallBackRequestBlocked() );
130
    Runnable runnable = new Runnable() {
141
    Runnable runnable = new Runnable() {
Lines 141-147 Link Here
141
  public void testWaitOnBackgroundThread_DuringLifecycle() throws Exception {
152
  public void testWaitOnBackgroundThread_DuringLifecycle() throws Exception {
142
    final Throwable[] uiCallBackServiceHandlerThrowable = { null };
153
    final Throwable[] uiCallBackServiceHandlerThrowable = { null };
143
    ServiceContext context = ContextProvider.getContext();
154
    ServiceContext context = ContextProvider.getContext();
144
    simulateUiCallBackThread( uiCallBackServiceHandlerThrowable, context );
155
    simulateUiCallBackRequest( uiCallBackServiceHandlerThrowable, context );
145
    assertNull( uiCallBackServiceHandlerThrowable[ 0 ] );
156
    assertNull( uiCallBackServiceHandlerThrowable[ 0 ] );
146
    assertTrue( manager.isCallBackRequestBlocked() );
157
    assertTrue( manager.isCallBackRequestBlocked() );
147
    Thread thread = new Thread( new Runnable() {
158
    Thread thread = new Thread( new Runnable() {
Lines 185-191 Link Here
185
  public void testCallBackRequestBlocking() throws Exception {
196
  public void testCallBackRequestBlocking() throws Exception {
186
    final Throwable[] uiCallBackServiceHandlerThrowable = { null };
197
    final Throwable[] uiCallBackServiceHandlerThrowable = { null };
187
    ServiceContext context = ContextProvider.getContext();
198
    ServiceContext context = ContextProvider.getContext();
188
    simulateUiCallBackThread( uiCallBackServiceHandlerThrowable, context );
199
    simulateUiCallBackRequest( uiCallBackServiceHandlerThrowable, context );
189
    assertNull( uiCallBackServiceHandlerThrowable[ 0 ] );
200
    assertNull( uiCallBackServiceHandlerThrowable[ 0 ] );
190
    assertTrue( manager.isCallBackRequestBlocked() );
201
    assertTrue( manager.isCallBackRequestBlocked() );
191
  }
202
  }
Lines 194-200 Link Here
194
    final Throwable[] uiCallBackServiceHandlerThrowable = { null };
205
    final Throwable[] uiCallBackServiceHandlerThrowable = { null };
195
    ServiceContext context = ContextProvider.getContext();
206
    ServiceContext context = ContextProvider.getContext();
196
    Thread uiCallBackThread
207
    Thread uiCallBackThread
197
      = simulateUiCallBackThread( uiCallBackServiceHandlerThrowable, context );
208
      = simulateUiCallBackRequest( uiCallBackServiceHandlerThrowable, context );
198
    simulateBackgroundAddition( context );
209
    simulateBackgroundAddition( context );
199
    assertFalse( manager.isCallBackRequestBlocked() );
210
    assertFalse( manager.isCallBackRequestBlocked() );
200
    assertFalse( uiCallBackThread.isAlive() );
211
    assertFalse( uiCallBackThread.isAlive() );
Lines 204-210 Link Here
204
  public void testCallBackRequestIsReleasedOnSessionInvalidate() throws Exception {
215
  public void testCallBackRequestIsReleasedOnSessionInvalidate() throws Exception {
205
    Throwable[] uiCallBackHandlerThrowable = { null };
216
    Throwable[] uiCallBackHandlerThrowable = { null };
206
    ServiceContext context = ContextProvider.getContext();
217
    ServiceContext context = ContextProvider.getContext();
207
    Thread uiCallBackThread = simulateUiCallBackThread( uiCallBackHandlerThrowable, context );
218
    Thread uiCallBackThread = simulateUiCallBackRequest( uiCallBackHandlerThrowable, context );
208
219
209
    context.getSessionStore().getHttpSession().invalidate();
220
    context.getSessionStore().getHttpSession().invalidate();
210
    uiCallBackThread.join();
221
    uiCallBackThread.join();
Lines 233-242 Link Here
233
    manager.setRequestCheckInterval( 20 );
244
    manager.setRequestCheckInterval( 20 );
234
    ServiceContext context1 = ContextProvider.getContext();
245
    ServiceContext context1 = ContextProvider.getContext();
235
    Throwable[] uiCallBackHandlerThrowable1 = { null };
246
    Throwable[] uiCallBackHandlerThrowable1 = { null };
236
    Thread uiCallBackThread1 = simulateUiCallBackThread( uiCallBackHandlerThrowable1, context1 );
247
    Thread uiCallBackThread1 = simulateUiCallBackRequest( uiCallBackHandlerThrowable1, context1 );
237
    ServiceContext context2 = createServiceContext( context1.getSessionStore().getHttpSession() );
248
    ServiceContext context2 = createServiceContext( context1.getSessionStore().getHttpSession() );
238
    Throwable[] uiCallBackHandlerThrowable2 = { null };
249
    Throwable[] uiCallBackHandlerThrowable2 = { null };
239
    Thread uiCallBackThread2 = simulateUiCallBackThread( uiCallBackHandlerThrowable2, context2 );
250
    Thread uiCallBackThread2 = simulateUiCallBackRequest( uiCallBackHandlerThrowable2, context2 );
240
251
241
    Thread.sleep( SLEEP_TIME );
252
    Thread.sleep( SLEEP_TIME );
242
253
Lines 261-267 Link Here
261
    };
272
    };
262
    ServiceContext context2 = createServiceContext( httpSession, response );
273
    ServiceContext context2 = createServiceContext( httpSession, response );
263
    Throwable[] uiCallBackHandlerThrowable = { null };
274
    Throwable[] uiCallBackHandlerThrowable = { null };
264
    Thread uiCallBackThread = simulateUiCallBackThread( uiCallBackHandlerThrowable, context2 );
275
    Thread uiCallBackThread = simulateUiCallBackRequest( uiCallBackHandlerThrowable, context2 );
265
276
266
    Thread.sleep( SLEEP_TIME );
277
    Thread.sleep( SLEEP_TIME );
267
278
Lines 275-281 Link Here
275
    ServiceContext context = ContextProvider.getContext();
286
    ServiceContext context = ContextProvider.getContext();
276
    // test runnables addition while no uiCallBack thread is not blocked
287
    // test runnables addition while no uiCallBack thread is not blocked
277
    Thread uiCallBackThread
288
    Thread uiCallBackThread
278
      = simulateUiCallBackThread( uiCallBackServiceHandlerThrowable, context );
289
      = simulateUiCallBackRequest( uiCallBackServiceHandlerThrowable, context );
279
    manager.notifyUIThreadEnd();
290
    manager.notifyUIThreadEnd();
280
    simulateBackgroundAddition( context );
291
    simulateBackgroundAddition( context );
281
    fakeRequestParam( display );
292
    fakeRequestParam( display );
Lines 564-570 Link Here
564
    }
575
    }
565
  }
576
  }
566
577
567
  private Thread simulateUiCallBackThread(
578
  private Thread simulateUiCallBackRequest(
568
    final Throwable[] uiCallBackServiceHandlerThrowable,
579
    final Throwable[] uiCallBackServiceHandlerThrowable,
569
    final ServiceContext context )
580
    final ServiceContext context )
570
    throws InterruptedException
581
    throws InterruptedException

Return to bug 353891