Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 27 additions & 8 deletions crates/apollo_storage/src/storage_reader_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,14 @@ use crate::{StorageError, StorageReader};
pub struct ServerConfig {
/// The socket address to bind the server to.
socket: SocketAddr,
/// Maximum number of concurrent requests the server can handle.
max_concurrency: usize,
/// Whether the server is enabled.
enable: bool,
}

impl ServerConfig {
/// Creates a new server configuration.
pub fn new(socket: SocketAddr, max_concurrency: usize, enable: bool) -> Self {
Self { socket, max_concurrency, enable }
pub fn new(socket: SocketAddr, enable: bool) -> Self {
Self { socket, enable }
}
}

Expand All @@ -42,19 +40,39 @@ pub trait StorageReaderServerHandler<Request, Response> {
/// A server for handling remote storage reader queries via a configurable request handler.
pub struct StorageReaderServer<RequestHandler, Request, Response>
where
RequestHandler: StorageReaderServerHandler<Request, Response>,
RequestHandler: StorageReaderServerHandler<Request, Response> + Clone,
Request: Serialize + DeserializeOwned + Send + 'static,
Response: Serialize + DeserializeOwned + Send + 'static,
{
app_state: AppState<RequestHandler, Request, Response>,
config: ServerConfig,
}

struct AppState<RequestHandler, Request, Response>
where
RequestHandler: StorageReaderServerHandler<Request, Response> + Clone,
{
storage_reader: StorageReader,
request_handler: RequestHandler,
config: ServerConfig,
_req_res: PhantomData<(Request, Response)>,
}

impl<RequestHandler, Request, Response> Clone for AppState<RequestHandler, Request, Response>
where
RequestHandler: StorageReaderServerHandler<Request, Response> + Clone,
{
fn clone(&self) -> Self {
Self {
storage_reader: self.storage_reader.clone(),
request_handler: self.request_handler.clone(),
_req_res: PhantomData,
}
}
}

impl<RequestHandler, Request, Response> StorageReaderServer<RequestHandler, Request, Response>
where
RequestHandler: StorageReaderServerHandler<Request, Response>,
RequestHandler: StorageReaderServerHandler<Request, Response> + Clone,
Request: Serialize + DeserializeOwned + Send + 'static,
Response: Serialize + DeserializeOwned + Send + 'static,
{
Expand All @@ -64,7 +82,8 @@ where
request_handler: RequestHandler,
config: ServerConfig,
) -> Self {
Self { storage_reader, request_handler, config, _req_res: PhantomData }
let app_state = AppState { storage_reader, request_handler, _req_res: PhantomData };
Self { app_state, config }
}

/// Starts the server to handle incoming requests.
Expand Down
Loading