-
Notifications
You must be signed in to change notification settings - Fork 19
User context
Nils Kilden-Pedersen edited this page Dec 12, 2015
·
8 revisions
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 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 // Assigns the data source to LegacyDB keyWhen submitting a task to an IExecutorService, the data source can be retrieved like this:
val exec: IExecutorService = _
exec.submitInstanceAware(ToKeyOwner("hello")) { hz =>
val dataSource = hz.userCtx(LegacyDB) // Retrieves local data source using LegacyDB key
}