Skip to content

Commit d07e22f

Browse files
committedMay 18, 2014
1) Upgrading to Spray 1.3
2) Upgrading to Scala 2.11 3) Upgrading to Amqp-client 1.4 (mainstream) 4) Upgrading to casbah 2.7.1
1 parent 8a6fd79 commit d07e22f

14 files changed

+106
-104
lines changed
 

‎CHANGELOG.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,9 @@
11
## 1.0 (April 24, 2014)
2-
* Initial OSS release
2+
* Initial OSS release
3+
4+
## 1.0.1 (May 18, 2014)
5+
* Spray 1.3 upgrade
6+
* Akka 2.3.2 upgrade
7+
* Scala 2.11 upgrade
8+
* Amqp Client 1.4 upgrade
9+
* Casbah 2.7.1 upgrade

‎README.md

+7-6
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ Support for MongoDB datasource is provided out-of-the-box.
1414
## Releases
1515
| Release | Date | Description |
1616
|:------------|:----------------|:------------|
17-
| Version 1.0 | April 2014 | Initial OSS release
17+
| Version 1.0 | April 2014 | Initial OSS release |
18+
| Version 1.0.1 | May 2014 | Upgrade to Spray 1.2 & Scala 2.11.0 |
1819

1920
## Changelog
2021
Changelog can be viewed in [CHANGELOG.md](https://github.com/Flipkart/flipcast/blob/master/CHANGELOG.md) file
@@ -37,12 +38,12 @@ Changelog can be viewed in [CHANGELOG.md](https://github.com/Flipkart/flipcast/b
3738

3839
## Library Dependencies
3940
--------------------
40-
* [spray](http://spray.io) 1.2.0
41-
* [Scala](http://www.scala-lang.org) 2.10.2
42-
* [akka.io](http://akka.io) 2.2.4
43-
* [amqp-client](https://github.com/sstone/amqp-client) - 1.3-ML4
41+
* [spray](http://spray.io) 1.3.1-20140423
42+
* [Scala](http://www.scala-lang.org) 2.11.0
43+
* [akka.io](http://akka.io) 2.3.2
44+
* [amqp-client](https://github.com/sstone/amqp-client) - 1.4
4445
* [java-apns](https://github.com/notnoop/java-apns) - 0.2.3
45-
* [casbah](http://mongodb.github.io/casbah) - 2.6.5
46+
* [casbah](http://mongodb.github.io/casbah) - 2.7.1
4647
* [hazelcast](http://hazelcast.org) - 3.1.2
4748

4849
## Infrastructure Dependencies

‎build.sbt

+14-14
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ name := "flipcast"
99

1010
version := "0.1"
1111

12-
scalaVersion := "2.10.2"
12+
scalaVersion := "2.11.0"
1313

1414
scalacOptions := Seq(
1515
"-encoding", "UTF-8",
@@ -30,15 +30,15 @@ resolvers ++= Seq(
3030
)
3131

3232
libraryDependencies ++= Seq(
33-
"io.spray" % "spray-can" % "1.2.0",
34-
"io.spray" % "spray-routing" % "1.2.0",
35-
"io.spray" % "spray-caching" % "1.2.0",
36-
"io.spray" % "spray-testkit" % "1.2.0" % "test",
37-
"io.spray" % "spray-client" % "1.2.0",
38-
"io.spray" % "spray-json_2.10" % "1.2.5",
39-
"com.typesafe.akka" %% "akka-actor" % "2.2.4",
40-
"com.typesafe.akka" %% "akka-slf4j" % "2.2.4",
41-
"com.typesafe.akka" %% "akka-testkit" % "2.2.4" % "test",
33+
"io.spray" %% "spray-can" % "1.3.1-20140423",
34+
"io.spray" %% "spray-routing" % "1.3.1-20140423",
35+
"io.spray" %% "spray-caching" % "1.3.1-20140423",
36+
"io.spray" %% "spray-testkit" % "1.3.1-20140423" % "test",
37+
"io.spray" %% "spray-client" % "1.3.1-20140423",
38+
"io.spray" %% "spray-json" % "1.2.6",
39+
"com.typesafe.akka" %% "akka-actor" % "2.3.2",
40+
"com.typesafe.akka" %% "akka-slf4j" % "2.3.2",
41+
"com.typesafe.akka" %% "akka-testkit" % "2.3.2" % "test",
4242
"ch.qos.logback" % "logback-classic" % "1.0.9",
4343
"com.fasterxml.uuid" % "java-uuid-generator" % "3.1.3",
4444
"com.codahale.metrics" % "metrics-logback" % "3.0.1",
@@ -48,12 +48,12 @@ libraryDependencies ++= Seq(
4848
"commons-validator" % "commons-validator" % "1.4.0",
4949
"commons-codec" % "commons-codec" % "1.5",
5050
"com.google.guava" % "guava" % "15.0",
51-
"com.fasterxml.jackson.module" % "jackson-module-scala_2.10" % "2.2.3",
5251
"com.notnoop.apns" % "apns" % "0.2.3",
53-
"org.mongodb" % "casbah_2.10" % "2.6.5",
54-
"com.github.sstone" % "amqp-client_2.10" % "1.3-ML4",
52+
"org.mongodb" %% "casbah" % "2.7.1",
53+
"com.github.sstone" %% "amqp-client" % "1.4",
5554
"commons-io" % "commons-io" % "2.4",
56-
"org.specs2" %% "specs2" % "1.13" % "test"
55+
"com.google.code.findbugs" % "jsr305" % "2.0.3",
56+
"org.specs2" %% "specs2" % "2.3.11" % "test"
5757
)
5858

5959
assemblySettings

‎project/build.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
sbt.version=0.12.3
1+
sbt.version=0.13.2

‎project/plugins.sbt

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ resolvers += Resolver.url("artifactory", url("http://scalasbt.artifactoryonline.
22

33
addSbtPlugin("io.spray" % "sbt-revolver" % "0.7.2")
44

5-
addSbtPlugin("com.typesafe.sbt" % "sbt-start-script" % "0.9.0")
5+
addSbtPlugin("com.typesafe.sbt" % "sbt-start-script" % "0.10.0")
66

7-
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.9.2")
7+
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.11.2")

‎sbt/sbt-launch.jar

75.5 KB
Binary file not shown.

‎src/main/scala/com/flipcast/mongo/ConnectionHelper.scala

+13-7
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import com.flipcast.Flipcast
1515
*/
1616
object ConnectionHelper {
1717

18-
val log = Logger(this.getClass.getSimpleName)
18+
val log = Logger(this.getClass().getSimpleName)
1919

2020
var dbClient: MongoClient = null
2121

@@ -39,7 +39,10 @@ object ConnectionHelper {
3939
socketTimeout = config.socketTimeout,
4040
writeConcern = WriteConcern.Safe,
4141
readPreference = ReadPreference.SecondaryPreferred,
42-
threadsAllowedToBlockForConnectionMultiplier = Runtime.getRuntime.availableProcessors() / 2
42+
threadsAllowedToBlockForConnectionMultiplier = {
43+
val nrOfThreads = Runtime.getRuntime.availableProcessors() / 2
44+
if(nrOfThreads >= 1) nrOfThreads else 1
45+
}
4346
)
4447
val servers = config.hosts.map( h => {
4548
val tokens = h.split(":")
@@ -48,8 +51,10 @@ object ConnectionHelper {
4851
val credentials = config.user match {
4952
case Some(user) =>
5053
config.password match {
51-
case Some(pass) => MongoCredential(user, config.database, pass.toCharArray)
52-
case _ => MongoCredential(user, config.database, "".toCharArray)
54+
case Some(pass) =>
55+
MongoCredential.createMongoCRCredential(user, config.database, pass.toCharArray)
56+
case _ =>
57+
MongoCredential.createMongoCRCredential(user, config.database, "".toCharArray)
5358
}
5459
case _ => None
5560
}
@@ -76,7 +81,7 @@ object ConnectionHelper {
7681
}
7782

7883
private def createDatabase() (implicit config: MongoConfig) {
79-
dbClient.dbNames.count( n => n == config.database) match {
84+
dbClient.dbNames().count( n => n == config.database) match {
8085
case 0 =>
8186
dbClient.getDB(config.database)
8287
log.info("Database created: " +config.database)
@@ -107,7 +112,7 @@ object ConnectionHelper {
107112
Flipcast.mongoConfig.sharding match {
108113
case true =>
109114
val shardKey = MongoDBObject("_id" -> "hashed")
110-
collection.ensureIndex(shardKey)
115+
collection.createIndex(shardKey)
111116
val result = dbClient.getDB("admin").command(MongoDBObject("shardCollection" -> name, "key" -> shardKey))
112117
log.info("Sharding sys_relations_metadata collection result: " +result)
113118
case _ => None
@@ -127,7 +132,8 @@ object ConnectionHelper {
127132
val collection = dbInstance.getCollection(collectionName)
128133
val indexKeys = MongoDBObject.newBuilder
129134
keys.foreach( k => indexKeys += k._1 -> k._2)
130-
collection.ensureIndex(indexKeys.result(), MongoDBObject("background" -> true, "name" -> idxName, "unique" -> false))
135+
collection.createIndex(indexKeys.result(), MongoDBObject("background" -> true, "name" -> idxName,
136+
"unique" -> false))
131137
}
132138

133139
}

‎src/main/scala/com/flipcast/push/common/DeviceDataSourceManager.scala

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.flipcast.push.common
22

3-
import scala.collection.mutable
3+
import java.util.concurrent.ConcurrentHashMap
4+
45

56
/**
67
* Device data source manager per config
@@ -12,8 +13,7 @@ object DeviceDataSourceManager {
1213
/**
1314
* Map of all registered data sources
1415
*/
15-
private val providerCache = new mutable.HashMap[String, DeviceDataSource]()
16-
with mutable.SynchronizedMap[String, DeviceDataSource]
16+
private val providerCache = new ConcurrentHashMap[String, DeviceDataSource]()
1717

1818

1919
/**
@@ -38,8 +38,8 @@ object DeviceDataSourceManager {
3838
*/
3939
def dataSource(configName: String) : DeviceDataSource = {
4040
providerCache.contains(configName) match {
41-
case true => providerCache(configName)
42-
case false => providerCache("default")
41+
case true => providerCache.get(configName)
42+
case false => providerCache.get("default")
4343
}
4444
}
4545
}

‎src/main/scala/com/flipcast/push/common/PushMessageTransformerRegistry.scala

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package com.flipcast.push.common
22

3-
import scala.collection.mutable
43
import akka.event.slf4j.Logger
54
import com.flipcast.push.example.DefaultPushMessageTransformer
5+
import java.util.concurrent.ConcurrentHashMap
66

77
/**
88
* A registry for all message transformations per config (Multi config support)
@@ -13,22 +13,21 @@ object PushMessageTransformerRegistry {
1313

1414
val log = Logger("PushMessageTransformerRegistry")
1515

16-
private val transformers = new mutable.HashMap[String, PushMessageTransformer]()
17-
with mutable.SynchronizedMap[String, PushMessageTransformer]
16+
private val transformers = new ConcurrentHashMap[String, PushMessageTransformer]()
1817

1918
def register(configName: String, transformer: PushMessageTransformer) {
2019
transformers.contains(configName) match {
2120
case true =>
2221
log.warn("Transformer already registered for: " +configName)
2322
case false =>
2423
log.info("Registering transformer for: " +configName)
25-
transformers += configName -> transformer
24+
transformers.put(configName, transformer)
2625
}
2726
}
2827

2928
def transformer(configName: String) : PushMessageTransformer = {
3029
transformers.contains(configName) match {
31-
case true => transformers(configName)
30+
case true => transformers.get(configName)
3231
case false =>
3332
log.warn("No transformers registered for config: " +configName +". Returning default transformer")
3433
DefaultPushMessageTransformer

‎src/main/scala/com/flipcast/push/gcm/service/FlipcastGcmRequestConsumer.scala

+4-6
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,10 @@ class FlipcastGcmRequestConsumer extends FlipcastRequestConsumer with FlipcastPu
9999
case true => None
100100
case false =>
101101
gcmResponse.results.foreach( reg => {
102-
try {
103-
reg.registration_id match {
104-
case Some(newId) =>
105-
Flipcast.serviceRegistry.actor("deviceIdAutoUpdateManager") ! DeviceIdAutoUpdateRequest(request.configName, request.registration_ids(idx), newId)
106-
case _ => None
107-
}
102+
reg.registration_id match {
103+
case Some(newId) =>
104+
Flipcast.serviceRegistry.actor("deviceIdAutoUpdateManager") ! DeviceIdAutoUpdateRequest(request.configName, request.registration_ids(idx), newId)
105+
case _ => None
108106
}
109107
idx = idx + 1
110108
})

‎src/main/scala/com/flipcast/push/mongo/MongoDeviceDataSource.scala

+9-9
Original file line numberDiff line numberDiff line change
@@ -167,14 +167,14 @@ object MongoDeviceDataSource extends DeviceDataSource {
167167
query += "configName" -> config
168168
val expr = query.result() ++ ("sync_version" $gt from)
169169
val total = collection.count(query.result())
170-
val byPlatform = collection.aggregate(MongoDBObject("$match" -> expr),
171-
MongoDBObject("$group" -> MongoDBObject("_id" -> "$osName", "counts" -> MongoDBObject("$sum" -> 1))))
172-
val byBrand = collection.aggregate(MongoDBObject("$match" -> expr),
173-
MongoDBObject("$group" -> MongoDBObject("_id" -> "$brand", "counts" -> MongoDBObject("$sum" -> 1))))
174-
val byModel = collection.aggregate(MongoDBObject("$match" -> expr),
175-
MongoDBObject("$group" -> MongoDBObject("_id" -> "$model", "counts" -> MongoDBObject("$sum" -> 1))))
176-
val byVersion = collection.aggregate(MongoDBObject("$match" -> expr),
177-
MongoDBObject("$group" -> MongoDBObject("_id" -> "$appVersion", "counts" -> MongoDBObject("$sum" -> 1))))
170+
val byPlatform = collection.aggregate(List(MongoDBObject("$match" -> expr),
171+
MongoDBObject("$group" -> MongoDBObject("_id" -> "$osName", "counts" -> MongoDBObject("$sum" -> 1)))).asJava)
172+
val byBrand = collection.aggregate(List(MongoDBObject("$match" -> expr),
173+
MongoDBObject("$group" -> MongoDBObject("_id" -> "$brand", "counts" -> MongoDBObject("$sum" -> 1)))).asJava)
174+
val byModel = collection.aggregate(List(MongoDBObject("$match" -> expr),
175+
MongoDBObject("$group" -> MongoDBObject("_id" -> "$model", "counts" -> MongoDBObject("$sum" -> 1)))).asJava)
176+
val byVersion = collection.aggregate(List(MongoDBObject("$match" -> expr),
177+
MongoDBObject("$group" -> MongoDBObject("_id" -> "$appVersion", "counts" -> MongoDBObject("$sum" -> 1)))).asJava)
178178
val resPlatform = byPlatform.results().asScala.map( d => {
179179
d.getAsOrElse[String]("_id", "Unknown") -> d.getAsOrElse[BigDecimal]("counts", 0).toLong
180180
})
@@ -251,7 +251,7 @@ object MongoDeviceDataSource extends DeviceDataSource {
251251
ConnectionHelper.createIndex(collectionName, Seq(("model", 1)))
252252
ConnectionHelper.createIndex(collectionName, Seq(("appName", 1)))
253253
ConnectionHelper.createIndex(collectionName, Seq(("appVersion", 1)))
254-
ConnectionHelper.collection("push_message_history").ensureIndex(MongoDBObject("sentDate" -> 0, "expireAfterSeconds" -> 604800))
254+
ConnectionHelper.collection("push_message_history").createIndex(MongoDBObject("sentDate" -> 0, "expireAfterSeconds" -> 604800))
255255
ConnectionHelper.createIndex(collectionName, Seq(("appName", 1), ("sentDate", 0), ("brand", 1)))
256256
ConnectionHelper.createIndex(collectionName, Seq(("osName", 1), ("sentDate", 0), ("brand", 1)))
257257
ConnectionHelper.createIndex(collectionName, Seq(("osName", 1), ("osVersion", 1), ("sentDate", 0), ("brand", 1)))

‎src/main/scala/com/flipcast/push/mpns/service/MPNSServicePool.scala

+5-6
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ package com.flipcast.push.mpns.service
22

33
import com.flipcast.Flipcast
44
import spray.can.Http
5-
import scala.collection.mutable
65
import com.flipcast.push.config.MpnsConfig
76
import spray.io.ClientSSLEngineProvider
87
import java.security.KeyStore
98
import java.io.FileInputStream
109
import javax.net.ssl.{SSLContext, KeyManagerFactory}
10+
import java.util.concurrent.ConcurrentHashMap
1111

1212
/**
1313
* Key for service pool
@@ -22,18 +22,17 @@ case class MpnsServiceKey(configName: String, host: String)
2222
*/
2323
object MPNSServicePool {
2424

25-
private val serviceCache = new mutable.HashMap[MpnsServiceKey, Http.Connect]()
26-
with mutable.SynchronizedMap[MpnsServiceKey, Http.Connect]
25+
private val serviceCache = new ConcurrentHashMap[MpnsServiceKey, Http.Connect]()
2726

2827
def service(configName: String, host: String) = {
2928
val key = MpnsServiceKey(configName, host)
3029
serviceCache.contains(key) match {
3130
case true =>
32-
serviceCache(key)
31+
serviceCache.get(key)
3332
case false =>
3433
val client = createClient(configName, host)
35-
serviceCache += key -> client
36-
serviceCache(key)
34+
serviceCache.put(key,client)
35+
serviceCache.get(key)
3736
}
3837
}
3938

‎src/main/scala/com/flipcast/rmq/ConnectionHelper.scala

+29-37
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
package com.flipcast.rmq
22

3-
import scala.collection.mutable
4-
import com.github.sstone.amqp.{Amqp, RabbitMQConnection}
3+
import com.github.sstone.amqp.{ChannelOwner, Consumer, ConnectionOwner, Amqp}
54
import java.util.concurrent.atomic.AtomicInteger
65
import com.flipcast.Flipcast
7-
import akka.actor.{ActorRef, ActorSystem}
8-
import com.rabbitmq.client.{AMQP, Address}
9-
import scala.concurrent.duration.Duration
10-
import java.util.concurrent.TimeUnit._
6+
import akka.actor.{PoisonPill, ActorRef, ActorSystem}
7+
import com.rabbitmq.client.{ConnectionFactory, AMQP, Address}
118
import com.github.sstone.amqp.Amqp._
129
import akka.event.slf4j.Logger
1310
import com.github.sstone.amqp.Amqp.DeclareQueue
@@ -16,6 +13,8 @@ import com.github.sstone.amqp.Amqp.QueueParameters
1613
import com.github.sstone.amqp.Amqp.DeclareExchange
1714
import com.github.sstone.amqp.Amqp.QueueBind
1815
import java.util.concurrent.{LinkedBlockingQueue, TimeUnit, ThreadPoolExecutor}
16+
import scala.concurrent.duration._
17+
import collection.JavaConverters._
1918

2019
/**
2120
* RabbitMQ connection helper
@@ -37,14 +36,14 @@ object ConnectionHelper {
3736

3837

3938
/**
40-
* Keep track of open connections
39+
* RMQ Connection
4140
*/
42-
val connections: mutable.HashMap[String, RabbitMQConnection] = new mutable.HashMap[String, RabbitMQConnection]() with mutable.SynchronizedMap[String, RabbitMQConnection]
41+
var rmqConnection: ActorRef = null
4342

4443
/**
4544
* Client properties that we need to set (in case of rmq cluster)
4645
*/
47-
val clientProps = Map("x-ha-policy" -> "all")
46+
val clientProps = Map[String, AnyRef]("ha-mode" -> "all", "x-ha-policy" -> "all", "x-priority" -> new Integer(10))
4847

4948
/**
5049
* Keep a count of connection
@@ -59,23 +58,18 @@ object ConnectionHelper {
5958
* @return A RabbitMQ connection
6059
*/
6160
private def createConnection() (implicit system: ActorSystem) = {
62-
val name = "flipcast-%s".format(connectionCount.incrementAndGet())
63-
val reconnectDelay = Duration(Flipcast.rmqConfig.reconnectDelay, MILLISECONDS)
64-
val executor = Option(executorService)
65-
val addresses = Flipcast.rmqConfig.hosts.map( h => {
66-
val tokens = h.split(":")
67-
new Address(tokens(0), tokens(1).toInt)
68-
}).toArray
69-
val conn = new RabbitMQConnection(name = name,
70-
vhost = Flipcast.rmqConfig.vhost,
71-
user = Flipcast.rmqConfig.user,
72-
password = Flipcast.rmqConfig.pass,
73-
reconnectionDelay = reconnectDelay,
74-
executor = executor,
75-
addresses = Option(addresses))
76-
conn.waitForConnection.await()
77-
connections.put(name, conn)
78-
conn
61+
if(rmqConnection == null) {
62+
val connectionFactory = new ConnectionFactory()
63+
connectionFactory.setClientProperties(clientProps.asJava)
64+
connectionFactory.setAutomaticRecoveryEnabled(true)
65+
connectionFactory.setNetworkRecoveryInterval(10)
66+
val addresses = Flipcast.rmqConfig.hosts.map( h => {
67+
val tokens = h.split(":")
68+
new Address(tokens(0), tokens(1).toInt)
69+
}).toArray
70+
rmqConnection = system.actorOf(ConnectionOwner.props(connectionFactory, 1 second, addresses = Option(addresses), executor = Option(executorService)))
71+
}
72+
rmqConnection
7973
}
8074

8175
/**
@@ -87,14 +81,13 @@ object ConnectionHelper {
8781
* @return ActorRef of consumer
8882
*/
8983
def createConsumer(queueName: String, exchange: String, listener: ActorRef, qos: Int) (implicit system: ActorSystem) = {
90-
val channelParameters = Option(ChannelParameters(qos))
9184
val exchangeParams = ExchangeParameters(name = exchange, passive = false,
9285
exchangeType = "direct", durable = true, autodelete = false, clientProps)
86+
val cParams = Option(ChannelParameters(qos))
87+
val queueParams = QueueParameters(queueName, passive = false, durable = true, exclusive = false, autodelete = false, clientProps)
9388
val connection = createConnection()
94-
val queueParams = QueueParameters(queueName, passive = false, durable = true, exclusive = false,
95-
autodelete = false, clientProps)
96-
val consumer = connection.createConsumer(exchangeParams, queueParams, queueName, listener,
97-
channelParams = channelParameters, autoack = false)
89+
val consumer = ConnectionOwner.createChildActor(connection, Consumer.props(listener, exchangeParams,queueParams, queueName,
90+
cParams, autoack = false))
9891
Amqp.waitForConnection(system, consumer).await()
9992
consumer ! DeclareExchange(exchangeParams)
10093
consumer ! DeclareQueue(queueParams)
@@ -114,10 +107,10 @@ object ConnectionHelper {
114107
val channelParameters = Option(ChannelParameters(1))
115108
val exchangeParams = ExchangeParameters(name = exchange, passive = false,
116109
exchangeType = "direct", durable = true, autodelete = false, clientProps)
117-
val connection = createConnection()
118110
val queueParams = QueueParameters(queueName, passive = false, durable = true, exclusive = false, autodelete = false,
119111
clientProps)
120-
val producer = connection.createChannelOwner(channelParameters)
112+
val connection = createConnection()
113+
val producer = ConnectionOwner.createChildActor(connection, ChannelOwner.props(channelParams = channelParameters))
121114
Amqp.waitForConnection(system, producer).await()
122115
producer ! DeclareExchange(exchangeParams)
123116
producer ! DeclareQueue(queueParams)
@@ -129,10 +122,9 @@ object ConnectionHelper {
129122
* Close all connections
130123
*/
131124
def stop() {
132-
connections.foreach( c => {
133-
log.info("Closing connection: " +c._1)
134-
c._2.stop
135-
})
125+
if(rmqConnection != null) {
126+
rmqConnection ! PoisonPill
127+
}
136128
}
137129

138130
}

‎src/main/scala/com/flipcast/services/ServiceRegistry.scala

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package com.flipcast.services
22

3-
import collection.mutable
43
import akka.actor.{Props, Actor, ActorSystem, ActorRef}
54
import scala.reflect.ClassTag
6-
import akka.routing.RoundRobinRouter
5+
import akka.routing.RoundRobinPool
6+
import java.util.concurrent.ConcurrentHashMap
77

88
/**
99
* Service registry for keeping all the service worker actors
@@ -18,7 +18,7 @@ class ServiceRegistry (implicit val system: ActorSystem) {
1818
/**
1919
* Map of all registered actors
2020
*/
21-
private val serviceCache = new mutable.HashMap[String, ActorRef]() with mutable.SynchronizedMap[String, ActorRef]
21+
private val serviceCache = new ConcurrentHashMap[String, ActorRef]()
2222

2323
/**
2424
* Register a actor into the registry
@@ -34,7 +34,7 @@ class ServiceRegistry (implicit val system: ActorSystem) {
3434
case 1 =>
3535
system.actorOf(Props[T], name)
3636
case _ =>
37-
system.actorOf(Props[T].withRouter(RoundRobinRouter(nrOfInstances = instances)), name)
37+
system.actorOf(Props[T].withRouter(RoundRobinPool(nrOfInstances = instances)), name)
3838
}
3939
serviceCache.put(name, aRef)
4040
}
@@ -48,7 +48,7 @@ class ServiceRegistry (implicit val system: ActorSystem) {
4848
*/
4949
def actor(name: String) = {
5050
serviceCache.contains(name) match {
51-
case true => serviceCache(name)
51+
case true => serviceCache.get(name)
5252
case false => throw new IllegalArgumentException("Invalid service! Service not registered")
5353
}
5454
}

0 commit comments

Comments
 (0)
Please sign in to comment.