1
0
mirror of https://github.com/fafhrd91/actix-web synced 2024-11-27 17:52:56 +01:00

update actix api

This commit is contained in:
Nikolay Kim 2018-02-12 01:13:06 -08:00
parent 285c66e7d8
commit 30bdf9cb5e
6 changed files with 33 additions and 38 deletions

View File

@ -6,9 +6,9 @@ use futures::unsync::oneshot;
use smallvec::SmallVec;
use actix::{Actor, ActorState, ActorContext, AsyncContext,
Address, SyncAddress, Handler, ResponseType, MessageResult, SpawnHandle};
Addr, Handler, ResponseType, MessageResult, SpawnHandle, Syn, Unsync};
use actix::fut::ActorFuture;
use actix::dev::{ContextImpl, Envelope, ToEnvelope, RemoteEnvelope};
use actix::dev::{ContextImpl, ToEnvelope, RemoteEnvelope};
use body::{Body, Binary};
use error::{Error, ErrorInternalServerError};
@ -83,12 +83,12 @@ impl<A, S> AsyncContext<A> for HttpContext<A, S> where A: Actor<Context=Self>
}
#[doc(hidden)]
#[inline]
fn local_address(&mut self) -> Address<A> {
fn unsync_address(&mut self) -> Addr<Unsync<A>> {
self.inner.unsync_address()
}
#[doc(hidden)]
#[inline]
fn sync_address(&mut self) -> SyncAddress<A> {
fn sync_address(&mut self) -> Addr<Syn<A>> {
self.inner.sync_address()
}
}
@ -205,15 +205,12 @@ impl<A, S> ActorHttpContext for HttpContext<A, S> where A: Actor<Context=Self>,
}
}
impl<A, S> ToEnvelope<A> for HttpContext<A, S>
where A: Actor<Context=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: ResponseType + Send + 'static, M::Item: Send, M::Error: Send,
{
#[inline]
fn pack<M>(msg: M, tx: Option<Sender<MessageResult<M>>>) -> Envelope<A>
where A: Handler<M>,
M: ResponseType + Send + 'static, M::Item: Send, M::Error: Send
{
RemoteEnvelope::envelope(msg, tx).into()
fn pack(msg: M, tx: Option<Sender<MessageResult<M>>>) -> Syn<A> {
Syn::new(Box::new(RemoteEnvelope::envelope(msg, tx)))
}
}

View File

@ -739,7 +739,7 @@ mod tests {
let req = HttpRequest::default();
let mut ctx = HttpContext::new(req.clone(), MyActor);
let addr: Address<_> = 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();

View File

@ -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<SyncAddress<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<SyncAddress<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: SyncAddress<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<SyncAddress<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) -> SyncAddress<Self>
pub fn start(mut self) -> Addr<Syn<Self>>
{
if self.sockets.is_empty() {
panic!("HttpServer::bind() has to be called before start()");
@ -288,9 +288,9 @@ impl<H: IntoHttpHandler> HttpServer<H>
// start http server actor
let signals = self.subscribe_to_signals();
let addr: SyncAddress<_> = Actor::start(self);
let addr: Addr<Syn<_>> = Actor::start(self);
signals.map(|signals| signals.send(
signal::Subscribe(addr.clone().into())));
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) -> SyncAddress<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: SyncAddress<_> = HttpServer::create(move |ctx| {
let addr: Addr<Syn<_>> = HttpServer::create(move |ctx| {
ctx.add_message_stream(
stream
.map_err(|_| ())
@ -443,7 +443,7 @@ impl<H: IntoHttpHandler> HttpServer<H>
self
});
signals.map(|signals| signals.send(
signal::Subscribe(addr.clone().into())));
signal::Subscribe(addr.clone().subscriber())));
addr
}
}

View File

@ -6,7 +6,7 @@ use std::sync::mpsc;
use std::str::FromStr;
use std::collections::HashMap;
use actix::{Arbiter, SyncAddress, System, SystemRunner, msgs};
use actix::{Arbiter, Addr, Syn, System, SystemRunner, msgs};
use cookie::Cookie;
use http::{Uri, Method, Version, HeaderMap, HttpTryFrom};
use http::header::{HeaderName, HeaderValue};
@ -56,7 +56,7 @@ pub struct TestServer {
addr: net::SocketAddr,
thread: Option<thread::JoinHandle<()>>,
system: SystemRunner,
server_sys: SyncAddress<System>,
server_sys: Addr<Syn<System>>,
}
impl TestServer {

View File

@ -103,7 +103,7 @@ pub struct WsClient {
http_err: Option<HttpError>,
origin: Option<HeaderValue>,
protocols: Option<String>,
conn: Address<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: Address<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,

View File

@ -5,9 +5,9 @@ use futures::unsync::oneshot;
use smallvec::SmallVec;
use actix::{Actor, ActorState, ActorContext, AsyncContext,
Address, SyncAddress, Handler, ResponseType, SpawnHandle, MessageResult};
Addr, Handler, ResponseType, SpawnHandle, MessageResult, Syn, Unsync};
use actix::fut::ActorFuture;
use actix::dev::{ContextImpl, Envelope, ToEnvelope, RemoteEnvelope};
use actix::dev::{ContextImpl, ToEnvelope, RemoteEnvelope};
use body::{Body, Binary};
use error::{Error, ErrorInternalServerError};
@ -67,13 +67,13 @@ impl<A, S> AsyncContext<A> for WebsocketContext<A, S> where A: Actor<Context=Sel
#[doc(hidden)]
#[inline]
fn local_address(&mut self) -> Address<A> {
fn unsync_address(&mut self) -> Addr<Unsync<A>> {
self.inner.unsync_address()
}
#[doc(hidden)]
#[inline]
fn sync_address(&mut self) -> SyncAddress<A> {
fn sync_address(&mut self) -> Addr<Syn<A>> {
self.inner.sync_address()
}
}
@ -217,14 +217,12 @@ impl<A, S> ActorHttpContext for WebsocketContext<A, S> where A: Actor<Context=Se
}
}
impl<A, S> ToEnvelope<A> for WebsocketContext<A, S>
where A: Actor<Context=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: ResponseType + Send + 'static, M::Item: Send, M::Error: Send,
{
#[inline]
fn pack<M>(msg: M, tx: Option<Sender<MessageResult<M>>>) -> Envelope<A>
where A: Handler<M>,
M: ResponseType + Send + 'static, M::Item: Send, M::Error: Send {
RemoteEnvelope::envelope(msg, tx).into()
fn pack(msg: M, tx: Option<Sender<MessageResult<M>>>) -> Syn<A> {
Syn::new(Box::new(RemoteEnvelope::envelope(msg, tx)))
}
}