Skip to main content

SharedEventQueue

Struct SharedEventQueue 

Source
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§

Source§

impl SharedEventQueue

Source

pub fn new() -> Result<Self>

Creates a queue with no subscription.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source§

impl SharedEventQueue

Source

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.

Trait Implementations§

Source§

impl Debug for SharedEventQueue

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.