Session

Struct Session 

Source
pub struct Session { /* private fields */ }
Expand description

Represents a connection to Tsurugi server.

Note: Should invoke Self::close before Self::drop to dispose the session.

§Examples

use tsubakuro_rust_core::prelude::*;

async fn example() -> Result<(), TgError> {
    let mut connection_option = ConnectionOption::new();
    connection_option.set_endpoint_url("tcp://localhost:12345");
    connection_option.set_application_name("Tsubakuro/Rust example");
    connection_option.set_session_label("example session");
    connection_option.set_default_timeout(std::time::Duration::from_secs(10));

    let session = Session::connect(&connection_option).await?;
    let client: SqlClient = session.make_client();

    session.close().await;
    Ok(())
}

See SqlClient.

Implementations§

Source§

impl Session

Source

pub async fn connect( connection_option: &ConnectionOption, ) -> Result<Arc<Session>, TgError>

Establishes a connection to the Tsurugi server.

Note: Should invoke Self::close before Self::drop to dispose the session.

§Examples
use tsubakuro_rust_core::prelude::*;

async fn example(connection_option: ConnectionOption) -> Result<(), TgError> {
    let session = Session::connect(&connection_option).await?;
    let client: SqlClient = session.make_client();

    session.close().await;
    Ok(())
}
Source

pub async fn connect_for( connection_option: &ConnectionOption, timeout: Duration, ) -> Result<Arc<Session>, TgError>

Establishes a connection to the Tsurugi server.

Note: Should invoke Self::close before Self::drop to dispose the session.

Source

pub async fn connect_async( connection_option: &ConnectionOption, ) -> Result<Job<Arc<Session>>, TgError>

Establishes a connection to the Tsurugi server.

Note: Should invoke Self::close before Self::drop to dispose the session.

Source

pub fn user_name(&self) -> Option<String>

Get user name.

since 0.5.0

Source

pub async fn has_encryption_key(&self) -> bool

Checks if the session has an encryption key.

For internal use.

since 0.5.0

Source

pub fn set_default_timeout(&self, timeout: Duration)

Set default timeout.

Source

pub fn default_timeout(&self) -> Duration

Get default timeout.

Source

pub fn make_client<T: ServiceClient>(self: &Arc<Session>) -> T

Creates a service client.

§Examples
use std::sync::Arc;
use tsubakuro_rust_core::prelude::*;

fn example(session: &Arc<Session>) {
    let client: SqlClient = session.make_client();
}
Source

pub async fn update_expiration_time( &self, expiration_time: Option<Duration>, ) -> Result<(), TgError>

Requests to update the session expiration time.

The resources underlying this session will be disposed after this session was expired. To extend the expiration time, clients should continue to send requests in this session, or update expiration time explicitly by using this method.

If the specified expiration time is too long, the server will automatically shorten it to its limit. Or, if the time is too short or less than zero, the server sometimes omits the request.

Source

pub async fn update_expiration_time_for( &self, expiration_time: Option<Duration>, timeout: Duration, ) -> Result<(), TgError>

Requests to update the session expiration time.

The resources underlying this session will be disposed after this session was expired. To extend the expiration time, clients should continue to send requests in this session, or update expiration time explicitly by using this method.

If the specified expiration time is too long, the server will automatically shorten it to its limit. Or, if the time is too short or less than zero, the server sometimes omits the request.

Source

pub async fn update_expiration_time_async( &self, expiration_time: Option<Duration>, ) -> Result<Job<()>, TgError>

Requests to update the session expiration time.

The resources underlying this session will be disposed after this session was expired. To extend the expiration time, clients should continue to send requests in this session, or update expiration time explicitly by using this method.

If the specified expiration time is too long, the server will automatically shorten it to its limit. Or, if the time is too short or less than zero, the server sometimes omits the request.

Source

pub async fn shutdown(&self, shutdown_type: ShutdownType) -> Result<(), TgError>

Request to shutdown the current session and wait for the running requests were finished.

Source

pub async fn shutdown_for( &self, shutdown_type: ShutdownType, timeout: Duration, ) -> Result<(), TgError>

Request to shutdown the current session and wait for the running requests were finished.

Source

pub async fn shutdown_async( &self, shutdown_type: ShutdownType, ) -> Result<Job<()>, TgError>

Request to shutdown the current session and wait for the running requests were finished.

Source

pub fn is_shutdowned(&self) -> bool

Check if the session is shut down.

Source

pub async fn close(&self) -> Result<(), TgError>

Disposes the current session.

This may not wait for complete the ongoing requests, and it may cause the requests may still be in progress after disconnected from the session. You can use Self::shutdown to safely close this session with waiting for complete the ongoing requests, if any.

Note: Should invoke close before Self::drop to dispose the session.

Source

pub fn is_closed(&self) -> bool

Check if the session is closed.

Trait Implementations§

Source§

impl Debug for Session

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Drop for Session

Source§

fn drop(&mut self)

Executes the destructor for this type. 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> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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

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

Source§

fn vzip(self) -> V

Source§

impl<T> ErasedDestructor for T
where T: 'static,