Struct zenoh_protocol::session::SessionManagerConfig[][src]

pub struct SessionManagerConfig {
    pub version: u8,
    pub whatami: WhatAmI,
    pub id: PeerId,
    pub handler: Arc<dyn SessionHandler + Send + Sync>,
}

Examples

use async_std::sync::Arc;
use async_trait::async_trait;
use zenoh_protocol::core::{PeerId, WhatAmI, whatami};
use zenoh_protocol::session::{DummySessionEventHandler, SessionEventHandler, Session, SessionHandler, SessionManager, SessionManagerConfig, SessionManagerOptionalConfig};

use zenoh_util::core::ZResult;

// Create my session handler to be notified when a new session is initiated with me
struct MySH;

impl MySH {
    fn new() -> MySH {
        MySH
    }
}

#[async_trait]
impl SessionHandler for MySH {
    async fn new_session(&self,
        _session: Session
    ) -> ZResult<Arc<dyn SessionEventHandler + Send + Sync>> {
        Ok(Arc::new(DummySessionEventHandler::new()))
    }
}

// Create the SessionManager
let config = SessionManagerConfig {
    version: 0,
    whatami: whatami::PEER,
    id: PeerId::from(uuid::Uuid::new_v4()),
    handler: Arc::new(MySH::new())
};
let manager = SessionManager::new(config, None);

// Create the SessionManager with optional configuration
let config = SessionManagerConfig {
    version: 0,
    whatami: whatami::PEER,
    id: PeerId::from(uuid::Uuid::new_v4()),
    handler: Arc::new(MySH::new())
};
// Setting a value to None means to use the default value
let opt_config = SessionManagerOptionalConfig {
    lease: Some(1_000),         // Set the default lease to 1s
    keep_alive: Some(100),      // Set the default keep alive interval to 100ms
    sn_resolution: None,        // Use the default sequence number resolution
    batch_size: None,           // Use the default batch size
    timeout: Some(10_000),      // Timeout of 10s when opening a session
    retries: Some(3),           // Tries to open a session 3 times before failure
    max_sessions: Some(5),      // Accept any number of sessions
    max_links: None,            // Allow any number of links in a single session
    peer_authenticator: None,   // Accept any incoming session
    link_authenticator: None,   // Accept any incoming link
};
let manager_opt = SessionManager::new(config, Some(opt_config));

Fields

version: u8whatami: WhatAmIid: PeerIdhandler: Arc<dyn SessionHandler + Send + Sync>

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,