Skip to main content

SparqlWebSocketHandler

Struct SparqlWebSocketHandler 

Source
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: bool

Whether initialize has been called.

Implementations§

Source§

impl<'a> SparqlWebSocketHandler<'a>

Source

pub fn new(quins: &'a [NQuin]) -> Self

Source

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.

Source

pub fn register_session(&mut self) -> Result<u64, String>

Register a new WebSocket session

Source

pub fn unregister_session(&mut self, session_id: u64) -> Result<(), String>

Unregister a WebSocket session

Source

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.

Source

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.

Source

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.

Source

pub fn unsubscribe_session(&mut self, session_id: u64) -> Result<(), String>

Unsubscribe a session from updates (session-based).

Source

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.

Source

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.

Source

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.

Source

pub fn get_subscriptions(&self) -> Vec<&Subscription>

List all active subscriptions.

Source

pub fn subscription_count(&self) -> usize

Count active subscriptions.

Source

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.

Source

pub fn handle_query(&self, query: &str) -> Result<Vec<u8>, String>

Execute a SPARQL query and return the results as serialized bytes in a simple JSON format. This is the WebSocket query handler entry point.

Source

pub fn stream_results(&self, results: &[u8], chunk_size: usize) -> Vec<Vec<u8>>

Split a serialized result buffer into chunks for streaming over WebSocket frames. Each chunk is at most chunk_size bytes (the final chunk may be smaller).

Trait Implementations§

Source§

impl<'a> Default for SparqlWebSocketHandler<'a>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

§

impl<S, A> Aggregate<Result<S, Error>> for A
where A: Aggregate<S>,

§

fn from_shares<T>(iter: T) -> Result<A, Error>
where T: IntoIterator<Item = Result<S, Error>>,

Aggregate shares in an MPC protocol.
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
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<T> NoneValue for T
where T: Default,

§

type NoneType = T

§

fn null_value() -> T

The none-equivalent value.
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
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.
§

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

§

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

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

§

impl<T> WasmNotSend for T
where T: Send,

§

impl<T> WasmNotSendSync for T
where T: WasmNotSend + WasmNotSync,

§

impl<T> WasmNotSync for T
where T: Sync,