WebSphere WebSphere Business Integration Message Service Clients for C/C++ Version 1.2.7 and .NET Version 1.2.6 Operating Systems: AIX, Linux, Solaris, Windows

Assignment ofXMS objects to variables in C++

This topic describes how XMS objects are assigned to variables in C++.

The assignment operator is overloaded on each of the XMS classes listed in Table 1. If an object is already assigned to one variable, and an application assigns the value of that variable to another variable of the same type, the precise action of the overloaded assignment operator depends on the type of the object being assigned: Table 1 indicates, for each type of object, whether the overloaded assignment operator makes a shallow or a deep copy of an object.
Table 1. The XMS classes on which the assignment operator is overloaded
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.

The following code fragment illustrates these concepts:
#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

Terms of Use | Rate this page

Last updated: 18 Jun 2008

© Copyright IBM Corporation 2005, 2008. All Rights Reserved.