This repository has been archived by the owner on May 31, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
BlendedJMSConnectionConfig.scala
125 lines (113 loc) · 4.18 KB
/
BlendedJMSConnectionConfig.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package blended.jms.utils
import blended.container.context.api.ContainerIdentifierService
import blended.jms.utils.ConnectionFactoryActivator.{CF_JNDI_NAME, DEFAULT_PWD, DEFAULT_USER, USE_JNDI}
import blended.updater.config.util.ConfigPropertyMapConverter
import blended.util.config.Implicits._
import com.typesafe.config.Config
import scala.util.{Failure, Success, Try}
object BlendedJMSConnectionConfig {
val defaultConfig = BlendedJMSConnectionConfig(
vendor = "",
provider = "",
enabled = true,
jmxEnabled = true,
pingEnabled = true,
pingTolerance = 5,
pingInterval = 30,
pingTimeout = 3000,
retryInterval = 5,
minReconnect = 300,
maxReconnectTimeout = -1,
clientId = "$[[" + ContainerIdentifierService.containerId + "]]",
defaultUser = None,
defaultPassword = None,
pingDestination = "topic:blended.ping",
properties = Map.empty,
useJndi = false,
jndiName = None,
cfEnabled = None,
cfClassName = None,
ctxtClassName = None,
jmsClassloader = None
)
def fromConfig(stringResolver : String => Try[Any])(vendor: String, provider: String, cfg: Config) : BlendedJMSConnectionConfig = {
val prov = cfg.getString("provider", provider)
val enabled = cfg.getBoolean("enabled", defaultConfig.enabled)
val jmxEnabled = cfg.getBoolean("jmxEnabled", defaultConfig.jmxEnabled)
val pingEnabled = cfg.getBoolean("pingEnabled", defaultConfig.pingEnabled)
val pingTolerance = cfg.getInt("pingTolerance", defaultConfig.pingTolerance)
val pingInterval = cfg.getInt("pingInterval", defaultConfig.pingInterval)
val pingTimeout = cfg.getInt("pingTimeout", defaultConfig.pingTimeout)
val retryInterval = cfg.getInt("retryInterval", defaultConfig.retryInterval)
val minReconnect = cfg.getInt("minReconnect", defaultConfig.minReconnect)
val maxReconnectTimeout = cfg.getInt("maxReconnectTimeout", defaultConfig.maxReconnectTimeout)
val clientId = if (cfg.hasPath("clientId"))
stringResolver(cfg.getString("clientId")) match {
case Failure(t) => throw t
case Success(id) => id.toString()
}
else
defaultConfig.clientId
val defaultUser = cfg.getStringOption(DEFAULT_USER)
val defaultPasswd = cfg.getStringOption(DEFAULT_PWD)
val destination = cfg.getString("destination", defaultConfig.pingDestination)
val properties : Map[String, String] =
ConfigPropertyMapConverter.getKeyAsPropertyMap(cfg,"properties", Option(() => defaultConfig.properties))
.mapValues { v =>
stringResolver(v) match {
case Failure(t) => throw t
case Success(s) => s.toString()
}
}
val jndiName = cfg.getStringOption(CF_JNDI_NAME)
val useJndi = cfg.getBoolean(USE_JNDI, defaultConfig.useJndi)
BlendedJMSConnectionConfig(
vendor = vendor,
enabled = enabled,
provider = prov,
jmxEnabled = jmxEnabled,
pingEnabled = pingEnabled,
pingTolerance = pingTolerance,
pingInterval = pingInterval,
pingTimeout = pingTimeout,
retryInterval = retryInterval,
minReconnect = minReconnect,
maxReconnectTimeout = maxReconnectTimeout,
clientId = clientId,
defaultUser = defaultUser,
defaultPassword = defaultPasswd,
pingDestination = destination,
properties = properties,
jndiName = jndiName,
useJndi = useJndi,
cfEnabled = None,
jmsClassloader = defaultConfig.jmsClassloader,
ctxtClassName = defaultConfig.ctxtClassName,
cfClassName = defaultConfig.cfClassName
)
}
}
case class BlendedJMSConnectionConfig(
vendor : String,
provider : String,
enabled : Boolean,
jmxEnabled : Boolean,
pingEnabled : Boolean,
pingTolerance : Int,
pingInterval : Int,
pingTimeout : Int,
retryInterval : Int,
minReconnect : Int,
maxReconnectTimeout: Int,
clientId : String,
defaultUser : Option[String],
defaultPassword : Option[String],
pingDestination : String,
properties : Map[String, String],
useJndi : Boolean,
jndiName : Option[String] = None,
cfEnabled : Option[BlendedJMSConnectionConfig => Boolean],
cfClassName: Option[String],
ctxtClassName : Option[String],
jmsClassloader : Option[ClassLoader]
)