Project

General

Profile

getComponentId() issue

Gabriel Rossetti
Added over 4 years ago

Hi all,

I called getComponentId()in my component and I was expecting to see my virtual host domain but instead I saw the real domain. I realize that I can have several virtual domaines so my question is, how can I tell my component that it should use one of the virtual hosts as the domain part of it's component ID (other than overriding getComponentId())?

Thanks,

Gabriel


Replies (10)

Added by Gabriel Rossetti over 4 years ago

Ok, I am answering myself, although I still find something a bit odd...

I found thta I could set:

my-comp/def-hostname=a.com

but I was expecting the component ID to use that, but it doesn't, does someone know why?

I ended up setting:

my-comp/def-hostname=a.com
my-comp/component-id=my-comp@a.com

but I still think that if I set the def-hostname and --comp-name-2 it should use those for the ID.

Added by Gabriel Rossetti over 4 years ago

Hmm...scratch that..setting those changes nothing, they are not taken into account thwen I call getComponentId() even though the config dump clearly says they are set.

Can someone help please?

Avatar?id=6023&size=32x32

Added by Artur Hefczyc TigaseTeam over 4 years ago

I called getComponentId()in my component and I was expecting to see my virtual host domain but instead I saw the real domain. I realize that I can have several virtual domaines so my question is, how can I tell my component that it should use one of the virtual hosts as the domain part of it's component ID (other than overriding getComponentId())?

You should not do this. Why do you need to do this?

Added by Gabriel Rossetti over 4 years ago

Artur Hefczyc wrote:

I called getComponentId()in my component and I was expecting to see my virtual host domain but instead I saw the real domain. I realize that I can have several virtual domaines so my question is, how can I tell my component that it should use one of the virtual hosts as the domain part of it's component ID (other than overriding getComponentId())?

You should not do this. Why do you need to do this?

I am generating and sending a msg from the component and I would like to access the component's address, the one that clients use to send messages to the component.

Why should I not do that?

BTW, I don know if it is just me but the javadoc on the methods is strange, it doesn't give any info just that it was formated using your template, so it makes it hard to know what a method does and does not do, etc. Maybe something went wrong with the formatters?

Avatar?id=6023&size=32x32

Added by Artur Hefczyc TigaseTeam over 4 years ago

Gabriel Rossetti wrote:

Artur Hefczyc wrote:

I called getComponentId()in my component and I was expecting to see my virtual host domain but instead I saw the real domain. I realize that I can have several virtual domaines so my question is, how can I tell my component that it should use one of the virtual hosts as the domain part of it's component ID (other than overriding getComponentId())?

You should not do this. Why do you need to do this?

I am generating and sending a msg from the component and I would like to access the component's address, the one that clients use to send messages to the component.

Indeed. As you correctly pointed out, you can have many virtual domains on the system. So assigning your component to one of them does not help and does not solve your problem. If you assign vhost1 to the component you may still receive stanzas from a user in vhost2.

The way to handle it correctly is to take domain from stanza received from a user, and send response back using user's domain.

Another option, less preferred is to use a protected field: vHostManager and call: getDefVHostItem() method on it, which gives you a default vhost for the installation.

Why should I not do that?

You should not change component's ID because this is an ID which identifies the component within entire installation. This is especially important in the clustered system. If you have the same component on each cluster node and you assign the same ID to each component, you effectively disables possibility to communicate with this component within the cluster.

BTW, I don know if it is just me but the javadoc on the methods is strange, it doesn't give any info just that it was formated using your template, so it makes it hard to know what a method does and does not do, etc. Maybe something went wrong with the formatters?

Yes, I am sorry for this. I am aware of it and JavaDoc is something we work on to improve.

Added by Gabriel Rossetti over 4 years ago

Artur Hefczyc wrote:

Gabriel Rossetti wrote:

Artur Hefczyc wrote:

I am generating and sending a msg from the component and I would like to access the component's address, the one that clients use to send messages to the component.

The way to handle it correctly is to take domain from stanza received from a user, and send response back using user's domain.

What about unsolicited msgs sent by the server? In this case I have no source user msg to go by.

Another option, less preferred is to use a protected field: vHostManager and call: getDefVHostItem() method on it, which gives you a default vhost for the installation.

Ok, I found the method (@vHostManager.getAllVHosts()@) to get all the vhosts (if I want to send unsolicited msgs to all domains).

Why should I not do that?

You should not change component's ID because this is an ID which identifies the component within entire installation. This is especially important in the clustered system. If you have the same component on each cluster node and you assign the same ID to each component, you effectively disables possibility to communicate with this component within the cluster.

Ok, I understand now.

BTW, I don know if it is just me but the javadoc on the methods is strange, it doesn't give any info just that it was formated using your template, so it makes it hard to know what a method does and does not do, etc. Maybe something went wrong with the formatters?

Yes, I am sorry for this. I am aware of it and JavaDoc is something we work on to improve.

Ok, thanks.

Added by Gabriel Rossetti over 4 years ago

For some reason, when I call the above methods in the my component's start() method they don't return the correct values, but if I call them in my processPacket() method they do; I would assume that when my component is started that the VHostManager should be loaded. I called super.start() at the very top of my start() method.

Added by Gabriel Rossetti over 4 years ago

I created a bug report for this since the virtual host config has already been read at this point and thus it should be availiable:

https://projects.tigase.org/issues/2423

Added by Gabriel Rossetti over 4 years ago

I'm updating this threwad in case someone is having the same issue:

Artur Hefczyc said:

The start() method is called only to start/initialize components' own data and mechanisms. All components start/can start at the same time concurrently, so there can be no dependency on any other component or assumption that something else is already initialized.

If you need to do something when the whole server started up and all other components are initialized, you can use initializationCompleted() method, which is called when the server is basically ready to process user's data. There are 2 remarks for this however:

The method initializationCompleted() really means that initialization is completed, even for your component. This really means that at this point the component must be ready to accept data for processing. Therefore, this method can be only used for some "post-initialization" actions or initialization of elements on which stanza processing does not depends.

The getDefVHostItem() is actually different from everything else. Hostname information is taken from DNS system which may take long time. It is executed on a separate thread, so the time when the real hostname is available to the system depends how quickly DNS system can obtain this information.

(copied from the bug report and re-formatted)

Thanks for the useful info.

    (1-10/10)