[ 
https://issues.apache.org/activemq/browse/AMQCPP-315?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=61566#action_61566
 ] 

Helen Huang commented on AMQCPP-315:
------------------------------------

I have looked at the code for IdGenerator again and I think I might understand 
what is going on.

std::string IdGenerator::generateId() const {
    std::string result;
    StaticData& statics = IdGenerator::getClassStaticData();
    synchronized( &statics.mutex ) {
        if( seed.empty() ) {
            if( prefix.empty() ) {
                this->seed = std::string( "ID:" ) + statics.hostname +
                             statics.UNIQUE_STUB + Long::toString( 
statics.instanceCount++ ) + ":";
            } else {
                this->seed = prefix + statics.UNIQUE_STUB + Long::toString( 
statics.instanceCount++ ) + ":";
            }
        }
        result = this->seed + Long::toString( this->sequence++ );
    }
    return result;
}

The second line in this function can be accessed by multiple threads:
StaticData& statics = IdGenerator::getClassStaticData();

The definition for IdGenerator::getClassStaticData() is
IdGenerator::StaticData& IdGenerator::getClassStaticData() {
     static IdGenerator::StaticData statics; 
    return statics;
}

The constructor of IdGenerator::StaticData calls InetAddress::getLocalHost() to 
get the host name.

It seems that this constructor can be entered by multiple threads at the same 
time and mess up the apr get host name functionality.

I have fixed the problem by making the "statics" variable a member of 
IdGenerator, and by adding the statement of "IdGenerator::StaticData 
IdGenerator::statics;" to IdGenerator.cpp. 

Attached please find the modified code in IdGenerator.h and .cpp. Hope this fix 
is acceptable to you :)

 Thanks!





> Advisory messages do not work with multiple listeners
> -----------------------------------------------------
>
>                 Key: AMQCPP-315
>                 URL: https://issues.apache.org/activemq/browse/AMQCPP-315
>             Project: ActiveMQ C++ Client
>          Issue Type: Bug
>    Affects Versions: 3.2.2
>         Environment: Windows, ActiveMQ 5.3.1
>            Reporter: Helen Huang
>            Assignee: Timothy Bish
>         Attachments: activemq.log, AdvisoryMessageListener2.zip, 
> vs2005-build.zip
>
>
> We found that the advisory messages do not work as expected when there are 
> multiple consumers listening to the same advisory topics.
> We have three applications, AdvisoryMessageListener, MessageListener, and 
> MessageSender.
> AdvisoryMessageListener listens to the following two topics:
> ActiveMQ.Advisory.Consumer.Topic.cpp.itemLookup
> ActiveMQ.Advisory.Producer.Topic.cpp.itemLookup
> MessageListener listens to topic: cpp.itemLookup
> MessageSender sends messages to topic: cpp.itemLookup
> If there is only one instance of AdvisoryMessageListener , then everything 
> work fine. We can get the advisory messages when we start/shut down 
> MessageListener or MessageSender . However, when we start a second instance 
> of AdvisoryMessageListener , it seems to knock out the existing connection of 
> the first  AdvisoryMessageListener. The first instance can no longer receive 
> any advisory messages after that. 
> This problem could be related to the problem reported in jira item 
> "AMQCPP-314 Starting app with Com using cms destroys connection of other app. 
> New problem with recent lib version". However in our problem,  we do not have 
> any COM layers.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to