use std::sync::Arc;
use rocketmq_protocol::protocol::remoting_command::RemotingCommand;
use rocketmq_runtime::TaskGroup;
use rocketmq_security_api::Principal;
use crate::deadline::RequestDeadline;
use crate::dispatch::AuthorizedCommandDispatcher;
use crate::dispatch::EmbeddedDispatchOutcome;
use crate::error::TransportError;
use crate::runtime::processor::RequestProcessor;
pub struct EmbeddedRequestHarness<P> {
dispatcher: Arc<AuthorizedCommandDispatcher<P>>,
task_group: TaskGroup,
principal: Principal,
}
impl<P> EmbeddedRequestHarness<P>
where
P: RequestProcessor + Clone + Sync + 'static,
{
#[must_use]
pub fn new(dispatcher: Arc<AuthorizedCommandDispatcher<P>>, task_group: TaskGroup, principal: Principal) -> Self {
Self {
dispatcher,
task_group,
principal,
}
}
pub async fn dispatch(
&self,
deadline: Option<RequestDeadline>,
command: RemotingCommand,
) -> Result<EmbeddedDispatchOutcome, TransportError> {
self.dispatcher
.dispatch_embedded(&self.task_group, self.principal.clone(), deadline, command)
.await
}
}