このトピックでは、C++ で XMS オブジェクトを変数に割り当てる方法について説明します。
クラス | シャロー・コピー | ディープ・コピー |
---|---|---|
BytesMessage | はい | |
Connection | はい | |
ConnectionFactory | はい | |
ConnectionMetaData | はい | |
Destination | はい | |
Exception | はい | |
IllegalStateException | はい | |
InitialContext | はい | |
InvalidClientIDException | はい | |
InvalidDestinationException | はい | |
InvalidSelectorException | はい | |
Iterator | はい | |
MapMessage | はい | |
Message | はい | |
MessageConsumer | はい | |
MessageEOFException | はい | |
MessageFormatException | はい | |
MessageNotReadableException | はい | |
MessageNotWritableException | はい | |
MessageProducer | はい | |
ObjectMessage | はい | |
Property | はい | |
QueueBrowser | はい | |
Requestor | はい | |
ResourceAllocationException | はい | |
SecurityException | はい | |
Session | はい | |
StreamMessage | はい | |
String | はい | |
TextMessage | はい | |
TransactionInProgressException | はい | |
TransactionRolledBackException | はい |
オブジェクトのシャロー・コピーが行われると、オブジェクトが削除されるのは、オブジェクトを参照するすべての変数がスコープの範囲外になった場合のみとなります。 オブジェクトを参照する変数がスコープの範囲外になる前に、アプリケーションがオブジェクトを閉じるか削除すると、そのアプリケーションは、変数を介してオブジェクトにアクセスすることができなくなります。
#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); }