From 335ca8ff3388c3b83e68c71ef9b02fbcdb001caa Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Mon, 12 Feb 2018 16:08:04 -0800 Subject: [PATCH] use new actix api --- guide/src/qs_3_5.md | 2 +- src/client/connector.rs | 3 ++- src/context.rs | 10 +++++----- src/pipeline.rs | 2 +- src/server/srv.rs | 18 +++++++++--------- src/test.rs | 2 +- src/ws/client.rs | 6 +++--- src/ws/context.rs | 10 +++++----- tests/test_server.rs | 4 ++-- 9 files changed, 29 insertions(+), 28 deletions(-) diff --git a/guide/src/qs_3_5.md b/guide/src/qs_3_5.md index 62f21b61b..ef35973d4 100644 --- a/guide/src/qs_3_5.md +++ b/guide/src/qs_3_5.md @@ -66,7 +66,7 @@ fn main() { }); let addr = rx.recv().unwrap(); - let _ = addr.call_fut( + let _ = addr.call( server::StopServer{graceful:true}).wait(); // <- Send `StopServer` message to server. } ``` diff --git a/src/client/connector.rs b/src/client/connector.rs index 2a0466cf2..8aa9322a4 100644 --- a/src/client/connector.rs +++ b/src/client/connector.rs @@ -191,7 +191,8 @@ impl Handler for ClientConnector { ActorResponse::async( Connector::from_registry() - .call(self, ResolveConnect::host_and_port(&host, port)) + .call(ResolveConnect::host_and_port(&host, port)) + .into_actor(self) .map_err(|_, _, _| ClientConnectorError::Disconnected) .and_then(move |res, _act, _| { #[cfg(feature="alpn")] diff --git a/src/context.rs b/src/context.rs index a8ccfd4e4..a3e168f6d 100644 --- a/src/context.rs +++ b/src/context.rs @@ -83,12 +83,12 @@ impl AsyncContext for HttpContext where A: Actor } #[doc(hidden)] #[inline] - fn unsync_address(&mut self) -> Addr> { + fn unsync_address(&mut self) -> Addr { self.inner.unsync_address() } #[doc(hidden)] #[inline] - fn sync_address(&mut self) -> Addr> { + fn sync_address(&mut self) -> Addr { self.inner.sync_address() } } @@ -205,12 +205,12 @@ impl ActorHttpContext for HttpContext where A: Actor, } } -impl ToEnvelope, M> for HttpContext +impl ToEnvelope for HttpContext where A: Actor> + Handler, M: Message + Send + 'static, M::Result: Send, { - fn pack(msg: M, tx: Option>) -> Syn { - Syn::new(Box::new(SyncEnvelope::envelope(msg, tx))) + fn pack(msg: M, tx: Option>) -> SyncEnvelope { + SyncEnvelope::new(msg, tx) } } diff --git a/src/pipeline.rs b/src/pipeline.rs index babd92199..18f9f261c 100644 --- a/src/pipeline.rs +++ b/src/pipeline.rs @@ -739,7 +739,7 @@ mod tests { let req = HttpRequest::default(); let mut ctx = HttpContext::new(req.clone(), MyActor); - let addr: Addr> = ctx.address(); + let addr: Addr = ctx.address(); let mut info = PipelineInfo::new(req); info.context = Some(Box::new(ctx)); let mut state = Completed::<(), Inner<()>>::init(&mut info).completed().unwrap(); diff --git a/src/server/srv.rs b/src/server/srv.rs index 4217ad5a1..a41e17c7f 100644 --- a/src/server/srv.rs +++ b/src/server/srv.rs @@ -36,12 +36,12 @@ pub struct HttpServer where H: IntoHttpHandler + 'static host: Option, keep_alive: Option, factory: Arc Vec + Send + Sync>, - workers: Vec>>>, + workers: Vec>>, sockets: HashMap, accept: Vec<(mio::SetReadiness, sync_mpsc::Sender)>, exit: bool, shutdown_timeout: u16, - signals: Option>>, + signals: Option>, no_signals: bool, } @@ -146,7 +146,7 @@ impl HttpServer where H: IntoHttpHandler + 'static } /// Set alternative address for `ProcessSignals` actor. - pub fn signals(mut self, addr: Addr>) -> Self { + pub fn signals(mut self, addr: Addr) -> Self { self.signals = Some(addr); self } @@ -227,7 +227,7 @@ impl HttpServer where H: IntoHttpHandler + 'static } // subscribe to os signals - fn subscribe_to_signals(&self) -> Option>> { + fn subscribe_to_signals(&self) -> Option> { if !self.no_signals { if let Some(ref signals) = self.signals { Some(signals.clone()) @@ -269,7 +269,7 @@ impl HttpServer /// let _ = sys.run(); // <- Run actix system, this method actually starts all async processes /// } /// ``` - pub fn start(mut self) -> Addr> + pub fn start(mut self) -> Addr { if self.sockets.is_empty() { panic!("HttpServer::bind() has to be called before start()"); @@ -288,7 +288,7 @@ impl HttpServer // start http server actor let signals = self.subscribe_to_signals(); - let addr: Addr> = Actor::start(self); + let addr: Addr = Actor::start(self); signals.map(|signals| signals.send( signal::Subscribe(addr.clone().subscriber()))); addr @@ -407,7 +407,7 @@ impl HttpServer /// Start listening for incoming connections from a stream. /// /// This method uses only one thread for handling incoming connections. - pub fn start_incoming(mut self, stream: S, secure: bool) -> Addr> + pub fn start_incoming(mut self, stream: S, secure: bool) -> Addr where S: Stream + 'static, T: AsyncRead + AsyncWrite + 'static, A: 'static @@ -435,7 +435,7 @@ impl HttpServer // start server let signals = self.subscribe_to_signals(); - let addr: Addr> = HttpServer::create(move |ctx| { + let addr: Addr = HttpServer::create(move |ctx| { ctx.add_message_stream( stream .map_err(|_| ()) @@ -536,7 +536,7 @@ impl Handler for HttpServer }; for worker in &self.workers { let tx2 = tx.clone(); - let fut = worker.call(self, StopWorker{graceful: dur}); + let fut = worker.call(StopWorker{graceful: dur}).into_actor(self); ActorFuture::then(fut, move |_, slf, _| { slf.workers.pop(); if slf.workers.is_empty() { diff --git a/src/test.rs b/src/test.rs index c98929f0a..48c1d9508 100644 --- a/src/test.rs +++ b/src/test.rs @@ -56,7 +56,7 @@ pub struct TestServer { addr: net::SocketAddr, thread: Option>, system: SystemRunner, - server_sys: Addr>, + server_sys: Addr, } impl TestServer { diff --git a/src/ws/client.rs b/src/ws/client.rs index 7800ab02f..4201c20e2 100644 --- a/src/ws/client.rs +++ b/src/ws/client.rs @@ -103,7 +103,7 @@ pub struct WsClient { http_err: Option, origin: Option, protocols: Option, - conn: Addr>, + conn: Addr, } impl WsClient { @@ -114,7 +114,7 @@ impl WsClient { } /// Create new websocket connection with custom `ClientConnector` - pub fn with_connector>(uri: S, conn: Addr>) -> WsClient { + pub fn with_connector>(uri: S, conn: Addr) -> WsClient { let mut cl = WsClient { request: ClientRequest::build(), err: None, @@ -200,7 +200,7 @@ impl WsClient { // get connection and start handshake Ok(Box::new( - self.conn.call_fut(Connect(request.uri().clone())) + self.conn.call(Connect(request.uri().clone())) .map_err(|_| WsClientError::Disconnected) .and_then(|res| match res { Ok(stream) => Either::A(WsHandshake::new(stream, request)), diff --git a/src/ws/context.rs b/src/ws/context.rs index 6f84ea483..b9214b749 100644 --- a/src/ws/context.rs +++ b/src/ws/context.rs @@ -67,13 +67,13 @@ impl AsyncContext for WebsocketContext where A: Actor Addr> { + fn unsync_address(&mut self) -> Addr { self.inner.unsync_address() } #[doc(hidden)] #[inline] - fn sync_address(&mut self) -> Addr> { + fn sync_address(&mut self) -> Addr { self.inner.sync_address() } } @@ -217,12 +217,12 @@ impl ActorHttpContext for WebsocketContext where A: Actor ToEnvelope, M> for WebsocketContext +impl ToEnvelope for WebsocketContext where A: Actor> + Handler, M: Message + Send + 'static, M::Result: Send { - fn pack(msg: M, tx: Option>) -> Syn { - Syn::new(Box::new(SyncEnvelope::envelope(msg, tx))) + fn pack(msg: M, tx: Option>) -> SyncEnvelope { + SyncEnvelope::new(msg, tx) } } diff --git a/tests/test_server.rs b/tests/test_server.rs index 3a8321c83..6c784ca9c 100644 --- a/tests/test_server.rs +++ b/tests/test_server.rs @@ -72,12 +72,12 @@ fn test_start() { assert!(reqwest::get(&format!("http://{}/", addr)).unwrap().status().is_success()); // pause - let _ = srv_addr.call_fut(server::PauseServer).wait(); + let _ = srv_addr.call(server::PauseServer).wait(); thread::sleep(time::Duration::from_millis(100)); assert!(net::TcpStream::connect(addr).is_err()); // resume - let _ = srv_addr.call_fut(server::ResumeServer).wait(); + let _ = srv_addr.call(server::ResumeServer).wait(); assert!(reqwest::get(&format!("http://{}/", addr)).unwrap().status().is_success()); }