WebSphere Message Service Clients for C/C++ and .NET, Version 1.2 운영 체제: Linux, Windows

C++의 XMS 오브젝트 지정

주제에서는 XMS 오브젝트를 C++의 변수에 지정하는 방법을 설명합니다.

대입 연산자는 표 1에 있는 각 XMS 클래스 목록에 오버로드됩니다. 오브젝트가 이미 하나의 변수에 지정되고 응용프로그램이 해당 변수의 값을 같은 유형의 다른 변수에 지정한 경우 오버로드된 대입 연산자의 정확한 조치는 지정된 오브젝트의 유형에 따라 다릅니다. 표 1는 각 유형의 오브젝트에 대해 오버로드된 대입 연산자가 오브젝트의 샐로우 또는 전체 복사를 작성할 것인지 표시합니다.
표 1. 대입 연산자가 오버로드되는 XMS 클래스
클래스 샐로우 복사 전체 복사
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);
}

Concept topic

이용약관 | 피드백

Timestamp icon마지막 갱신 날짜: 3 Mar 2006
(C) Copyright IBM Corporation 2005. All Rights Reserved.
이 Information Center는 Eclipse 기술 기반입니다. (http://www.eclipse.org 웹 사이트 참조)