-
- All Implemented Interfaces:
-
com.tds.common.reactor.Subscription
public class NewThreadWorker extends Scheduler.Worker implements Subscription
Represents a Scheduler.Worker that runs on its own unique and single-threaded ScheduledExecutorService created via Executors.
-
-
Field Summary
Fields Modifier and Type Field Description volatile boolean
isUnsubscribed
public final static int
PURGE_FREQUENCY
-
Constructor Summary
Constructors Constructor Description NewThreadWorker(ThreadFactory threadFactory)
-
Method Summary
Modifier and Type Method Description boolean
isUnsubscribed()
Indicates whether this {@code Subscription}
is currently unsubscribed.static void
registerExecutor(ScheduledThreadPoolExecutor service)
Registers the given executor service and starts the purge thread if not already started. static void
deregisterExecutor(ScheduledExecutorService service)
Deregisters the executor service. static boolean
tryEnableCancelPolicy(ScheduledExecutorService executor)
Tries to enable the Java 7+ setRemoveOnCancelPolicy. Subscription
schedule(Action0 action)
Schedules an Action for execution. Subscription
schedule(Action0 action, long delayTime, TimeUnit unit)
Schedules an Action for execution at some point in the future. ScheduledAction
scheduleActual(Action0 action, long delayTime, TimeUnit unit)
Schedules the given action by wrapping it into a ScheduledAction on theunderlying ExecutorService, returning the ScheduledAction. ScheduledAction
scheduleActual(Action0 action, long delayTime, TimeUnit unit, CompositeSubscription parent)
ScheduledAction
scheduleActual(Action0 action, long delayTime, TimeUnit unit, SubscriptionList parent)
void
unsubscribe()
Stops the receipt of notifications on the Subscriber that was registered when this Subscriptionwas received. -
-
Constructor Detail
-
NewThreadWorker
NewThreadWorker(ThreadFactory threadFactory)
-
-
Method Detail
-
isUnsubscribed
boolean isUnsubscribed()
Indicates whether this
{@code Subscription}
is currently unsubscribed.
-
registerExecutor
static void registerExecutor(ScheduledThreadPoolExecutor service)
Registers the given executor service and starts the purge thread if not already started.
{@code public}
visibility reason: called from other package(s) within RxJava- Parameters:
service
- a scheduled thread pool executor instance
-
deregisterExecutor
static void deregisterExecutor(ScheduledExecutorService service)
Deregisters the executor service.
{@code public}
visibility reason: called from other package(s) within RxJava- Parameters:
service
- a scheduled thread pool executor instance
-
tryEnableCancelPolicy
static boolean tryEnableCancelPolicy(ScheduledExecutorService executor)
Tries to enable the Java 7+ setRemoveOnCancelPolicy.
{@code public}
visibility reason: called from other package(s) within RxJava.If the method returns false, the registerExecutor maybe called to enable the backup option of purging the executors.- Parameters:
executor
- the executor to call setRemoveOnCancelPolicy if available.
-
schedule
Subscription schedule(Action0 action)
Schedules an Action for execution.
- Parameters:
action
- Action to schedule
-
schedule
Subscription schedule(Action0 action, long delayTime, TimeUnit unit)
Schedules an Action for execution at some point in the future.
Note to implementors: non-positive
{@code delayTime}
should be regarded as non-delayed schedule, i.e.,as if the schedule was called.- Parameters:
action
- the Action to scheduledelayTime
- time to wait before executing the action; non-positive values indicate an non-delayedscheduleunit
- the time unit of{@code delayTime}
-
scheduleActual
ScheduledAction scheduleActual(Action0 action, long delayTime, TimeUnit unit)
Schedules the given action by wrapping it into a ScheduledAction on theunderlying ExecutorService, returning the ScheduledAction.
- Parameters:
action
- the action to wrap and scheduledelayTime
- the delay in executionunit
- the time unit of the delay
-
scheduleActual
ScheduledAction scheduleActual(Action0 action, long delayTime, TimeUnit unit, CompositeSubscription parent)
-
scheduleActual
ScheduledAction scheduleActual(Action0 action, long delayTime, TimeUnit unit, SubscriptionList parent)
-
unsubscribe
void unsubscribe()
Stops the receipt of notifications on the Subscriber that was registered when this Subscriptionwas received.
This allows deregistering an Subscriber before it has finished receiving all events (i.e. beforeonCompleted is called).
-
-
-
-