+str enable custom Attributes, add a few more helper methods for attribute querying
This commit is contained in:
parent
e50a5ee6fc
commit
8e0373731d
2 changed files with 30 additions and 4 deletions
|
|
@ -5,9 +5,7 @@ package akka.stream
|
|||
|
||||
import akka.event.Logging
|
||||
import scala.annotation.tailrec
|
||||
import scala.collection.immutable
|
||||
import scala.reflect.{ classTag, ClassTag }
|
||||
import akka.stream.impl.Stages.SymbolicStage
|
||||
import akka.japi.function
|
||||
|
||||
/**
|
||||
|
|
@ -53,12 +51,28 @@ final case class Attributes(attributeList: List[Attributes.Attribute] = Nil) {
|
|||
case None ⇒ default
|
||||
}
|
||||
|
||||
/**
|
||||
* Java API: Get the first (least specific) attribute of a given `Class` or subclass thereof.
|
||||
* If no such attribute exists the `default` value is returned.
|
||||
*/
|
||||
def getFirstAttribute[T <: Attribute](c: Class[T], default: T): T =
|
||||
getFirstAttribute(c) match {
|
||||
case Some(a) ⇒ a
|
||||
case None ⇒ default
|
||||
}
|
||||
|
||||
/**
|
||||
* Java API: Get the last (most specific) attribute of a given `Class` or subclass thereof.
|
||||
*/
|
||||
def getAttribute[T <: Attribute](c: Class[T]): Option[T] =
|
||||
Option(attributeList.foldLeft(null.asInstanceOf[T])((acc, attr) ⇒ if (c.isInstance(attr)) c.cast(attr) else acc))
|
||||
|
||||
/**
|
||||
* Java API: Get the first (least specific) attribute of a given `Class` or subclass thereof.
|
||||
*/
|
||||
def getFirstAttribute[T <: Attribute](c: Class[T]): Option[T] =
|
||||
attributeList.find(c isInstance _).map(c cast _)
|
||||
|
||||
/**
|
||||
* Get the last (most specific) attribute of a given type parameter T `Class` or subclass thereof.
|
||||
* If no such attribute exists the `default` value is returned.
|
||||
|
|
@ -66,12 +80,25 @@ final case class Attributes(attributeList: List[Attributes.Attribute] = Nil) {
|
|||
def get[T <: Attribute: ClassTag](default: T) =
|
||||
getAttribute(classTag[T].runtimeClass.asInstanceOf[Class[T]], default)
|
||||
|
||||
/**
|
||||
* Get the first (least specific) attribute of a given type parameter T `Class` or subclass thereof.
|
||||
* If no such attribute exists the `default` value is returned.
|
||||
*/
|
||||
def getFirst[T <: Attribute: ClassTag](default: T) =
|
||||
getAttribute(classTag[T].runtimeClass.asInstanceOf[Class[T]], default)
|
||||
|
||||
/**
|
||||
* Get the last (most specific) attribute of a given type parameter T `Class` or subclass thereof.
|
||||
*/
|
||||
def get[T <: Attribute: ClassTag] =
|
||||
getAttribute(classTag[T].runtimeClass.asInstanceOf[Class[T]])
|
||||
|
||||
/**
|
||||
* Get the first (least specific) attribute of a given type parameter T `Class` or subclass thereof.
|
||||
*/
|
||||
def getFirst[T <: Attribute: ClassTag] =
|
||||
getFirstAttribute(classTag[T].runtimeClass.asInstanceOf[Class[T]])
|
||||
|
||||
/**
|
||||
* Adds given attributes to the end of these attributes.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -55,8 +55,7 @@ private[akka] case class ActorMaterializerImpl(system: ActorSystem,
|
|||
case InputBuffer(initial, max) ⇒ s.withInputBuffer(initial, max)
|
||||
case Dispatcher(dispatcher) ⇒ s.withDispatcher(dispatcher)
|
||||
case SupervisionStrategy(decider) ⇒ s.withSupervisionStrategy(decider)
|
||||
case l: LogLevels ⇒ s
|
||||
case Name(_) ⇒ s
|
||||
case _ ⇒ s
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue