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
impl Session
Sourcepub async fn connect(
connection_option: &ConnectionOption,
) -> Result<Arc<Session>, TgError>
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(())
}Sourcepub async fn connect_for(
connection_option: &ConnectionOption,
timeout: Duration,
) -> Result<Arc<Session>, TgError>
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.
Sourcepub async fn connect_async(
connection_option: &ConnectionOption,
) -> Result<Job<Arc<Session>>, TgError>
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.
Sourcepub async fn has_encryption_key(&self) -> bool
pub async fn has_encryption_key(&self) -> bool
Checks if the session has an encryption key.
For internal use.
since 0.5.0
Sourcepub fn set_default_timeout(&self, timeout: Duration)
pub fn set_default_timeout(&self, timeout: Duration)
Set default timeout.
Sourcepub fn default_timeout(&self) -> Duration
pub fn default_timeout(&self) -> Duration
Get default timeout.
Sourcepub fn make_client<T: ServiceClient>(self: &Arc<Session>) -> T
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();
}Sourcepub async fn update_expiration_time(
&self,
expiration_time: Option<Duration>,
) -> Result<(), TgError>
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.
Sourcepub async fn update_expiration_time_for(
&self,
expiration_time: Option<Duration>,
timeout: Duration,
) -> Result<(), TgError>
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.
Sourcepub async fn update_expiration_time_async(
&self,
expiration_time: Option<Duration>,
) -> Result<Job<()>, TgError>
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.
Sourcepub async fn shutdown(&self, shutdown_type: ShutdownType) -> Result<(), TgError>
pub async fn shutdown(&self, shutdown_type: ShutdownType) -> Result<(), TgError>
Request to shutdown the current session and wait for the running requests were finished.
Sourcepub async fn shutdown_for(
&self,
shutdown_type: ShutdownType,
timeout: Duration,
) -> Result<(), TgError>
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.
Sourcepub async fn shutdown_async(
&self,
shutdown_type: ShutdownType,
) -> Result<Job<()>, TgError>
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.
Sourcepub fn is_shutdowned(&self) -> bool
pub fn is_shutdowned(&self) -> bool
Check if the session is shut down.
Sourcepub async fn close(&self) -> Result<(), TgError>
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.