Top Description Fields Constructors Methods
rx.internal.schedulers

public Class NewThreadWorker

extends Worker
implements Subscription
Class Inheritance
All Implemented Interfaces
rx.Subscription
Known Direct Subclasses
rx.internal.schedulers.CachedThreadScheduler.ThreadWorker, rx.internal.schedulers.EventLoopsScheduler.PoolWorker
Imports
java.lang.reflect.*, java.util.*, java.util.concurrent.*, java.util.concurrent.atomic.AtomicReference, rx.*, rx.exceptions.Exceptions, rx.functions.Action0, rx.internal.util.*, rx.plugins.*, rx.subscriptions.*

Represents a Scheduler.Worker that runs on its own unique and single-threaded ScheduledExecutorService created via Executors.

Field Summary

Modifier and TypeField and Description
private static volatile Object
private final ScheduledExecutorService
private static final ConcurrentHashMap<ScheduledThreadPoolExecutor, ScheduledThreadPoolExecutor>
private static final String
FREQUENCY_KEY

The purge frequency in milliseconds.

pack-priv volatile boolean
private static final AtomicReference<ScheduledExecutorService>
private static final String
PURGE_FORCE_KEY

Force the use of purge (true/false).

public static final int
PURGE_FREQUENCY

The purge frequency in milliseconds.

private static final String
private static final Object
SET_REMOVE_ON_CANCEL_POLICY_METHOD_NOT_SUPPORTED

Possible value of cachedSetRemoveOnCancelPolicyMethod which means that cancel policy is not supported.

private static final boolean

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static void
deregisterExecutor(ScheduledExecutorService
a scheduled thread pool executor instance
service
)

Deregisters the executor service.

pack-priv static Method

Returns:

"setRemoveOnCancelPolicy(boolean)" Method or null if required Method was not found.
findSetRemoveOnCancelPolicyMethod
(ScheduledExecutorService
whose class will be used to search for required method.
executor
)

Tries to find "setRemoveOnCancelPolicy(boolean)" method in the class of passed executor.

public boolean
isUnsubscribed()

Implements rx.Subscription.isUnsubscribed.

Indicates whether this Subscription is currently unsubscribed.
pack-priv static void
purgeExecutors()

Purges each registered executor and eagerly evicts shutdown executors.

public static void
registerExecutor(ScheduledThreadPoolExecutor
a scheduled thread pool executor instance
service
)

Registers the given executor service and starts the purge thread if not already started.

public Subscription
schedule(final Action0
Action to schedule
action
)

Implements abstract rx.Scheduler.Worker.schedule.

Schedules an Action for execution.
public Subscription
schedule(final Action0
the Action to schedule
action
,
long
time to wait before executing the action; non-positive values indicate an non-delayed schedule
delayTime
,
TimeUnit
the time unit of delayTime
unit
)

Implements abstract rx.Scheduler.Worker.schedule.

Schedules an Action for execution at some point in the future.
public ScheduledAction

Returns:

the wrapper ScheduledAction
scheduleActual
(final Action0
the action to wrap and schedule
action
,
long
the delay in execution
delayTime
,
TimeUnit
the time unit of the delay
unit
)

Schedules the given action by wrapping it into a ScheduledAction on the underlying ExecutorService, returning the ScheduledAction.

public ScheduledAction
scheduleActual(final Action0 action, long delayTime, TimeUnit unit, CompositeSubscription parent)

public ScheduledAction
scheduleActual(final Action0 action, long delayTime, TimeUnit unit, SubscriptionList parent)

public static boolean

Returns:

true if the policy was successfully enabled
tryEnableCancelPolicy
(ScheduledExecutorService
the executor to call setRemoveOnCancelPolicy if available.
executor
)

Tries to enable the Java 7+ setRemoveOnCancelPolicy.

public void
unsubscribe()

Implements rx.Subscription.unsubscribe.

Stops the receipt of notifications on the Subscriber that was registered when this Subscription was received.
Inherited from rx.Scheduler.Worker:
nowschedulePeriodically

Field Detail

cachedSetRemoveOnCancelPolicyMethodback to summary
private static volatile Object cachedSetRemoveOnCancelPolicyMethod

Improves performance of tryEnableCancelPolicy(ScheduledExecutorService). Also, it works even for inheritance: Method of base class can be invoked on the instance of child class.

executorback to summary
private final ScheduledExecutorService executor
EXECUTORSback to summary
private static final ConcurrentHashMap<ScheduledThreadPoolExecutor, ScheduledThreadPoolExecutor> EXECUTORS
FREQUENCY_KEYback to summary
private static final String FREQUENCY_KEY

The purge frequency in milliseconds.

isUnsubscribedback to summary
pack-priv volatile boolean isUnsubscribed
PURGEback to summary
private static final AtomicReference<ScheduledExecutorService> PURGE
PURGE_FORCE_KEYback to summary
private static final String PURGE_FORCE_KEY

Force the use of purge (true/false).

PURGE_FREQUENCYback to summary
public static final int PURGE_FREQUENCY

The purge frequency in milliseconds.

PURGE_THREAD_PREFIXback to summary
private static final String PURGE_THREAD_PREFIX
SET_REMOVE_ON_CANCEL_POLICY_METHOD_NOT_SUPPORTEDback to summary
private static final Object SET_REMOVE_ON_CANCEL_POLICY_METHOD_NOT_SUPPORTED

Possible value of cachedSetRemoveOnCancelPolicyMethod which means that cancel policy is not supported.

SHOULD_TRY_ENABLE_CANCEL_POLICYback to summary
private static final boolean SHOULD_TRY_ENABLE_CANCEL_POLICY

Constructor Detail

NewThreadWorkerback to summary
public NewThreadWorker(ThreadFactory threadFactory)

Method Detail

deregisterExecutorback to summary
public static void deregisterExecutor(ScheduledExecutorService service)

Deregisters the executor service.

public visibility reason: called from other package(s) within RxJava

Parameters
service:ScheduledExecutorService

a scheduled thread pool executor instance

findSetRemoveOnCancelPolicyMethodback to summary
pack-priv static Method findSetRemoveOnCancelPolicyMethod(ScheduledExecutorService executor)

Tries to find "setRemoveOnCancelPolicy(boolean)" method in the class of passed executor.

Parameters
executor:ScheduledExecutorService

whose class will be used to search for required method.

Returns:Method

"setRemoveOnCancelPolicy(boolean)" Method or null if required Method was not found.

isUnsubscribedback to summary
public boolean isUnsubscribed()

Implements rx.Subscription.isUnsubscribed.

Doc from rx.Subscription.isUnsubscribed.

Indicates whether this Subscription is currently unsubscribed.

Returns:boolean

true if this Subscription is currently unsubscribed, false otherwise

Annotations
@Override
purgeExecutorsback to summary
pack-priv static void purgeExecutors()

Purges each registered executor and eagerly evicts shutdown executors.

registerExecutorback to summary
public static void registerExecutor(ScheduledThreadPoolExecutor service)

Registers the given executor service and starts the purge thread if not already started.

public visibility reason: called from other package(s) within RxJava

Parameters
service:ScheduledThreadPoolExecutor

a scheduled thread pool executor instance

scheduleback to summary
public Subscription schedule(final Action0 action)

Implements abstract rx.Scheduler.Worker.schedule.

Doc from rx.Scheduler.Worker.schedule.

Schedules an Action for execution.

Parameters
action:Action0

Action to schedule

Returns:Subscription

a subscription to be able to prevent or cancel the execution of the action

Annotations
@Override
scheduleback to summary
public Subscription schedule(final Action0 action, long delayTime, TimeUnit unit)

Implements abstract rx.Scheduler.Worker.schedule.

Doc from rx.Scheduler.Worker.schedule.

Schedules an Action for execution at some point in the future.

Note to implementors: non-positive delayTime should be regarded as non-delayed schedule, i.e., as if the schedule(rx.functions.Action0) was called.

Parameters
action:Action0

the Action to schedule

delayTime:long

time to wait before executing the action; non-positive values indicate an non-delayed schedule

unit:TimeUnit

the time unit of delayTime

Returns:Subscription

a subscription to be able to prevent or cancel the execution of the action

Annotations
@Override
scheduleActualback to summary
public ScheduledAction scheduleActual(final Action0 action, long delayTime, TimeUnit unit)

Schedules the given action by wrapping it into a ScheduledAction on the underlying ExecutorService, returning the ScheduledAction.

Parameters
action:Action0

the action to wrap and schedule

delayTime:long

the delay in execution

unit:TimeUnit

the time unit of the delay

Returns:ScheduledAction

the wrapper ScheduledAction

scheduleActualback to summary
public ScheduledAction scheduleActual(final Action0 action, long delayTime, TimeUnit unit, CompositeSubscription parent)
scheduleActualback to summary
public ScheduledAction scheduleActual(final Action0 action, long delayTime, TimeUnit unit, SubscriptionList parent)
tryEnableCancelPolicyback to summary
public static boolean tryEnableCancelPolicy(ScheduledExecutorService executor)

Tries to enable the Java 7+ setRemoveOnCancelPolicy.

public visibility reason: called from other package(s) within RxJava. If the method returns false, the registerExecutor(ScheduledThreadPoolExecutor) may be called to enable the backup option of purging the executors.

Parameters
executor:ScheduledExecutorService

the executor to call setRemoveOnCancelPolicy if available.

Returns:boolean

true if the policy was successfully enabled

unsubscribeback to summary
public void unsubscribe()

Implements rx.Subscription.unsubscribe.

Doc from rx.Subscription.unsubscribe.

Stops the receipt of notifications on the Subscriber that was registered when this Subscription was received.

This allows deregistering an Subscriber before it has finished receiving all events (i.e. before onCompleted is called).

Annotations
@Override