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)
/* * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ #include <qpid/messaging/Connection.h> #include <qpid/messaging/Message.h> #include <qpid/messaging/Sender.h> #include <qpid/messaging/Session.h> #include <iostream> using namespace qpid::messaging; class Producer { public: Producer(Session session, const std::string& address) : sender(session.createSender(address)) {} void send(const std::string& text) { sender.send(Message(text), true); } private: Sender sender; }; int main(int, char**) { Connection connection; connection.open(); Session session = connection.createSession(); Producer original(session, "amq.topic"); Producer copy(original); copy.send("Hello, from the copy!"); original.send("Hello, from the original!"); session.close(); connection.close(); }
--------------------------------------------------------------------- Apache Qpid - AMQP Messaging Implementation Project: http://qpid.apache.org Use/Interact: mailto:[email protected]
