pub struct FixApplicationHandle { /* private fields */ }Expand description
A handle on a FIX engine instance.
The FixApplicationHandle allows for requesting the basic operations of starting the FIX connection, sending
a message to the peer, and ending the connection.
The handle offers asynchronous and synchronous APIs for these operations. As well as functions
that return immedietly with a oneshot::Receiver that will eventually return the result of the
operation.
The underlying engine could stop running at any moment for a variety of reasons. Only until you
attempt an operation, will you learn the engine has stopped by receiving an
ApplicationError::SessionEnded.
FixApplicationHandle impl’s Clone, Send and Sync and therefore multiple
copies of the handle can be made and passed to different threads that can all request messages
to be sent. Only one thread has to call end for the engine to terminate the connection.
§Example - Multiple Threads
use forgefix::{
SessionSettings, FixApplicationInitiator, ApplicationError
};
use forgefix::fix::{encode::MessageBuilder, generated::MsgType};
let (handle, mut receiver) = FixApplicationInitiator::build(settings)?
.initiate()
.await?;
receiver.close();
// FixApplicationHandle can be cloned
let handle1 = handle.clone();
let handle2 = handle.clone();
// FixApplicationHandle clones can be sent across threads and tasks
let h1 = tokio::spawn(async move {
// thread logic here...
let builder = MessageBuilder::new(
&handle1.begin_string(),
MsgType::ORDER_SINGLE.into()
);
handle1.send_message_async(builder).await
// ...
});
// send to multiple tasks...
let h2 = tokio::spawn(async move {
let builder = MessageBuilder::new(
&handle2.begin_string(),
MsgType::ORDER_SINGLE.into()
);
handle2.send_message_async(builder).await
});
// wait for all threads to finish...
let (res1, res2) = tokio::join!(h1, h2);
res1??;
res2??;
// end the FIX connection
handle.end_async().await?;
Implementations§
Source§impl FixApplicationHandle
impl FixApplicationHandle
Sourcepub fn start(&self) -> Result<Receiver<bool>, ApplicationError>
pub fn start(&self) -> Result<Receiver<bool>, ApplicationError>
Send a request to the engine to start the connection and return immediately.
The receiver will eventually yield true if a connection was successfully established, or
false othersize.
Sourcepub async fn start_async(&self) -> Result<(), ApplicationError>
pub async fn start_async(&self) -> Result<(), ApplicationError>
Send a request to the engine to start the connection and await asynchronously.
Sourcepub fn start_sync(&self) -> Result<(), ApplicationError>
pub fn start_sync(&self) -> Result<(), ApplicationError>
Send a request to the engine to start a connection, and block until a result is returned.
Sourcepub fn send_message(
&self,
builder: MessageBuilder,
) -> Result<Receiver<bool>, ApplicationError>
pub fn send_message( &self, builder: MessageBuilder, ) -> Result<Receiver<bool>, ApplicationError>
Send a request to the engine to send the message in the MessageBuilder to the peer, and return immediately.
If the request was successfully sent to the engine, a oneshot::Receiver will be
returned.
The receiver will yield true once the message has successfully sent over the TCP
connection. It will yeild false if a message cannot be sent.
Sourcepub async fn send_message_async(
&self,
builder: MessageBuilder,
) -> Result<(), ApplicationError>
pub async fn send_message_async( &self, builder: MessageBuilder, ) -> Result<(), ApplicationError>
Send a request to the engine to send the message in builder and await asynchronously.
Sourcepub fn send_message_sync(
&self,
builder: MessageBuilder,
) -> Result<(), ApplicationError>
pub fn send_message_sync( &self, builder: MessageBuilder, ) -> Result<(), ApplicationError>
Send a request to the engine to send the message in builder and block until a result is
returned.
Sourcepub fn end(&self) -> Result<Receiver<bool>, ApplicationError>
pub fn end(&self) -> Result<Receiver<bool>, ApplicationError>
Send a request to the engine to end the FIX connection, and return immediately.
If the request was successfully send to the engine, a oneshot::Receiver will be
returned.
The receiver will yield true is the FIX connection is over, and ended without any issues.
Otherwise it will be false.
Sourcepub async fn end_async(&self) -> Result<(), ApplicationError>
pub async fn end_async(&self) -> Result<(), ApplicationError>
Send a request to the engine to end the FIX connection, and await asynchronously.
Sourcepub fn end_sync(&self) -> Result<(), ApplicationError>
pub fn end_sync(&self) -> Result<(), ApplicationError>
Send a request to the engine to end the FIX connection, and block until a result is returned.
Sourcepub fn begin_string(&self) -> Arc<String>
pub fn begin_string(&self) -> Arc<String>
Get the BeginString(8) of this FIX Session. Should generally be "FIX.4.2".
Trait Implementations§
Source§impl Clone for FixApplicationHandle
impl Clone for FixApplicationHandle
Source§fn clone(&self) -> FixApplicationHandle
fn clone(&self) -> FixApplicationHandle
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more