From 5f97d519673d2ad05d4739a409728ac10f271393 Mon Sep 17 00:00:00 2001 From: debris Date: Wed, 2 Mar 2016 05:46:38 +0100 Subject: [PATCH] renamed poll_indexed to poll_manager --- rpc/src/v1/helpers/mod.rs | 4 ++-- .../{poll_indexer.rs => poll_manager.rs} | 22 +++++++++---------- rpc/src/v1/impls/eth.rs | 8 +++---- 3 files changed, 17 insertions(+), 17 deletions(-) rename rpc/src/v1/helpers/{poll_indexer.rs => poll_manager.rs} (88%) diff --git a/rpc/src/v1/helpers/mod.rs b/rpc/src/v1/helpers/mod.rs index d212d74ab..b1a5c05ba 100644 --- a/rpc/src/v1/helpers/mod.rs +++ b/rpc/src/v1/helpers/mod.rs @@ -14,8 +14,8 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . -mod poll_indexer; +mod poll_manager; mod poll_filter; -pub use self::poll_indexer::PollIndexer; +pub use self::poll_manager::PollManager; pub use self::poll_filter::PollFilter; diff --git a/rpc/src/v1/helpers/poll_indexer.rs b/rpc/src/v1/helpers/poll_manager.rs similarity index 88% rename from rpc/src/v1/helpers/poll_indexer.rs rename to rpc/src/v1/helpers/poll_manager.rs index 11cb30935..1e7addb25 100644 --- a/rpc/src/v1/helpers/poll_indexer.rs +++ b/rpc/src/v1/helpers/poll_manager.rs @@ -39,30 +39,30 @@ impl Clone for PollInfo where F: Clone { } /// Indexes all poll requests. -/// +/// /// Lazily garbage collects unused polls info. -pub struct PollIndexer where T: Timer { +pub struct PollManager where T: Timer { polls: TransientHashMap, T>, next_available_id: PollId } -impl PollIndexer { +impl PollManager { /// Creates new instance of indexer. pub fn new() -> Self { - PollIndexer::new_with_timer(Default::default()) + PollManager::new_with_timer(Default::default()) } } -impl PollIndexer where T: Timer { +impl PollManager where T: Timer { pub fn new_with_timer(timer: T) -> Self { - PollIndexer { + PollManager { polls: TransientHashMap::new_with_timer(POLL_LIFETIME, timer), next_available_id: 0 } } - /// Returns id which can be used for new poll. - /// + /// Returns id which can be used for new poll. + /// /// Stores information when last poll happend. pub fn create_poll(&mut self, filter: F, block: BlockNumber) -> PollId { self.polls.prune(); @@ -84,7 +84,7 @@ impl PollIndexer where T: Timer { } /// Returns number of block when last poll happend. - pub fn get_poll(&mut self, id: &PollId) -> Option<&PollInfo> { + pub fn get_poll_info(&mut self, id: &PollId) -> Option<&PollInfo> { self.polls.prune(); self.polls.get(id) } @@ -99,7 +99,7 @@ impl PollIndexer where T: Timer { mod tests { use std::cell::RefCell; use transient_hashmap::Timer; - use v1::helpers::PollIndexer; + use v1::helpers::PollManager; struct TestTimer<'a> { time: &'a RefCell @@ -118,7 +118,7 @@ mod tests { time: &time }; - let mut indexer = PollIndexer::new_with_timer(timer); + let mut indexer = PollManager::new_with_timer(timer); assert_eq!(indexer.create_poll(false, 20), 0); assert_eq!(indexer.create_poll(true, 20), 1); diff --git a/rpc/src/v1/impls/eth.rs b/rpc/src/v1/impls/eth.rs index 32c143a84..880c45041 100644 --- a/rpc/src/v1/impls/eth.rs +++ b/rpc/src/v1/impls/eth.rs @@ -25,7 +25,7 @@ use ethcore::views::*; use ethcore::ethereum::denominations::shannon; use v1::traits::{Eth, EthFilter}; use v1::types::{Block, BlockTransactions, BlockNumber, Bytes, SyncStatus, SyncInfo, Transaction, OptionalValue, Index, Filter, Log}; -use v1::helpers::{PollFilter, PollIndexer}; +use v1::helpers::{PollFilter, PollManager}; /// Eth rpc implementation. pub struct EthClient { @@ -214,7 +214,7 @@ impl Eth for EthClient { /// Eth filter rpc implementation. pub struct EthFilterClient { client: Weak, - polls: Mutex>, + polls: Mutex>, } impl EthFilterClient { @@ -222,7 +222,7 @@ impl EthFilterClient { pub fn new(client: &Arc) -> Self { EthFilterClient { client: Arc::downgrade(client), - polls: Mutex::new(PollIndexer::new()) + polls: Mutex::new(PollManager::new()) } } } @@ -263,7 +263,7 @@ impl EthFilter for EthFilterClient { let client = take_weak!(self.client); from_params::<(Index,)>(params) .and_then(|(index,)| { - let info = self.polls.lock().unwrap().get_poll(&index.value()).cloned(); + let info = self.polls.lock().unwrap().get_poll_info(&index.value()).cloned(); match info { None => Ok(Value::Array(vec![] as Vec)), Some(info) => match info.filter {