Free up name ThinClientService
This commit is contained in:
@ -12,22 +12,22 @@ use std::io::sink;
|
|||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use streamer;
|
use streamer;
|
||||||
use thin_client_service::ThinClientService;
|
use thin_client_service::RequestProcessor;
|
||||||
|
|
||||||
pub struct EntryWriter<'a> {
|
pub struct EntryWriter<'a> {
|
||||||
accounting_stage: &'a AccountingStage,
|
accounting_stage: &'a AccountingStage,
|
||||||
thin_client_service: &'a ThinClientService,
|
request_processor: &'a RequestProcessor,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> EntryWriter<'a> {
|
impl<'a> EntryWriter<'a> {
|
||||||
/// Create a new Tpu that wraps the given Accountant.
|
/// Create a new Tpu that wraps the given Accountant.
|
||||||
pub fn new(
|
pub fn new(
|
||||||
accounting_stage: &'a AccountingStage,
|
accounting_stage: &'a AccountingStage,
|
||||||
thin_client_service: &'a ThinClientService,
|
request_processor: &'a RequestProcessor,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
EntryWriter {
|
EntryWriter {
|
||||||
accounting_stage,
|
accounting_stage,
|
||||||
thin_client_service,
|
request_processor,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,8 +41,7 @@ impl<'a> EntryWriter<'a> {
|
|||||||
"{}",
|
"{}",
|
||||||
serde_json::to_string(&entry).expect("'entry' to_strong in fn write_entry")
|
serde_json::to_string(&entry).expect("'entry' to_strong in fn write_entry")
|
||||||
).expect("writeln! in fn write_entry");
|
).expect("writeln! in fn write_entry");
|
||||||
self.thin_client_service
|
self.request_processor.notify_entry_info_subscribers(&entry);
|
||||||
.notify_entry_info_subscribers(&entry);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn write_entries<W: Write>(&self, writer: &Mutex<W>) -> Result<Vec<Entry>> {
|
fn write_entries<W: Write>(&self, writer: &Mutex<W>) -> Result<Vec<Entry>> {
|
||||||
|
@ -62,18 +62,18 @@ pub enum Response {
|
|||||||
EntryInfo(EntryInfo),
|
EntryInfo(EntryInfo),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct ThinClientService {
|
pub struct RequestProcessor {
|
||||||
//pub output: Mutex<Receiver<Response>>,
|
//pub output: Mutex<Receiver<Response>>,
|
||||||
//response_sender: Mutex<Sender<Response>>,
|
//response_sender: Mutex<Sender<Response>>,
|
||||||
accountant: Arc<Accountant>,
|
accountant: Arc<Accountant>,
|
||||||
entry_info_subscribers: Mutex<Vec<SocketAddr>>,
|
entry_info_subscribers: Mutex<Vec<SocketAddr>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ThinClientService {
|
impl RequestProcessor {
|
||||||
/// Create a new Tpu that wraps the given Accountant.
|
/// Create a new Tpu that wraps the given Accountant.
|
||||||
pub fn new(accountant: Arc<Accountant>) -> Self {
|
pub fn new(accountant: Arc<Accountant>) -> Self {
|
||||||
//let (response_sender, output) = channel();
|
//let (response_sender, output) = channel();
|
||||||
ThinClientService {
|
RequestProcessor {
|
||||||
//output: Mutex::new(output),
|
//output: Mutex::new(output),
|
||||||
//response_sender: Mutex::new(response_sender),
|
//response_sender: Mutex::new(response_sender),
|
||||||
accountant,
|
accountant,
|
||||||
|
14
src/tpu.rs
14
src/tpu.rs
@ -17,11 +17,11 @@ use std::sync::{Arc, Mutex, RwLock};
|
|||||||
use std::thread::{spawn, JoinHandle};
|
use std::thread::{spawn, JoinHandle};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use streamer;
|
use streamer;
|
||||||
use thin_client_service::ThinClientService;
|
use thin_client_service::RequestProcessor;
|
||||||
|
|
||||||
pub struct Tpu {
|
pub struct Tpu {
|
||||||
accounting_stage: AccountingStage,
|
accounting_stage: AccountingStage,
|
||||||
thin_client_service: ThinClientService,
|
request_processor: RequestProcessor,
|
||||||
}
|
}
|
||||||
|
|
||||||
type SharedTpu = Arc<Tpu>;
|
type SharedTpu = Arc<Tpu>;
|
||||||
@ -29,10 +29,10 @@ type SharedTpu = Arc<Tpu>;
|
|||||||
impl Tpu {
|
impl Tpu {
|
||||||
/// Create a new Tpu that wraps the given Accountant.
|
/// Create a new Tpu that wraps the given Accountant.
|
||||||
pub fn new(accounting_stage: AccountingStage) -> Self {
|
pub fn new(accounting_stage: AccountingStage) -> Self {
|
||||||
let thin_client_service = ThinClientService::new(accounting_stage.accountant.clone());
|
let request_processor = RequestProcessor::new(accounting_stage.accountant.clone());
|
||||||
Tpu {
|
Tpu {
|
||||||
accounting_stage,
|
accounting_stage,
|
||||||
thin_client_service,
|
request_processor,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,7 +44,7 @@ impl Tpu {
|
|||||||
writer: Mutex<W>,
|
writer: Mutex<W>,
|
||||||
) -> JoinHandle<()> {
|
) -> JoinHandle<()> {
|
||||||
spawn(move || loop {
|
spawn(move || loop {
|
||||||
let entry_writer = EntryWriter::new(&obj.accounting_stage, &obj.thin_client_service);
|
let entry_writer = EntryWriter::new(&obj.accounting_stage, &obj.request_processor);
|
||||||
let _ = entry_writer.write_and_send_entries(&broadcast, &blob_recycler, &writer);
|
let _ = entry_writer.write_and_send_entries(&broadcast, &blob_recycler, &writer);
|
||||||
if exit.load(Ordering::Relaxed) {
|
if exit.load(Ordering::Relaxed) {
|
||||||
info!("broadcat_service exiting");
|
info!("broadcat_service exiting");
|
||||||
@ -55,7 +55,7 @@ impl Tpu {
|
|||||||
|
|
||||||
pub fn drain_service(obj: SharedTpu, exit: Arc<AtomicBool>) -> JoinHandle<()> {
|
pub fn drain_service(obj: SharedTpu, exit: Arc<AtomicBool>) -> JoinHandle<()> {
|
||||||
spawn(move || {
|
spawn(move || {
|
||||||
let entry_writer = EntryWriter::new(&obj.accounting_stage, &obj.thin_client_service);
|
let entry_writer = EntryWriter::new(&obj.accounting_stage, &obj.request_processor);
|
||||||
loop {
|
loop {
|
||||||
let _ = entry_writer.drain_entries();
|
let _ = entry_writer.drain_entries();
|
||||||
if exit.load(Ordering::Relaxed) {
|
if exit.load(Ordering::Relaxed) {
|
||||||
@ -75,7 +75,7 @@ impl Tpu {
|
|||||||
blob_recycler: packet::BlobRecycler,
|
blob_recycler: packet::BlobRecycler,
|
||||||
) -> JoinHandle<()> {
|
) -> JoinHandle<()> {
|
||||||
spawn(move || loop {
|
spawn(move || loop {
|
||||||
let e = obj.thin_client_service.process_request_packets(
|
let e = obj.request_processor.process_request_packets(
|
||||||
&obj.accounting_stage,
|
&obj.accounting_stage,
|
||||||
&verified_receiver,
|
&verified_receiver,
|
||||||
&responder_sender,
|
&responder_sender,
|
||||||
|
Reference in New Issue
Block a user