Why is AbstractComponent.initialize() final?

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?

Thanks.

Hi Sdub,

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?

Guenther,

Thanks for the reply.

I’ve tried calling that - it (the serverName call) consistently returns null

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.

Great, thank you very much.

Ok, after this change I think it’s consequent to implement the

public abstract String getDomain();

method and return the domainpart of the JID, or do I miss something?

You’re right. Go for it.

Done.