Default Servants
3 min read
3 min read
3 min read
3 min read
3 min read
3 min read
A default servant is a servant that implements many Ice objects: for each request, it acts as the Ice object whose identity the request carries. With a default servant, an application can provide a very large number of Ice objects, for example one Ice object for each record of a database, without creating a servant for each of them.
Registering a Default Servant
You register a default servant for a category, the value of the category field in the identity of the Ice objects it implements. addDefaultServantaddDefaultServantaddDefaultServantaddDefaultServantaddDefaultServantaddDefaultServantaddDefaultServant registers a default servant for a category, and removeDefaultServantremoveDefaultServantremoveDefaultServantremoveDefaultServantremoveDefaultServantremoveDefaultServantremoveDefaultServant removes the default servant of a category and returns it. Each category has at most one default servant, but you can register the same servant for several categories.
When the active servant map (ASM) of an object adapter has no servant for the identity and facet of a request, the object adapter dispatches this request to the default servant registered for the category of the identity. When there is no such default servant, it dispatches the request to the default servant registered for the empty category. A default servant receives the requests for all the facets of the Ice objects it implements.
A default servant usually implements a skeleton generated by the Slice compiler, but it can be any dispatcher.
Implementing a Default Servant
A default servant finds the target Ice object from the identity in the Current object of each request. The name of the identity typically holds everything it needs, such as the key of a database record.
A default servant keeps no state for the Ice objects it implements: each dispatch reads the state of its Ice object, for example from a database.
A default servant that implements a skeleton generated by the Slice compiler implements a single interface, so all its Ice objects have this interface. To provide Ice objects with several interfaces this way, you can use one category per interface, such as Sensor and Switch, and register a default servant for each category. Using a non-empty category from the start makes it easier to add a default servant for another interface later.