mirror of
https://gitee.com/jmix/cuba.git
synced 2024-12-01 10:47:37 +08:00
PL-1758 JavaDoc for UIAccessor and IllegalConcurrentAccessException
This commit is contained in:
parent
c5645ab63c
commit
ff4965290e
@ -56,6 +56,7 @@ public class DesktopBackgroundWorker implements BackgroundWorker {
|
||||
@Override
|
||||
public <T, V> BackgroundTaskHandler<V> handle(BackgroundTask<T, V> task) {
|
||||
checkNotNull(task);
|
||||
checkUIAccess();
|
||||
|
||||
// create task handler
|
||||
DesktopTaskExecutor<T, V> taskExecutor = new DesktopTaskExecutor<>(task);
|
||||
@ -68,6 +69,8 @@ public class DesktopBackgroundWorker implements BackgroundWorker {
|
||||
|
||||
@Override
|
||||
public UIAccessor getUIAccessor() {
|
||||
checkUIAccess();
|
||||
|
||||
return new DesktopUIAccessor();
|
||||
}
|
||||
|
||||
|
@ -30,12 +30,16 @@ public interface BackgroundWorker {
|
||||
* @param <V> task result type
|
||||
* @param task background task instance
|
||||
* @return task handler
|
||||
* @throws IllegalConcurrentAccessException in case of call from non UI thread
|
||||
*/
|
||||
@ExecutedOnUIThread
|
||||
<T, V> BackgroundTaskHandler<V> handle(BackgroundTask<T, V> task);
|
||||
|
||||
/**
|
||||
* Obtain UI access for later use from background thread. Can be invoked only from UI thread.
|
||||
*
|
||||
* @return ui accessor object that allows to read/write state of UI
|
||||
* @throws IllegalConcurrentAccessException in case of call from non UI thread
|
||||
*/
|
||||
@ExecutedOnUIThread
|
||||
UIAccessor getUIAccessor();
|
||||
|
@ -16,8 +16,11 @@
|
||||
|
||||
package com.haulmont.cuba.gui.executors;
|
||||
|
||||
/**
|
||||
* Exception that is thrown in case of incorrect access to a shared data from a thread that does not own necessary lock.
|
||||
*/
|
||||
public class IllegalConcurrentAccessException extends RuntimeException {
|
||||
public IllegalConcurrentAccessException() {
|
||||
super("UI Shared state was accessed from background thread");
|
||||
super("UI Shared state was accessed from a background thread");
|
||||
}
|
||||
}
|
@ -16,8 +16,33 @@
|
||||
|
||||
package com.haulmont.cuba.gui.executors;
|
||||
|
||||
/**
|
||||
* Interface that allows to read/write state of UI from background threads.
|
||||
*
|
||||
* @see BackgroundWorker#getUIAccessor()
|
||||
*/
|
||||
public interface UIAccessor {
|
||||
/**
|
||||
* Provides exclusive access to UI state from outside a UI event handling thread.
|
||||
*
|
||||
* The given runnable is executed while holding the UI lock to ensure
|
||||
* exclusive access to UI state.
|
||||
*
|
||||
* Please note that the runnable might be invoked on a different thread or
|
||||
* later on the current thread, which means that custom thread locals might
|
||||
* not have the expected values when the runnable is executed.
|
||||
*
|
||||
* @param runnable runnable
|
||||
*/
|
||||
void access(Runnable runnable);
|
||||
|
||||
/**
|
||||
* Locks the UI and runs the provided Runnable right away.
|
||||
*
|
||||
* The given runnable is executed while holding the UI lock to ensure
|
||||
* exclusive access to UI state.
|
||||
*
|
||||
* @param runnable runnable
|
||||
*/
|
||||
void accessSynchronously(Runnable runnable);
|
||||
}
|
@ -128,6 +128,8 @@ public class WebBackgroundWorker implements BackgroundWorker {
|
||||
|
||||
@Override
|
||||
public UIAccessor getUIAccessor() {
|
||||
checkUIAccess();
|
||||
|
||||
return new WebUIAccessor(UI.getCurrent());
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user