#include <ApplicationDataManager.h>
Inheritance diagram for cluster::ApplicationDataManager:


Public Member Functions | |
| ApplicationDataManager () | |
| virtual | ~ApplicationDataManager () |
| vpr::GUID | getHandlerGUID () |
| Get the GUID associated with this plugin. | |
| void | handlePacket (Packet *packet, gadget::Node *node) |
| Handle a incoming packet. | |
| virtual void | preDraw () |
| Called each frame by the kernel to update all application level data(ApplicationData). | |
| virtual void | postPostFrame () |
| Called each frame by the kernel to update the cluster after the InputManager has updated it's data. | |
| virtual void | sendRequests () |
| Send all pending requests for ApplicationData to other Nodes. | |
| virtual bool | isPluginReady () |
| Is this ClusterPlugin ready for the cluster to start the application. | |
| virtual std::string | getPluginName () |
| Return the name of this ClusterPlugin. | |
| virtual std::string | getHandlerName () |
| virtual void | recoverFromLostNode (gadget::Node *lost_node) |
| Virtual function used to inform all handlers that the network has lost its connection to the given Node. | |
| bool | configAdd (jccl::ConfigElementPtr element) |
| Add the pending element to the configuration. | |
| bool | configRemove (jccl::ConfigElementPtr element) |
| Remove the pending element from the current configuration. | |
| bool | configCanHandle (jccl::ConfigElementPtr element) |
| Checks if this handler can process element. | |
| virtual void | addSerializableObject (vpr::SerializableObject *object) |
| Add a ApplicationData object to the current configuration. | |
| void | removeApplicationData (ApplicationData *old_user_data) |
| Remove the ApplicationData object from the current configuration. | |
| void | dumpApplicationData () |
| Print a list of all ApplicationData objects currently in the configuration. | |
Definition at line 56 of file ApplicationDataManager.h.
| cluster::ApplicationDataManager::ApplicationDataManager | ( | ) |
| cluster::ApplicationDataManager::~ApplicationDataManager | ( | ) | [virtual] |
| vpr::GUID cluster::ApplicationDataManager::getHandlerGUID | ( | ) | [inline, virtual] |
Get the GUID associated with this plugin.
Implements gadget::PacketHandler.
Definition at line 68 of file ApplicationDataManager.h.
Referenced by addSerializableObject(), configAdd(), and handlePacket().
| void cluster::ApplicationDataManager::handlePacket | ( | Packet * | packet, | |
| gadget::Node * | node | |||
| ) | [virtual] |
Handle a incoming packet.
Implements gadget::PacketHandler.
Definition at line 90 of file ApplicationDataManager.cpp.
References cluster::ApplicationDataServer::addClient(), gadgetDBG_RIM(), cluster::ApplicationDataAck::getAck(), getHandlerGUID(), cluster::ApplicationDataAck::getId(), cluster::ApplicationDataRequest::getId(), cluster::Packet::getPacketType(), cluster::Header::RIM_APPDATA_ACK, cluster::Header::RIM_APPDATA_REQ, cluster::Header::RIM_DATA_PACKET, and gadget::Node::send().
00091 { 00092 if ( NULL != packet && NULL != node ) 00093 { 00094 switch ( packet->getPacketType() ) 00095 { 00096 case cluster::Header::RIM_DATA_PACKET: 00097 { 00098 DataPacket* temp_data_packet = dynamic_cast<DataPacket*>(packet); 00099 vprASSERT(NULL != temp_data_packet && "Dynamic cast failed!"); 00100 00101 // Find the ApplicationData Object that we have received data 00102 // for. 00103 ApplicationData* user_data = 00104 getRemoteApplicationData(temp_data_packet->getObjectId()); 00105 if (user_data != NULL) 00106 { 00107 // Create a object reader to parse the object's data with 00108 vpr::BufferObjectReader* temp_reader = 00109 new vpr::BufferObjectReader(temp_data_packet->getDeviceData()); 00110 00111 // Parse the object's data using the temporary ObjectReader 00112 user_data->readObject(temp_reader); 00113 } 00114 break; 00115 } 00116 case cluster::Header::RIM_APPDATA_REQ: 00117 { 00118 ApplicationDataRequest* temp_request = 00119 dynamic_cast<ApplicationDataRequest*>(packet); 00120 vprASSERT(NULL != temp_request && "Dynamic cast failed!"); 00121 00122 // Find the ApplicationDataServer that is serving the data for 00123 // this requested object. 00124 ApplicationDataServer* temp_app_data_server = 00125 getApplicationDataServer(temp_request->getId()); 00126 ApplicationDataAck* temp_ack(NULL); 00127 00128 // -If a ApplicationDataServer for this object exists 00129 // -Add the requesting node as a client 00130 // -Respond with an ACK 00131 // -Else 00132 // -Respond with an NACK 00133 // -Free the memory used be the ACK/NACK 00134 00135 if (temp_app_data_server != NULL) 00136 { 00137 temp_app_data_server->addClient(node); 00138 temp_ack = new ApplicationDataAck(getHandlerGUID(), 00139 temp_request->getId(), true); 00140 } 00141 else 00142 { 00143 temp_ack = new ApplicationDataAck(getHandlerGUID(), 00144 temp_request->getId(), false); 00145 } 00146 node->send(temp_ack); 00147 delete temp_ack; 00148 break; 00149 } 00150 case cluster::Header::RIM_APPDATA_ACK: 00151 { 00152 ApplicationDataAck* temp_ack = 00153 dynamic_cast<ApplicationDataAck*>(packet); 00154 vprASSERT(NULL != temp_ack && "Dynamic cast failed!"); 00155 00156 // -If we received an ACK 00157 // -Remove the coresponding ApplicationDataRequest from the 00158 // pending list 00159 if (temp_ack->getAck()) 00160 { 00161 removePendingApplicationDataRequest(temp_ack->getId()); 00162 } 00163 break; 00164 } 00165 default: 00166 vprDEBUG(gadgetDBG_RIM,vprDBG_WARNING_LVL) 00167 << clrOutBOLD(clrCYAN,"[ApplicationDataManager] ") 00168 << "Don't know how to handle a packet of type: " 00169 << packet->getPacketType() << std::endl << vprDEBUG_FLUSH; 00170 break; 00171 } // End switch 00172 } // End if 00173 }
| void cluster::ApplicationDataManager::preDraw | ( | ) | [virtual] |
Called each frame by the kernel to update all application level data(ApplicationData).
Implements cluster::ClusterPlugin.
Definition at line 337 of file ApplicationDataManager.cpp.
References gadgetDBG_RIM().
00338 { 00339 //mFrameNumber++; 00340 00341 // Send ApplicationData 00342 vprDEBUG(gadgetDBG_RIM, vprDBG_HVERB_LVL) 00343 << clrOutBOLD(clrMAGENTA,"[ApplicationDataManager::preDraw()]") 00344 << "Sending ApplicationData.\n" << vprDEBUG_FLUSH; 00345 00346 vpr::Guard<vpr::Mutex> guard(mApplicationDataServersLock); 00347 00348 std::map<vpr::GUID, ApplicationDataServer*>::iterator application_data_servers_begin = mApplicationDataServers.begin(); 00349 std::map<vpr::GUID, ApplicationDataServer*>::iterator application_data_servers_end = mApplicationDataServers.end(); 00350 00351 // For each ApplicationDataServer on this node, serialize the data and send it to each of it's clients. 00352 for (std::map<vpr::GUID, ApplicationDataServer*>::iterator i = application_data_servers_begin; 00353 i != application_data_servers_end; 00354 ++i) 00355 { 00356 (*i).second->serializeAndSend(); 00357 } 00358 }
| void cluster::ApplicationDataManager::postPostFrame | ( | ) | [virtual] |
Called each frame by the kernel to update the cluster after the InputManager has updated it's data.
Implements cluster::ClusterPlugin.
Definition at line 334 of file ApplicationDataManager.cpp.
| void cluster::ApplicationDataManager::sendRequests | ( | ) | [virtual] |
Send all pending requests for ApplicationData to other Nodes.
Reimplemented from cluster::ClusterPlugin.
Definition at line 360 of file ApplicationDataManager.cpp.
References gadget::Node::CONNECTED, gadget::Node::NEWCONNECTION, and gadget::Node::PENDING.
00361 { 00362 // Send ApplicationData Requests 00363 vpr::Guard<vpr::Mutex> guard(mPendingApplicationDataRequestsLock); 00364 00365 std::map<ApplicationDataRequest*, std::string>::iterator begin = mPendingApplicationDataRequests.begin(); 00366 std::map<ApplicationDataRequest*, std::string>::iterator end = mPendingApplicationDataRequests.end(); 00367 std::map<ApplicationDataRequest*, std::string>::iterator i; 00368 00369 // For each pending ApplicationData request 00370 for (i = begin ; i != end ; ++i) 00371 { 00372 // Get the Node that the request is for. 00373 gadget::Node* temp_node = 00374 ClusterManager::instance()->getNetwork()->getNodeByHostname((*i).second); 00375 00376 // If the node exists in the ClusterNetwork 00377 if (temp_node != NULL) 00378 { 00379 // If the Node is connected 00380 if ( gadget::Node::CONNECTED == temp_node->getStatus() || 00381 gadget::Node::NEWCONNECTION == temp_node->getStatus() ) 00382 { 00383 // Send the request 00384 temp_node->send((*i).first); 00385 } 00386 else 00387 { 00388 // Else add the Node to the list of pending Nodes so that we 00389 // will connect to it. 00390 temp_node->setStatus(gadget::Node::PENDING); 00391 } // End if 00392 } // End if 00393 } // End for 00394 }
| bool cluster::ApplicationDataManager::isPluginReady | ( | ) | [virtual] |
Is this ClusterPlugin ready for the cluster to start the application.
Reimplemented from cluster::ClusterPlugin.
Definition at line 82 of file ApplicationDataManager.cpp.
00083 { 00084 // This plugin will be ready when it does not have any more 00085 // PendingApplicationDataRequests 00086 vpr::Guard<vpr::Mutex> guard(mPendingApplicationDataRequestsLock); 00087 return(0 == mPendingApplicationDataRequests.size()); 00088 }
| virtual std::string cluster::ApplicationDataManager::getPluginName | ( | ) | [inline, virtual] |
Return the name of this ClusterPlugin.
Implements cluster::ClusterPlugin.
Definition at line 101 of file ApplicationDataManager.h.
| virtual std::string cluster::ApplicationDataManager::getHandlerName | ( | ) | [inline, virtual] |
| virtual void cluster::ApplicationDataManager::recoverFromLostNode | ( | gadget::Node * | lost_node | ) | [inline, virtual] |
Virtual function used to inform all handlers that the network has lost its connection to the given Node.
Implements gadget::PacketHandler.
Definition at line 110 of file ApplicationDataManager.h.
| bool cluster::ApplicationDataManager::configAdd | ( | jccl::ConfigElementPtr | element | ) | [virtual] |
Add the pending element to the configuration.
Implements cluster::ClusterPlugin.
Definition at line 184 of file ApplicationDataManager.cpp.
References gadgetDBG_RIM(), getHandlerGUID(), and gadget::AbstractNetworkManager::isLocalHost().
00185 { 00186 if (recognizeApplicationDataManagerConfig(element)) 00187 { 00188 vprDEBUG(gadgetDBG_RIM,vprDBG_WARNING_LVL) 00189 << clrOutBOLD(clrCYAN,"[ApplicationDataManager] ") 00190 << "The ApplicationDataMananger does not currently support a " 00191 << "need for configuration element: " << element->getName() 00192 << "\n" << vprDEBUG_FLUSH; 00193 return(true); 00194 } 00195 else if (recognizeApplicationDataConfig(element)) 00196 { 00197 std::string guid_string = element->getProperty<std::string>("guid"); 00198 vpr::GUID guid(guid_string); 00199 std::string hostname = element->getProperty<std::string>("hostname"); 00200 00201 vpr::Guard<vpr::Mutex> guard(mNeedsConfigedLock); 00202 std::vector<ApplicationData*>::iterator begin = mNeedsConfiged.begin(); 00203 std::vector<ApplicationData*>::iterator end = mNeedsConfiged.end(); 00204 std::vector<ApplicationData*>::iterator i; 00205 00206 for (i = begin ; i != end ; ++i) 00207 { 00208 if ((*i)->getId() == guid) 00209 { 00210 vprDEBUG(gadgetDBG_RIM,vprDBG_CONFIG_LVL) 00211 << "[ApplicationDataManager::configAdd()] " 00212 << "Configuring ApplicationData object " << guid.toString() 00213 << " on host: " << hostname << std::endl << vprDEBUG_FLUSH; 00214 00215 (*i)->setHostname(hostname); 00216 00217 if (ClusterNetwork::isLocalHost(hostname)) 00218 { 00219 // This application data is local. 00220 (*i)->setIsLocal(true); 00221 00222 // Adding a new ApplicationData server. 00223 vpr::Guard<vpr::Mutex> guard(mApplicationDataServersLock); 00224 ApplicationDataServer* new_appdata_server = 00225 new ApplicationDataServer(guid, (*i), mHandlerGUID); 00226 mApplicationDataServers[guid] = new_appdata_server; 00227 } 00228 else 00229 { 00230 // This application data is not local. 00231 (*i)->setIsLocal(false); 00232 00233 // Create a ApplicationDataRequest. 00234 ApplicationDataRequest* new_appdata_req = 00235 new ApplicationDataRequest(getHandlerGUID(), guid); 00236 00237 // Add ApplicationData request to pending list. 00238 addPendingApplicationDataRequest(new_appdata_req, hostname); 00239 00240 // Add ApplicationData to Remote Vector. 00241 vpr::Guard<vpr::Mutex> guard(mRemoteApplicationDataLock); 00242 mRemoteApplicationData[guid] = (*i); 00243 } 00244 } 00245 mNeedsConfiged.erase(i); 00246 return true; 00247 } 00248 00249 vprDEBUG(gadgetDBG_RIM, vprDBG_CONFIG_LVL) 00250 << "[ApplicationDataManager::configAdd()] " 00251 << "No unconfigured ApplicationData object found" 00252 << std::endl << vprDEBUG_FLUSH; 00253 00254 return false; 00255 } 00256 else 00257 { 00258 vprDEBUG(gadgetDBG_RIM,vprDBG_WARNING_LVL) 00259 << "[ApplicationDataManager::configAdd()] " 00260 << clrOutBOLD(clrRED, "WARNING: ") 00261 << "Don't know how to handle the configuration element: " 00262 << element->getName() << std::endl << vprDEBUG_FLUSH; 00263 return(false); 00264 } 00265 }
| bool cluster::ApplicationDataManager::configRemove | ( | jccl::ConfigElementPtr | element | ) | [virtual] |
Remove the pending element from the current configuration.
Implements cluster::ClusterPlugin.
Definition at line 273 of file ApplicationDataManager.cpp.
References gadgetDBG_RIM().
00274 { 00275 if (recognizeApplicationDataManagerConfig(element)) 00276 { 00277 vprDEBUG(gadgetDBG_RIM,vprDBG_WARNING_LVL) 00278 << clrOutBOLD(clrCYAN,"[ApplicationDataManager] ") 00279 << "The ApplicationDataMananger does not currently support a " 00280 << "need for configuration element: " << element->getName() 00281 << "\n" << vprDEBUG_FLUSH; 00282 return(true); 00283 } 00284 else if (recognizeApplicationDataManagerConfig(element)) 00285 { 00286 vprDEBUG(gadgetDBG_RIM,vprDBG_WARNING_LVL) 00287 << clrOutBOLD(clrCYAN,"[ApplicationDataManager] ") 00288 << "The ApplicationDataMananger does not currently support a " 00289 << "need for configuration element: " << element->getName() 00290 << "\n" << vprDEBUG_FLUSH; 00291 return(true); 00292 } 00293 else 00294 { 00295 vprDEBUG(gadgetDBG_RIM,vprDBG_WARNING_LVL) 00296 << "[ApplicationDataManager::ConfigRemove()] " 00297 << clrOutBOLD(clrRED, "WARNING: ") 00298 << "Don't know how to handle the configuration element: " 00299 << element->getName() << std::endl << vprDEBUG_FLUSH; 00300 return(false); 00301 } 00302 }
| bool cluster::ApplicationDataManager::configCanHandle | ( | jccl::ConfigElementPtr | element | ) | [virtual] |
Checks if this handler can process element.
Typically, an implementation of handler will check the element's description name/token to decide if it knows how to deal with it.
Implements cluster::ClusterPlugin.
Definition at line 310 of file ApplicationDataManager.cpp.
00311 { 00312 return( recognizeApplicationDataManagerConfig(element) || 00313 recognizeApplicationDataConfig(element) ); 00314 }
| void cluster::ApplicationDataManager::addSerializableObject | ( | vpr::SerializableObject * | object | ) | [virtual] |
Add a ApplicationData object to the current configuration.
Reimplemented from cluster::ClusterPlugin.
Definition at line 448 of file ApplicationDataManager.cpp.
References gadgetDBG_RIM(), getHandlerGUID(), cluster::ApplicationData::getHostname(), cluster::ApplicationData::getId(), gadget::AbstractNetworkManager::isLocalHost(), cluster::ClusterPlugin::setActive(), and cluster::ApplicationData::setIsLocal().
00449 { 00450 ApplicationData* new_app_data = static_cast<ApplicationData*>(object); 00451 00452 vpr::GUID id = new_app_data->getId(); 00453 std::string hostname = new_app_data->getHostname(); 00454 00455 vprDEBUG(gadgetDBG_RIM,vprDBG_CONFIG_LVL) 00456 << clrOutBOLD(clrMAGENTA,"[ApplicationDataManager]") 00457 << " Adding ApplicationData: " << id.toString() 00458 << std::endl << vprDEBUG_FLUSH; 00459 00460 // This plugin is now being used(active) 00461 setActive(true); 00462 00463 if ("" == hostname) 00464 { 00465 vpr::Guard<vpr::Mutex> guard(mNeedsConfigedLock); 00466 mNeedsConfiged.push_back(new_app_data); 00467 } 00468 else 00469 { 00470 if (ClusterNetwork::isLocalHost(hostname)) 00471 { 00472 // This application data is local. 00473 new_app_data->setIsLocal(true); 00474 00475 // Adding a new ApplicationData server. 00476 vpr::Guard<vpr::Mutex> guard(mApplicationDataServersLock); 00477 ApplicationDataServer* new_appdata_server = new ApplicationDataServer(id, new_app_data, mHandlerGUID); 00478 mApplicationDataServers[id] = new_appdata_server; 00479 } 00480 else 00481 { 00482 // This application data is not local. 00483 new_app_data->setIsLocal(false); 00484 00485 // Create a ApplicationDataRequest. 00486 ApplicationDataRequest* new_appdata_req = new ApplicationDataRequest(getHandlerGUID() ,id); 00487 00488 // Add ApplicationData request to pending list. 00489 addPendingApplicationDataRequest(new_appdata_req, hostname); 00490 00491 // Add ApplicationData to Remote Vector. 00492 vpr::Guard<vpr::Mutex> guard(mRemoteApplicationDataLock); 00493 mRemoteApplicationData[id] = new_app_data; 00494 } 00495 } 00496 }
| void cluster::ApplicationDataManager::removeApplicationData | ( | ApplicationData * | old_user_data | ) |
Remove the ApplicationData object from the current configuration.
Definition at line 498 of file ApplicationDataManager.cpp.
References gadgetDBG_RIM(), cluster::ApplicationData::getHostname(), and cluster::ApplicationData::getId().
00499 { 00500 vpr::GUID id = old_app_data->getId(); 00501 std::string hostname = old_app_data->getHostname(); 00502 00503 vprDEBUG(gadgetDBG_RIM,vprDBG_CONFIG_LVL) 00504 << clrOutBOLD(clrMAGENTA,"[ApplicationDataManager]") 00505 << " Removing ApplicationData: " << id.toString() 00506 << std::endl << vprDEBUG_FLUSH; 00507 00508 // Remove Pending ApplicationData 00509 removePendingApplicationDataRequest(old_app_data->getId()); 00510 /* 00511 // Remove Active ApplicationData 00512 vpr::Guard<vpr::Mutex> guard(mApplicationDataLock); 00513 for (std::vector<cluster::ApplicationData*>::iterator i = mApplicationData.begin(); 00514 i != mApplicationData.end(); 00515 ++i) 00516 { 00517 if ((*i) == old_user_data) 00518 { 00519 mApplicationData.erase(i); 00520 return; 00521 } 00522 } 00523 */ 00524 }
| void cluster::ApplicationDataManager::dumpApplicationData | ( | ) |
Print a list of all ApplicationData objects currently in the configuration.
Definition at line 526 of file ApplicationDataManager.cpp.
References gadgetDBG_RIM().
00527 { 00528 vprDEBUG(gadgetDBG_RIM,vprDBG_CONFIG_LVL) 00529 << clrOutBOLD(clrMAGENTA,"[ApplicationDataManager]") 00530 << " Listing All Application Level ApplicationData" 00531 << std::endl << vprDEBUG_FLUSH; 00532 00533 vpr::Guard<vpr::Mutex> ads_guard(mApplicationDataServersLock); 00534 00535 std::map<vpr::GUID, ApplicationDataServer*>::iterator ads_begin = 00536 mApplicationDataServers.begin(); 00537 std::map<vpr::GUID, ApplicationDataServer*>::iterator ads_end = 00538 mApplicationDataServers.end(); 00539 std::map<vpr::GUID, ApplicationDataServer*>::iterator ads; 00540 00541 vprDEBUG(gadgetDBG_RIM,vprDBG_CONFIG_LVL) 00542 << "ApplicationDataServers:" << std::endl << vprDEBUG_FLUSH; 00543 00544 for (ads = ads_begin ; ads != ads_end ; ++ads) 00545 { 00546 vprDEBUG(gadgetDBG_RIM,vprDBG_CONFIG_LVL) 00547 << " Server: " << (*ads).first << std::endl << vprDEBUG_FLUSH; 00548 } 00549 00550 vpr::Guard<vpr::Mutex> rad_guard(mRemoteApplicationDataLock); 00551 00552 std::map<vpr::GUID, ApplicationData*>::iterator rad_begin = 00553 mRemoteApplicationData.begin(); 00554 std::map<vpr::GUID, ApplicationData*>::iterator rad_end = 00555 mRemoteApplicationData.end(); 00556 std::map<vpr::GUID, ApplicationData*>::iterator rad; 00557 00558 vprDEBUG(gadgetDBG_RIM,vprDBG_CONFIG_LVL) 00559 << "Remote ApplicationData Objects:" << std::endl << vprDEBUG_FLUSH; 00560 00561 for (rad = rad_begin ; rad != rad_end ; ++rad) 00562 { 00563 vprDEBUG(gadgetDBG_RIM,vprDBG_CONFIG_LVL) 00564 << "Hostname: " << (*rad).second->getHostname() 00565 << "GUID: " << (*rad).second->getId() 00566 << std::endl << vprDEBUG_FLUSH; 00567 } 00568 }
1.5.1