mirror of
https://github.com/actix/actix-web.git
synced 2024-12-20 23:26:44 +00:00
use new actix api
This commit is contained in:
parent
720d8c36c1
commit
335ca8ff33
9 changed files with 29 additions and 28 deletions
|
@ -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.
|
||||
}
|
||||
```
|
||||
|
|
|
@ -191,7 +191,8 @@ impl Handler<Connect> 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")]
|
||||
|
|
|
@ -83,12 +83,12 @@ impl<A, S> AsyncContext<A> for HttpContext<A, S> where A: Actor<Context=Self>
|
|||
}
|
||||
#[doc(hidden)]
|
||||
#[inline]
|
||||
fn unsync_address(&mut self) -> Addr<Unsync<A>> {
|
||||
fn unsync_address(&mut self) -> Addr<Unsync, A> {
|
||||
self.inner.unsync_address()
|
||||
}
|
||||
#[doc(hidden)]
|
||||
#[inline]
|
||||
fn sync_address(&mut self) -> Addr<Syn<A>> {
|
||||
fn sync_address(&mut self) -> Addr<Syn, A> {
|
||||
self.inner.sync_address()
|
||||
}
|
||||
}
|
||||
|
@ -205,12 +205,12 @@ impl<A, S> ActorHttpContext for HttpContext<A, S> where A: Actor<Context=Self>,
|
|||
}
|
||||
}
|
||||
|
||||
impl<A, M, S> ToEnvelope<Syn<A>, M> for HttpContext<A, S>
|
||||
impl<A, M, S> ToEnvelope<Syn, A, M> for HttpContext<A, S>
|
||||
where A: Actor<Context=HttpContext<A, S>> + Handler<M>,
|
||||
M: Message + Send + 'static, M::Result: Send,
|
||||
{
|
||||
fn pack(msg: M, tx: Option<Sender<M::Result>>) -> Syn<A> {
|
||||
Syn::new(Box::new(SyncEnvelope::envelope(msg, tx)))
|
||||
fn pack(msg: M, tx: Option<Sender<M::Result>>) -> SyncEnvelope<A> {
|
||||
SyncEnvelope::new(msg, tx)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -739,7 +739,7 @@ mod tests {
|
|||
|
||||
let req = HttpRequest::default();
|
||||
let mut ctx = HttpContext::new(req.clone(), MyActor);
|
||||
let addr: Addr<Unsync<_>> = ctx.address();
|
||||
let addr: Addr<Unsync, _> = ctx.address();
|
||||
let mut info = PipelineInfo::new(req);
|
||||
info.context = Some(Box::new(ctx));
|
||||
let mut state = Completed::<(), Inner<()>>::init(&mut info).completed().unwrap();
|
||||
|
|
|
@ -36,12 +36,12 @@ pub struct HttpServer<H> where H: IntoHttpHandler + 'static
|
|||
host: Option<String>,
|
||||
keep_alive: Option<u64>,
|
||||
factory: Arc<Fn() -> Vec<H> + Send + Sync>,
|
||||
workers: Vec<Addr<Syn<Worker<H::Handler>>>>,
|
||||
workers: Vec<Addr<Syn, Worker<H::Handler>>>,
|
||||
sockets: HashMap<net::SocketAddr, net::TcpListener>,
|
||||
accept: Vec<(mio::SetReadiness, sync_mpsc::Sender<Command>)>,
|
||||
exit: bool,
|
||||
shutdown_timeout: u16,
|
||||
signals: Option<Addr<Syn<signal::ProcessSignals>>>,
|
||||
signals: Option<Addr<Syn, signal::ProcessSignals>>,
|
||||
no_signals: bool,
|
||||
}
|
||||
|
||||
|
@ -146,7 +146,7 @@ impl<H> HttpServer<H> where H: IntoHttpHandler + 'static
|
|||
}
|
||||
|
||||
/// Set alternative address for `ProcessSignals` actor.
|
||||
pub fn signals(mut self, addr: Addr<Syn<signal::ProcessSignals>>) -> Self {
|
||||
pub fn signals(mut self, addr: Addr<Syn, signal::ProcessSignals>) -> Self {
|
||||
self.signals = Some(addr);
|
||||
self
|
||||
}
|
||||
|
@ -227,7 +227,7 @@ impl<H> HttpServer<H> where H: IntoHttpHandler + 'static
|
|||
}
|
||||
|
||||
// subscribe to os signals
|
||||
fn subscribe_to_signals(&self) -> Option<Addr<Syn<signal::ProcessSignals>>> {
|
||||
fn subscribe_to_signals(&self) -> Option<Addr<Syn, signal::ProcessSignals>> {
|
||||
if !self.no_signals {
|
||||
if let Some(ref signals) = self.signals {
|
||||
Some(signals.clone())
|
||||
|
@ -269,7 +269,7 @@ impl<H: IntoHttpHandler> HttpServer<H>
|
|||
/// let _ = sys.run(); // <- Run actix system, this method actually starts all async processes
|
||||
/// }
|
||||
/// ```
|
||||
pub fn start(mut self) -> Addr<Syn<Self>>
|
||||
pub fn start(mut self) -> Addr<Syn, Self>
|
||||
{
|
||||
if self.sockets.is_empty() {
|
||||
panic!("HttpServer::bind() has to be called before start()");
|
||||
|
@ -288,7 +288,7 @@ impl<H: IntoHttpHandler> HttpServer<H>
|
|||
|
||||
// start http server actor
|
||||
let signals = self.subscribe_to_signals();
|
||||
let addr: Addr<Syn<_>> = Actor::start(self);
|
||||
let addr: Addr<Syn, _> = Actor::start(self);
|
||||
signals.map(|signals| signals.send(
|
||||
signal::Subscribe(addr.clone().subscriber())));
|
||||
addr
|
||||
|
@ -407,7 +407,7 @@ impl<H: IntoHttpHandler> HttpServer<H>
|
|||
/// Start listening for incoming connections from a stream.
|
||||
///
|
||||
/// This method uses only one thread for handling incoming connections.
|
||||
pub fn start_incoming<T, A, S>(mut self, stream: S, secure: bool) -> Addr<Syn<Self>>
|
||||
pub fn start_incoming<T, A, S>(mut self, stream: S, secure: bool) -> Addr<Syn, Self>
|
||||
where S: Stream<Item=(T, A), Error=io::Error> + 'static,
|
||||
T: AsyncRead + AsyncWrite + 'static,
|
||||
A: 'static
|
||||
|
@ -435,7 +435,7 @@ impl<H: IntoHttpHandler> HttpServer<H>
|
|||
|
||||
// start server
|
||||
let signals = self.subscribe_to_signals();
|
||||
let addr: Addr<Syn<_>> = HttpServer::create(move |ctx| {
|
||||
let addr: Addr<Syn, _> = HttpServer::create(move |ctx| {
|
||||
ctx.add_message_stream(
|
||||
stream
|
||||
.map_err(|_| ())
|
||||
|
@ -536,7 +536,7 @@ impl<H: IntoHttpHandler> Handler<StopServer> for HttpServer<H>
|
|||
};
|
||||
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() {
|
||||
|
|
|
@ -56,7 +56,7 @@ pub struct TestServer {
|
|||
addr: net::SocketAddr,
|
||||
thread: Option<thread::JoinHandle<()>>,
|
||||
system: SystemRunner,
|
||||
server_sys: Addr<Syn<System>>,
|
||||
server_sys: Addr<Syn, System>,
|
||||
}
|
||||
|
||||
impl TestServer {
|
||||
|
|
|
@ -103,7 +103,7 @@ pub struct WsClient {
|
|||
http_err: Option<HttpError>,
|
||||
origin: Option<HeaderValue>,
|
||||
protocols: Option<String>,
|
||||
conn: Addr<Unsync<ClientConnector>>,
|
||||
conn: Addr<Unsync, ClientConnector>,
|
||||
}
|
||||
|
||||
impl WsClient {
|
||||
|
@ -114,7 +114,7 @@ impl WsClient {
|
|||
}
|
||||
|
||||
/// Create new websocket connection with custom `ClientConnector`
|
||||
pub fn with_connector<S: AsRef<str>>(uri: S, conn: Addr<Unsync<ClientConnector>>) -> WsClient {
|
||||
pub fn with_connector<S: AsRef<str>>(uri: S, conn: Addr<Unsync, ClientConnector>) -> 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)),
|
||||
|
|
|
@ -67,13 +67,13 @@ impl<A, S> AsyncContext<A> for WebsocketContext<A, S> where A: Actor<Context=Sel
|
|||
|
||||
#[doc(hidden)]
|
||||
#[inline]
|
||||
fn unsync_address(&mut self) -> Addr<Unsync<A>> {
|
||||
fn unsync_address(&mut self) -> Addr<Unsync, A> {
|
||||
self.inner.unsync_address()
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
#[inline]
|
||||
fn sync_address(&mut self) -> Addr<Syn<A>> {
|
||||
fn sync_address(&mut self) -> Addr<Syn, A> {
|
||||
self.inner.sync_address()
|
||||
}
|
||||
}
|
||||
|
@ -217,12 +217,12 @@ impl<A, S> ActorHttpContext for WebsocketContext<A, S> where A: Actor<Context=Se
|
|||
}
|
||||
}
|
||||
|
||||
impl<A, M, S> ToEnvelope<Syn<A>, M> for WebsocketContext<A, S>
|
||||
impl<A, M, S> ToEnvelope<Syn, A, M> for WebsocketContext<A, S>
|
||||
where A: Actor<Context=WebsocketContext<A, S>> + Handler<M>,
|
||||
M: Message + Send + 'static, M::Result: Send
|
||||
{
|
||||
fn pack(msg: M, tx: Option<Sender<M::Result>>) -> Syn<A> {
|
||||
Syn::new(Box::new(SyncEnvelope::envelope(msg, tx)))
|
||||
fn pack(msg: M, tx: Option<Sender<M::Result>>) -> SyncEnvelope<A> {
|
||||
SyncEnvelope::new(msg, tx)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue