You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@qpid.apache.org by Davide Anastasia <Da...@qualitycapital.com> on 2012/03/01 11:19:54 UTC

Default copy constructor behaviour for the class messaging::Receiver and messaging::Sender

Hi All,

What is the default behaviour for the copy constructor of the classes
messaging::Receiver and messaging::Sender?

I've spent a huge amount of time yesterday to figure out why this class
didn't work:

 

class Producer

{

public:

    //! \brief ctor

    Producer(qpid::messaging::Session& session, const std::string&
exchange, const std::string& topic);

    //! \brief dtor

    ~Producer();

 

    //! \brief

    void operator()();

 

private:

    std::string m_address;

 

    qpid::messaging::Session& m_session;

    qpid::messaging::Sender m_sender;

};

 

When an instance of this class is given to
boost::thread_group::create_thread, a new instance is created using the
implicit copy constructor, which just performs a member-to-member blind
copy. Unfortunately, receiver didn't work properly after the copy (which
makes me wonder how the copy constructor for the class messaging::Sender
is implemented) and I had to write an explicit copy constructor that
creates a new messaging::Sender on the same address. That solved the
problem. Is this a bug or a defined behaviour? It seems to me that the
copy constructor just creates a blank Sender. (messaging::Receiver shows
the same problem).

 

Other question: is there a way to allocate messaging::Sender and
messaging::Receiver on the heap?

 

Best,

 

Davide Anastasia
Analyst, Research & Development


Quality Capital Management Ltd.
QCM House * Horizon Business Village
No. 1 Brooklands Road
Weybridge * Surrey KT13 0TJ
United Kingdom

Tel: +44 (0) 1932 334 400
Fax: +44 (0) 1932 334 415
Email: Davide.Anastasia@QualityCapital.com
<ma...@QualityCapital.com> 

www.qualitycapital.com <http://www.qualitycapital.com/> 

________________________________

This email and any attachments are confidential and intended solely for
the use of the individual(s) to whom it is addressed. 

Any views or opinions presented are solely those of the author and do
not necessarily represent those of Quality Capital Management Ltd. If
you are not the intended recipient, be advised that you have received
this email in error and that any use, dissemination, printing,
forwarding or copying of this email is strictly prohibited. Please
contact the sender if you have received this email in error. You should
also be aware that emails are susceptible to interference and you should
not assume that the contents of this email originated from the sender
above or that they have been accurately reproduced in their original
form. Quality Capital Management Ltd is authorised and regulated by the
Financial Services Authority in the UK and is a member of the National
Futures Association in the US. 

________________________________

 


RE: Default copy constructor behaviour for the class messaging::Receiver and messaging::Sender

Posted by Davide Anastasia <Da...@qualitycapital.com>.
Hi Gordon,
Thanks for your help: your example indeed works (and it is in fact the
kind of behaviour that I was expecting from this class). I will
investigate further on my code to see whether I was doing some other
mistake.

Best,
Davide


-----Original Message-----
From: Gordon Sim [mailto:gsim@redhat.com] 
Sent: 01 March 2012 14:45
To: users@qpid.apache.org
Subject: Re: Default copy constructor behaviour for the class
messaging::Receiver and messaging::Sender

On 03/01/2012 10:19 AM, Davide Anastasia wrote:
> What is the default behaviour for the copy constructor of the classes 
> messaging::Receiver and messaging::Sender?

All the common classes in the messaging API are 'handles' and can be
copied and assigned as expected. I.e. if creating a copy, both the
original and the copy refer to the same
sender/receiver/session/connection.

[...]
> It seems to me that the
> copy constructor just creates a blank Sender. (messaging::Receiver 
> shows the same problem).

It shouldn't. Does the attached example work for you? It creates a very
simple Producer class with a Sender as a member, uses the default copy
constructor for that to create a copy of that and then sends a message
using the sender in both original and copied instance.

(run e.g. the drain example to see the output: drain -f amq.topic)

---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:users-subscribe@qpid.apache.org


Re: Default copy constructor behaviour for the class messaging::Receiver and messaging::Sender

Posted by Gordon Sim <gs...@redhat.com>.
On 03/01/2012 10:19 AM, Davide Anastasia wrote:
> What is the default behaviour for the copy constructor of the classes
> messaging::Receiver and messaging::Sender?

All the common classes in the messaging API are 'handles' and can be 
copied and assigned as expected. I.e. if creating a copy, both the 
original and the copy refer to the same sender/receiver/session/connection.

[...]
> It seems to me that the
> copy constructor just creates a blank Sender. (messaging::Receiver shows
> the same problem).

It shouldn't. Does the attached example work for you? It creates a very 
simple Producer class with a Sender as a member, uses the default copy 
constructor for that to create a copy of that and then sends a message 
using the sender in both original and copied instance.

(run e.g. the drain example to see the output: drain -f amq.topic)