Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

osg::ClusterNetwork Class Reference
[Cluster]

Refcounted structure to hold all cluster connections. More...

#include <OSGClusterNetwork.h>

Inheritance diagram for osg::ClusterNetwork:

osg::MemoryObject List of all members.

Public Types

typedef std::vector< Connection * > ConnectionsT
typedef std::map< UInt32,
ClusterNetwork * > 
ConnectionInfoMapT
enum  { ALL_NODES = 0xf00000 }

Public Member Functions

Get
*ConnectiongetMainConnection (void)
GroupConnectiongetMainGroupConnection (void)
PointConnectiongetMainPointConnection (void)
ConnectiongetConnection (UInt32 id)
GroupConnectiongetGroupConnection (UInt32 id)
PointConnectiongetPointConnection (UInt32 id)
RemoteAspectgetAspect (void)
ConnectionsTgetConnection (void)
Set
*void setAspect (RemoteAspect *aspect)
void setMainConnection (Connection *connection)
void setConnection (UInt32 id, Connection *connection)
establish connection
*void connectAllPointToPoint (UInt32 thidId, const std::string &connectionType)
void connectAllGroupToPoint (UInt32 thidId, const std::string &connectionType)
Reference Counting
*void addRef (void)
void subRef (void)
Int32 getRefCount (void)

Static Public Member Functions

static access
*static ClusterNetworkgetInstance (UInt32 ClusterWindowId)

Protected Types

typedef MemoryObject Inherited

Protected Member Functions

Constructors
ClusterNetwork (UInt32 clusterWindowId)
Destructor
*virtual ~ClusterNetwork (void)

Protected Attributes

Fields
*RemoteAspect_aspect
Connection_mainConnection
ConnectionsT _connection
UInt32 _id

Private Member Functions

 ClusterNetwork (const ClusterNetwork &source)
ClusterNetworkoperator= (const ClusterNetwork &source)

Static Private Attributes

static ConnectionInfoMapT _map

Detailed Description

The ClusterNetwork holds all Connections between servers and client. Main reason for this class is to enable cross-connections between servers that are neccessary to implement e.g. Hybrid sort-first sort-last algorithms. This class is a container for all connections between cluster nodes. The cluster network is not part of the cluster window or the cluster server because it is used on the client and the server side and it is accessable from all aspects. If all connections are established, then getMainConnection provides the connection from client to all servers. getConnection(n) is the connection to the server with id n. If n is the current server id then this connection is connected to all other servers.

Definition at line 58 of file OSGClusterNetwork.h.


Member Typedef Documentation

typedef std::vector<Connection *> osg::ClusterNetwork::ConnectionsT
 

Definition at line 63 of file OSGClusterNetwork.h.

typedef std::map<UInt32,ClusterNetwork *> osg::ClusterNetwork::ConnectionInfoMapT
 

Definition at line 64 of file OSGClusterNetwork.h.

typedef MemoryObject osg::ClusterNetwork::Inherited [protected]
 

Definition at line 112 of file OSGClusterNetwork.h.


Member Enumeration Documentation

anonymous enum
 

Enumerator:
ALL_NODES 

Definition at line 65 of file OSGClusterNetwork.h.

00065 { ALL_NODES   = 0xf00000 };


Constructor & Destructor Documentation

ClusterNetwork::ClusterNetwork UInt32  id  )  [protected]
 

Constructor documentation

Definition at line 77 of file OSGClusterNetwork.cpp.

Referenced by getInstance().

00077                                         :
00078     Inherited(),
00079     _aspect(NULL),
00080     _mainConnection(NULL),
00081     _connection(),
00082     _id(id)
00083 {
00084 }

ClusterNetwork::~ClusterNetwork void   )  [protected, virtual]
 

Destructor documentation

Definition at line 91 of file OSGClusterNetwork.cpp.

References _aspect, _connection, _id, _mainConnection, and _map.

00092 {
00093     if(_aspect)
00094         delete _aspect;
00095     _aspect=NULL;
00096     if(_mainConnection)
00097         delete _mainConnection;
00098     _mainConnection=NULL;
00099     for(ConnectionsT::iterator c = _connection.begin();
00100         c != _connection.end();
00101         ++c)
00102     {
00103         if(*c)
00104             delete (*c);
00105         (*c)=NULL;
00106     }
00107     _connection.clear();
00108     ConnectionInfoMapT::iterator ci=_map.find(_id);
00109     if(ci!=_map.end())
00110     {
00111         _map.erase(ci);
00112     }
00113 }

osg::ClusterNetwork::ClusterNetwork const ClusterNetwork source  )  [private]
 


Member Function Documentation

Connection * ClusterNetwork::getMainConnection void   ) 
 

get main connection. The main connection is used to sync the network aspects

Definition at line 121 of file OSGClusterNetwork.cpp.

References _mainConnection.

Referenced by osg::MultiDisplayWindow::clientSwap(), osg::ClusterWindow::frameInit(), osg::ClusterWindow::init(), osg::ClusterWindow::renderAllViewports(), osg::SortFirstWindow::serverInit(), osg::SortFirstWindow::serverSwap(), osg::MultiDisplayWindow::serverSwap(), and osg::ClusterWindow::swap().

00122 {
00123     return _mainConnection;
00124 }

GroupConnection * ClusterNetwork::getMainGroupConnection void   ) 
 

get main connection as group connection. If main connection is a point connection, then NULL is returned

Definition at line 129 of file OSGClusterNetwork.cpp.

References _mainConnection.

Referenced by osg::SortFirstWindow::clientInit(), osg::SortFirstWindow::clientSwap(), connectAllGroupToPoint(), and connectAllPointToPoint().

00130 {
00131     return dynamic_cast<GroupConnection*>(_mainConnection);
00132 }

PointConnection * ClusterNetwork::getMainPointConnection void   ) 
 

get main connection as point connection. If main connection is a group connection, then NULL is returned

Definition at line 137 of file OSGClusterNetwork.cpp.

References _mainConnection.

00138 {
00139     return dynamic_cast<PointConnection*>(_mainConnection);
00140 }

Connection * ClusterNetwork::getConnection UInt32  id  ) 
 

get connection with the given id

Definition at line 144 of file OSGClusterNetwork.cpp.

References _connection.

00145 {
00146     if(id<_connection.size())
00147         return _connection[id];
00148     else
00149         return NULL;
00150 }

GroupConnection * ClusterNetwork::getGroupConnection UInt32  id  ) 
 

get connection as group connection. If main connection is a point connection, then NULL is returned

Definition at line 155 of file OSGClusterNetwork.cpp.

References getConnection().

Referenced by connectAllGroupToPoint(), and connectAllPointToPoint().

00156 {
00157     return dynamic_cast<GroupConnection*>(getConnection(id));
00158 }

PointConnection * ClusterNetwork::getPointConnection UInt32  id  ) 
 

get main connection as point connection. If main connection is a group connection, then NULL is returned

Definition at line 163 of file OSGClusterNetwork.cpp.

References getConnection().

Referenced by connectAllGroupToPoint(), and connectAllPointToPoint().

00164 {
00165     return dynamic_cast<PointConnection*>(getConnection(id));
00166 }

RemoteAspect * ClusterNetwork::getAspect void   ) 
 

get remote aspect

Definition at line 170 of file OSGClusterNetwork.cpp.

References _aspect.

Referenced by osg::ClusterWindow::frameInit(), osg::ClusterWindow::renderAllViewports(), osg::ClusterWindow::setStatistics(), and osg::ClusterWindow::swap().

00171 {
00172     return _aspect;
00173 }

ClusterNetwork::ConnectionsT & ClusterNetwork::getConnection void   ) 
 

get main connection. The main connection is used to sync the network aspects

Definition at line 175 of file OSGClusterNetwork.cpp.

References _connection.

Referenced by getGroupConnection(), and getPointConnection().

00176 {
00177     return _connection;
00178 }

void ClusterNetwork::setAspect RemoteAspect aspect  ) 
 

Set remote Aspect

Definition at line 185 of file OSGClusterNetwork.cpp.

References _aspect.

Referenced by osg::ClusterWindow::init().

00186 {
00187     _aspect=aspect;
00188 }

void ClusterNetwork::setMainConnection Connection connection  ) 
 

Set main connection. This is the connection for aspect sync

Definition at line 192 of file OSGClusterNetwork.cpp.

References _mainConnection.

Referenced by osg::ClusterWindow::init().

00193 {
00194     _mainConnection=connection;
00195 }

void ClusterNetwork::setConnection UInt32  id,
Connection connection
 

Set connection

Definition at line 199 of file OSGClusterNetwork.cpp.

References _connection.

00200 {
00201     while(id<_connection.size())
00202         _connection.push_back(NULL);
00203     _connection[id]=connection;
00204 }

void ClusterNetwork::connectAllPointToPoint UInt32  thisId,
const std::string &  connectionType
 

crossconnect servers and the client.

Each Server is connected with all other servers with a point to point connection. Thre connection number N is used to read from node N and to write to node N. If N is equal to the servers id then the connection is used to exchange data with the client. The client gathers all connections in a GroupConnection. So all Server-Server communication is done with point to point connections and if N=server id then a point to group connection is used to communicate with the client.

Definition at line 220 of file OSGClusterNetwork.cpp.

References _connection, _mainConnection, osg::Connection::acceptPoint(), osg::Connection::Channel, osg::PointConnection::connectGroup(), osg::ConnectionFactory::createGroup(), osg::ConnectionFactory::createPoint(), osg::BinaryDataHandler::flush(), osg::GroupConnection::getChannelCount(), getGroupConnection(), getMainGroupConnection(), getPointConnection(), osg::BinaryDataHandler::getValue(), osg::BinaryDataHandler::putValue(), osg::GroupConnection::resetSelection(), osg::Connection::selectChannel(), osg::GroupConnection::subSelection(), and osg::ConnectionFactory::the().

00223 {
00224     bool                                   isClient;
00225     UInt32                                 servers;
00226     Connection                            *addressSource;
00227     UInt32                                 id,c;
00228     std::map<UInt32,std::string>           address;
00229     std::vector<UInt32>                    fromId;
00230     std::vector<UInt32>                    toId;
00231     std::vector<std::string>               toAddr;
00232     UInt32                                 addrCount;
00233     Connection::Channel                    channel;
00234     std::string                            clientAddress;
00235 
00236     // determine if this is a server 
00237     if(dynamic_cast<GroupConnection*>(_mainConnection))
00238         isClient = true;
00239     else
00240         isClient = false;
00241     // communicate server count
00242     if(isClient)
00243     {
00244         servers = getMainGroupConnection()->getChannelCount();
00245         _mainConnection->putValue(servers);
00246         _mainConnection->flush();
00247     }
00248     else
00249     {
00250         _mainConnection->getValue(servers);
00251     }
00252 
00253     addrCount = (servers+1) * servers / 2;
00254     fromId.resize(addrCount);
00255     toId.resize  (addrCount);
00256     toAddr.resize(addrCount);
00257 
00258     _connection.resize(servers+1);
00259     // send all addresses
00260     for(id = 0; id <= servers; ++id)
00261     {
00262         if(isClient && id == thisId)
00263             _connection[id] = 
00264                 ConnectionFactory::the().createGroup(connectionType);
00265         else
00266             _connection[id] = 
00267                 ConnectionFactory::the().createPoint(connectionType);
00268         if(id > thisId)
00269         {
00270             _mainConnection->putValue(id);
00271             _mainConnection->putValue(thisId);
00272             _mainConnection->putValue(_connection[id]->bind());
00273             _mainConnection->flush();
00274         }
00275     }
00276     // read and retransmit all addresses
00277     if(isClient)
00278     {
00279         for(c = 0 ; c < addrCount ; ++c)
00280         {
00281             channel = getMainGroupConnection()->selectChannel();
00282             getMainGroupConnection()->getValue(fromId[c]);
00283             getMainGroupConnection()->getValue(toId[c]);
00284             getMainGroupConnection()->getValue(toAddr[c]);
00285             // remember client to server
00286             if(fromId[c] == thisId)
00287             {
00288                 address[toId[c]] = toAddr[c];
00289                 getMainGroupConnection()->subSelection(channel);
00290             }
00291         }
00292         getMainGroupConnection()->resetSelection();
00293         for(c = 0 ; c < addrCount ; ++c)
00294         {
00295             _mainConnection->putValue(fromId[c]);
00296             _mainConnection->putValue(toId[c]);
00297             _mainConnection->putValue(toAddr[c]);
00298         }
00299         _mainConnection->flush();
00300     }
00301     // receive all addresses
00302     if(!isClient)
00303     {
00304         _mainConnection->selectChannel();
00305         for(c = 0 ; c < (servers+1) * servers / 2 ; ++c)
00306         {
00307             _mainConnection->getValue(fromId[c]);
00308             _mainConnection->getValue(toId[c]);
00309             _mainConnection->getValue(toAddr[c]);
00310             if(fromId[c] == thisId)
00311                 address[toId[c]] = toAddr[c];
00312         }
00313     }
00314     // connect to all
00315     for(id = 0; id <= servers; ++id)
00316     {
00317         if(id > thisId)
00318         {
00319             _connection[id]->acceptPoint();
00320         }
00321         if(id < thisId)
00322         {
00323             for(;;)
00324                 try
00325                 {
00326                     _connection[id]->connectPoint(address[id]);
00327                     break;
00328                 }
00329                 catch(...)
00330                 {
00331                 }
00332         }
00333     }
00334 
00335     // connect all servers with the client.
00336     if(isClient)
00337     {
00338         _mainConnection->putValue(_connection[thisId]->bind());
00339         _mainConnection->flush();
00340         for(id=0 ; id < servers ; ++id)
00341         {
00342             getGroupConnection(thisId)->acceptPoint();
00343         }
00344     }
00345     else
00346     {
00347         _mainConnection->getValue(clientAddress);
00348         for(;;)
00349             try
00350             {
00351                 getPointConnection(thisId)->connectGroup(clientAddress);
00352                 break;
00353             }
00354             catch(...)
00355             {
00356             }
00357     }
00358 }

void ClusterNetwork::connectAllGroupToPoint UInt32  thisId,
const std::string &  connectionType
 

crossconnect servers and the client.

Each server is connected over a GroupConnection with all other servers. Connection N is used to read and write to the server with id N. If N is equal to the current server id, then write operations are passed to all other servers and read collects data from all other servers. The client connection is stored in the index equal to the number of servers.

Definition at line 370 of file OSGClusterNetwork.cpp.

References _connection, _mainConnection, osg::Connection::acceptPoint(), osg::Connection::Channel, osg::PointConnection::connectGroup(), osg::ConnectionFactory::createGroup(), osg::ConnectionFactory::createPoint(), osg::BinaryDataHandler::flush(), osg::GroupConnection::getChannelCount(), getGroupConnection(), getMainGroupConnection(), getPointConnection(), osg::GroupConnection::getSelectionCount(), osg::BinaryDataHandler::getValue(), osg::BinaryDataHandler::putValue(), osg::GroupConnection::resetSelection(), osg::Connection::selectChannel(), osg::GroupConnection::subSelection(), and osg::ConnectionFactory::the().

00373 {
00374     UInt32                                 id,toId;
00375     bool                                   isClient;
00376     UInt32                                 servers;
00377     std::map<UInt32,std::string>           address;
00378     Connection::Channel                    channel;
00379     std::string                            groupAddress;
00380 
00381     // determine if this is a server 
00382     if(dynamic_cast<GroupConnection*>(_mainConnection))
00383         isClient = true;
00384     else
00385         isClient = false;
00386 
00387     // communicate server count
00388     if(isClient)
00389     {
00390         servers = getMainGroupConnection()->getChannelCount();
00391         _mainConnection->putValue(servers);
00392         _mainConnection->flush();
00393     }
00394     else
00395     {
00396         _mainConnection->getValue(servers);
00397     }
00398     
00399     // create all connections
00400     _connection.resize(servers+1);
00401     for(id = 0; id <= servers; ++id)
00402     {
00403         if(id == thisId)
00404         {
00405             _connection[id] = 
00406                 ConnectionFactory::the().createGroup(connectionType);
00407             groupAddress = _connection[id]->bind();
00408         }
00409         else
00410             _connection[id] = 
00411                 ConnectionFactory::the().createPoint(connectionType);
00412     }
00413     if(isClient)
00414     {
00415         address[thisId] = groupAddress;
00416         while(getMainGroupConnection()->getSelectionCount())
00417         {
00418             channel = _mainConnection->selectChannel();
00419             getMainGroupConnection()->subSelection(channel);
00420             getMainGroupConnection()->getValue(groupAddress);
00421             address[channel] = groupAddress;
00422         }
00423         getMainGroupConnection()->resetSelection();
00424         for(id = 0; id <= servers; ++id)
00425         {
00426             _mainConnection->putValue(address[id]);
00427         }
00428         _mainConnection->flush();
00429     }
00430     else
00431     {
00432         _mainConnection->putValue(groupAddress);
00433         _mainConnection->flush();
00434         for(id = 0; id <= servers; ++id)
00435         {
00436             _mainConnection->getValue(groupAddress);
00437             address[id] = groupAddress;
00438         }
00439     }
00440 
00441     for(id = 1; id <= servers; ++id)
00442     {
00443         toId = (thisId+id)%(servers+1);
00444         if(thisId & 1)
00445         {
00446             getGroupConnection(thisId)->acceptPoint();
00447             getPointConnection(toId)->connectGroup(address[toId]);
00448         }
00449         else
00450         {
00451             getPointConnection(toId)->connectGroup(address[toId]);
00452             getGroupConnection(thisId)->acceptPoint();
00453         }
00454     }
00455 }

ClusterNetwork * ClusterNetwork::getInstance UInt32  clusterWindowId  )  [static]
 

Get an instance of the ClusterNetwork with the given container id

Definition at line 462 of file OSGClusterNetwork.cpp.

References _map, and ClusterNetwork().

Referenced by osg::ClusterWindow::getNetwork().

00463 {
00464     ConnectionInfoMapT::iterator ci=_map.find(clusterWindowId);
00465     if(ci==_map.end())
00466     {
00467         ClusterNetwork *ciP=new ClusterNetwork(clusterWindowId);
00468         _map[clusterWindowId]=ciP;
00469         return ciP;
00470     }
00471     else
00472     {
00473         return ci->second;
00474     }
00475 }

ClusterNetwork& osg::ClusterNetwork::operator= const ClusterNetwork source  )  [private]
 

void MemoryObject::addRef void   )  [inherited]
 

Definition at line 64 of file OSGMemoryObject.cpp.

References osg::MemoryObject::_refCount.

Referenced by osg::SharedObjectHandler::getSharedObject(), and osg::SharedObjectHandler::initialize().

00065 {
00066     _refCount++;
00067 }

void MemoryObject::subRef void   )  [inherited]
 

Definition at line 69 of file OSGMemoryObject.cpp.

References osg::MemoryObject::_refCount.

00070 {
00071     _refCount--;
00072 
00073     if(_refCount <= 0)
00074         delete this;
00075 }

Int32 MemoryObject::getRefCount void   )  [inherited]
 

Definition at line 77 of file OSGMemoryObject.cpp.

References osg::MemoryObject::_refCount.

00078 {
00079     return _refCount;
00080 }


Member Data Documentation

* RemoteAspect* osg::ClusterNetwork::_aspect [protected]
 

Definition at line 132 of file OSGClusterNetwork.h.

Referenced by getAspect(), setAspect(), and ~ClusterNetwork().

Connection* osg::ClusterNetwork::_mainConnection [protected]
 

Definition at line 133 of file OSGClusterNetwork.h.

Referenced by connectAllGroupToPoint(), connectAllPointToPoint(), getMainConnection(), getMainGroupConnection(), getMainPointConnection(), setMainConnection(), and ~ClusterNetwork().

ConnectionsT osg::ClusterNetwork::_connection [protected]
 

Definition at line 134 of file OSGClusterNetwork.h.

Referenced by connectAllGroupToPoint(), connectAllPointToPoint(), getConnection(), setConnection(), and ~ClusterNetwork().

UInt32 osg::ClusterNetwork::_id [protected]
 

Definition at line 135 of file OSGClusterNetwork.h.

Referenced by ~ClusterNetwork().

ClusterNetwork::ConnectionInfoMapT ClusterNetwork::_map [static, private]
 

Definition at line 480 of file OSGClusterNetwork.cpp.

Referenced by getInstance(), and ~ClusterNetwork().


The documentation for this class was generated from the following files:
Generated on Thu Aug 25 04:13:02 2005 for OpenSG by  doxygen 1.4.3