- Type Parameters:
- V- the type of object returned by the Service
- All Implemented Interfaces:
- Worker<V>,- EventTarget
- Direct Known Subclasses:
- ScheduledService
public abstract class Service<V> extends Object implements Worker<V>, EventTarget
A Service is a non-visual component encapsulating the information required to perform some work on one or more background threads. As part of the JavaFX UI library, the Service knows about the JavaFX Application thread and is designed to relieve the application developer from the burden of managing multithreaded code that interacts with the user interface. As such, all of the methods and state on the Service are intended to be invoked exclusively from the JavaFX Application thread. The only exception to this, is when initially configuring a Service, which may safely be done from any thread, and initially starting a Service, which may also safely be done from any thread. However, once the Service has been initialized and started, it may only thereafter be used from the FX thread.
     A Service creates and manages a Task that performs the work
     on the background thread.
     Service implements Worker. As such, you can observe the state of
     the background task and optionally cancel it. Service is a reusable
     Worker, meaning that it can be reset and restarted. Due to this, a Service
     can be constructed declaratively and restarted on demand.
     Once a Service is started, it will schedule its Task and listen for
     changes to the state of the Task. A Task does not hold a reference to the
     Service that started it, meaning that a running Task will not prevent
     the Service from being garbage collected.
 
     If an Executor is specified on the Service,
     then it will be used to actually execute the service. Otherwise,
     a daemon thread will be created and executed. If you wish to create
     non-daemon threads, then specify a custom Executor (for example,
     you could use a ThreadPoolExecutor with a custom
     ThreadFactory).
 
     Because a Service is intended to simplify declarative use cases, subclasses
     should expose as properties the input parameters to the work to be done.
     For example, suppose I wanted to write a Service which read the first line
     from any URL and returned it as a String. Such a Service might be defined,
     such that it had a single property, url. It might be implemented
     as:
 
     public static class FirstLineService extends Service<String> {
         private StringProperty url = new SimpleStringProperty(this, "url");
         public final void setUrl(String value) { url.set(value); }
         public final String getUrl() { return url.get(); }
         public final StringProperty urlProperty() { return url; }
         protected Task createTask() {
             final String _url = getUrl();
             return new Task<String>() {
                 protected String call() throws Exception {
                     URL u = new URL(_url);
                     BufferedReader in = new BufferedReader(
                             new InputStreamReader(u.openStream()));
                     String result = in.readLine();
                     in.close();
                     return result;
                 }
             };
         }
     }
     The Service by default uses a thread pool Executor with some unspecified default or maximum thread pool size. This is done so that naive code will not completely swamp the system by creating thousands of Threads.
- Since:
- JavaFX 2.0
- 
Property SummaryProperties Type Property Description ReadOnlyObjectProperty<Throwable>exceptionGets the ReadOnlyObjectProperty representing any exception which occurred.ObjectProperty<Executor>executorThe executor to use for running this Service.ReadOnlyStringPropertymessageGets the ReadOnlyStringProperty representing the message.ObjectProperty<EventHandler<WorkerStateEvent>>onCancelledThe onCancelled event handler is called whenever the Task state transitions to the CANCELLED state.ObjectProperty<EventHandler<WorkerStateEvent>>onFailedThe onFailed event handler is called whenever the Task state transitions to the FAILED state.ObjectProperty<EventHandler<WorkerStateEvent>>onReadyThe onReady event handler is called whenever the Task state transitions to the READY state.ObjectProperty<EventHandler<WorkerStateEvent>>onRunningThe onRunning event handler is called whenever the Task state transitions to the RUNNING state.ObjectProperty<EventHandler<WorkerStateEvent>>onScheduledThe onSchedule event handler is called whenever the Task state transitions to the SCHEDULED state.ObjectProperty<EventHandler<WorkerStateEvent>>onSucceededThe onSucceeded event handler is called whenever the Task state transitions to the SUCCEEDED state.ReadOnlyDoublePropertyprogressGets the ReadOnlyDoubleProperty representing the progress.ReadOnlyBooleanPropertyrunningGets the ReadOnlyBooleanProperty representing whether the Worker is running.ReadOnlyObjectProperty<Worker.State>stateGets the ReadOnlyObjectProperty representing the current state.ReadOnlyStringPropertytitleGets the ReadOnlyStringProperty representing the title.ReadOnlyDoublePropertytotalWorkGets the ReadOnlyDoubleProperty representing the maximum amount of work that needs to be done.ReadOnlyObjectProperty<V>valueGets the ReadOnlyObjectProperty representing the value.ReadOnlyDoublePropertyworkDoneGets the ReadOnlyDoubleProperty representing the current progress.
- 
Nested Class SummaryNested classes/interfaces inherited from interface javafx.concurrent.WorkerWorker.State
- 
Constructor SummaryConstructors Modifier Constructor Description protectedService()Create a new Service.
- 
Method SummaryModifier and Type Method Description <T extends Event>
 voidaddEventFilter(EventType<T> eventType, EventHandler<? super T> eventFilter)Registers an event filter to this task.<T extends Event>
 voidaddEventHandler(EventType<T> eventType, EventHandler<? super T> eventHandler)Registers an event handler to this task.EventDispatchChainbuildEventDispatchChain(EventDispatchChain tail)Construct an event dispatch chain for this target.booleancancel()Cancels any currently running Task, if any.protected voidcancelled()A protected convenience method for subclasses, called whenever the state of the Service has transitioned to the CANCELLED state.protected abstract Task<V>createTask()Invoked after the Service is started on the JavaFX Application Thread.ReadOnlyObjectProperty<Throwable>exceptionProperty()Gets the ReadOnlyObjectProperty representing any exception which occurred.protected voidexecuteTask(Task<V> task)Uses theexecutordefined on this Service to execute the given task.ObjectProperty<Executor>executorProperty()The executor to use for running this Service.protected voidfailed()A protected convenience method for subclasses, called whenever the state of the Service has transitioned to the FAILED state.protected voidfireEvent(Event event)Fires the specified event.ThrowablegetException()Gets the value of the property exception.ExecutorgetExecutor()Gets the value of the property executor.StringgetMessage()Gets the value of the property message.EventHandler<WorkerStateEvent>getOnCancelled()The onCancelled event handler is called whenever the Task state transitions to the CANCELLED state.EventHandler<WorkerStateEvent>getOnFailed()The onFailed event handler is called whenever the Task state transitions to the FAILED state.EventHandler<WorkerStateEvent>getOnReady()The onReady event handler is called whenever the Task state transitions to the READY state.EventHandler<WorkerStateEvent>getOnRunning()The onRunning event handler is called whenever the Task state transitions to the RUNNING state.EventHandler<WorkerStateEvent>getOnScheduled()The onSchedule event handler is called whenever the Task state transitions to the SCHEDULED state.EventHandler<WorkerStateEvent>getOnSucceeded()The onSucceeded event handler is called whenever the Task state transitions to the SUCCEEDED state.doublegetProgress()Gets the value of the property progress.Worker.StategetState()Gets the value of the property state.StringgetTitle()Gets the value of the property title.doublegetTotalWork()Gets the value of the property totalWork.VgetValue()Gets the value of the property value.doublegetWorkDone()Gets the value of the property workDone.booleanisRunning()Gets the value of the property running.ReadOnlyStringPropertymessageProperty()Gets the ReadOnlyStringProperty representing the message.ObjectProperty<EventHandler<WorkerStateEvent>>onCancelledProperty()The onCancelled event handler is called whenever the Task state transitions to the CANCELLED state.ObjectProperty<EventHandler<WorkerStateEvent>>onFailedProperty()The onFailed event handler is called whenever the Task state transitions to the FAILED state.ObjectProperty<EventHandler<WorkerStateEvent>>onReadyProperty()The onReady event handler is called whenever the Task state transitions to the READY state.ObjectProperty<EventHandler<WorkerStateEvent>>onRunningProperty()The onRunning event handler is called whenever the Task state transitions to the RUNNING state.ObjectProperty<EventHandler<WorkerStateEvent>>onScheduledProperty()The onSchedule event handler is called whenever the Task state transitions to the SCHEDULED state.ObjectProperty<EventHandler<WorkerStateEvent>>onSucceededProperty()The onSucceeded event handler is called whenever the Task state transitions to the SUCCEEDED state.ReadOnlyDoublePropertyprogressProperty()Gets the ReadOnlyDoubleProperty representing the progress.protected voidready()A protected convenience method for subclasses, called whenever the state of the Service has transitioned to the READY state.<T extends Event>
 voidremoveEventFilter(EventType<T> eventType, EventHandler<? super T> eventFilter)Unregisters a previously registered event filter from this task.<T extends Event>
 voidremoveEventHandler(EventType<T> eventType, EventHandler<? super T> eventHandler)Unregisters a previously registered event handler from this task.voidreset()Resets the Service.voidrestart()Cancels any currently running Task, if any, and restarts this Service.protected voidrunning()A protected convenience method for subclasses, called whenever the state of the Service has transitioned to the RUNNING state.ReadOnlyBooleanPropertyrunningProperty()Gets the ReadOnlyBooleanProperty representing whether the Worker is running.protected voidscheduled()A protected convenience method for subclasses, called whenever the state of the Service has transitioned to the SCHEDULED state.protected <T extends Event>
 voidsetEventHandler(EventType<T> eventType, EventHandler<? super T> eventHandler)Sets the handler to use for this event type.voidsetExecutor(Executor value)Sets the value of the property executor.voidsetOnCancelled(EventHandler<WorkerStateEvent> value)The onCancelled event handler is called whenever the Task state transitions to the CANCELLED state.voidsetOnFailed(EventHandler<WorkerStateEvent> value)The onFailed event handler is called whenever the Task state transitions to the FAILED state.voidsetOnReady(EventHandler<WorkerStateEvent> value)The onReady event handler is called whenever the Task state transitions to the READY state.voidsetOnRunning(EventHandler<WorkerStateEvent> value)The onRunning event handler is called whenever the Task state transitions to the RUNNING state.voidsetOnScheduled(EventHandler<WorkerStateEvent> value)The onSchedule event handler is called whenever the Task state transitions to the SCHEDULED state.voidsetOnSucceeded(EventHandler<WorkerStateEvent> value)The onSucceeded event handler is called whenever the Task state transitions to the SUCCEEDED state.voidstart()Starts this Service.ReadOnlyObjectProperty<Worker.State>stateProperty()Gets the ReadOnlyObjectProperty representing the current state.protected voidsucceeded()A protected convenience method for subclasses, called whenever the state of the Service has transitioned to the SUCCEEDED state.ReadOnlyStringPropertytitleProperty()Gets the ReadOnlyStringProperty representing the title.ReadOnlyDoublePropertytotalWorkProperty()Gets the ReadOnlyDoubleProperty representing the maximum amount of work that needs to be done.ReadOnlyObjectProperty<V>valueProperty()Gets the ReadOnlyObjectProperty representing the value.ReadOnlyDoublePropertyworkDoneProperty()Gets the ReadOnlyDoubleProperty representing the current progress.
- 
Property Details- 
state- Specified by:
- statePropertyin interface- Worker<V>
- See Also:
- getState()
 
- 
value- Specified by:
- valuePropertyin interface- Worker<V>
- See Also:
- getValue()
 
- 
exception- Specified by:
- exceptionPropertyin interface- Worker<V>
- See Also:
- getException()
 
- 
workDone- Specified by:
- workDonePropertyin interface- Worker<V>
- See Also:
- getWorkDone()
 
- 
totalWork- Specified by:
- totalWorkPropertyin interface- Worker<V>
- See Also:
- getTotalWork()
 
- 
progress- Specified by:
- progressPropertyin interface- Worker<V>
- See Also:
- getProgress()
 
- 
running- Specified by:
- runningPropertyin interface- Worker<V>
- See Also:
- isRunning()
 
- 
message- Specified by:
- messagePropertyin interface- Worker<V>
- See Also:
- getMessage()
 
- 
title- Specified by:
- titlePropertyin interface- Worker<V>
- See Also:
- getTitle()
 
- 
executorThe executor to use for running this Service. If no executor is specified, then a new daemon thread will be created and used for running the Service using some default executor.- See Also:
- getExecutor(),- setExecutor(Executor)
 
- 
onReadyThe onReady event handler is called whenever the Task state transitions to the READY state.- Since:
- JavaFX 2.1
- See Also:
- getOnReady(),- setOnReady(EventHandler)
 
- 
onScheduledThe onSchedule event handler is called whenever the Task state transitions to the SCHEDULED state.- Since:
- JavaFX 2.1
- See Also:
- getOnScheduled(),- setOnScheduled(EventHandler)
 
- 
onRunningThe onRunning event handler is called whenever the Task state transitions to the RUNNING state.- Since:
- JavaFX 2.1
- See Also:
- getOnRunning(),- setOnRunning(EventHandler)
 
- 
onSucceededThe onSucceeded event handler is called whenever the Task state transitions to the SUCCEEDED state.- Since:
- JavaFX 2.1
- See Also:
- getOnSucceeded(),- setOnSucceeded(EventHandler)
 
- 
onCancelledThe onCancelled event handler is called whenever the Task state transitions to the CANCELLED state.- Since:
- JavaFX 2.1
- See Also:
- getOnCancelled(),- setOnCancelled(EventHandler)
 
- 
onFailedThe onFailed event handler is called whenever the Task state transitions to the FAILED state.- Since:
- JavaFX 2.1
- See Also:
- getOnFailed(),- setOnFailed(EventHandler)
 
 
- 
- 
Constructor Details- 
Serviceprotected Service()Create a new Service.
 
- 
- 
Method Details- 
getStateGets the value of the property state.
- 
statePropertyDescription copied from interface:WorkerGets the ReadOnlyObjectProperty representing the current state.- Specified by:
- statePropertyin interface- Worker<V>
- See Also:
- getState()
 
- 
getValueGets the value of the property value.
- 
valuePropertyDescription copied from interface:WorkerGets the ReadOnlyObjectProperty representing the value.- Specified by:
- valuePropertyin interface- Worker<V>
- See Also:
- getValue()
 
- 
getExceptionGets the value of the property exception.- Specified by:
- getExceptionin interface- Worker<V>
- Property description:
- Returns:
- the exception, if one occurred
 
- 
exceptionPropertyDescription copied from interface:WorkerGets the ReadOnlyObjectProperty representing any exception which occurred.- Specified by:
- exceptionPropertyin interface- Worker<V>
- See Also:
- getException()
 
- 
getWorkDonepublic final double getWorkDone()Gets the value of the property workDone.- Specified by:
- getWorkDonein interface- Worker<V>
- Property description:
- Returns:
- the amount of work done
- See Also:
- Worker.totalWorkProperty(),- Worker.progressProperty()
 
- 
workDonePropertyDescription copied from interface:WorkerGets the ReadOnlyDoubleProperty representing the current progress.- Specified by:
- workDonePropertyin interface- Worker<V>
- See Also:
- getWorkDone()
 
- 
getTotalWorkpublic final double getTotalWork()Gets the value of the property totalWork.- Specified by:
- getTotalWorkin interface- Worker<V>
- Property description:
- Returns:
- the total work to be done
- See Also:
- Worker.workDoneProperty(),- Worker.progressProperty()
 
- 
totalWorkPropertyDescription copied from interface:WorkerGets the ReadOnlyDoubleProperty representing the maximum amount of work that needs to be done. These "work units" have meaning to the Worker implementation, such as the number of bytes that need to be downloaded or the number of images to process or some other such metric.- Specified by:
- totalWorkPropertyin interface- Worker<V>
- See Also:
- getTotalWork()
 
- 
getProgresspublic final double getProgress()Gets the value of the property progress.- Specified by:
- getProgressin interface- Worker<V>
- Property description:
- Returns:
- the current progress
- See Also:
- Worker.workDoneProperty(),- Worker.totalWorkProperty()
 
- 
progressPropertyDescription copied from interface:WorkerGets the ReadOnlyDoubleProperty representing the progress.- Specified by:
- progressPropertyin interface- Worker<V>
- See Also:
- getProgress()
 
- 
isRunningpublic final boolean isRunning()Gets the value of the property running.
- 
runningPropertyDescription copied from interface:WorkerGets the ReadOnlyBooleanProperty representing whether the Worker is running.- Specified by:
- runningPropertyin interface- Worker<V>
- See Also:
- isRunning()
 
- 
getMessageGets the value of the property message.- Specified by:
- getMessagein interface- Worker<V>
- Property description:
- Returns:
- the current message
 
- 
messagePropertyDescription copied from interface:WorkerGets the ReadOnlyStringProperty representing the message.- Specified by:
- messagePropertyin interface- Worker<V>
- See Also:
- getMessage()
 
- 
getTitleGets the value of the property title.
- 
titlePropertyDescription copied from interface:WorkerGets the ReadOnlyStringProperty representing the title.- Specified by:
- titlePropertyin interface- Worker<V>
- See Also:
- getTitle()
 
- 
setExecutorSets the value of the property executor.- Property description:
- The executor to use for running this Service. If no executor is specified, then a new daemon thread will be created and used for running the Service using some default executor.
 
- 
getExecutorGets the value of the property executor.- Property description:
- The executor to use for running this Service. If no executor is specified, then a new daemon thread will be created and used for running the Service using some default executor.
 
- 
executorPropertyThe executor to use for running this Service. If no executor is specified, then a new daemon thread will be created and used for running the Service using some default executor.- See Also:
- getExecutor(),- setExecutor(Executor)
 
- 
onReadyPropertyThe onReady event handler is called whenever the Task state transitions to the READY state.- Since:
- JavaFX 2.1
- See Also:
- getOnReady(),- setOnReady(EventHandler)
 
- 
getOnReadyThe onReady event handler is called whenever the Task state transitions to the READY state.- Returns:
- the onReady event handler, if any
- Since:
- JavaFX 2.1
 
- 
setOnReadyThe onReady event handler is called whenever the Task state transitions to the READY state.- Parameters:
- value- the event handler, can be null to clear it
- Since:
- JavaFX 2.1
 
- 
readyprotected void ready()A protected convenience method for subclasses, called whenever the state of the Service has transitioned to the READY state. This method is invoked after the Service has been fully transitioned to the new state.- Since:
- JavaFX 2.1
 
- 
onScheduledPropertyThe onSchedule event handler is called whenever the Task state transitions to the SCHEDULED state.- Since:
- JavaFX 2.1
- See Also:
- getOnScheduled(),- setOnScheduled(EventHandler)
 
- 
getOnScheduledThe onSchedule event handler is called whenever the Task state transitions to the SCHEDULED state.- Returns:
- the onScheduled event handler, if any
- Since:
- JavaFX 2.1
 
- 
setOnScheduledThe onSchedule event handler is called whenever the Task state transitions to the SCHEDULED state.- Parameters:
- value- the event handler, can be null to clear it
- Since:
- JavaFX 2.1
 
- 
scheduledprotected void scheduled()A protected convenience method for subclasses, called whenever the state of the Service has transitioned to the SCHEDULED state. This method is invoked after the Service has been fully transitioned to the new state.- Since:
- JavaFX 2.1
 
- 
onRunningPropertyThe onRunning event handler is called whenever the Task state transitions to the RUNNING state.- Since:
- JavaFX 2.1
- See Also:
- getOnRunning(),- setOnRunning(EventHandler)
 
- 
getOnRunningThe onRunning event handler is called whenever the Task state transitions to the RUNNING state.- Returns:
- the onRunning event handler, if any
- Since:
- JavaFX 2.1
 
- 
setOnRunningThe onRunning event handler is called whenever the Task state transitions to the RUNNING state.- Parameters:
- value- the event handler, can be null to clear it
- Since:
- JavaFX 2.1
 
- 
runningprotected void running()A protected convenience method for subclasses, called whenever the state of the Service has transitioned to the RUNNING state. This method is invoked after the Service has been fully transitioned to the new state.- Since:
- JavaFX 2.1
 
- 
onSucceededPropertyThe onSucceeded event handler is called whenever the Task state transitions to the SUCCEEDED state.- Since:
- JavaFX 2.1
- See Also:
- getOnSucceeded(),- setOnSucceeded(EventHandler)
 
- 
getOnSucceededThe onSucceeded event handler is called whenever the Task state transitions to the SUCCEEDED state.- Returns:
- the onSucceeded event handler, if any
- Since:
- JavaFX 2.1
 
- 
setOnSucceededThe onSucceeded event handler is called whenever the Task state transitions to the SUCCEEDED state.- Parameters:
- value- the event handler, can be null to clear it
- Since:
- JavaFX 2.1
 
- 
succeededprotected void succeeded()A protected convenience method for subclasses, called whenever the state of the Service has transitioned to the SUCCEEDED state. This method is invoked after the Service has been fully transitioned to the new state.- Since:
- JavaFX 2.1
 
- 
onCancelledPropertyThe onCancelled event handler is called whenever the Task state transitions to the CANCELLED state.- Since:
- JavaFX 2.1
- See Also:
- getOnCancelled(),- setOnCancelled(EventHandler)
 
- 
getOnCancelledThe onCancelled event handler is called whenever the Task state transitions to the CANCELLED state.- Returns:
- the onCancelled event handler, if any
- Since:
- JavaFX 2.1
 
- 
setOnCancelledThe onCancelled event handler is called whenever the Task state transitions to the CANCELLED state.- Parameters:
- value- the event handler, can be null to clear it
- Since:
- JavaFX 2.1
 
- 
cancelledprotected void cancelled()A protected convenience method for subclasses, called whenever the state of the Service has transitioned to the CANCELLED state. This method is invoked after the Service has been fully transitioned to the new state.- Since:
- JavaFX 2.1
 
- 
onFailedPropertyThe onFailed event handler is called whenever the Task state transitions to the FAILED state.- Since:
- JavaFX 2.1
- See Also:
- getOnFailed(),- setOnFailed(EventHandler)
 
- 
getOnFailedThe onFailed event handler is called whenever the Task state transitions to the FAILED state.- Returns:
- the onFailed event handler, if any
- Since:
- JavaFX 2.1
 
- 
setOnFailedThe onFailed event handler is called whenever the Task state transitions to the FAILED state.- Parameters:
- value- the event handler, can be null to clear it
- Since:
- JavaFX 2.1
 
- 
failedprotected void failed()A protected convenience method for subclasses, called whenever the state of the Service has transitioned to the FAILED state. This method is invoked after the Service has been fully transitioned to the new state.- Since:
- JavaFX 2.1
 
- 
cancelpublic boolean cancel()Cancels any currently running Task, if any. The state will be set to CANCELLED.
- 
restartpublic void restart()Cancels any currently running Task, if any, and restarts this Service. The state will be reset to READY prior to execution. This method should only be called on the FX application thread.
- 
resetpublic void reset()Resets the Service. May only be called while in one of the finish states, that is, SUCCEEDED, FAILED, or CANCELLED, or when READY. This method should only be called on the FX application thread.
- 
startpublic void start()Starts this Service. The Service must be in the READY state to succeed in this call. This method should only be called on the FX application thread.
- 
executeTaskUses the executordefined on this Service to execute the given task. If theexecutoris null, then a default executor is used which will create a new daemon thread on which to execute this task.This method is intended only to be called by the Service implementation. - Parameters:
- task- a non-null task to execute
- Since:
- JavaFX 2.1
 
- 
addEventHandlerpublic final <T extends Event> void addEventHandler(EventType<T> eventType, EventHandler<? super T> eventHandler)Registers an event handler to this task. Any event filters are first processed, then the specified onFoo event handlers, and finally any event handlers registered by this method. As with other events in the scene graph, if an event is consumed, it will not continue dispatching.- Type Parameters:
- T- the specific event class of the handler
- Parameters:
- eventType- the type of the events to receive by the handler
- eventHandler- the handler to register
- Throws:
- NullPointerException- if the event type or handler is null
- Since:
- JavaFX 2.1
 
- 
removeEventHandlerpublic final <T extends Event> void removeEventHandler(EventType<T> eventType, EventHandler<? super T> eventHandler)Unregisters a previously registered event handler from this task. One handler might have been registered for different event types, so the caller needs to specify the particular event type from which to unregister the handler.- Type Parameters:
- T- the specific event class of the handler
- Parameters:
- eventType- the event type from which to unregister
- eventHandler- the handler to unregister
- Throws:
- NullPointerException- if the event type or handler is null
- Since:
- JavaFX 2.1
 
- 
addEventFilterpublic final <T extends Event> void addEventFilter(EventType<T> eventType, EventHandler<? super T> eventFilter)Registers an event filter to this task. Registered event filters get an event before any associated event handlers.- Type Parameters:
- T- the specific event class of the filter
- Parameters:
- eventType- the type of the events to receive by the filter
- eventFilter- the filter to register
- Throws:
- NullPointerException- if the event type or filter is null
- Since:
- JavaFX 2.1
 
- 
removeEventFilterpublic final <T extends Event> void removeEventFilter(EventType<T> eventType, EventHandler<? super T> eventFilter)Unregisters a previously registered event filter from this task. One filter might have been registered for different event types, so the caller needs to specify the particular event type from which to unregister the filter.- Type Parameters:
- T- the specific event class of the filter
- Parameters:
- eventType- the event type from which to unregister
- eventFilter- the filter to unregister
- Throws:
- NullPointerException- if the event type or filter is null
- Since:
- JavaFX 2.1
 
- 
setEventHandlerprotected final <T extends Event> void setEventHandler(EventType<T> eventType, EventHandler<? super T> eventHandler)Sets the handler to use for this event type. There can only be one such handler specified at a time. This handler is guaranteed to be called first. This is used for registering the user-defined onFoo event handlers.- Type Parameters:
- T- the specific event class of the handler
- Parameters:
- eventType- the event type to associate with the given eventHandler
- eventHandler- the handler to register, or null to unregister
- Throws:
- NullPointerException- if the event type is null
- Since:
- JavaFX 2.1
 
- 
fireEventFires the specified event. Any event filter encountered will be notified and can consume the event. If not consumed by the filters, the event handlers on this task are notified. If these don't consume the event either, then all event handlers are called and can consume the event.This method must be called on the FX user thread. - Parameters:
- event- the event to fire
- Since:
- JavaFX 2.1
 
- 
buildEventDispatchChainDescription copied from interface:EventTargetConstruct an event dispatch chain for this target. The event dispatch chain contains event dispatchers which might be interested in processing of events targeted at thisEventTarget. This event target is not automatically added to the chain, so if it wants to process events, it needs to add anEventDispatcherfor itself to the chain.In the case the event target is part of some hierarchy, the chain for it is usually built from event dispatchers collected from the root of the hierarchy to the event target. The event dispatch chain is constructed by modifications to the provided initial event dispatch chain. The returned chain should have the initial chain at its end so the dispatchers should be prepended to the initial chain. The caller shouldn't assume that the initial chain remains unchanged nor that the returned value will reference a different chain. - Specified by:
- buildEventDispatchChainin interface- EventTarget
- Parameters:
- tail- the initial chain to build from
- Returns:
- the resulting event dispatch chain for this target
 
- 
createTaskInvoked after the Service is started on the JavaFX Application Thread. Implementations should save off any state into final variables prior to creating the Task, since accessing properties defined on the Service within the background thread code of the Task will result in exceptions. For example:protected Task createTask() { final String url = myService.getUrl(); return new Task<String>() { protected String call() { URL u = new URL("http://www.oracle.com"); BufferedReader in = new BufferedReader( new InputStreamReader(u.openStream())); String result = in.readLine(); in.close(); return result; } } }If the Task is a pre-defined class (as opposed to being an anonymous class), and if it followed the recommended best-practice, then there is no need to save off state prior to constructing the Task since its state is completely provided in its constructor. protected Task createTask() { // This is safe because getUrl is called on the FX Application // Thread and the FirstLineReaderTasks stores it as an // immutable property return new FirstLineReaderTask(myService.getUrl()); }- Returns:
- the Task to execute
 
 
-