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 (-8 / +2 lines)
Lines 46-52 Link Here
46
  private boolean uiThreadRunning;
46
  private boolean uiThreadRunning;
47
  // indicates whether the display has runnables to execute
47
  // indicates whether the display has runnables to execute
48
  private boolean hasRunnables;
48
  private boolean hasRunnables;
49
  private boolean wakeCalled;
50
  private int requestCheckInterval;
49
  private int requestCheckInterval;
51
  private transient CallBackRequestTracker callBackRequestTracker;
50
  private transient CallBackRequestTracker callBackRequestTracker;
52
51
Lines 54-60 Link Here
54
    lock = new SerializableLock();
53
    lock = new SerializableLock();
55
    idManager = new IdManager();
54
    idManager = new IdManager();
56
    uiThreadRunning = false;
55
    uiThreadRunning = false;
57
    wakeCalled = false;
58
    requestCheckInterval = DEFAULT_REQUEST_CHECK_INTERVAL;
56
    requestCheckInterval = DEFAULT_REQUEST_CHECK_INTERVAL;
59
    callBackRequestTracker = new CallBackRequestTracker();
57
    callBackRequestTracker = new CallBackRequestTracker();
60
  }
58
  }
Lines 75-81 Link Here
75
73
76
  public void releaseBlockedRequest() {
74
  public void releaseBlockedRequest() {
77
    synchronized( lock ) {
75
    synchronized( lock ) {
78
      wakeCalled = true;
79
      lock.notifyAll();
76
      lock.notifyAll();
80
    }
77
    }
81
  }
78
  }
Lines 138-145 Link Here
138
        SessionTerminationListener listener = attachSessionTerminationListener();
135
        SessionTerminationListener listener = attachSessionTerminationListener();
139
        try {
136
        try {
140
          boolean canRelease = false;
137
          boolean canRelease = false;
141
          wakeCalled = false;
138
          while( !canRelease ) {
142
          while( !wakeCalled && !canRelease ) {
143
            lock.wait( requestCheckInterval );
139
            lock.wait( requestCheckInterval );
144
            canRelease = canReleaseBlockedRequest( response, requestStartTime );
140
            canRelease = canReleaseBlockedRequest( response, requestStartTime );
145
          }
141
          }
Lines 159-167 Link Here
159
    return result;
155
    return result;
160
  }
156
  }
161
157
162
  private boolean canReleaseBlockedRequest( HttpServletResponse response, 
158
  private boolean canReleaseBlockedRequest( HttpServletResponse response, long requestStartTime ) {
163
                                            long requestStartTime ) 
164
  {
165
    boolean result = false;
159
    boolean result = false;
166
    if( !mustBlockCallBackRequest() ) {
160
    if( !mustBlockCallBackRequest() ) {
167
      result = true;
161
      result = true;
(-)src/org/eclipse/rwt/internal/uicallback/UICallBackServiceHandler.java (-9 / +30 lines)
Lines 37-61 Link Here
37
    boolean success = UICallBackManager.getInstance().processRequest( response );
37
    boolean success = UICallBackManager.getInstance().processRequest( response );
38
    if( success && sessionStore.isBound() ) {
38
    if( success && sessionStore.isBound() ) {
39
      JavaScriptResponseWriter writer = new JavaScriptResponseWriter( response );
39
      JavaScriptResponseWriter writer = new JavaScriptResponseWriter( response );
40
      writeUICallBackActivation( writer );
40
      writeUICallBackDeactivation( writer );
41
      writeUIRequestNeeded( writer );
41
      writeUIRequestNeeded( writer );
42
    }
42
    }
43
  }
43
  }
44
44
45
  public static void writeUICallBackActivation( JavaScriptResponseWriter writer ) {
45
  public static void writeUICallBackActivation( JavaScriptResponseWriter writer ) {
46
    boolean actual = UICallBackManager.getInstance().needsActivation();
46
    boolean actual = UICallBackManager.getInstance().needsActivation();
47
    ISessionStore sessionStore = ContextProvider.getSession();
47
    boolean preserved = getPreservedUICallBackActivation();
48
    Boolean preserved = ( Boolean )sessionStore.getAttribute( ATTR_NEEDS_UICALLBACK );
48
    if( preserved != actual && actual ) {
49
    if( preserved == null ) {
49
      writeUICallBackActivation( writer, actual );
50
      preserved = Boolean.FALSE;
50
      ISessionStore sessionStore = ContextProvider.getSession();
51
      sessionStore.setAttribute( ATTR_NEEDS_UICALLBACK, Boolean.valueOf( actual ) );
51
    }
52
    }
52
    if( preserved.booleanValue() != actual ) {
53
  }
53
      writer.write(   "org.eclipse.swt.Request.getInstance().setUiCallBackActive( "
54
54
                    + Boolean.toString( actual )
55
  public static void writeUICallBackDeactivation( JavaScriptResponseWriter writer ) {
55
                    + " );" );
56
    boolean actual = UICallBackManager.getInstance().needsActivation();
57
    boolean preserved = getPreservedUICallBackActivation();
58
    if( preserved != actual && !actual ) {
59
      writeUICallBackActivation( writer, actual );
60
      ISessionStore sessionStore = ContextProvider.getSession();
56
      sessionStore.setAttribute( ATTR_NEEDS_UICALLBACK, Boolean.valueOf( actual ) );
61
      sessionStore.setAttribute( ATTR_NEEDS_UICALLBACK, Boolean.valueOf( actual ) );
57
    }
62
    }
58
  }
63
  }
64
  
65
  private static void writeUICallBackActivation( JavaScriptResponseWriter writer, boolean value ) {
66
    writer.write(   "org.eclipse.swt.Request.getInstance().setUiCallBackActive( "
67
                  + Boolean.toString( value )
68
                  + " );" );
69
  }
70
71
  private static boolean getPreservedUICallBackActivation() {
72
    boolean result = false;
73
    ISessionStore sessionStore = ContextProvider.getSession();
74
    Boolean preserved = ( Boolean )sessionStore.getAttribute( ATTR_NEEDS_UICALLBACK );
75
    if( preserved != null ) {
76
      result = preserved.booleanValue();
77
    }
78
    return result;
79
  }
59
80
60
  static void writeUIRequestNeeded( JavaScriptResponseWriter writer ) {
81
  static void writeUIRequestNeeded( JavaScriptResponseWriter writer ) {
61
    if( UICallBackManager.getInstance().hasRunnables() ) {
82
    if( UICallBackManager.getInstance().hasRunnables() ) {
(-)src/org/eclipse/swt/widgets/Display.java (-1 / +6 lines)
Lines 1198-1204 Link Here
1198
      if( thread != Thread.currentThread() ) {
1198
      if( thread != Thread.currentThread() ) {
1199
        UICallBack.runNonUIThreadWithFakeContext( this, new Runnable() {
1199
        UICallBack.runNonUIThreadWithFakeContext( this, new Runnable() {
1200
          public void run() {
1200
          public void run() {
1201
            UICallBackManager.getInstance().releaseBlockedRequest();
1201
            synchronizer.asyncExec( new WakeRunnable() );
1202
          }
1202
          }
1203
        } );
1203
        } );
1204
      }
1204
      }
Lines 2282-2287 Link Here
2282
  /////////////////
2282
  /////////////////
2283
  // Inner classes
2283
  // Inner classes
2284
2284
2285
  private static class WakeRunnable implements Runnable, SerializableCompatibility {
2286
    public void run() {
2287
    }
2288
  }
2289
  
2285
  private static class FilterEntry implements IFilterEntry, SerializableCompatibility {
2290
  private static class FilterEntry implements IFilterEntry, SerializableCompatibility {
2286
2291
2287
    private final int eventType;
2292
    private final int eventType;
(-)src/org/eclipse/rwt/internal/uicallback/UICallBackManager_Test.java (-6 / +7 lines)
Lines 105-112 Link Here
105
    assertNull( uiCallBackServiceHandlerThrowable[ 0 ] );
105
    assertNull( uiCallBackServiceHandlerThrowable[ 0 ] );
106
    assertTrue( manager.isCallBackRequestBlocked() );
106
    assertTrue( manager.isCallBackRequestBlocked() );
107
107
108
    manager.setHasRunnables( true );
108
    manager.wakeClient();
109
    manager.wakeClient();
109
    thread.join();
110
    thread.join();
111
    
110
    assertFalse( manager.isCallBackRequestBlocked() );
112
    assertFalse( manager.isCallBackRequestBlocked() );
111
    assertFalse( thread.isAlive() );
113
    assertFalse( thread.isAlive() );
112
  }
114
  }
Lines 138-160 Link Here
138
  }
140
  }
139
141
140
  // same test as above, but while UIThread running
142
  // same test as above, but while UIThread running
141
  public void testWaitOnBackgroundThread_DuringLifecycle() throws Exception {
143
  public void testWaitOnBackgroundThreadDuringLifecycle() throws Throwable {
142
    final Throwable[] uiCallBackServiceHandlerThrowable = { null };
144
    final Throwable[] uiCallBackServiceHandlerThrowable = { null };
143
    ServiceContext context = ContextProvider.getContext();
145
    ServiceContext context = ContextProvider.getContext();
144
    simulateUiCallBackThread( uiCallBackServiceHandlerThrowable, context );
146
    simulateUiCallBackThread( uiCallBackServiceHandlerThrowable, context );
145
    assertNull( uiCallBackServiceHandlerThrowable[ 0 ] );
147
    assertNull( uiCallBackServiceHandlerThrowable[ 0 ] );
146
    assertTrue( manager.isCallBackRequestBlocked() );
148
    assertTrue( manager.isCallBackRequestBlocked() );
147
    Thread thread = new Thread( new Runnable() {
149
    Runnable runnable = new Runnable() {
148
      public void run() {
150
      public void run() {
149
        display.wake();
151
        display.wake();
150
      }
152
      }
151
    } );
153
    };
152
    // assume that UIThread is currently running the life cycle
154
    // assume that UIThread is currently running the life cycle
153
    manager.notifyUIThreadStart();
155
    manager.notifyUIThreadStart();
154
    thread.start();
156
    Fixture.runInThread( runnable );
155
    thread.join();
156
    Thread.sleep( SLEEP_TIME );
157
    manager.notifyUIThreadEnd();
157
    manager.notifyUIThreadEnd();
158
    Thread.sleep( SLEEP_TIME );
158
    assertFalse( manager.isCallBackRequestBlocked() );
159
    assertFalse( manager.isCallBackRequestBlocked() );
159
  }
160
  }
160
161
(-)src/org/eclipse/rwt/internal/uicallback/UICallBackServiceHandler_Test.java (-16 / +46 lines)
Lines 18-27 Link Here
18
18
19
import junit.framework.TestCase;
19
import junit.framework.TestCase;
20
20
21
import org.eclipse.rap.rwt.testfixture.*;
21
import org.eclipse.rap.rwt.testfixture.Fixture;
22
import org.eclipse.rap.rwt.testfixture.TestResponse;
22
import org.eclipse.rap.rwt.testfixture.internal.NoOpRunnable;
23
import org.eclipse.rap.rwt.testfixture.internal.NoOpRunnable;
23
import org.eclipse.rwt.internal.lifecycle.JavaScriptResponseWriter;
24
import org.eclipse.rwt.internal.lifecycle.JavaScriptResponseWriter;
24
import org.eclipse.rwt.internal.service.ContextProvider;
25
import org.eclipse.rwt.internal.service.ContextProvider;
26
import org.eclipse.rwt.internal.service.RequestParams;
27
import org.eclipse.swt.internal.widgets.displaykit.DisplayLCA;
25
import org.eclipse.swt.widgets.Display;
28
import org.eclipse.swt.widgets.Display;
26
29
27
30
Lines 65-71 Link Here
65
    
68
    
66
    Fixture.fakeNewRequest();
69
    Fixture.fakeNewRequest();
67
    UICallBackManager.getInstance().deactivateUICallBacksFor( "id" );
70
    UICallBackManager.getInstance().deactivateUICallBacksFor( "id" );
68
    UICallBackServiceHandler.writeUICallBackActivation( getResponseWriter() );
71
    UICallBackServiceHandler.writeUICallBackDeactivation( getResponseWriter() );
69
    
72
    
70
    assertEquals( DISABLE_UI_CALLBACK, Fixture.getAllMarkup() );
73
    assertEquals( DISABLE_UI_CALLBACK, Fixture.getAllMarkup() );
71
  }
74
  }
Lines 78-88 Link Here
78
    Fixture.fakeNewRequest();
81
    Fixture.fakeNewRequest();
79
    display.dispose();
82
    display.dispose();
80
    UICallBackManager.getInstance().deactivateUICallBacksFor( "id" );
83
    UICallBackManager.getInstance().deactivateUICallBacksFor( "id" );
81
    UICallBackServiceHandler.writeUICallBackActivation( getResponseWriter() );
84
    UICallBackServiceHandler.writeUICallBackDeactivation( getResponseWriter() );
82
    
85
    
83
    assertEquals( DISABLE_UI_CALLBACK, Fixture.getAllMarkup() );
86
    assertEquals( DISABLE_UI_CALLBACK, Fixture.getAllMarkup() );
84
  }
87
  }
88
  
89
  public void testWriteUICallBackDeactivateIsNotSentFromUIRequest() throws Exception {
90
    Display display = new Display();
91
    UICallBackManager.getInstance().activateUICallBacksFor( "id" );
92
    UICallBackServiceHandler.writeUICallBackActivation( getResponseWriter() );
93
    
94
    Fixture.fakeNewRequest();
95
    Fixture.fakeRequestParam( RequestParams.UIROOT, "w1" );
96
    UICallBackManager.getInstance().deactivateUICallBacksFor( "id" );
97
    new DisplayLCA().render( display );
98
    
99
    assertFalse( Fixture.getAllMarkup().contains( DISABLE_UI_CALLBACK ) );
100
  }
85
101
102
  public void testWriteUICallBackDeactivateIsSentFromServiceHandler() throws Exception {
103
    UICallBackManager.getInstance().activateUICallBacksFor( "id" );
104
    UICallBackServiceHandler.writeUICallBackActivation( getResponseWriter() );
105
    
106
    Fixture.fakeNewRequest();
107
    UICallBackManager.getInstance().deactivateUICallBacksFor( "id" );
108
    new UICallBackServiceHandler().service();
109
    
110
    assertEquals( DISABLE_UI_CALLBACK, Fixture.getAllMarkup() );
111
  }
112
  
86
  public void testWriteUICallBackActivateTwice() throws Exception {
113
  public void testWriteUICallBackActivateTwice() throws Exception {
87
    UICallBackManager.getInstance().activateUICallBacksFor( "id" );
114
    UICallBackManager.getInstance().activateUICallBacksFor( "id" );
88
    UICallBackServiceHandler.writeUICallBackActivation( getResponseWriter() );
115
    UICallBackServiceHandler.writeUICallBackActivation( getResponseWriter() );
Lines 100-118 Link Here
100
    assertEquals( "", Fixture.getAllMarkup() );
127
    assertEquals( "", Fixture.getAllMarkup() );
101
  }
128
  }
102
129
103
  public void testUICallBackActivationUpdated() throws Exception {
104
    Display display = new Display();
105
    UICallBackManager.getInstance().activateUICallBacksFor( "id" );
106
    UICallBackServiceHandler.writeUICallBackActivation( getResponseWriter() );
107
    Fixture.fakeNewRequest();
108
    UICallBackManager.getInstance().deactivateUICallBacksFor( "id" );
109
    display.asyncExec( new NoOpRunnable() );    
110
111
    new UICallBackServiceHandler().service();
112
113
    assertTrue( Fixture.getAllMarkup().contains( DISABLE_UI_CALLBACK ) );
114
  }
115
116
  public void testWriteUICallBackActivationWithoutDisplay() throws Exception {
130
  public void testWriteUICallBackActivationWithoutDisplay() throws Exception {
117
    UICallBackServiceHandler.writeUICallBackActivation( getResponseWriter() );
131
    UICallBackServiceHandler.writeUICallBackActivation( getResponseWriter() );
118
132
Lines 154-159 Link Here
154
    
168
    
155
    assertEquals( SEND_UI_REQUEST, Fixture.getAllMarkup() );
169
    assertEquals( SEND_UI_REQUEST, Fixture.getAllMarkup() );
156
  }
170
  }
171
  
172
  public void testWriteUiRequestNeededAfterWake() throws Throwable {
173
    final Display display = new Display();
174
    UICallBackManager.getInstance().activateUICallBacksFor( "id" );
175
    Fixture.fakeNewRequest();
176
    
177
    Runnable runnable = new Runnable() {
178
      public void run() {
179
        display.wake();
180
      }
181
    };
182
    Fixture.runInThread( runnable );
183
    new UICallBackServiceHandler().service();
184
    
185
    assertEquals( SEND_UI_REQUEST, Fixture.getAllMarkup() );
186
  }
157
187
158
  public void testWriteUICallBackActivateWithoutStateInfo() throws Exception {
188
  public void testWriteUICallBackActivateWithoutStateInfo() throws Exception {
159
    Fixture.replaceStateInfo( null );
189
    Fixture.replaceStateInfo( null );

Return to bug 353891