Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
wilyle committed Nov 13, 2023
1 parent 5f15239 commit 0de30e3
Show file tree
Hide file tree
Showing 14 changed files with 23 additions and 28 deletions.
4 changes: 3 additions & 1 deletion contracts/src/provider_proxy_selector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ use crate::{entity::Entity, provider_proxy::ProviderProxyFactory};
#[async_trait]
pub trait ProviderProxySelector {
/// Registers a `ProviderProxyFactory` with this selector.
fn register<TFactory: ProviderProxyFactory + Send + Sync + 'static>(&mut self) -> Result<(), ProviderProxySelectorError>;
fn register<TFactory: ProviderProxyFactory + Send + Sync + 'static>(
&mut self,
) -> Result<(), ProviderProxySelectorError>;

/// Updates an existing proxy for an entity if possible,
/// otherwise creates a new proxy to handle that entity.
Expand Down
3 changes: 2 additions & 1 deletion freyja/src/cartographer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,8 @@ mod cartographer_tests {
CheckForWorkResponse, GetMappingResponse, MappingClientError, SendInventoryRequest,
SendInventoryResponse,
},
provider_proxy_selector::ProviderProxySelectorError, provider_proxy::ProviderProxyFactory,
provider_proxy::ProviderProxyFactory,
provider_proxy_selector::ProviderProxySelectorError,
};

mock! {
Expand Down
3 changes: 2 additions & 1 deletion freyja/src/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,9 @@ mod emitter_tests {
use freyja_contracts::{
cloud_adapter::{CloudAdapterError, CloudAdapterErrorKind},
entity::Entity,
provider_proxy::ProviderProxyFactory,
provider_proxy_selector::ProviderProxySelectorError,
signal::{Emission, EmissionPolicy}, provider_proxy::ProviderProxyFactory,
signal::{Emission, EmissionPolicy},
};

mock! {
Expand Down
3 changes: 2 additions & 1 deletion freyja/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ use emitter::Emitter;
use freyja_common::signal_store::SignalStore;
use freyja_contracts::{
cloud_adapter::CloudAdapter, digital_twin_adapter::DigitalTwinAdapter,
mapping_client::MappingClient, provider_proxy::SignalValue, provider_proxy_selector::ProviderProxySelector,
mapping_client::MappingClient, provider_proxy::SignalValue,
provider_proxy_selector::ProviderProxySelector,
};
use provider_proxy_selector::provider_proxy_selector_impl::ProviderProxySelectorImpl;

Expand Down
3 changes: 1 addition & 2 deletions provider_proxies/grpc/v1/src/grpc_provider_proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ impl ProviderProxy for GRPCProviderProxy {
.serve(addr);

tokio::spawn(async move {
let _ = server_future
.await;
let _ = server_future.await;
});

info!("Started a GRPCProviderProxy!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub struct GRPCProviderProxyFactory {}
impl ProviderProxyFactory for GRPCProviderProxyFactory {
/// Create a new `GRPCProviderProxyFactory`
fn new() -> Self {
Self { }
Self {}
}

/// Check to see whether this factory can create a proxy for the requested entity.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,7 @@ impl ProviderProxy for HttpMockProviderProxy {
.map_err(ProviderProxyError::communication)?;

tokio::spawn(async move {
let _ = builder
.serve(router.into_make_service())
.await;
let _ = builder.serve(router.into_make_service()).await;
});

info!(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub struct HttpMockProviderProxyFactory {}
impl ProviderProxyFactory for HttpMockProviderProxyFactory {
/// Create a new `GRPCProviderProxyFactory`
fn new() -> Self {
Self { }
Self {}
}

/// Check to see whether this factory can create a proxy for the requested entity.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ impl ProviderProxy for InMemoryMockProviderProxy {
async fn start(&self) -> Result<(), ProviderProxyError> {
let entity_operation_map = self.entity_operation_map.clone();
let signal_values_queue = self.signal_values_queue.clone();
let signal_update_frequency = self.signal_update_frequency.clone();
let signal_update_frequency = self.signal_update_frequency;
let data = self.data.clone();

tokio::spawn(async move {
Expand All @@ -140,11 +140,8 @@ impl ProviderProxy for InMemoryMockProviderProxy {

let data = data.lock().await;
for entity_id in entities_with_subscribe {
let _ = Self::generate_signal_value(
&entity_id,
signal_values_queue.clone(),
&data,
);
let _ =
Self::generate_signal_value(&entity_id, signal_values_queue.clone(), &data);
}

tokio::time::sleep(signal_update_frequency).await;
Expand Down Expand Up @@ -178,11 +175,7 @@ impl ProviderProxy for InMemoryMockProviderProxy {

let data = self.data.lock().await;
if operation == GET_OPERATION {
let _ = Self::generate_signal_value(
entity_id,
self.signal_values_queue.clone(),
&data,
);
let _ = Self::generate_signal_value(entity_id, self.signal_values_queue.clone(), &data);
}

Ok(())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub struct InMemoryMockProviderProxyFactory {}
impl ProviderProxyFactory for InMemoryMockProviderProxyFactory {
/// Create a new `GRPCProviderProxyFactory`
fn new() -> Self {
Self { }
Self {}
}

/// Check to see whether this factory can create a proxy for the requested entity.
Expand Down
2 changes: 1 addition & 1 deletion provider_proxies/mqtt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ This proxy supports the following configuration settings:

- `keep_alive_interval_s`: The keep alive interval for MQTT communications, in seconds

This adapter supports [config overrides](../../../docs/config-overrides.md). The override filename is `mqtt_proxy_config.json`, and the default config is located at `res/mqtt_proxy_config.default.json`.
This adapter supports [config overrides](../../docs/config-overrides.md). The override filename is `mqtt_proxy_config.json`, and the default config is located at `res/mqtt_proxy_config.default.json`.

## Integrating with this Proxy

Expand Down
2 changes: 0 additions & 2 deletions provider_proxies/mqtt/src/mqtt_provider_proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ const MQTT_CLIENT_ID_PREFIX: &str = "freyja-mqtt-proxy";
/// Interfaces with providers which support GRPC. Based on the Ibeji mixed sample.
/// Note that the current implementation works on the assumption that there is a
/// one-to-one mapping of topic to entity id.
/// TODO: can this deadlock?
pub struct MqttProviderProxy {
/// The proxy config
config: Config,
Expand Down Expand Up @@ -112,7 +111,6 @@ impl ProviderProxy for MqttProviderProxy {
if let Some(m) = msg {
let subsciptions = subscriptions.lock().await;
let entity_id = subsciptions.get(m.topic()).unwrap().clone();
// TODO: additional parsing for value?
let value = message_utils::parse_value(m.payload_str().to_string());
signal_values_queue.push(SignalValue { entity_id, value });
} else {
Expand Down
2 changes: 1 addition & 1 deletion provider_proxies/mqtt/src/mqtt_provider_proxy_factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub struct MqttProviderProxyFactory {}
impl ProviderProxyFactory for MqttProviderProxyFactory {
/// Create a new `GRPCProviderProxyFactory`
fn new() -> Self {
Self { }
Self {}
}

/// Check to see whether this factory can create a proxy for the requested entity.
Expand Down
4 changes: 3 additions & 1 deletion provider_proxy_selector/src/provider_proxy_selector_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ impl ProviderProxySelectorImpl {
#[async_trait]
impl ProviderProxySelector for ProviderProxySelectorImpl {
/// Registers a `ProviderProxyFactory` with this selector.
fn register<TFactory: ProviderProxyFactory + Send + Sync + 'static>(&mut self) -> Result<(), ProviderProxySelectorError> {
fn register<TFactory: ProviderProxyFactory + Send + Sync + 'static>(
&mut self,
) -> Result<(), ProviderProxySelectorError> {
self.factories.push(Box::new(TFactory::new()) as _);
Ok(())
}
Expand Down

0 comments on commit 0de30e3

Please sign in to comment.