User context - hazelcast/hazelcast-scala GitHub Wiki
User context is a feature of Hazelcast that allows you to access arbitrary member-local objects e.g. when executing remote tasks.
In hazelcast-scala it's available on Config
and HazelcastInstance
(like Java) and is a type-safe wrapper around the ConcurrentMap
interface that the main API provides.
This example defines a typed key for a legacy JDBC DataSource:
object LegacyDB extends UserContext.Key[DataSource]
val dataSource: DataSource = ??? // <- Real data source goes here
conf.userCtx(LegacyDB) = dataSource // Type-safe assignment of data source to key
When submitting a task to an IExecutorService
, the data source can be retrieved like this:
val exec: IExecutorService = ???
exec.submit(ToOne) { hz =>
val dataSource: DataSource = hz.userCtx(LegacyDB) // Type-safe retrieval of instance-local DataSource
}