pub struct SharedEventQueue { /* private fields */ }Expand description
A queue of the events of many subscriptions, each attached with a tag (EventQueue.create()): a poll returns
each event with the tag of its subscription. Its Executor runs the work of models, of the instrument profile
collector and of promise handlers inside the polls.
A subscription leaves the queue only by being closed; the queue stays open then. The queue closes when
close is called, or when it and every executor it lent are dropped. The queue can be shared by
threads, but poll it from one thread at a time.
Implementations§
Sourcepub fn attach<E: SubscriptionItem>(
&self,
subscription: &DXFeedSubscription<E>,
tag: i64,
) -> Result<()>
pub fn attach<E: SubscriptionItem>( &self, subscription: &DXFeedSubscription<E>, tag: i64, ) -> Result<()>
Attaches subscription, whose events then come with tag; tags need not be unique. A subscription of any
endpoint may be attached.
Attach it before the symbols are added to a subscription attached to a feed. A subscription with an executor or
a queue, or one attached to a feed that has symbols, is Error::Java of java.lang.IllegalStateException. A
closed subscription, or one attached to a closed queue, is attached as left: its events are dropped and counted.
On a subscription that has symbols, add its event listeners first.
Sourcepub fn get_executor(&self) -> Result<Executor>
pub fn get_executor(&self) -> Result<Executor>
The executor of the queue: the work posted to it runs inside the polls, on the polling thread. Give it to the
models, the collector, the endpoint builder or Promise::when_done_async.
The executor keeps the queue open as the queue itself does; the executor of a closed queue runs the work at
once, on the posting thread, without calling the listeners of the application. A subscription that has it as
its executor gets its events by its listeners, not by the polls. The calls of a model that notify on the
calling thread (set_symbol, clear) call its listener there, not in a poll.
For a subscription that has it as its executor, also inherited from an endpoint built with it,
DXFeed::detach_subscription_and_clear and
DXEndpoint::close_and_await_termination wait until a poll
runs the pending work or the queue is closed: never call them on the polling thread.
Sourcepub fn poll(
&self,
timeout: Option<Duration>,
limit: usize,
) -> Result<PollResult<Vec<(i64, Event)>>>
pub fn poll( &self, timeout: Option<Duration>, limit: usize, ) -> Result<PollResult<Vec<(i64, Event)>>>
Waits for the events of the attached subscriptions and the work of the executor, and returns the events with
their tags, as EventQueue::poll does; the listeners of the subscriptions and of the models on the queue run
in the poll, on this thread. PollResult::NoEvents also comes when only the work of the executor ran.
Inside a listener or a callback of the crate it returns Error::InCallback.
Sourcepub fn wake_up(&self) -> Result<()>
pub fn wake_up(&self) -> Result<()>
Makes the poll in progress, or the next one, return PollResult::NoEvents at once unless it has events;
several wake-ups before a poll wake up one poll.
Sourcepub fn close(&self) -> Result<()>
pub fn close(&self) -> Result<()>
Closes the queue, as EventQueue::close does; the pending work of the executor runs on this thread without
calling the listeners of the application, and its later work runs at once on the posting thread.
Sourcepub fn get_dropped_events(&self) -> Result<i64>
pub fn get_dropped_events(&self) -> Result<i64>
The number of the events of the attached subscriptions that were lost, which never decreases; it is one for
the whole queue, see DXFeedSubscription::get_total_dropped_events for each subscription.
Sourcepub unsafe fn set_ready_signal(&self, signal: ReadySignal) -> Result<()>
pub unsafe fn set_ready_signal(&self, signal: ReadySignal) -> Result<()>
Sets, replaces or removes the ready signal of the queue, as EventQueue::set_ready_signal does; the work of
the executor also signals. Needs the cargo feature experimental.
§Safety
As for EventQueue::set_ready_signal: the object must stay open until another signal replaces it,
ReadySignal::None removes it, close returns or a poll returns PollResult::Closed. A
live executor of the queue keeps it open, so dropping the queue alone does not stop the writes.
Sourcepub fn into_stream(self) -> Result<TaggedEventStream>
pub fn into_stream(self) -> Result<TaggedEventStream>
Turns the queue into a stream of owned events with their tags. The subscriptions already attached stay
attached; attach more through TaggedEventStream::queue.
A thread that cannot be started is Error::Io; the queue is closed then.