-
Couldn't load subscription status.
- Fork 19
User context
Nils Kilden-Pedersen edited this page Jul 14, 2016
·
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 (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 keyWhen 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
}