This topic describes how XMS objects are assigned to variables in C++.
Class | Shallow copy | Deep copy |
---|---|---|
BytesMessage | Yes | |
Connection | Yes | |
ConnectionFactory | Yes | |
ConnectionMetaData | Yes | |
Destination | Yes | |
Exception | Yes | |
IllegalStateException | Yes | |
InitialContext | Yes | |
InvalidClientIDException | Yes | |
InvalidDestinationException | Yes | |
InvalidSelectorException | Yes | |
Iterator | Yes | |
MapMessage | Yes | |
Message | Yes | |
MessageConsumer | Yes | |
MessageEOFException | Yes | |
MessageFormatException | Yes | |
MessageNotReadableException | Yes | |
MessageNotWritableException | Yes | |
MessageProducer | Yes | |
ObjectMessage | Yes | |
Property | Yes | |
QueueBrowser | Yes | |
Requestor | Yes | |
ResourceAllocationException | Yes | |
SecurityException | Yes | |
Session | Yes | |
StreamMessage | Yes | |
String | Yes | |
TextMessage | Yes | |
TransactionInProgressException | Yes | |
TransactionRolledBackException | Yes |
When a shallow copy of an object is made, the object is deleted only when all the variables that reference the object go out of scope. If the application closes or deletes the object before the variables that reference the object go out of scope, the application can no longer access the object through any of the variables.
#include <xms.hpp> using namespace std; int main(int argc, char *argv[]) { xms::ConnectionFactory cf; xms::Connection conn; xms::Session sess; xms::Session sess2; cf.setIntProperty(XMSC_CONNECTION_TYPE, XMSC_CT_RTT); cf.setIntProperty(XMSC_RTT_CONNECTION_PROTOCOL, XMSC_RTT_CP_TCP); cf.setStringProperty(XMSC_RTT_HOST_NAME, "localhost"); cf.setIntProperty(XMSC_RTT_PORT, 1506); conn = cf.createConnection(); sess = conn.createSession(); // Make a shallow copy of the Session object. sess2 = sess; // Set a property in the Session object using the sess2 variable. sess2.setStringProperty("property", "test"); // Make another shallow copy of the Session object. if (sess2.isNull() != xmsTRUE) { xms::Session sess3 = sess2; // Set another property in the Session object, this time using // the sess3 variable. sess3.setStringProperty("another property", "test"); } // The sess3 variable is now out of scope, but the second property // is still set in the Session object. // Close the Session object. sess.close(); // The Session object is now closed and can no longer be accessed // through the sess2 variable. As a result, the following statement // causes "invalid session" to be written to the standard output // stream. if (sess2.isNull() == xmsTRUE) { cout << "invalid session" << endl; } return(0); }