pub struct SparqlWebSocketHandler<'a> {
pub quins: &'a [NQuin],
pub sessions: [Option<WebSocketSession>; 32],
pub session_count: u8,
pub subscriptions: HashMap<String, Subscription>,
pub initialized: bool,
}Expand description
SPARQL WebSocket handler
Fields§
§quins: &'a [NQuin]§sessions: [Option<WebSocketSession>; 32]§session_count: u8§subscriptions: HashMap<String, Subscription>Active subscriptions keyed by subscription id.
initialized: boolWhether initialize has been called.
Implementations§
Source§impl<'a> SparqlWebSocketHandler<'a>
impl<'a> SparqlWebSocketHandler<'a>
pub fn new(quins: &'a [NQuin]) -> Self
Sourcepub fn initialize(&mut self) -> Result<(), String>
pub fn initialize(&mut self) -> Result<(), String>
Initialize the handler for use. Resets subscription state and marks the handler ready. Must be called before subscribing/notifying so downstream code can rely on a deterministic start state.
Sourcepub fn register_session(&mut self) -> Result<u64, String>
pub fn register_session(&mut self) -> Result<u64, String>
Register a new WebSocket session
Sourcepub fn unregister_session(&mut self, session_id: u64) -> Result<(), String>
pub fn unregister_session(&mut self, session_id: u64) -> Result<(), String>
Unregister a WebSocket session
Sourcepub fn handle_query_formatted(
&self,
query: &str,
format: &str,
_session_id: u64,
) -> Result<String, String>
pub fn handle_query_formatted( &self, query: &str, format: &str, _session_id: u64, ) -> Result<String, String>
Handle a WebSocket query, returning formatted output (json or xml).
This is the format-aware, session-scoped variant. The simpler
handle_query returns serialized JSON bytes.
Sourcepub fn stream_query_results(
&self,
query: &str,
chunk_size: usize,
_session_id: u64,
) -> Result<Vec<String>, String>
pub fn stream_query_results( &self, query: &str, chunk_size: usize, _session_id: u64, ) -> Result<Vec<String>, String>
Stream query results in chunks, executing the query and formatting each
chunk as JSON. This is the query-executing variant. The simpler
stream_results splits an already-serialized
byte buffer.
Sourcepub fn subscribe_session(
&mut self,
session_id: u64,
query: &str,
) -> Result<u64, String>
pub fn subscribe_session( &mut self, session_id: u64, query: &str, ) -> Result<u64, String>
Subscribe a session to real-time updates for a query (session-based).
This is the numeric-session variant. The string-keyed
subscribe is the subscription notification API.
Sourcepub fn unsubscribe_session(&mut self, session_id: u64) -> Result<(), String>
pub fn unsubscribe_session(&mut self, session_id: u64) -> Result<(), String>
Unsubscribe a session from updates (session-based).
Sourcepub fn notify_session_subscribers(&self, query_hash: u64) -> Vec<u64>
pub fn notify_session_subscribers(&self, query_hash: u64) -> Vec<u64>
Notify session subscribers of updates (session-based), returning the
session ids whose active query matches query_hash.
Sourcepub fn subscribe(
&mut self,
client_id: &str,
query: &str,
) -> Result<String, String>
pub fn subscribe( &mut self, client_id: &str, query: &str, ) -> Result<String, String>
Register a subscription for a client and return the subscription id.
The subscription id is derived from the query (via
generate_60bit_token) so the same query re-subscribed by the same
client yields a stable id. The query and client_id are stored in the
subscriptions map for later notification.
Sourcepub fn unsubscribe(&mut self, subscription_id: &str) -> Result<(), String>
pub fn unsubscribe(&mut self, subscription_id: &str) -> Result<(), String>
Remove a subscription by its id. Returns an error if the subscription does not exist.
Sourcepub fn get_subscriptions(&self) -> Vec<&Subscription>
pub fn get_subscriptions(&self) -> Vec<&Subscription>
List all active subscriptions.
Sourcepub fn subscription_count(&self) -> usize
pub fn subscription_count(&self) -> usize
Count active subscriptions.
Sourcepub fn notify_subscribers(&self, event_data: &str) -> Vec<(String, String)>
pub fn notify_subscribers(&self, event_data: &str) -> Vec<(String, String)>
Notify all active subscribers of an event.
For each subscription, returns a (client_id, notification_message)
pair. The notification message is a JSON-like string containing the
subscription’s query and the event data, so a transport layer can push
it directly to the connected client.
Trait Implementations§
Auto Trait Implementations§
impl<'a> Freeze for SparqlWebSocketHandler<'a>
impl<'a> RefUnwindSafe for SparqlWebSocketHandler<'a>
impl<'a> Send for SparqlWebSocketHandler<'a>
impl<'a> Sync for SparqlWebSocketHandler<'a>
impl<'a> Unpin for SparqlWebSocketHandler<'a>
impl<'a> UnsafeUnpin for SparqlWebSocketHandler<'a>
impl<'a> UnwindSafe for SparqlWebSocketHandler<'a>
Blanket Implementations§
§impl<S, A> Aggregate<Result<S, Error>> for Awhere
A: Aggregate<S>,
impl<S, A> Aggregate<Result<S, Error>> for Awhere
A: Aggregate<S>,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more