Spec-Zone .ru
спецификации, руководства, описания, API
001/*
002 * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation.  Oracle designates this
008 * particular file as subject to the "Classpath" exception as provided
009 * by Oracle in the LICENSE file that accompanied this code.
010 *
011 * This code is distributed in the hope that it will be useful, but WITHOUT
012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
014 * version 2 for more details (a copy is included in the LICENSE file that
015 * accompanied this code).
016 *
017 * You should have received a copy of the GNU General Public License version
018 * 2 along with this work; if not, write to the Free Software Foundation,
019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020 *
021 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
022 * or visit www.oracle.com if you need additional information or have any
023 * questions.
024 */
025
026package javafx.concurrent;
027
028import javafx.event.Event;
029import javafx.event.EventTarget;
030import javafx.event.EventType;
031
032/**
033 * An event which occurs whenever the state changes on a Worker. Both
034 * {@link Task} and {@link Service} support listening to state events.
035 */
036public class WorkerStateEvent extends Event {
037    /**
038     * Common supertype for all worker state event types.
039     */
040    public static final EventType<WorkerStateEvent> ANY =
041            new EventType<WorkerStateEvent>(Event.ANY, "WORKER_STATE");
042
043    /**
044     * This event occurs when the state of a Worker implementation has
045     * transitioned to the READY state.
046     */
047    public static final EventType<WorkerStateEvent> WORKER_STATE_READY =
048            new EventType<WorkerStateEvent>(WorkerStateEvent.ANY, "WORKER_STATE_READY");
049
050    /**
051     * This event occurs when the state of a Worker implementation has
052     * transitioned to the SCHEDULED state.
053     */
054    public static final EventType<WorkerStateEvent> WORKER_STATE_SCHEDULED =
055            new EventType<WorkerStateEvent>(WorkerStateEvent.ANY, "WORKER_STATE_SCHEDULED");
056
057    /**
058     * This event occurs when the state of a Worker implementation has
059     * transitioned to the RUNNING state.
060     */
061    public static final EventType<WorkerStateEvent> WORKER_STATE_RUNNING =
062            new EventType<WorkerStateEvent>(WorkerStateEvent.ANY, "WORKER_STATE_RUNNING");
063
064    /**
065     * This event occurs when the state of a Worker implementation has
066     * transitioned to the SUCCEEDED state.
067     */
068    public static final EventType<WorkerStateEvent> WORKER_STATE_SUCCEEDED =
069            new EventType<WorkerStateEvent>(WorkerStateEvent.ANY, "WORKER_STATE_SUCCEEDED");
070
071    /**
072     * This event occurs when the state of a Worker implementation has
073     * transitioned to the CANCELLED state.
074     */
075    public static final EventType<WorkerStateEvent> WORKER_STATE_CANCELLED =
076            new EventType<WorkerStateEvent>(WorkerStateEvent.ANY, "WORKER_STATE_CANCELLED");
077
078    /**
079     * This event occurs when the state of a Worker implementation has
080     * transitioned to the FAILED state.
081     */
082    public static final EventType<WorkerStateEvent> WORKER_STATE_FAILED =
083            new EventType<WorkerStateEvent>(WorkerStateEvent.ANY, "WORKER_STATE_FAILED");
084
085    /**
086     * Create a new WorkerStateEvent. Specify the worker and the event type.
087     *
088     * @param worker The Worker which is firing the event. The Worker really
089     *               should be an EventTarget, otherwise the EventTarget
090     *               for the event will be null.
091     * @param eventType The type of event. This should not be null.
092     */
093    public WorkerStateEvent(Worker worker, EventType<? extends WorkerStateEvent> eventType) {
094        super(worker, worker instanceof EventTarget ? (EventTarget) worker : null, eventType);
095    }
096
097    @Override public Worker getSource() {
098        return (Worker) super.getSource();
099    }
100}