이 주제에서는 XMS 오브젝트를 C++의 변수에 지정하는 방법을 설명합니다.
클래스 | 샐로우 복사 | 전체 복사 |
---|---|---|
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 | |
등록 정보 | Yes | |
QueueBrowser | Yes | |
Requestor | Yes | |
ResourceAllocationException | Yes | |
SecurityException | Yes | |
Session | Yes | |
StreamMessage | Yes | |
string | Yes | |
TextMessage | Yes | |
TransactionInProgressException | Yes | |
TransactionRolledBackException | Yes |
오브젝트의 샐로우 복사가 작성되면 오브젝트를 참조하는 모든 변수가 범위를 벗어날 때만 오브젝트가 삭제됩니다. 오브젝트를 참조하는 변수가 범위를 벗어나기 전에 응용프로그램이 오브젝트를 닫거나 삭제하면 응용프로그램은 더 이상 변수를 통해 오브젝트에 액세스할 수 없습니다.
#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); }