Why was the AbstractComponent.initialize() method marked final?
Prior to 1.2.1, I was overriding it to get to the JID that was being passed in so that I could parse out the domain as set by the server I was connecting to. There may be a better way to get this, but I haven’t found it yet
Currently, my component has different domains on each developer’s environment and getting the domain value at runtime from the JID passed into initialize() was a convenient solution. Is there another way to do this that I’m missing?
Currently, my component has different domains on each developer’s environment and getting the domain value at runtime from the JID passed into initialize() was a convenient solution. Is there another way to do this that I’m missing?
try
if (compMan == null) {
throw new IllegalStateException("Component not yet initialized!");
}
String serverDomain = compMan.getServerName();
to get the domain of your XMPP server, or do you want to get the subdomain of your component?
I think not exposing the JID is an oversight. AbstractComponent is an implementation that I have been using for years, but I never had to use the JID of the component itself. Nonetheless, as it is provided by the Component interface, I feel we should expose it in AbstractComponent too. I’ve filed TINDER-36 to track the required changes.
As for the question why initialize() is final: We will introduce monitoring functionality, that is going to be initialized in that method. If a subclass overrides it, the soon-to-be-added functionality will fail. In anticipation, the initialization method was made final. To provide developers a similar hook, the pre- and postComponentStart() methods were introduced. Their usage pattern is slightly different (it’s based on Component#start() rather than initialize() ) but this too was done intentionally: Component#start() can be “undone” with Component#shutdown() which is handy when developing a component that needs to be restartable. There is no such “undo” method for initialize().
I’ve added a protected field that will hold the JID after initialization of the AbstractComponent in SVN. Feel free to checkout the code and build the library itself - this change should be the only difference between such a custom build and the 1.2.1 release.