Skip to content
Permalink
Browse files

Applying Scalariform settings to scala files

  • Loading branch information...
atooni committed Jun 4, 2019
1 parent b813cc2 commit 98581c41aa5e660f5e45426bcd2dba9e73823c35
Showing 460 changed files with 4,698 additions and 4,664 deletions.
@@ -8,15 +8,16 @@ import javax.net.ssl.SSLContext

class BrokerActivator
extends DominoActivator
with ActorSystemWatching {
with ActorSystemWatching {

private[this] val log = Logger[BrokerActivator]

whenBundleActive {
whenActorSystemAvailable { osgiCfg =>

val brokerConfigs = osgiCfg.config.getConfigMap("broker", Map.empty).map { case (brokerName, cfg) =>
(brokerName -> BrokerConfig.create(brokerName, osgiCfg.idSvc, cfg).get)
val brokerConfigs = osgiCfg.config.getConfigMap("broker", Map.empty).map {
case (brokerName, cfg) =>
(brokerName -> BrokerConfig.create(brokerName, osgiCfg.idSvc, cfg).get)
}

val withSsl = brokerConfigs.values.exists(_.withSsl)
@@ -22,7 +22,7 @@ import scala.util.control.NonFatal
object BrokerControlSupervisor {

def props(
cfg: OSGIActorConfig,
cfg : OSGIActorConfig,
sslContext : Option[SSLContext],
broker : List[BrokerConfig]
) : Props = Props(new BrokerControlSupervisor(
@@ -32,7 +32,7 @@ object BrokerControlSupervisor {

class BrokerControlSupervisor(
cfg : OSGIActorConfig,
sslContext: Option[SSLContext],
sslContext : Option[SSLContext],
broker : List[BrokerConfig]
) extends Actor {

@@ -41,11 +41,11 @@ class BrokerControlSupervisor(
private case object Start
private case object Stop

override def preStart(): Unit = {
override def preStart() : Unit = {
self ! Start
}

override def receive: Receive = {
override def receive : Receive = {
case Start =>

log.info(s"Starting ${getClass().getSimpleName()} with [${broker.mkString(",")}]")
@@ -80,15 +80,15 @@ object BrokerControlActor {
) : Props = Props(new BrokerControlActor(brokerCfg, cfg, sslCtxt))
}

class BrokerControlActor(brokerCfg: BrokerConfig, cfg: OSGIActorConfig, sslCtxt: Option[SSLContext])
class BrokerControlActor(brokerCfg : BrokerConfig, cfg : OSGIActorConfig, sslCtxt : Option[SSLContext])
extends Actor {

private[this] val log = Logger[BrokerControlActor]
private[this] var broker : Option[BrokerService] = None
private[this] var svcReg : Option[ServiceRegistration[_]] = None
private[this] val uuid = UUID.randomUUID().toString()

override def toString: String = s"BrokerControlActor(${brokerCfg})"
override def toString : String = s"BrokerControlActor(${brokerCfg})"

private[this] def startBroker() : Unit = {

@@ -108,7 +108,7 @@ class BrokerControlActor(brokerCfg: BrokerConfig, cfg: OSGIActorConfig, sslCtxt:
val b = brokerFactory.createBroker(new URI(uri))
broker = Some(b)

sslCtxt.foreach{ ctxt =>
sslCtxt.foreach { ctxt =>
val amqSslContext = new org.apache.activemq.broker.SslContext()
amqSslContext.setSSLContext(ctxt)
b.setSslContext(amqSslContext)
@@ -134,13 +134,13 @@ class BrokerControlActor(brokerCfg: BrokerConfig, cfg: OSGIActorConfig, sslCtxt:
}
}

private[this] def registerService(brokerCfg : BrokerConfig): Unit = {
private[this] def registerService(brokerCfg : BrokerConfig) : Unit = {
if (svcReg.isEmpty) {
new Object with ServiceProviding {

override protected def capsuleContext: CapsuleContext = new SimpleDynamicCapsuleContext()
override protected def capsuleContext : CapsuleContext = new SimpleDynamicCapsuleContext()

override protected def bundleContext: BundleContext = cfg.bundleContext
override protected def bundleContext : BundleContext = cfg.bundleContext

val url = s"vm://${brokerCfg.brokerName}?create=false"

@@ -184,26 +184,26 @@ class BrokerControlActor(brokerCfg: BrokerConfig, cfg: OSGIActorConfig, sslCtxt:
svcReg = None
}

override def preRestart(reason: Throwable, message: Option[Any]): Unit = {
override def preRestart(reason : Throwable, message : Option[Any]) : Unit = {
log.error(reason)(s"Error starting Active MQ broker [${brokerCfg.brokerName}]")
super.preRestart(reason, message)
}

override def postStop(): Unit = broker.foreach{ b =>
override def postStop() : Unit = broker.foreach { b =>
b.stop()
b.waitUntilStopped()
}

private val jvmId = ManagementFactory.getRuntimeMXBean().getName()

override def receive : Receive = {
override def receive : Receive = {
case BrokerControlActor.StartBroker =>
log.trace(s"Received StartBroker Command for [$brokerCfg] [$jvmId][$uuid-${BrokerControlActor.debugCnt.incrementAndGet()}]")
if (broker.isEmpty) { startBroker() }
case started : BrokerControlActor.BrokerStarted =>
log.trace(s"Received BrokerStarted Event for [$brokerCfg] [$jvmId][$uuid-${BrokerControlActor.debugCnt.incrementAndGet()}]")
if (started.uuid == uuid) {
broker.foreach{ _ => registerService(brokerCfg) }
broker.foreach { _ => registerService(brokerCfg) }
}
case BrokerControlActor.StopBroker =>
log.trace(s"Received StopBroker Command for [$brokerCfg] [$jvmId][$uuid-${BrokerControlActor.debugCnt.incrementAndGet()}]")
@@ -18,10 +18,9 @@ class BrokerActivatorSpec extends SimplePojoContainerSpec
with PojoSrTestHelper
with Matchers {

override def baseDir: String = new File(BlendedTestSupport.projectTestOutput, "container").getAbsolutePath()
override def baseDir : String = new File(BlendedTestSupport.projectTestOutput, "container").getAbsolutePath()


override def bundles: Seq[(String, BundleActivator)] = Seq(
override def bundles : Seq[(String, BundleActivator)] = Seq(
"blended.akka" -> new BlendedAkkaActivator(),
"blended.activemq.brokerstarter" -> new BrokerActivator()
)
@@ -30,8 +29,8 @@ class BrokerActivatorSpec extends SimplePojoContainerSpec

"start the configured brokers correctly" in {
implicit val timeout = 10.seconds
waitOnService[IdAwareConnectionFactory](registry)(Some("(&(vendor=activemq)(provider=blended))")) should be (defined)
waitOnService[IdAwareConnectionFactory](registry)(Some("(&(vendor=activemq)(provider=broker2))")) should be (defined)
waitOnService[IdAwareConnectionFactory](registry)(Some("(&(vendor=activemq)(provider=blended))")) should be(defined)
waitOnService[IdAwareConnectionFactory](registry)(Some("(&(vendor=activemq)(provider=broker2))")) should be(defined)
}
}

@@ -9,11 +9,10 @@ trait ConnectionVerifierFactory {
}

trait ConnectionVerifier {
def verifyConnection(cf : IdAwareConnectionFactory)(implicit eCtxt: ExecutionContext) : Future[Boolean]
def verifyConnection(cf : IdAwareConnectionFactory)(implicit eCtxt : ExecutionContext) : Future[Boolean]
}

trait VerificationFailedHandler {
def verificationFailed(cf: IdAwareConnectionFactory) : Unit
def verificationFailed(cf : IdAwareConnectionFactory) : Unit
}


@@ -31,8 +31,8 @@ class RoundtripConnectionVerifier(
private val log : Logger = Logger[RoundtripConnectionVerifier]
private val verified : Promise[Boolean] = Promise[Boolean]()

override def verifyConnection(cf: IdAwareConnectionFactory)(implicit eCtxt: ExecutionContext): Future[Boolean] = {
after[Unit](10.millis, system. scheduler) {
override def verifyConnection(cf : IdAwareConnectionFactory)(implicit eCtxt : ExecutionContext) : Future[Boolean] = {
after[Unit](10.millis, system.scheduler) {
Future {
probe(cf)
}
@@ -41,7 +41,7 @@ class RoundtripConnectionVerifier(
verified.future
}

private def probe(cf: IdAwareConnectionFactory) : Unit = {
private def probe(cf : IdAwareConnectionFactory) : Unit = {

implicit val materializer : Materializer = ActorMaterializer()
implicit val eCtxt : ExecutionContext = system.dispatcher
@@ -100,11 +100,11 @@ class RoundtripConnectionVerifier(
}
}

private def scheduleRetry(cf: IdAwareConnectionFactory) : Unit = {
private def scheduleRetry(cf : IdAwareConnectionFactory) : Unit = {

implicit val eCtxt : ExecutionContext = system.dispatcher

after[Unit](retryInterval, system.scheduler){
after[Unit](retryInterval, system.scheduler) {
Future { probe(cf) }
}
}
@@ -38,32 +38,33 @@ class AmqClientActivator extends DominoActivator with ActorSystemWatching {
whenAdvancedServicePresent[ConnectionVerifierFactory](s"(name=$verifierName)") { verifierFactory =>
whenAdvancedServicePresent[VerificationFailedHandler](s"(name=$failedHandlerName)") { failedHandler =>

val cfg: Config = osgiCfg.config
implicit val system: ActorSystem = osgiCfg.system
val cfg : Config = osgiCfg.config
implicit val system : ActorSystem = osgiCfg.system

// TODO: Include connection verifier
val cfgMap: Map[String, Config] = cfg.getConfigMap("connections", Map.empty)
val cfgMap : Map[String, Config] = cfg.getConfigMap("connections", Map.empty)
log.info(s"Verifying ActiveMQ client connection(s) : [${cfgMap.values.mkString(",")}]")

cfgMap.foreach { case (key, config) =>
val connectionCfg: ConnectionConfig = BlendedJMSConnectionConfig.fromConfig(
stringResolver = osgiCfg.idSvc.resolvePropertyString
)(
vendor = "activemq",
provider = key,
cfg = config
).copy(
cfClassName = Some(classOf[ActiveMQConnectionFactory].getName())
)

val cf: IdAwareConnectionFactory = new BlendedSingleConnectionFactory(
connectionCfg, Some(osgiCfg.bundleContext)
)

val verified : Future[Boolean] = verifierFactory.createConnectionVerifier().verifyConnection(cf)

verified.onComplete {
case Success(b) => if (b) {
cfgMap.foreach {
case (key, config) =>
val connectionCfg : ConnectionConfig = BlendedJMSConnectionConfig.fromConfig(
stringResolver = osgiCfg.idSvc.resolvePropertyString
)(
vendor = "activemq",
provider = key,
cfg = config
).copy(
cfClassName = Some(classOf[ActiveMQConnectionFactory].getName())
)

val cf : IdAwareConnectionFactory = new BlendedSingleConnectionFactory(
connectionCfg, Some(osgiCfg.bundleContext)
)

val verified : Future[Boolean] = verifierFactory.createConnectionVerifier().verifyConnection(cf)

verified.onComplete {
case Success(b) => if (b) {
log.info(s"Connection [${cf.vendor}:${cf.provider}] verified and ready to use.")
cf.providesService[ConnectionFactory, IdAwareConnectionFactory](
"vendor" -> connectionCfg.vendor,
@@ -73,9 +74,9 @@ class AmqClientActivator extends DominoActivator with ActorSystemWatching {
log.warn(s"Failed to verify connection [${cf.vendor}:${cf.provider}]...invoking failed handler")
failedHandler.verificationFailed(cf)
}
case Failure(t) =>
s"Unable to verify connection [${cf.vendor}:${cf.provider}]. This connection will not be active"
}
case Failure(t) =>
s"Unable to verify connection [${cf.vendor}:${cf.provider}]. This connection will not be active"
}
}
}
}
@@ -6,9 +6,9 @@ import blended.jms.utils.IdAwareConnectionFactory
import scala.concurrent.{ExecutionContext, Future}

class DefaultConnectionVerifierFactory extends ConnectionVerifierFactory {
override def createConnectionVerifier(): ConnectionVerifier = new DefaultConnectionVerifier()
override def createConnectionVerifier() : ConnectionVerifier = new DefaultConnectionVerifier()
}

class DefaultConnectionVerifier extends ConnectionVerifier {
override def verifyConnection(cf: IdAwareConnectionFactory)(implicit eCtxt : ExecutionContext): Future[Boolean] = Future { true }
override def verifyConnection(cf : IdAwareConnectionFactory)(implicit eCtxt : ExecutionContext) : Future[Boolean] = Future { true }
}
@@ -16,9 +16,9 @@ class DefaultClientActivatorSpec extends SimplePojoContainerSpec
with LoggingFreeSpecLike
with PojoSrTestHelper {

override def baseDir: String = new File(BlendedTestSupport.projectTestOutput, "default").getAbsolutePath()
override def baseDir : String = new File(BlendedTestSupport.projectTestOutput, "default").getAbsolutePath()

override def bundles: Seq[(String, BundleActivator)] = Seq(
override def bundles : Seq[(String, BundleActivator)] = Seq(
"blended.akka" -> new BlendedAkkaActivator(),
"blended.activemq.client" -> new AmqClientActivator()
)
@@ -21,22 +21,22 @@ class FailingClientActivatorSpec extends SimplePojoContainerSpec
with PojoSrTestHelper
with Matchers {

override def baseDir: String = new File(BlendedTestSupport.projectTestOutput, "failing").getAbsolutePath()
override def baseDir : String = new File(BlendedTestSupport.projectTestOutput, "failing").getAbsolutePath()

var failed : List[String] = List.empty

private class FailingActivator extends DominoActivator {

private val failFactory : ConnectionVerifierFactory = new ConnectionVerifierFactory {

override def createConnectionVerifier(): ConnectionVerifier = new ConnectionVerifier {
override def verifyConnection(cf: IdAwareConnectionFactory)(implicit eCtxt: ExecutionContext): Future[Boolean] = Future { false }
override def createConnectionVerifier() : ConnectionVerifier = new ConnectionVerifier {
override def verifyConnection(cf : IdAwareConnectionFactory)(implicit eCtxt : ExecutionContext) : Future[Boolean] = Future { false }
}

}

private val failHandler : VerificationFailedHandler = new VerificationFailedHandler {
override def verificationFailed(cf: IdAwareConnectionFactory): Unit = {
override def verificationFailed(cf : IdAwareConnectionFactory) : Unit = {
failed = (s"${cf.vendor}:${cf.provider}") :: failed
}
}
@@ -47,7 +47,7 @@ class FailingClientActivatorSpec extends SimplePojoContainerSpec
}
}

override def bundles: Seq[(String, BundleActivator)] = Seq(
override def bundles : Seq[(String, BundleActivator)] = Seq(
"failing" -> new FailingActivator,
"blended.akka" -> new BlendedAkkaActivator(),
"blended.activemq.client" -> new AmqClientActivator()
@@ -62,7 +62,7 @@ class FailingClientActivatorSpec extends SimplePojoContainerSpec
intercept[MandatoryServiceUnavailable](mandatoryService[IdAwareConnectionFactory](registry)(Some("(&(vendor=activemq)(provider=conn1))")))
intercept[MandatoryServiceUnavailable](mandatoryService[IdAwareConnectionFactory](registry)(Some("(&(vendor=activemq)(provider=conn2))")))

failed should have size(2)
failed should have size (2)
}
}
}
@@ -41,7 +41,7 @@ class RoundtripConnectionVerifierSpec extends LoggingFreeSpec
cf = new ActiveMQConnectionFactory("vm://roundtrip?create=false")
)

override protected def afterAll(): Unit = {
override protected def afterAll() : Unit = {
broker.stop()
broker.waitUntilStopped()

@@ -9,33 +9,33 @@ object HttpQueueConfig {

val queuesPath = "queues"

def fromConfig(cfg: Config): HttpQueueConfig = {
val queues : Map[(String, String), ProviderQueueConfig]= cfg.hasPath(queuesPath) match {
def fromConfig(cfg : Config) : HttpQueueConfig = {
val queues : Map[(String, String), ProviderQueueConfig] = cfg.hasPath(queuesPath) match {
case false => Map.empty
case true =>
val provider : Seq[(String, String)] =
for(
v <- cfg.getObject(queuesPath).keySet().asScala.toSeq ;
for (
v <- cfg.getObject(queuesPath).keySet().asScala.toSeq;
p <- cfg.getConfig(queuesPath).getObject(v).keySet().asScala.toSeq
) yield (v, p)

provider.map { case (v,p) =>
val providerCfg = cfg.getConfig(queuesPath).getConfig(v).getConfig(p)
provider.map {
case (v, p) =>
val providerCfg = cfg.getConfig(queuesPath).getConfig(v).getConfig(p)

val path = providerCfg.getString("path", p)
val queueNames = providerCfg.getStringList("queues", List.empty)
(v,p) -> ProviderQueueConfig(path, queueNames)
val path = providerCfg.getString("path", p)
val queueNames = providerCfg.getStringList("queues", List.empty)
(v, p) -> ProviderQueueConfig(path, queueNames)
}.toMap
}

HttpQueueConfig(queues)
}
}

case class ProviderQueueConfig(path: String, queueNames : List[String])
case class ProviderQueueConfig(path : String, queueNames : List[String])

case class HttpQueueConfig(
httpQueues : Map[(String, String), ProviderQueueConfig]
)


0 comments on commit 98581c4

Please sign in to comment.
You can’t perform that action at this time.