The following tutorial will show you how to utilize the lookup system to add and remove instances from the lookup. The lookup provides an easy way to register and unregister capabilities in INTGeoServer v3. It is similar in concept to the Java "ServiceLoader" API. It is also much easier to use as it uses annotations.
When INTGeoServer starts, the lookup system scans all classes for annotations which register or unregister instances. The registration annotations include a position attribute. This attribute will determine the order in which registered instances show up in the lookup. This can be used to give an instance of one class higher priority than another, and if it can't handle the task, an instance with lower priority can do the task.
The first annotation is the SelfRegistration annotation. This annotation is added to a class to register an instance of itself into the lookup. The following example shows how to use the self registration. The lookupClass is the base class that the registered instance inherits from.
@SelfRegistration(lookupClass = AbstractServiceRequestHandler.class, position = 1000)
public class FindAllWellsHandler extends AbstractServiceRequestHandler {
...
}
The next annotation is the ClassUnregistration annotation. This annotation is added to a class to unregister an instance of another class. The following example shows how to use the unregistration to override another instance. The default is unregistered, and then the self registration is used.
@ClassUnregistration(lookupClass = AbstractActorsController.class, registeredClass = DefaultActorsController.class)
@SelfRegistration(lookupClass = AbstractActorsController.class, position = 100)
public class ServletActorsController extends AbstractActorsController {
...
}
The final annotation is the ClassRegistration annotation. This annotation is used to register any arbitrary instance. This allows the developer to register multiple instances which are used by a particular class.
@SelfRegistration(lookupClass = ClassToRegister.class, registeredClass=FirstClass.class, position = 100)
@SelfRegistration(lookupClass = ClassToRegister.class, registeredClass=SecondClass.class, position = 200)
@SelfRegistration(lookupClass = OtherClassToRegister.class, registeredClass=OtherClass, position = 300)
public class RegistersClasses() {
...
}
Classes need to have an empty public constructor to be registered in the lookup. Two classes can share the same lookup position, but this will trigger a warning at startup.
By default, all classes are scanned for lookup registrations. For performance reasons, some jar files can be excluded from this scan.