Spec-Zone .ru
спецификации, руководства, описания, API
|
public interface Worker<V>
A Worker is an object which performs some work in one or more background
threads, and who's state is observable and available to JavaFX applications
and is usable from the main JavaFX Application thread. This interface is
primarily implemented by both Task
and Service
, providing
a common API among both classes which makes it easier for libraries and
frameworks to provide workers which work well when developing user interfaces.
A Worker may or may not be reusable depending on the implementation. A
Task
, for example, is not reusable while a Service
is.
A Worker has a well defined life cycle. Every Worker begins in the
Worker.State.READY
state. When the Worker has been scheduled for work
(for example, when a Service's Service.start()
method is called), it is transitioned to Worker.State.SCHEDULED
. Even
Workers which are not technically scheduled, but started immediately
(such as with FutureTask.run()
) will transition through
the Worker.State.SCHEDULED
on its way to the Worker.State.RUNNING
state.
When the Worker is actually performing its work, the state will have been
transitioned to Worker.State.RUNNING
. If the Worker completes normally,
it will end in the Worker.State.SUCCEEDED
state, and the result of the
Worker will be set as the value
property. If however an Exception
occurs during the execution of the Worker, then the state will be set to
Worker.State.FAILED
and the exception
property will be set
to the Exception which occurred.
At any time prior to the conclusion of the Worker (that is, if the state
is not already Worker.State.SUCCEEDED
or Worker.State.FAILED
) the developer
may invoke the cancel()
method. If called, the
Worker will cease execution (if possible, including use of Thread.interrupt)
and the state changed to Worker.State.CANCELLED
.
The only valid beginning state for a Worker is Worker.State.READY
, and the
valid ending states are Worker.State.CANCELLED
, Worker.State.SUCCEEDED
,
and Worker.State.FAILED
. The running
property is set to
true when the state is either Worker.State.SCHEDULED
or Worker.State.RUNNING
.
The Worker's progress can be monitored via three different properties,
totalWork
, workDone
, and progress
.
These properties are set by the actual implementation of the Worker
interface, but can be observed by anybody. The workDone
is
a number between -1 (meaning indeterminate progress) and
totalWork
, inclusive. When workDone == totalWork
the progress
will be 100% (or 1). totalWork
will be a number between -1 and Long.MAX_VALUE, inclusive. The progress
will be either -1 (meaning indeterminate), or a value between 0 and 1, inclusive,
representing 0% through 100%.
A Worker which is in the Worker.State.READY
or Worker.State.SCHEDULED
states
will always have workDone
and progress
set to -1.
A Worker which is in the Worker.State.SUCCEEDED
state will always have
workDone == totalWork
and progress == 1
. In any
other state, the values for these properties may be any value in their
respective valid ranges.
Type | Property and Description |
---|---|
ReadOnlyObjectProperty<java.lang.Throwable> |
exception
Gets the ReadOnlyObjectProperty representing any exception which occurred.
|
ReadOnlyStringProperty |
message
Gets the ReadOnlyStringProperty representing the message.
|
ReadOnlyDoubleProperty |
progress
Gets the ReadOnlyDoubleProperty representing the progress.
|
ReadOnlyBooleanProperty |
running
Gets the ReadOnlyBooleanProperty representing whether the Worker is running.
|
ReadOnlyObjectProperty<Worker.State> |
state
Gets the ReadOnlyObjectProperty representing the current state.
|
ReadOnlyStringProperty |
title
Gets the ReadOnlyStringProperty representing the title.
|
ReadOnlyDoubleProperty |
totalWork
Gets the ReadOnlyDoubleProperty representing the maximum amount of work
that needs to be done.
|
ReadOnlyObjectProperty<V> |
value
Gets the ReadOnlyObjectProperty representing the value.
|
ReadOnlyDoubleProperty |
workDone
Gets the ReadOnlyDoubleProperty representing the current progress.
|
Modifier and Type | Interface and Description |
---|---|
static class |
Worker.State
The state of a Worker.
|
Modifier and Type | Method and Description |
---|---|
boolean |
cancel()
Terminates execution of this Worker.
|
ReadOnlyObjectProperty<java.lang.Throwable> |
exceptionProperty()
Gets the ReadOnlyObjectProperty representing any exception which occurred.
|
java.lang.Throwable |
getException()
Indicates the exception which occurred while the Worker was running, if any.
|
java.lang.String |
getMessage()
Gets a message associated with the current state of this Worker.
|
double |
getProgress()
Indicates the current progress of this Worker in terms of percent complete.
|
Worker.State |
getState()
Specifies the current state of this Worker.
|
java.lang.String |
getTitle()
An optional title that should be associated with this Worker.
|
double |
getTotalWork()
Indicates a maximum value for the
workDoneProperty() property. |
V |
getValue()
Specifies the value, or result, of this Worker.
|
double |
getWorkDone()
Indicates the current amount of work that has been completed.
|
boolean |
isRunning()
True if the state is either SCHEDULED or RUNNING.
|
ReadOnlyStringProperty |
messageProperty()
Gets the ReadOnlyStringProperty representing the message.
|
ReadOnlyDoubleProperty |
progressProperty()
Gets the ReadOnlyDoubleProperty representing the progress.
|
ReadOnlyBooleanProperty |
runningProperty()
Gets the ReadOnlyBooleanProperty representing whether the Worker is running.
|
ReadOnlyObjectProperty<Worker.State> |
stateProperty()
Gets the ReadOnlyObjectProperty representing the current state.
|
ReadOnlyStringProperty |
titleProperty()
Gets the ReadOnlyStringProperty representing the title.
|
ReadOnlyDoubleProperty |
totalWorkProperty()
Gets the ReadOnlyDoubleProperty representing the maximum amount of work
that needs to be done.
|
ReadOnlyObjectProperty<V> |
valueProperty()
Gets the ReadOnlyObjectProperty representing the value.
|
ReadOnlyDoubleProperty |
workDoneProperty()
Gets the ReadOnlyDoubleProperty representing the current progress.
|
ReadOnlyObjectProperty<Worker.State> stateProperty
getState()
ReadOnlyObjectProperty<V> valueProperty
getValue()
ReadOnlyObjectProperty<java.lang.Throwable> exceptionProperty
getException()
ReadOnlyDoubleProperty workDoneProperty
getWorkDone()
ReadOnlyDoubleProperty totalWorkProperty
getTotalWork()
ReadOnlyDoubleProperty progressProperty
getProgress()
ReadOnlyBooleanProperty runningProperty
isRunning()
ReadOnlyStringProperty messageProperty
getMessage()
ReadOnlyStringProperty titleProperty
getTitle()
Worker.State getState()
ReadOnlyObjectProperty<Worker.State> stateProperty()
getState()
V getValue()
ReadOnlyObjectProperty<V> valueProperty()
getValue()
java.lang.Throwable getException()
null
, there is no known exception, even if
the status is FAILED. If this property is not null
, it will most
likely contain an exception that describes the cause of failure.ReadOnlyObjectProperty<java.lang.Throwable> exceptionProperty()
getException()
double getWorkDone()
totalWorkProperty()
,
progressProperty()
ReadOnlyDoubleProperty workDoneProperty()
getWorkDone()
double getTotalWork()
workDoneProperty()
property. The
totalWork will either be -1 (indicating that the amount of work
to do is indeterminate), or it will be a non-zero value less than or
equal to Double.MAX_VALUE.workDoneProperty()
,
progressProperty()
ReadOnlyDoubleProperty totalWorkProperty()
getTotalWork()
double getProgress()
workDoneProperty()
,
totalWorkProperty()
ReadOnlyDoubleProperty progressProperty()
getProgress()
boolean isRunning()
ProgressIndicator
, you will typically bind the visibility
of the ProgressIndicator to the Worker's running property, and the progress of the
ProgressIndicator to the Worker's progress property.ReadOnlyBooleanProperty runningProperty()
isRunning()
java.lang.String getMessage()
ReadOnlyStringProperty messageProperty()
getMessage()
java.lang.String getTitle()
ReadOnlyStringProperty titleProperty()
getTitle()
boolean cancel()
Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved. Use is subject to