|
|
@@ -1,12 +1,14 @@
|
|
|
use async_std::sync::{Arc, Mutex};
|
|
|
use std::convert::TryInto;
|
|
|
-use std::net::SocketAddr;
|
|
|
+use std::net::SocketAddr;
|
|
|
|
|
|
use super::reqrep::{Publisher, RepProtocol, Reply, ReqProtocol, Request, Subscriber};
|
|
|
use crate::{Error, Result};
|
|
|
|
|
|
use async_executor::Executor;
|
|
|
|
|
|
+use log::*;
|
|
|
+
|
|
|
pub type Slabs = Vec<Vec<u8>>;
|
|
|
|
|
|
#[repr(u8)]
|
|
|
@@ -37,11 +39,11 @@ impl GatewayService {
|
|
|
let mut socket = RepProtocol::new(self.addr.clone());
|
|
|
|
|
|
let (send, recv) = socket.start().await?;
|
|
|
- println!("server started");
|
|
|
+ info!("server started: bind to {}", self.addr.to_string());
|
|
|
|
|
|
self.publisher.lock().await.start().await?;
|
|
|
|
|
|
- println!("publisher started");
|
|
|
+ info!("publisher started");
|
|
|
|
|
|
let handle_request_task = executor.spawn(self.handle_request(send.clone(), recv.clone()));
|
|
|
|
|
|
@@ -70,15 +72,15 @@ impl GatewayService {
|
|
|
// publish to all subscribes
|
|
|
self.publisher.lock().await.publish(slab).await?;
|
|
|
|
|
|
- println!("received putslab msg");
|
|
|
+ info!("received putslab msg");
|
|
|
}
|
|
|
1 => {
|
|
|
// GETSLAB
|
|
|
- println!("received getslab msg");
|
|
|
+ info!("received getslab msg");
|
|
|
}
|
|
|
2 => {
|
|
|
// GETLASTINDEX
|
|
|
- println!("received getlastindex msg");
|
|
|
+ info!("received getlastindex msg");
|
|
|
}
|
|
|
_ => {
|
|
|
return Err(Error::ServicesError("wrong command"));
|
|
|
@@ -145,7 +147,7 @@ pub async fn fetch_slabs_loop(
|
|
|
let mut subscriber = subscriber.lock().await;
|
|
|
slab = subscriber.fetch().await?;
|
|
|
}
|
|
|
- println!("received new slab from subscriber");
|
|
|
+ info!("received new slab from subscriber");
|
|
|
slabs.lock().await.push(slab);
|
|
|
}
|
|
|
}
|