Class LocalizedTaskWrapper<T,V>
- Type Parameters:
T- task progress measurement unitV- result type
Dialog or some View. For instance
if we need to show some dialog when task is running (e.g. updating the progress).
See example in DialogsImpl.BackgroundTaskDialogBuilderImpl.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classEncapsulates the context in which a localized task is executed, providing access to the associatedLocalizedTaskWrapper.Nested classes/interfaces inherited from class io.jmix.flowui.backgroundtask.BackgroundTask
BackgroundTask.ProgressListener<T,V>, BackgroundTask.ProgressListenerAdapter<T, V> -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Consumer<LocalizedTaskWrapper.CloseViewContext>protected DefaultUiExceptionHandlerprotected Messagesprotected Notificationsprotected BackgroundTask<T,V> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcanceled()Provides exclusive access to this UI from outside a request handling thread when the task is canceled byBackgroundTaskHandler.cancel()invocation.voidProvides exclusive access to this UI from outside a request handling thread when the task is completed.Returns the close view handler, which is a consumer that is executed when a particular view or task needs to be closed.Called by the execution environment in UI thread to prepare some execution parameters.booleanProvides exclusive access to this UI from outside a request handling thread if the taskBackgroundTask.run(TaskLifeCycle)method raised an exception.booleanProvides exclusive access to this UI from outside a request handling thread if the task timeout is exceeded.protected voidvoidProvides exclusive access to this UI from outside a request handling thread on progress change.run(TaskLifeCycle<T> lifeCycle) Main method that performs a task.voidsetCloseViewHandler(Consumer<LocalizedTaskWrapper.CloseViewContext> closeViewHandler) Sets a consumer as the close view handler.voidsetDefaultUiExceptionHandler(DefaultUiExceptionHandler defaultUiExceptionHandler) voidsetMessages(Messages messages) voidsetNotifications(Notifications notifications) protected voidMethods inherited from class io.jmix.flowui.backgroundtask.BackgroundTask
addProgressListener, getOwnerView, getProgressListeners, getTimeoutMilliseconds, getTimeoutSeconds, removeProgressListener
-
Field Details
-
messages
-
notifications
-
defaultUiExceptionHandler
-
wrappedTask
-
closeViewHandler
-
-
Constructor Details
-
LocalizedTaskWrapper
-
-
Method Details
-
setMessages
-
setNotifications
-
setDefaultUiExceptionHandler
@Autowired public void setDefaultUiExceptionHandler(DefaultUiExceptionHandler defaultUiExceptionHandler) -
getCloseViewHandler
Returns the close view handler, which is a consumer that is executed when a particular view or task needs to be closed.- Returns:
- the close view handler as a
ConsumerofLocalizedTaskWrapper.CloseViewContext, ornullif no handler is set.
-
setCloseViewHandler
public void setCloseViewHandler(@Nullable Consumer<LocalizedTaskWrapper.CloseViewContext> closeViewHandler) Sets a consumer as the close view handler. The provided handler defines the actions to execute when a view needs to be closed.- Parameters:
closeViewHandler- aConsumerofLocalizedTaskWrapper.CloseViewContextthat handles view closure, ornullto remove an existing handler.
-
getParams
Description copied from class:BackgroundTaskCalled by the execution environment in UI thread to prepare some execution parameters. These parameters can be requested by the working thread inside theBackgroundTask.run(TaskLifeCycle)method by callingTaskLifeCycle.getParams().- Overrides:
getParamsin classBackgroundTask<T,V> - Returns:
- parameters map or null if parameters are not needed
-
run
Description copied from class:BackgroundTaskMain method that performs a task.
Called by the execution environment in a separate working thread.
Implementation of this method should support interruption:- In long loops check
TaskLifeCycle.isInterrupted()and return if it is true - Don't swallow
InterruptedException- return from the method or don't catch it at all
- Specified by:
runin classBackgroundTask<T,V> - Parameters:
lifeCycle- lifecycle object that allows the main method to interact with the execution environment- Returns:
- task result
- Throws:
Exception- exception in a working thread
- In long loops check
-
handleException
Description copied from class:BackgroundTaskProvides exclusive access to this UI from outside a request handling thread if the taskBackgroundTask.run(TaskLifeCycle)method raised an exception.Please note that the command 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 command is executed.
UI.getCurrent(),VaadinSession.getCurrent()andVaadinService.getCurrent()are set according to this UI before executing the command. Other standard CurrentInstance values such asVaadinService.getCurrentRequest()andVaadinService.getCurrentResponse()will not be defined.- Overrides:
handleExceptionin classBackgroundTask<T,V> - Parameters:
ex- exception- Returns:
- true if this method implementation actually handles the exception. Used for chaining handlers.
- See Also:
-
UI.access(Command)
-
handleTimeoutException
public boolean handleTimeoutException()Description copied from class:BackgroundTaskProvides exclusive access to this UI from outside a request handling thread if the task timeout is exceeded.Please note that the command 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 command is executed.
UI.getCurrent(),VaadinSession.getCurrent()andVaadinService.getCurrent()are set according to this UI before executing the command. Other standard CurrentInstance values such asVaadinService.getCurrentRequest()andVaadinService.getCurrentResponse()will not be defined.- Overrides:
handleTimeoutExceptionin classBackgroundTask<T,V> - Returns:
- true if this method implementation actually handles this event. Used for chaining handlers.
- See Also:
-
UI.access(Command)
-
done
Description copied from class:BackgroundTaskProvides exclusive access to this UI from outside a request handling thread when the task is completed.Please note that the command 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 command is executed.
UI.getCurrent(),VaadinSession.getCurrent()andVaadinService.getCurrent()are set according to this UI before executing the command. Other standard CurrentInstance values such asVaadinService.getCurrentRequest()andVaadinService.getCurrentResponse()will not be defined.- Overrides:
donein classBackgroundTask<T,V> - Parameters:
result- result of execution returned byBackgroundTask.run(TaskLifeCycle)method- See Also:
-
UI.access(Command)
-
canceled
public void canceled()Description copied from class:BackgroundTaskProvides exclusive access to this UI from outside a request handling thread when the task is canceled byBackgroundTaskHandler.cancel()invocation.This method is not called in case of timeout expiration or owner view closing.
Please note that the command 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 command is executed.
UI.getCurrent(),VaadinSession.getCurrent()andVaadinService.getCurrent()are set according to this UI before executing the command. Other standard CurrentInstance values such asVaadinService.getCurrentRequest()andVaadinService.getCurrentResponse()will not be defined.- Overrides:
canceledin classBackgroundTask<T,V> - See Also:
-
UI.access(Command)
-
progress
Description copied from class:BackgroundTaskProvides exclusive access to this UI from outside a request handling thread on progress change.Please note that the command 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 command is executed.
UI.getCurrent(),VaadinSession.getCurrent()andVaadinService.getCurrent()are set according to this UI before executing the command. Other standard CurrentInstance values such asVaadinService.getCurrentRequest()andVaadinService.getCurrentResponse()will not be defined.- Overrides:
progressin classBackgroundTask<T,V> - Parameters:
changes- list of changes since previous invocation- See Also:
-
UI.access(Command)
-
showExecutionError
-
notifyCloseViewHandler
protected void notifyCloseViewHandler()
-