Merge pull request #939 from akka/wip-2776-√
#2776 - deprecating and introducing alternatives for methods and parame...
This commit is contained in:
commit
5b477e99e7
8 changed files with 32 additions and 30 deletions
|
|
@ -372,15 +372,15 @@ trait FSM[S, D] extends Listeners with ActorLogging {
|
||||||
* timer does not exist, has previously been canceled or if it was a
|
* timer does not exist, has previously been canceled or if it was a
|
||||||
* single-shot timer whose message was already received.
|
* single-shot timer whose message was already received.
|
||||||
*/
|
*/
|
||||||
@deprecated("Use isTimerActive(name) instead.", "2.2")
|
@deprecated("use isTimerActive instead", "2.2")
|
||||||
final def timerActive_?(name: String) = isTimerActive(name)
|
final def timerActive_?(name: String): Boolean = isTimerActive(name)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inquire whether the named timer is still active. Returns true unless the
|
* Inquire whether the named timer is still active. Returns true unless the
|
||||||
* timer does not exist, has previously been canceled or if it was a
|
* timer does not exist, has previously been canceled or if it was a
|
||||||
* single-shot timer whose message was already received.
|
* single-shot timer whose message was already received.
|
||||||
*/
|
*/
|
||||||
final def isTimerActive(name: String) = timers contains name
|
final def isTimerActive(name: String): Boolean = timers contains name
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set state timeout explicitly. This method can safely be used from within a
|
* Set state timeout explicitly. This method can safely be used from within a
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,6 @@
|
||||||
|
|
||||||
package akka.actor
|
package akka.actor
|
||||||
|
|
||||||
import language.existentials
|
|
||||||
|
|
||||||
import akka.dispatch._
|
import akka.dispatch._
|
||||||
import akka.japi.Creator
|
import akka.japi.Creator
|
||||||
import scala.reflect.ClassTag
|
import scala.reflect.ClassTag
|
||||||
|
|
|
||||||
|
|
@ -128,9 +128,13 @@ object TypedActor extends ExtensionId[TypedActorExtension] with ExtensionIdProvi
|
||||||
case class MethodCall(method: Method, parameters: Array[AnyRef]) {
|
case class MethodCall(method: Method, parameters: Array[AnyRef]) {
|
||||||
|
|
||||||
def isOneWay = method.getReturnType == java.lang.Void.TYPE
|
def isOneWay = method.getReturnType == java.lang.Void.TYPE
|
||||||
def returnsFuture_? = classOf[Future[_]].isAssignableFrom(method.getReturnType)
|
def returnsFuture = classOf[Future[_]] isAssignableFrom method.getReturnType
|
||||||
def returnsJOption_? = classOf[akka.japi.Option[_]].isAssignableFrom(method.getReturnType)
|
def returnsJOption = classOf[akka.japi.Option[_]] isAssignableFrom method.getReturnType
|
||||||
def returnsOption_? = classOf[scala.Option[_]].isAssignableFrom(method.getReturnType)
|
def returnsOption = classOf[scala.Option[_]] isAssignableFrom method.getReturnType
|
||||||
|
|
||||||
|
@deprecated("use returnsFuture instead", "2.2") def returnsFuture_? = returnsFuture
|
||||||
|
@deprecated("use returnsJOption instead", "2.2") def returnsJOption_? = returnsJOption
|
||||||
|
@deprecated("use returnsOption instead", "2.2") def returnsOption_? = returnsOption
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invokes the Method on the supplied instance
|
* Invokes the Method on the supplied instance
|
||||||
|
|
@ -296,7 +300,7 @@ object TypedActor extends ExtensionId[TypedActorExtension] with ExtensionIdProvi
|
||||||
if (m.isOneWay) m(me)
|
if (m.isOneWay) m(me)
|
||||||
else {
|
else {
|
||||||
try {
|
try {
|
||||||
if (m.returnsFuture_?) {
|
if (m.returnsFuture) {
|
||||||
val s = sender
|
val s = sender
|
||||||
m(me).asInstanceOf[Future[Any]] onComplete {
|
m(me).asInstanceOf[Future[Any]] onComplete {
|
||||||
case Failure(f) ⇒ s ! Status.Failure(f)
|
case Failure(f) ⇒ s ! Status.Failure(f)
|
||||||
|
|
@ -400,12 +404,12 @@ object TypedActor extends ExtensionId[TypedActorExtension] with ExtensionIdProvi
|
||||||
case _ ⇒
|
case _ ⇒
|
||||||
import akka.pattern.ask
|
import akka.pattern.ask
|
||||||
MethodCall(method, args) match {
|
MethodCall(method, args) match {
|
||||||
case m if m.isOneWay ⇒ actor ! m; null //Null return value
|
case m if m.isOneWay ⇒ actor ! m; null //Null return value
|
||||||
case m if m.returnsFuture_? ⇒ ask(actor, m)(timeout)
|
case m if m.returnsFuture ⇒ ask(actor, m)(timeout)
|
||||||
case m if m.returnsJOption_? || m.returnsOption_? ⇒
|
case m if m.returnsJOption || m.returnsOption ⇒
|
||||||
val f = ask(actor, m)(timeout)
|
val f = ask(actor, m)(timeout)
|
||||||
(try { Await.ready(f, timeout.duration).value } catch { case _: TimeoutException ⇒ None }) match {
|
(try { Await.ready(f, timeout.duration).value } catch { case _: TimeoutException ⇒ None }) match {
|
||||||
case None | Some(Success(null)) ⇒ if (m.returnsJOption_?) JOption.none[Any] else None
|
case None | Some(Success(null)) ⇒ if (m.returnsJOption) JOption.none[Any] else None
|
||||||
case Some(t: Try[_]) ⇒ t.get.asInstanceOf[AnyRef]
|
case Some(t: Try[_]) ⇒ t.get.asInstanceOf[AnyRef]
|
||||||
}
|
}
|
||||||
case m ⇒ Await.result(ask(actor, m)(timeout), timeout.duration).asInstanceOf[AnyRef]
|
case m ⇒ Await.result(ask(actor, m)(timeout), timeout.duration).asInstanceOf[AnyRef]
|
||||||
|
|
@ -655,8 +659,8 @@ class TypedActorExtension(system: ExtendedActorSystem) extends TypedActorFactory
|
||||||
/**
|
/**
|
||||||
* INTERNAL USE ONLY
|
* INTERNAL USE ONLY
|
||||||
*/
|
*/
|
||||||
private[akka] def invocationHandlerFor(typedActor_? : AnyRef): TypedActorInvocationHandler =
|
private[akka] def invocationHandlerFor(@deprecatedName('typedActor_?) typedActor: AnyRef): TypedActorInvocationHandler =
|
||||||
if ((typedActor_? ne null) && Proxy.isProxyClass(typedActor_?.getClass)) typedActor_? match {
|
if ((typedActor ne null) && Proxy.isProxyClass(typedActor.getClass)) typedActor match {
|
||||||
case null ⇒ null
|
case null ⇒ null
|
||||||
case other ⇒ Proxy.getInvocationHandler(other) match {
|
case other ⇒ Proxy.getInvocationHandler(other) match {
|
||||||
case null ⇒ null
|
case null ⇒ null
|
||||||
|
|
|
||||||
|
|
@ -450,7 +450,6 @@ abstract class MessageDispatcherConfigurator(val config: Config, val prerequisit
|
||||||
}
|
}
|
||||||
|
|
||||||
class ThreadPoolExecutorConfigurator(config: Config, prerequisites: DispatcherPrerequisites) extends ExecutorServiceConfigurator(config, prerequisites) {
|
class ThreadPoolExecutorConfigurator(config: Config, prerequisites: DispatcherPrerequisites) extends ExecutorServiceConfigurator(config, prerequisites) {
|
||||||
import ThreadPoolConfigBuilder.conf_?
|
|
||||||
|
|
||||||
val threadPoolConfig: ThreadPoolConfig = createThreadPoolConfigBuilder(config, prerequisites).config
|
val threadPoolConfig: ThreadPoolConfig = createThreadPoolConfigBuilder(config, prerequisites).config
|
||||||
|
|
||||||
|
|
@ -461,15 +460,15 @@ class ThreadPoolExecutorConfigurator(config: Config, prerequisites: DispatcherPr
|
||||||
.setCorePoolSizeFromFactor(config getInt "core-pool-size-min", config getDouble "core-pool-size-factor", config getInt "core-pool-size-max")
|
.setCorePoolSizeFromFactor(config getInt "core-pool-size-min", config getDouble "core-pool-size-factor", config getInt "core-pool-size-max")
|
||||||
.setMaxPoolSizeFromFactor(config getInt "max-pool-size-min", config getDouble "max-pool-size-factor", config getInt "max-pool-size-max")
|
.setMaxPoolSizeFromFactor(config getInt "max-pool-size-min", config getDouble "max-pool-size-factor", config getInt "max-pool-size-max")
|
||||||
.configure(
|
.configure(
|
||||||
conf_?(Some(config getInt "task-queue-size") flatMap {
|
Some(config getInt "task-queue-size") flatMap {
|
||||||
case size if size > 0 ⇒
|
case size if size > 0 ⇒
|
||||||
Some(config getString "task-queue-type") map {
|
Some(config getString "task-queue-type") map {
|
||||||
case "array" ⇒ ThreadPoolConfig.arrayBlockingQueue(size, false) //TODO config fairness?
|
case "array" ⇒ ThreadPoolConfig.arrayBlockingQueue(size, false) //TODO config fairness?
|
||||||
case "" | "linked" ⇒ ThreadPoolConfig.linkedBlockingQueue(size)
|
case "" | "linked" ⇒ ThreadPoolConfig.linkedBlockingQueue(size)
|
||||||
case x ⇒ throw new IllegalArgumentException("[%s] is not a valid task-queue-type [array|linked]!" format x)
|
case x ⇒ throw new IllegalArgumentException("[%s] is not a valid task-queue-type [array|linked]!" format x)
|
||||||
}
|
} map { qf ⇒ (q: ThreadPoolConfigBuilder) ⇒ q.setQueueFactory(qf) }
|
||||||
case _ ⇒ None
|
case _ ⇒ None
|
||||||
})(queueFactory ⇒ _.setQueueFactory(queueFactory)))
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
def createExecutorServiceFactory(id: String, threadFactory: ThreadFactory): ExecutorServiceFactory =
|
def createExecutorServiceFactory(id: String, threadFactory: ThreadFactory): ExecutorServiceFactory =
|
||||||
|
|
|
||||||
|
|
@ -99,10 +99,6 @@ case class ThreadPoolConfig(allowCorePoolTimeout: Boolean = ThreadPoolConfig.def
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
object ThreadPoolConfigBuilder {
|
|
||||||
def conf_?[T](opt: Option[T])(fun: (T) ⇒ ThreadPoolConfigBuilder ⇒ ThreadPoolConfigBuilder): Option[(ThreadPoolConfigBuilder) ⇒ ThreadPoolConfigBuilder] = opt map fun
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A DSL to configure and create a MessageDispatcher with a ThreadPoolExecutor
|
* A DSL to configure and create a MessageDispatcher with a ThreadPoolExecutor
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -31,3 +31,11 @@ API changes to FSM and TestFSMRef
|
||||||
The ``timerActive_?`` method has been deprecated in both the ``FSM`` trait and the ``TestFSMRef``
|
The ``timerActive_?`` method has been deprecated in both the ``FSM`` trait and the ``TestFSMRef``
|
||||||
class. You should now use the ``isTimerActive`` method instead. The old method will remain
|
class. You should now use the ``isTimerActive`` method instead. The old method will remain
|
||||||
throughout 2.2.x. It will be removed in Akka 2.3.
|
throughout 2.2.x. It will be removed in Akka 2.3.
|
||||||
|
|
||||||
|
ThreadPoolConfigBuilder
|
||||||
|
=======================
|
||||||
|
|
||||||
|
``akka.dispatch.ThreadPoolConfigBuilder`` companion object has been removed,
|
||||||
|
and with it the ``conf_?`` method that was essentially only a type-inferencer aid for creation
|
||||||
|
of optional transformations on ``ThreadPoolConfigBuilder``.
|
||||||
|
Instead use: ``option.map(o => (t: ThreadPoolConfigBuilder) => t.op(o))``.
|
||||||
|
|
@ -232,7 +232,7 @@ class TestkitDocSpec extends AkkaSpec with DefaultTimeout with ImplicitSender {
|
||||||
//#test-probe-forward
|
//#test-probe-forward
|
||||||
}
|
}
|
||||||
|
|
||||||
"demonstrate " in {
|
"demonstrate calling thread dispatcher" in {
|
||||||
//#calling-thread-dispatcher
|
//#calling-thread-dispatcher
|
||||||
import akka.testkit.CallingThreadDispatcher
|
import akka.testkit.CallingThreadDispatcher
|
||||||
val ref = system.actorOf(Props[MyActor].withDispatcher(CallingThreadDispatcher.Id))
|
val ref = system.actorOf(Props[MyActor].withDispatcher(CallingThreadDispatcher.Id))
|
||||||
|
|
|
||||||
|
|
@ -75,11 +75,8 @@ class TestFSMRef[S, D, T <: Actor](
|
||||||
*/
|
*/
|
||||||
def cancelTimer(name: String) { fsm.cancelTimer(name) }
|
def cancelTimer(name: String) { fsm.cancelTimer(name) }
|
||||||
|
|
||||||
/**
|
@deprecated("Use isTimerActive", "2.2")
|
||||||
* Proxy for FSM.timerActive_?.
|
def timerActive_?(name: String): Boolean = isTimerActive(name)
|
||||||
*/
|
|
||||||
@deprecated("Use isTimerActive(name) instead.", "2.2")
|
|
||||||
def timerActive_?(name: String) = isTimerActive(name)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Proxy for FSM.isTimerActive.
|
* Proxy for FSM.isTimerActive.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue