Replacing use of == null and != null for Scala
This commit is contained in:
parent
0cc2e26a91
commit
ebf3dd0b52
25 changed files with 59 additions and 63 deletions
|
|
@ -630,7 +630,6 @@ trait ActorRef extends
|
||||||
override def hashCode: Int = HashCode.hash(HashCode.SEED, uuid)
|
override def hashCode: Int = HashCode.hash(HashCode.SEED, uuid)
|
||||||
|
|
||||||
override def equals(that: Any): Boolean = {
|
override def equals(that: Any): Boolean = {
|
||||||
that != null &&
|
|
||||||
that.isInstanceOf[ActorRef] &&
|
that.isInstanceOf[ActorRef] &&
|
||||||
that.asInstanceOf[ActorRef].uuid == uuid
|
that.asInstanceOf[ActorRef].uuid == uuid
|
||||||
}
|
}
|
||||||
|
|
@ -1302,7 +1301,7 @@ class LocalActorRef private[akka](
|
||||||
} catch {
|
} catch {
|
||||||
case e: NoSuchFieldException =>
|
case e: NoSuchFieldException =>
|
||||||
val parent = clazz.getSuperclass
|
val parent = clazz.getSuperclass
|
||||||
if (parent != null) findActorSelfField(parent)
|
if (parent ne null) findActorSelfField(parent)
|
||||||
else throw new IllegalActorStateException(
|
else throw new IllegalActorStateException(
|
||||||
toString + " is not an Actor since it have not mixed in the 'Actor' trait")
|
toString + " is not an Actor since it have not mixed in the 'Actor' trait")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ object Config {
|
||||||
|
|
||||||
val HOME = {
|
val HOME = {
|
||||||
val systemHome = System.getenv("AKKA_HOME")
|
val systemHome = System.getenv("AKKA_HOME")
|
||||||
if (systemHome == null || systemHome.length == 0 || systemHome == ".") {
|
if ((systemHome eq null) || systemHome.length == 0 || systemHome == ".") {
|
||||||
val optionHome = System.getProperty("akka.home", "")
|
val optionHome = System.getProperty("akka.home", "")
|
||||||
if (optionHome.length != 0) Some(optionHome)
|
if (optionHome.length != 0) Some(optionHome)
|
||||||
else None
|
else None
|
||||||
|
|
@ -52,7 +52,7 @@ object Config {
|
||||||
"\n\tdue to: " + e.toString)
|
"\n\tdue to: " + e.toString)
|
||||||
}
|
}
|
||||||
Configgy.config
|
Configgy.config
|
||||||
} else if (getClass.getClassLoader.getResource("akka.conf") != null) {
|
} else if (getClass.getClassLoader.getResource("akka.conf") ne null) {
|
||||||
try {
|
try {
|
||||||
Configgy.configureFromResource("akka.conf", getClass.getClassLoader)
|
Configgy.configureFromResource("akka.conf", getClass.getClassLoader)
|
||||||
ConfigLogger.log.info("Config loaded from the application classpath.")
|
ConfigLogger.log.info("Config loaded from the application classpath.")
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,6 @@ final class MessageInvocation(val receiver: ActorRef,
|
||||||
}
|
}
|
||||||
|
|
||||||
override def equals(that: Any): Boolean = {
|
override def equals(that: Any): Boolean = {
|
||||||
that != null &&
|
|
||||||
that.isInstanceOf[MessageInvocation] &&
|
that.isInstanceOf[MessageInvocation] &&
|
||||||
that.asInstanceOf[MessageInvocation].receiver.actor == receiver.actor &&
|
that.asInstanceOf[MessageInvocation].receiver.actor == receiver.actor &&
|
||||||
that.asInstanceOf[MessageInvocation].message == message
|
that.asInstanceOf[MessageInvocation].message == message
|
||||||
|
|
|
||||||
|
|
@ -165,7 +165,6 @@ object Transaction {
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
override def equals(that: Any): Boolean = synchronized {
|
override def equals(that: Any): Boolean = synchronized {
|
||||||
that != null &&
|
|
||||||
that.isInstanceOf[Transaction] &&
|
that.isInstanceOf[Transaction] &&
|
||||||
that.asInstanceOf[Transaction].id == this.id
|
that.asInstanceOf[Transaction].id == this.id
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ import java.security.MessageDigest
|
||||||
*/
|
*/
|
||||||
object Helpers extends Logging {
|
object Helpers extends Logging {
|
||||||
|
|
||||||
implicit def null2Option[T](t: T): Option[T] = if (t != null) Some(t) else None
|
implicit def null2Option[T](t: T): Option[T] = Option(t)
|
||||||
|
|
||||||
def intToBytes(value: Int): Array[Byte] = {
|
def intToBytes(value: Int): Array[Byte] = {
|
||||||
val bytes = new Array[Byte](4)
|
val bytes = new Array[Byte](4)
|
||||||
|
|
@ -41,7 +41,7 @@ object Helpers extends Logging {
|
||||||
* if the actual type is not assignable from the given one.
|
* if the actual type is not assignable from the given one.
|
||||||
*/
|
*/
|
||||||
def narrow[T](o: Option[Any]): Option[T] = {
|
def narrow[T](o: Option[Any]): Option[T] = {
|
||||||
require(o != null, "Option to be narrowed must not be null!")
|
require((o ne null), "Option to be narrowed must not be null!")
|
||||||
o.asInstanceOf[Option[T]]
|
o.asInstanceOf[Option[T]]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -104,7 +104,7 @@ class TypedActorInfo(context: CamelContext, clazz: Class[_], strategy: Parameter
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val superclass = clazz.getSuperclass
|
val superclass = clazz.getSuperclass
|
||||||
if (superclass != null && !superclass.equals(classOf[AnyRef])) {
|
if ((superclass ne null) && !superclass.equals(classOf[AnyRef])) {
|
||||||
introspect(superclass)
|
introspect(superclass)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -207,7 +207,7 @@ trait AuthenticationActor[C <: Credentials] extends Actor {
|
||||||
//Turns the aforementioned header value into an option
|
//Turns the aforementioned header value into an option
|
||||||
def authOption(r: Req): Option[String] = {
|
def authOption(r: Req): Option[String] = {
|
||||||
val a = auth(r)
|
val a = auth(r)
|
||||||
if (a != null && a.length > 0) Some(a) else None
|
if ((a ne null) && a.length > 0) Some(a) else None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -221,7 +221,7 @@ trait TransactionProtocol extends Logging {
|
||||||
private def storeInThreadLocal(tx: Transaction) = suspendedTx.set(tx)
|
private def storeInThreadLocal(tx: Transaction) = suspendedTx.set(tx)
|
||||||
|
|
||||||
private def fetchFromThreadLocal: Option[Transaction] = {
|
private def fetchFromThreadLocal: Option[Transaction] = {
|
||||||
if (suspendedTx != null && suspendedTx.get() != null) Some(suspendedTx.get.asInstanceOf[Transaction])
|
if ((suspendedTx ne null) && (suspendedTx.get() ne null)) Some(suspendedTx.get.asInstanceOf[Transaction])
|
||||||
else None
|
else None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -344,7 +344,7 @@ MapStorageBackend[Array[Byte], Array[Byte]] with
|
||||||
}
|
}
|
||||||
|
|
||||||
def initStoreClients() = {
|
def initStoreClients() = {
|
||||||
if (storeClientFactory != null) {
|
if (storeClientFactory ne null) {
|
||||||
storeClientFactory.close
|
storeClientFactory.close
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -115,7 +115,6 @@ object RemoteServer {
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
override def equals(that: Any): Boolean = {
|
override def equals(that: Any): Boolean = {
|
||||||
that != null &&
|
|
||||||
that.isInstanceOf[Address] &&
|
that.isInstanceOf[Address] &&
|
||||||
that.asInstanceOf[Address].hostname == hostname &&
|
that.asInstanceOf[Address].hostname == hostname &&
|
||||||
that.asInstanceOf[Address].port == port
|
that.asInstanceOf[Address].port == port
|
||||||
|
|
|
||||||
|
|
@ -337,7 +337,7 @@ object TypedActorSerialization {
|
||||||
proxy: AnyRef, format: Format[T]): SerializedTypedActorRefProtocol = {
|
proxy: AnyRef, format: Format[T]): SerializedTypedActorRefProtocol = {
|
||||||
|
|
||||||
val init = AspectInitRegistry.initFor(proxy)
|
val init = AspectInitRegistry.initFor(proxy)
|
||||||
if (init == null) throw new IllegalArgumentException("Proxy for typed actor could not be found in AspectInitRegistry.")
|
if (init eq null) throw new IllegalArgumentException("Proxy for typed actor could not be found in AspectInitRegistry.")
|
||||||
|
|
||||||
SerializedTypedActorRefProtocol.newBuilder
|
SerializedTypedActorRefProtocol.newBuilder
|
||||||
.setActorRef(ActorSerialization.toSerializedActorRefProtocol(init.actorRef, format))
|
.setActorRef(ActorSerialization.toSerializedActorRefProtocol(init.actorRef, format))
|
||||||
|
|
|
||||||
|
|
@ -201,18 +201,18 @@ class ServerInitiatedRemoteActorSpec extends JUnitSuite {
|
||||||
def shouldRegisterAndUnregister {
|
def shouldRegisterAndUnregister {
|
||||||
val actor1 = actorOf[RemoteActorSpecActorUnidirectional]
|
val actor1 = actorOf[RemoteActorSpecActorUnidirectional]
|
||||||
server.register("my-service-1", actor1)
|
server.register("my-service-1", actor1)
|
||||||
assert(server.actors().get("my-service-1") != null, "actor registered")
|
assert(server.actors().get("my-service-1") ne null, "actor registered")
|
||||||
server.unregister("my-service-1")
|
server.unregister("my-service-1")
|
||||||
assert(server.actors().get("my-service-1") == null, "actor unregistered")
|
assert(server.actors().get("my-service-1") eq null, "actor unregistered")
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
def shouldRegisterAndUnregisterByUuid {
|
def shouldRegisterAndUnregisterByUuid {
|
||||||
val actor1 = actorOf[RemoteActorSpecActorUnidirectional]
|
val actor1 = actorOf[RemoteActorSpecActorUnidirectional]
|
||||||
server.register("uuid:" + actor1.uuid, actor1)
|
server.register("uuid:" + actor1.uuid, actor1)
|
||||||
assert(server.actorsByUuid().get(actor1.uuid.toString) != null, "actor registered")
|
assert(server.actorsByUuid().get(actor1.uuid.toString) ne null, "actor registered")
|
||||||
server.unregister("uuid:" + actor1.uuid)
|
server.unregister("uuid:" + actor1.uuid)
|
||||||
assert(server.actorsByUuid().get(actor1.uuid) == null, "actor unregistered")
|
assert(server.actorsByUuid().get(actor1.uuid) eq null, "actor unregistered")
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -100,9 +100,9 @@ class ActorFactoryBean extends AbstractFactoryBean[AnyRef] with Logging with App
|
||||||
}
|
}
|
||||||
|
|
||||||
private[akka] def createTypedInstance() : AnyRef = {
|
private[akka] def createTypedInstance() : AnyRef = {
|
||||||
if (interface == null || interface == "") throw new AkkaBeansException(
|
if ((interface eq null) || interface == "") throw new AkkaBeansException(
|
||||||
"The 'interface' part of the 'akka:actor' element in the Spring config file can't be null or empty string")
|
"The 'interface' part of the 'akka:actor' element in the Spring config file can't be null or empty string")
|
||||||
if (implementation == null || implementation == "") throw new AkkaBeansException(
|
if ((implementation eq null) || implementation == "") throw new AkkaBeansException(
|
||||||
"The 'implementation' part of the 'akka:typed-actor' element in the Spring config file can't be null or empty string")
|
"The 'implementation' part of the 'akka:typed-actor' element in the Spring config file can't be null or empty string")
|
||||||
|
|
||||||
val typedActor: AnyRef = TypedActor.newInstance(interface.toClass, implementation.toClass, createConfig)
|
val typedActor: AnyRef = TypedActor.newInstance(interface.toClass, implementation.toClass, createConfig)
|
||||||
|
|
@ -121,7 +121,7 @@ class ActorFactoryBean extends AbstractFactoryBean[AnyRef] with Logging with App
|
||||||
* Create an UntypedActor.
|
* Create an UntypedActor.
|
||||||
*/
|
*/
|
||||||
private[akka] def createUntypedInstance() : ActorRef = {
|
private[akka] def createUntypedInstance() : ActorRef = {
|
||||||
if (implementation == null || implementation == "") throw new AkkaBeansException(
|
if ((implementation eq null) || implementation == "") throw new AkkaBeansException(
|
||||||
"The 'implementation' part of the 'akka:untyped-actor' element in the Spring config file can't be null or empty string")
|
"The 'implementation' part of the 'akka:untyped-actor' element in the Spring config file can't be null or empty string")
|
||||||
val actorRef = Actor.actorOf(implementation.toClass)
|
val actorRef = Actor.actorOf(implementation.toClass)
|
||||||
if (timeout > 0) {
|
if (timeout > 0) {
|
||||||
|
|
@ -199,11 +199,11 @@ class ActorFactoryBean extends AbstractFactoryBean[AnyRef] with Logging with App
|
||||||
config
|
config
|
||||||
}
|
}
|
||||||
|
|
||||||
private[akka] def isRemote = (host != null) && (!host.isEmpty)
|
private[akka] def isRemote = (host ne null) && (!host.isEmpty)
|
||||||
|
|
||||||
private[akka] def hasDispatcher =
|
private[akka] def hasDispatcher =
|
||||||
(dispatcher != null) &&
|
(dispatcher ne null) &&
|
||||||
(dispatcher.dispatcherType != null) &&
|
(dispatcher.dispatcherType ne null) &&
|
||||||
(!dispatcher.dispatcherType.isEmpty)
|
(!dispatcher.dispatcherType.isEmpty)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -28,18 +28,18 @@ trait ActorParser extends BeanParser with DispatcherParser {
|
||||||
val dispatcherElement = DomUtils.getChildElementByTagName(element, DISPATCHER_TAG)
|
val dispatcherElement = DomUtils.getChildElementByTagName(element, DISPATCHER_TAG)
|
||||||
val propertyEntries = DomUtils.getChildElementsByTagName(element, PROPERTYENTRY_TAG)
|
val propertyEntries = DomUtils.getChildElementsByTagName(element, PROPERTYENTRY_TAG)
|
||||||
|
|
||||||
if (remoteElement != null) {
|
if (remoteElement ne null) {
|
||||||
objectProperties.host = mandatory(remoteElement, HOST)
|
objectProperties.host = mandatory(remoteElement, HOST)
|
||||||
objectProperties.port = mandatory(remoteElement, PORT)
|
objectProperties.port = mandatory(remoteElement, PORT)
|
||||||
objectProperties.serverManaged = (remoteElement.getAttribute(MANAGED_BY) != null) && (remoteElement.getAttribute(MANAGED_BY).equals(SERVER_MANAGED))
|
objectProperties.serverManaged = (remoteElement.getAttribute(MANAGED_BY) ne null) && (remoteElement.getAttribute(MANAGED_BY).equals(SERVER_MANAGED))
|
||||||
val serviceName = remoteElement.getAttribute(SERVICE_NAME)
|
val serviceName = remoteElement.getAttribute(SERVICE_NAME)
|
||||||
if ((serviceName != null) && (!serviceName.isEmpty)) {
|
if ((serviceName ne null) && (!serviceName.isEmpty)) {
|
||||||
objectProperties.serviceName = serviceName
|
objectProperties.serviceName = serviceName
|
||||||
objectProperties.serverManaged = true
|
objectProperties.serverManaged = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dispatcherElement != null) {
|
if (dispatcherElement ne null) {
|
||||||
val dispatcherProperties = parseDispatcher(dispatcherElement)
|
val dispatcherProperties = parseDispatcher(dispatcherElement)
|
||||||
objectProperties.dispatcher = dispatcherProperties
|
objectProperties.dispatcher = dispatcherProperties
|
||||||
}
|
}
|
||||||
|
|
@ -108,7 +108,7 @@ trait BeanParser extends Logging {
|
||||||
* @param attribute name of the mandatory attribute
|
* @param attribute name of the mandatory attribute
|
||||||
*/
|
*/
|
||||||
def mandatory(element: Element, attribute: String): String = {
|
def mandatory(element: Element, attribute: String): String = {
|
||||||
if ((element.getAttribute(attribute) == null) || (element.getAttribute(attribute).isEmpty)) {
|
if ((element.getAttribute(attribute) eq null) || (element.getAttribute(attribute).isEmpty)) {
|
||||||
throw new IllegalArgumentException("Mandatory attribute missing: " + attribute)
|
throw new IllegalArgumentException("Mandatory attribute missing: " + attribute)
|
||||||
} else {
|
} else {
|
||||||
element.getAttribute(attribute)
|
element.getAttribute(attribute)
|
||||||
|
|
@ -122,7 +122,7 @@ trait BeanParser extends Logging {
|
||||||
*/
|
*/
|
||||||
def mandatoryElement(element: Element, childName: String): Element = {
|
def mandatoryElement(element: Element, childName: String): Element = {
|
||||||
val childElement = DomUtils.getChildElementByTagName(element, childName);
|
val childElement = DomUtils.getChildElementByTagName(element, childName);
|
||||||
if (childElement == null) {
|
if (childElement eq null) {
|
||||||
throw new IllegalArgumentException("Mandatory element missing: '<akka:" + childName + ">'")
|
throw new IllegalArgumentException("Mandatory element missing: '<akka:" + childName + ">'")
|
||||||
} else {
|
} else {
|
||||||
childElement
|
childElement
|
||||||
|
|
@ -150,7 +150,7 @@ trait DispatcherParser extends BeanParser {
|
||||||
if (hasRef(element)) {
|
if (hasRef(element)) {
|
||||||
val ref = element.getAttribute(REF)
|
val ref = element.getAttribute(REF)
|
||||||
dispatcherElement = element.getOwnerDocument.getElementById(ref)
|
dispatcherElement = element.getOwnerDocument.getElementById(ref)
|
||||||
if (dispatcherElement == null) {
|
if (dispatcherElement eq null) {
|
||||||
throw new IllegalArgumentException("Referenced dispatcher not found: '" + ref + "'")
|
throw new IllegalArgumentException("Referenced dispatcher not found: '" + ref + "'")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -173,7 +173,7 @@ trait DispatcherParser extends BeanParser {
|
||||||
}
|
}
|
||||||
|
|
||||||
val threadPoolElement = DomUtils.getChildElementByTagName(dispatcherElement, THREAD_POOL_TAG);
|
val threadPoolElement = DomUtils.getChildElementByTagName(dispatcherElement, THREAD_POOL_TAG);
|
||||||
if (threadPoolElement != null) {
|
if (threadPoolElement ne null) {
|
||||||
if (properties.dispatcherType == THREAD_BASED) {
|
if (properties.dispatcherType == THREAD_BASED) {
|
||||||
throw new IllegalArgumentException("Element 'thread-pool' not allowed for this dispatcher type.")
|
throw new IllegalArgumentException("Element 'thread-pool' not allowed for this dispatcher type.")
|
||||||
}
|
}
|
||||||
|
|
@ -220,7 +220,7 @@ trait DispatcherParser extends BeanParser {
|
||||||
|
|
||||||
def hasRef(element: Element): Boolean = {
|
def hasRef(element: Element): Boolean = {
|
||||||
val ref = element.getAttribute(REF)
|
val ref = element.getAttribute(REF)
|
||||||
(ref != null) && !ref.isEmpty
|
(ref ne null) && !ref.isEmpty
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ class ConfiggyPropertyPlaceholderConfigurer extends PropertyPlaceholderConfigure
|
||||||
* @param configgyResource akka.conf
|
* @param configgyResource akka.conf
|
||||||
*/
|
*/
|
||||||
override def setLocation(configgyResource: Resource) {
|
override def setLocation(configgyResource: Resource) {
|
||||||
if (configgyResource == null) throw new IllegalArgumentException("Property 'config' must be set")
|
if (configgyResource eq null) throw new IllegalArgumentException("Property 'config' must be set")
|
||||||
val properties = loadAkkaConfig(configgyResource)
|
val properties = loadAkkaConfig(configgyResource)
|
||||||
setProperties(properties)
|
setProperties(properties)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ object DispatcherFactoryBean {
|
||||||
case _ => throw new IllegalArgumentException("unknown dispatcher type")
|
case _ => throw new IllegalArgumentException("unknown dispatcher type")
|
||||||
}
|
}
|
||||||
// build threadpool
|
// build threadpool
|
||||||
if ((properties.threadPool != null) && (properties.threadPool.queue != null)) {
|
if ((properties.threadPool ne null) && (properties.threadPool.queue ne null)) {
|
||||||
var threadPoolBuilder = dispatcher.asInstanceOf[ThreadPoolBuilder]
|
var threadPoolBuilder = dispatcher.asInstanceOf[ThreadPoolBuilder]
|
||||||
threadPoolBuilder = properties.threadPool.queue match {
|
threadPoolBuilder = properties.threadPool.queue match {
|
||||||
case VAL_BOUNDED_ARRAY_BLOCKING_QUEUE => threadPoolBuilder.withNewThreadPoolWithArrayBlockingQueueWithCapacityAndFairness(properties.threadPool.capacity, properties.threadPool.fairness)
|
case VAL_BOUNDED_ARRAY_BLOCKING_QUEUE => threadPoolBuilder.withNewThreadPoolWithArrayBlockingQueueWithCapacityAndFairness(properties.threadPool.capacity, properties.threadPool.fairness)
|
||||||
|
|
@ -59,7 +59,7 @@ object DispatcherFactoryBean {
|
||||||
if (properties.threadPool.mailboxCapacity > -1) {
|
if (properties.threadPool.mailboxCapacity > -1) {
|
||||||
threadPoolBuilder.setMailboxCapacity(properties.threadPool.mailboxCapacity)
|
threadPoolBuilder.setMailboxCapacity(properties.threadPool.mailboxCapacity)
|
||||||
}
|
}
|
||||||
if ((properties.threadPool.rejectionPolicy != null) && (!properties.threadPool.rejectionPolicy.isEmpty)) {
|
if ((properties.threadPool.rejectionPolicy ne null) && (!properties.threadPool.rejectionPolicy.isEmpty)) {
|
||||||
val policy: RejectedExecutionHandler = properties.threadPool.rejectionPolicy match {
|
val policy: RejectedExecutionHandler = properties.threadPool.rejectionPolicy match {
|
||||||
case "abort-policy" => new AbortPolicy()
|
case "abort-policy" => new AbortPolicy()
|
||||||
case "caller-runs-policy" => new CallerRunsPolicy()
|
case "caller-runs-policy" => new CallerRunsPolicy()
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ object StringReflect {
|
||||||
* @author michaelkober
|
* @author michaelkober
|
||||||
*/
|
*/
|
||||||
class StringReflect(val self: String) {
|
class StringReflect(val self: String) {
|
||||||
if (self == null || self == "") throw new IllegalArgumentException("Class name can't be null or empty string [" + self + "]")
|
if ((self eq null) || self == "") throw new IllegalArgumentException("Class name can't be null or empty string [" + self + "]")
|
||||||
def toClass[T <: AnyRef]: Class[T] = {
|
def toClass[T <: AnyRef]: Class[T] = {
|
||||||
val clazz = Class.forName(self)
|
val clazz = Class.forName(self)
|
||||||
clazz.asInstanceOf[Class[T]]
|
clazz.asInstanceOf[Class[T]]
|
||||||
|
|
|
||||||
|
|
@ -33,11 +33,11 @@ class SupervisionBeanDefinitionParser extends AbstractSingleBeanDefinitionParser
|
||||||
val strategyElement = mandatoryElement(element, STRATEGY_TAG)
|
val strategyElement = mandatoryElement(element, STRATEGY_TAG)
|
||||||
val typedActorsElement = DomUtils.getChildElementByTagName(element, TYPED_ACTORS_TAG)
|
val typedActorsElement = DomUtils.getChildElementByTagName(element, TYPED_ACTORS_TAG)
|
||||||
val untypedActorsElement = DomUtils.getChildElementByTagName(element, UNTYPED_ACTORS_TAG)
|
val untypedActorsElement = DomUtils.getChildElementByTagName(element, UNTYPED_ACTORS_TAG)
|
||||||
if ((typedActorsElement == null) && (untypedActorsElement == null)) {
|
if ((typedActorsElement eq null) && (untypedActorsElement eq null)) {
|
||||||
throw new IllegalArgumentException("One of 'akka:typed-actors' or 'akka:untyped-actors' needed.")
|
throw new IllegalArgumentException("One of 'akka:typed-actors' or 'akka:untyped-actors' needed.")
|
||||||
}
|
}
|
||||||
parseRestartStrategy(strategyElement, builder)
|
parseRestartStrategy(strategyElement, builder)
|
||||||
if (typedActorsElement != null) {
|
if (typedActorsElement ne null) {
|
||||||
builder.addPropertyValue("typed", AkkaSpringConfigurationTags.TYPED_ACTOR_TAG)
|
builder.addPropertyValue("typed", AkkaSpringConfigurationTags.TYPED_ACTOR_TAG)
|
||||||
parseTypedActorList(typedActorsElement, builder)
|
parseTypedActorList(typedActorsElement, builder)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -57,8 +57,8 @@ class SupervisionFactoryBean extends AbstractFactoryBean[AnyRef] {
|
||||||
private[akka] def createComponent(props: ActorProperties): Component = {
|
private[akka] def createComponent(props: ActorProperties): Component = {
|
||||||
import StringReflect._
|
import StringReflect._
|
||||||
val lifeCycle = if (!props.lifecycle.isEmpty && props.lifecycle.equalsIgnoreCase(VAL_LIFECYCYLE_TEMPORARY)) new LifeCycle(new Temporary()) else new LifeCycle(new Permanent())
|
val lifeCycle = if (!props.lifecycle.isEmpty && props.lifecycle.equalsIgnoreCase(VAL_LIFECYCYLE_TEMPORARY)) new LifeCycle(new Temporary()) else new LifeCycle(new Permanent())
|
||||||
val isRemote = (props.host != null) && (!props.host.isEmpty)
|
val isRemote = (props.host ne null) && (!props.host.isEmpty)
|
||||||
val withInterface = (props.interface != null) && (!props.interface.isEmpty)
|
val withInterface = (props.interface ne null) && (!props.interface.isEmpty)
|
||||||
if (isRemote) {
|
if (isRemote) {
|
||||||
//val remote = new RemoteAddress(props.host, props.port)
|
//val remote = new RemoteAddress(props.host, props.port)
|
||||||
val remote = new RemoteAddress(props.host, props.port.toInt)
|
val remote = new RemoteAddress(props.host, props.port.toInt)
|
||||||
|
|
@ -82,7 +82,7 @@ class SupervisionFactoryBean extends AbstractFactoryBean[AnyRef] {
|
||||||
private[akka] def createSupervise(props: ActorProperties): Server = {
|
private[akka] def createSupervise(props: ActorProperties): Server = {
|
||||||
import StringReflect._
|
import StringReflect._
|
||||||
val lifeCycle = if (!props.lifecycle.isEmpty && props.lifecycle.equalsIgnoreCase(VAL_LIFECYCYLE_TEMPORARY)) new LifeCycle(new Temporary()) else new LifeCycle(new Permanent())
|
val lifeCycle = if (!props.lifecycle.isEmpty && props.lifecycle.equalsIgnoreCase(VAL_LIFECYCYLE_TEMPORARY)) new LifeCycle(new Temporary()) else new LifeCycle(new Permanent())
|
||||||
val isRemote = (props.host != null) && (!props.host.isEmpty)
|
val isRemote = (props.host ne null) && (!props.host.isEmpty)
|
||||||
val actorRef = Actor.actorOf(props.target.toClass)
|
val actorRef = Actor.actorOf(props.target.toClass)
|
||||||
if (props.timeout > 0) {
|
if (props.timeout > 0) {
|
||||||
actorRef.setTimeout(props.timeout)
|
actorRef.setTimeout(props.timeout)
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ class DispatcherBeanDefinitionParserTest extends Spec with ShouldMatchers {
|
||||||
type="executor-based-event-driven"
|
type="executor-based-event-driven"
|
||||||
name="myDispatcher"/>
|
name="myDispatcher"/>
|
||||||
var props = parser.parseDispatcher(dom(xml).getDocumentElement);
|
var props = parser.parseDispatcher(dom(xml).getDocumentElement);
|
||||||
assert(props != null)
|
assert(props ne null)
|
||||||
assert(props.dispatcherType === "executor-based-event-driven")
|
assert(props.dispatcherType === "executor-based-event-driven")
|
||||||
assert(props.name === "myDispatcher")
|
assert(props.name === "myDispatcher")
|
||||||
|
|
||||||
|
|
@ -45,7 +45,7 @@ class DispatcherBeanDefinitionParserTest extends Spec with ShouldMatchers {
|
||||||
keep-alive="2000"
|
keep-alive="2000"
|
||||||
rejection-policy="caller-runs-policy"/>
|
rejection-policy="caller-runs-policy"/>
|
||||||
val props = parser.parseThreadPool(dom(xml).getDocumentElement);
|
val props = parser.parseThreadPool(dom(xml).getDocumentElement);
|
||||||
assert(props != null)
|
assert(props ne null)
|
||||||
assert(props.queue == "bounded-array-blocking-queue")
|
assert(props.queue == "bounded-array-blocking-queue")
|
||||||
assert(props.capacity == 100)
|
assert(props.capacity == 100)
|
||||||
assert(props.fairness)
|
assert(props.fairness)
|
||||||
|
|
@ -66,7 +66,7 @@ class DispatcherBeanDefinitionParserTest extends Spec with ShouldMatchers {
|
||||||
keep-alive="1000"/>
|
keep-alive="1000"/>
|
||||||
</akka:dispatcher>
|
</akka:dispatcher>
|
||||||
val props = parser.parseDispatcher(dom(xml).getDocumentElement);
|
val props = parser.parseDispatcher(dom(xml).getDocumentElement);
|
||||||
assert(props != null)
|
assert(props ne null)
|
||||||
assert(props.dispatcherType == "executor-based-event-driven")
|
assert(props.dispatcherType == "executor-based-event-driven")
|
||||||
assert(props.name == "myDispatcher")
|
assert(props.name == "myDispatcher")
|
||||||
assert(props.threadPool.corePoolSize == 2)
|
assert(props.threadPool.corePoolSize == 2)
|
||||||
|
|
@ -97,7 +97,7 @@ class DispatcherBeanDefinitionParserTest extends Spec with ShouldMatchers {
|
||||||
type="hawt"
|
type="hawt"
|
||||||
aggregate="false"/>
|
aggregate="false"/>
|
||||||
var props = parser.parseDispatcher(dom(xml).getDocumentElement);
|
var props = parser.parseDispatcher(dom(xml).getDocumentElement);
|
||||||
assert(props != null)
|
assert(props ne null)
|
||||||
assert(props.dispatcherType === "hawt")
|
assert(props.dispatcherType === "hawt")
|
||||||
assert(props.aggregate === false)
|
assert(props.aggregate === false)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@ class DispatcherSpringFeatureTest extends FeatureSpec with ShouldMatchers {
|
||||||
scenario("get a dispatcher via ref from context") {
|
scenario("get a dispatcher via ref from context") {
|
||||||
val context = new ClassPathXmlApplicationContext("/dispatcher-config.xml")
|
val context = new ClassPathXmlApplicationContext("/dispatcher-config.xml")
|
||||||
val pojo = context.getBean("typed-actor-with-dispatcher-ref").asInstanceOf[IMyPojo]
|
val pojo = context.getBean("typed-actor-with-dispatcher-ref").asInstanceOf[IMyPojo]
|
||||||
assert(pojo != null)
|
assert(pojo ne null)
|
||||||
}
|
}
|
||||||
|
|
||||||
scenario("get a executor-event-driven-dispatcher with blocking-queue with unbounded capacity from context") {
|
scenario("get a executor-event-driven-dispatcher with blocking-queue with unbounded capacity from context") {
|
||||||
|
|
@ -99,7 +99,7 @@ class DispatcherSpringFeatureTest extends FeatureSpec with ShouldMatchers {
|
||||||
scenario("get a executor-based-event-driven-work-stealing-dispatcher from context") {
|
scenario("get a executor-based-event-driven-work-stealing-dispatcher from context") {
|
||||||
val context = new ClassPathXmlApplicationContext("/dispatcher-config.xml")
|
val context = new ClassPathXmlApplicationContext("/dispatcher-config.xml")
|
||||||
val dispatcher = context.getBean("executor-based-event-driven-work-stealing-dispatcher").asInstanceOf[ExecutorBasedEventDrivenWorkStealingDispatcher]
|
val dispatcher = context.getBean("executor-based-event-driven-work-stealing-dispatcher").asInstanceOf[ExecutorBasedEventDrivenWorkStealingDispatcher]
|
||||||
assert(dispatcher != null)
|
assert(dispatcher ne null)
|
||||||
assert(dispatcher.name === "akka:event-driven-work-stealing:dispatcher:workStealingDispatcher")
|
assert(dispatcher.name === "akka:event-driven-work-stealing:dispatcher:workStealingDispatcher")
|
||||||
val executor = getThreadPoolExecutorAndAssert(dispatcher)
|
val executor = getThreadPoolExecutorAndAssert(dispatcher)
|
||||||
assert(executor.getQueue().isInstanceOf[BlockingQueue[Runnable]])
|
assert(executor.getQueue().isInstanceOf[BlockingQueue[Runnable]])
|
||||||
|
|
@ -108,7 +108,7 @@ class DispatcherSpringFeatureTest extends FeatureSpec with ShouldMatchers {
|
||||||
scenario("get a hawt-dispatcher from context") {
|
scenario("get a hawt-dispatcher from context") {
|
||||||
val context = new ClassPathXmlApplicationContext("/dispatcher-config.xml")
|
val context = new ClassPathXmlApplicationContext("/dispatcher-config.xml")
|
||||||
val dispatcher = context.getBean("hawt-dispatcher").asInstanceOf[HawtDispatcher]
|
val dispatcher = context.getBean("hawt-dispatcher").asInstanceOf[HawtDispatcher]
|
||||||
assert(dispatcher != null)
|
assert(dispatcher ne null)
|
||||||
assert(dispatcher.toString === "HawtDispatchEventDrivenDispatcher")
|
assert(dispatcher.toString === "HawtDispatchEventDrivenDispatcher")
|
||||||
assert(dispatcher.aggregate === false)
|
assert(dispatcher.aggregate === false)
|
||||||
}
|
}
|
||||||
|
|
@ -116,7 +116,7 @@ class DispatcherSpringFeatureTest extends FeatureSpec with ShouldMatchers {
|
||||||
scenario("get a thread-based-dispatcher for typed actor from context") {
|
scenario("get a thread-based-dispatcher for typed actor from context") {
|
||||||
val context = new ClassPathXmlApplicationContext("/dispatcher-config.xml")
|
val context = new ClassPathXmlApplicationContext("/dispatcher-config.xml")
|
||||||
val pojo = context.getBean("typed-actor-with-thread-based-dispatcher").asInstanceOf[IMyPojo]
|
val pojo = context.getBean("typed-actor-with-thread-based-dispatcher").asInstanceOf[IMyPojo]
|
||||||
assert(pojo != null)
|
assert(pojo ne null)
|
||||||
}
|
}
|
||||||
|
|
||||||
scenario("get a thread-based-dispatcher for untyped from context") {
|
scenario("get a thread-based-dispatcher for untyped from context") {
|
||||||
|
|
@ -138,7 +138,7 @@ class DispatcherSpringFeatureTest extends FeatureSpec with ShouldMatchers {
|
||||||
val field = pool.getClass.getDeclaredField("se$scalablesolutions$akka$dispatch$ThreadPoolBuilder$$threadPoolBuilder")
|
val field = pool.getClass.getDeclaredField("se$scalablesolutions$akka$dispatch$ThreadPoolBuilder$$threadPoolBuilder")
|
||||||
field.setAccessible(true)
|
field.setAccessible(true)
|
||||||
val executor = field.get(pool).asInstanceOf[ThreadPoolExecutor]
|
val executor = field.get(pool).asInstanceOf[ThreadPoolExecutor]
|
||||||
assert(executor != null)
|
assert(executor ne null)
|
||||||
executor;
|
executor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ class SupervisionBeanDefinitionParserTest extends Spec with ShouldMatchers {
|
||||||
|
|
||||||
it("should be able to parse typed actor configuration") {
|
it("should be able to parse typed actor configuration") {
|
||||||
val props = parser.parseActor(createTypedActorElement);
|
val props = parser.parseActor(createTypedActorElement);
|
||||||
assert(props != null)
|
assert(props ne null)
|
||||||
assert(props.timeout == 1000)
|
assert(props.timeout == 1000)
|
||||||
assert(props.target == "foo.bar.MyPojo")
|
assert(props.target == "foo.bar.MyPojo")
|
||||||
assert(props.transactional)
|
assert(props.transactional)
|
||||||
|
|
@ -37,7 +37,7 @@ class SupervisionBeanDefinitionParserTest extends Spec with ShouldMatchers {
|
||||||
it("should parse the supervisor restart strategy") {
|
it("should parse the supervisor restart strategy") {
|
||||||
parser.parseSupervisor(createSupervisorElement, builder);
|
parser.parseSupervisor(createSupervisorElement, builder);
|
||||||
val strategy = builder.getBeanDefinition.getPropertyValues.getPropertyValue("restartStrategy").getValue.asInstanceOf[RestartStrategy]
|
val strategy = builder.getBeanDefinition.getPropertyValues.getPropertyValue("restartStrategy").getValue.asInstanceOf[RestartStrategy]
|
||||||
assert(strategy != null)
|
assert(strategy ne null)
|
||||||
assert(strategy.scheme match {
|
assert(strategy.scheme match {
|
||||||
case x:AllForOne => true
|
case x:AllForOne => true
|
||||||
case _ => false })
|
case _ => false })
|
||||||
|
|
@ -48,7 +48,7 @@ class SupervisionBeanDefinitionParserTest extends Spec with ShouldMatchers {
|
||||||
it("should parse the supervised typed actors") {
|
it("should parse the supervised typed actors") {
|
||||||
parser.parseSupervisor(createSupervisorElement, builder);
|
parser.parseSupervisor(createSupervisorElement, builder);
|
||||||
val supervised = builder.getBeanDefinition.getPropertyValues.getPropertyValue("supervised").getValue.asInstanceOf[List[ActorProperties]]
|
val supervised = builder.getBeanDefinition.getPropertyValues.getPropertyValue("supervised").getValue.asInstanceOf[List[ActorProperties]]
|
||||||
assert(supervised != null)
|
assert(supervised ne null)
|
||||||
expect(4) { supervised.length }
|
expect(4) { supervised.length }
|
||||||
val iterator = supervised.iterator
|
val iterator = supervised.iterator
|
||||||
val prop1 = iterator.next
|
val prop1 = iterator.next
|
||||||
|
|
|
||||||
|
|
@ -34,11 +34,11 @@ class SupervisorSpringFeatureTest extends FeatureSpec with ShouldMatchers {
|
||||||
val myConfigurator = context.getBean("supervision1").asInstanceOf[TypedActorConfigurator]
|
val myConfigurator = context.getBean("supervision1").asInstanceOf[TypedActorConfigurator]
|
||||||
// get TypedActors
|
// get TypedActors
|
||||||
val foo = myConfigurator.getInstance(classOf[IFoo])
|
val foo = myConfigurator.getInstance(classOf[IFoo])
|
||||||
assert(foo != null)
|
assert(foo ne null)
|
||||||
val bar = myConfigurator.getInstance(classOf[IBar])
|
val bar = myConfigurator.getInstance(classOf[IBar])
|
||||||
assert(bar != null)
|
assert(bar ne null)
|
||||||
val pojo = myConfigurator.getInstance(classOf[IMyPojo])
|
val pojo = myConfigurator.getInstance(classOf[IMyPojo])
|
||||||
assert(pojo != null)
|
assert(pojo ne null)
|
||||||
}
|
}
|
||||||
|
|
||||||
scenario("get a supervisor for untyped actors from context") {
|
scenario("get a supervisor for untyped actors from context") {
|
||||||
|
|
@ -51,7 +51,7 @@ class SupervisorSpringFeatureTest extends FeatureSpec with ShouldMatchers {
|
||||||
val context = new ClassPathXmlApplicationContext("/supervisor-config.xml")
|
val context = new ClassPathXmlApplicationContext("/supervisor-config.xml")
|
||||||
val myConfigurator = context.getBean("supervision-with-dispatcher").asInstanceOf[TypedActorConfigurator]
|
val myConfigurator = context.getBean("supervision-with-dispatcher").asInstanceOf[TypedActorConfigurator]
|
||||||
val foo = myConfigurator.getInstance(classOf[IFoo])
|
val foo = myConfigurator.getInstance(classOf[IFoo])
|
||||||
assert(foo != null)
|
assert(foo ne null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ class TypedActorBeanDefinitionParserTest extends Spec with ShouldMatchers {
|
||||||
</akka:typed-actor>
|
</akka:typed-actor>
|
||||||
|
|
||||||
val props = parser.parseActor(dom(xml).getDocumentElement);
|
val props = parser.parseActor(dom(xml).getDocumentElement);
|
||||||
assert(props != null)
|
assert(props ne null)
|
||||||
assert(props.timeout === 1000)
|
assert(props.timeout === 1000)
|
||||||
assert(props.target === "foo.bar.MyPojo")
|
assert(props.target === "foo.bar.MyPojo")
|
||||||
assert(props.transactional)
|
assert(props.transactional)
|
||||||
|
|
@ -53,7 +53,7 @@ class TypedActorBeanDefinitionParserTest extends Spec with ShouldMatchers {
|
||||||
<akka:dispatcher type="thread-based" name="my-thread-based-dispatcher"/>
|
<akka:dispatcher type="thread-based" name="my-thread-based-dispatcher"/>
|
||||||
</akka:typed-actor>
|
</akka:typed-actor>
|
||||||
val props = parser.parseActor(dom(xml).getDocumentElement);
|
val props = parser.parseActor(dom(xml).getDocumentElement);
|
||||||
assert(props != null)
|
assert(props ne null)
|
||||||
assert(props.dispatcher.dispatcherType === "thread-based")
|
assert(props.dispatcher.dispatcherType === "thread-based")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -63,7 +63,7 @@ class TypedActorBeanDefinitionParserTest extends Spec with ShouldMatchers {
|
||||||
<akka:remote host="com.some.host" port="9999"/>
|
<akka:remote host="com.some.host" port="9999"/>
|
||||||
</akka:typed-actor>
|
</akka:typed-actor>
|
||||||
val props = parser.parseActor(dom(xml).getDocumentElement);
|
val props = parser.parseActor(dom(xml).getDocumentElement);
|
||||||
assert(props != null)
|
assert(props ne null)
|
||||||
assert(props.host === "com.some.host")
|
assert(props.host === "com.some.host")
|
||||||
assert(props.port === "9999")
|
assert(props.port === "9999")
|
||||||
assert(!props.serverManaged)
|
assert(!props.serverManaged)
|
||||||
|
|
@ -75,7 +75,7 @@ class TypedActorBeanDefinitionParserTest extends Spec with ShouldMatchers {
|
||||||
<akka:remote host="com.some.host" port="9999" service-name="my-service"/>
|
<akka:remote host="com.some.host" port="9999" service-name="my-service"/>
|
||||||
</akka:typed-actor>
|
</akka:typed-actor>
|
||||||
val props = parser.parseActor(dom(xml).getDocumentElement);
|
val props = parser.parseActor(dom(xml).getDocumentElement);
|
||||||
assert(props != null)
|
assert(props ne null)
|
||||||
assert(props.host === "com.some.host")
|
assert(props.host === "com.some.host")
|
||||||
assert(props.port === "9999")
|
assert(props.port === "9999")
|
||||||
assert(props.serviceName === "my-service")
|
assert(props.serviceName === "my-service")
|
||||||
|
|
|
||||||
|
|
@ -543,7 +543,7 @@ object TypedActor extends Logging {
|
||||||
}
|
}
|
||||||
|
|
||||||
def isTransactional(clazz: Class[_]): Boolean = {
|
def isTransactional(clazz: Class[_]): Boolean = {
|
||||||
if (clazz == null) false
|
if (clazz eq null) false
|
||||||
else if (clazz.isAssignableFrom(classOf[TypedTransactor])) true
|
else if (clazz.isAssignableFrom(classOf[TypedTransactor])) true
|
||||||
else isTransactional(clazz.getSuperclass)
|
else isTransactional(clazz.getSuperclass)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue