Skip to content

Commit

Permalink
Introducing Akka stream attributes in order to configure http request a…
Browse files Browse the repository at this point in the history
  • Loading branch information
sfali committed Aug 24, 2024
1 parent 7626390 commit f1de209
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (C) since 2016 Lightbend Inc. <https://www.lightbend.com>
*/

package akka.stream.alpakka
package azure
package storage

import akka.stream.Attributes
import akka.stream.Attributes.Attribute

/**
* Akka Stream attributes that are used when materializing AzureStorage stream blueprints.
*/
object StorageAttributes {

/**
* Settings to use for the S3 stream
*/
def settings(settings: StorageSettings): Attributes = Attributes(StorageSettingsValue(settings))

/**
* Config path which will be used to resolve required AzureStorage settings
*/
def settingsPath(path: String): Attributes = Attributes(StorageSettingsPath(path))
}

final class StorageSettingsPath private (val path: String) extends Attribute
object StorageSettingsPath {
val Default: StorageSettingsPath = StorageSettingsPath(StorageSettings.ConfigPath)

def apply(path: String) = new StorageSettingsPath(path)
}

final class StorageSettingsValue private (val settings: StorageSettings) extends Attribute
object StorageSettingsValue {
def apply(settings: StorageSettings) = new StorageSettingsValue(settings)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright (C) since 2016 Lightbend Inc. <https://www.lightbend.com>
*/

package akka.stream.alpakka
package azure
package storage

import akka.actor.{
ActorSystem,
ClassicActorSystemProvider,
ExtendedActorSystem,
Extension,
ExtensionId,
ExtensionIdProvider
}

/**
* Manages one [[StorageSettings]] per `ActorSystem`.
*/
final class StorageExt private (sys: ExtendedActorSystem) extends Extension {
val settings: StorageSettings = settings(StorageSettings.ConfigPath)

def settings(prefix: String): StorageSettings = StorageSettings(sys.settings.config.getConfig(prefix))
}

object StorageExt extends ExtensionId[StorageExt] with ExtensionIdProvider {
override def lookup: StorageExt.type = StorageExt
override def createExtension(system: ExtendedActorSystem) = new StorageExt(system)

/**
* Java API.
* Get the Storage extension with the classic actors API.
*/
override def get(system: ActorSystem): StorageExt = super.apply(system)

/**
* Java API.
* Get the Storage extension with the new actors API.
*/
override def get(system: ClassicActorSystemProvider): StorageExt = super.apply(system)
}

0 comments on commit f1de209

Please sign in to comment.