00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef __GZ_DIST_MANAGER_H__
00022 #define __GZ_DIST_MANAGER_H__
00023
00029
00030 #include "gzDistBase.h"
00031 #include "gzDistRemoteMessage.h"
00032 #include "gzDistClientThreadPool.h"
00033 #include "gzDistServer.h"
00034
00035
00036 class gzDistManagerMessage;
00037 class gzDistRemoteChannelInterface;
00038 class gzDistDebugClient;
00039
00040
00041
00042
00043
00045
00054 class gzDistManager : public gzDistThreadSafeReference, protected gzThread
00055 {
00056 friend class gzDistSession;
00057 friend class gzDistSessionIterator;
00058 friend class gzDistClientInterface;
00059
00060 public:
00061
00063
00078 GZ_DIST_EXPORT gzBool start(gzDistRemoteChannelInterface* sessionChannel = NULL,
00079 gzDistRemoteChannelInterface* serverChannel = NULL);
00080
00082
00088 GZ_DIST_EXPORT gzVoid shutDown(gzBool wait = FALSE);
00089
00091
00093 GZ_DIST_EXPORT gzBool isRunning();
00094
00096
00106 GZ_DIST_EXPORT gzDistSessionPtr getSession(const gzString& sessionName, const gzBool create = FALSE, gzBool global = FALSE, gzDistServerPriority prio = GZ_DIST_SERVER_PRIO_NORMAL);
00107
00108
00110
00115 GZ_DIST_EXPORT gzVoid registerFactory(const gzDistEventPtr& event);
00116
00118
00123 GZ_DIST_EXPORT gzVoid registerFactory(const gzDistObjectPtr& object);
00124
00126
00132 GZ_DIST_EXPORT gzVoid unregisterFactory(gzType* classType);
00133
00135
00138 GZ_DIST_EXPORT gzVoid clearEventFactories();
00139
00141
00144 GZ_DIST_EXPORT gzVoid clearObjectFactories();
00145
00147
00152 GZ_DIST_EXPORT gzDistObject* getObject(const gzString& className, const gzString& objectName = GZ_DIST_NO_NAME);
00153
00155
00159 GZ_DIST_EXPORT gzDistEvent* getEvent(const gzString& className);
00160
00162
00169 GZ_DIST_EXPORT gzType* getObjectType(const gzString& className);
00170
00172
00179 GZ_DIST_EXPORT gzType* getEventType(const gzString& className);
00180
00182
00193 GZ_DIST_EXPORT gzBool processCustomThreadClients(gzBool waitForTrigger = FALSE);
00194
00196
00200 GZ_DIST_EXPORT gzBool enableDebug(gzBool enable);
00201
00203
00208 GZ_DIST_EXPORT gzBool hasPendingData();
00209
00211
00216
00217
00218
00219
00221
00223 GZ_DIST_EXPORT static gzDistManagerPtr getManager(gzBool create = FALSE);
00224
00226
00232 GZ_DIST_EXPORT static gzBool enableFastMemory(gzUInt size = 10);
00233
00235
00239 GZ_DIST_EXPORT static gzVoid trigger();
00240
00241 protected:
00242
00244
00245 gzDistManager();
00246
00248 virtual ~gzDistManager();
00249
00250 private:
00251
00252
00253
00254
00255 gzBool registerClient(gzDistClientInterface* client, gzULong poolId, gzDistThreadInterface*& thread);
00256
00257
00258 gzBool unregisterClient(gzDistClientInterface* client, gzULong poolId);
00259
00260
00261 gzBool subscribeSessions(gzDistClientInterface* client, gzBool notifyExisting = FALSE, gzInt timeOut = GZ_DIST_ASYNCHRONOUS);
00262
00263
00264 gzBool unsubscribeSessions(gzDistClientInterface* client, gzInt timeOut = GZ_DIST_SYNCHRONOUS);
00265
00266
00267
00268
00269 gzVoid process();
00270
00271
00272 gzBool processSessions();
00273
00274
00275
00276 gzBool processManagerMessages();
00277
00278
00279 gzVoid processManagerMessage(gzDistManagerMessage* message);
00280
00281
00282 gzBool processClients();
00283
00284
00285 gzBool processClientMessage(gzDistClientInterface* client, gzDistClientMessage* message);
00286
00287
00288 gzVoid createSession(gzDistSessionPtr& session, const gzString& sessionName, gzBool global, gzDistServerPriority prio);
00289
00290
00291 gzVoid addManagerMessage(gzDistManagerMessage* message);
00292
00293
00294
00295 gzVoid notifySessionSubscribers(gzDistSession* session, gzBool newSession);
00296
00297
00298 gzVoid addManagerMessager(gzDistManagerMessage* message);
00299
00300
00301
00302 gzBool waitAck(gzDistManagerMessage* message, const gzInt timeOut);
00303
00304
00305
00306 gzBool checkRemoveSession(gzDistSession* session);
00307
00308
00309 gzVoid shutDownClients();
00310
00311
00312 gzBool checkPendingData();
00313
00314
00315 gzBool unsubscribeAttributeValue(const gzString& attrName, gzDistObject* object, gzDistSession* session, gzDistClientInterface* client);
00316
00317
00318
00319
00320 gzVoid debugSessionSubscribers(gzDistClientInterface* subscriber, gzBool newClient);
00321
00322
00323 gzVoid debugManagerClients(gzDistClientInterface* subscriber, gzBool newClient);
00324
00325
00326 gzVoid debugJoinedClients(gzDistClientInterface* subscriber, gzDistSession* session, gzBool newClient);
00327
00328
00329 gzVoid debugObjectSubscribers(gzType* objectType, gzDistSession* session, gzDistClientInterface* subscriber, gzBool newClient);
00330
00331
00332 gzVoid debugEventSubscribers(gzType* eventType, gzDistSession* session, gzDistClientInterface* subscriber, gzBool newClient);
00333
00334
00335
00336
00337 gzRefDict<gzString, gzDistSession> m_sessions;
00338
00339
00340 gzMutex m_sessionsLocker;
00341
00342
00343 gzList<gzDistClientInterface> m_sessionSubscribers;
00344
00345
00346 gzRefList<gzDistManagerMessage> m_managerMessages;
00347
00348
00349 gzList<gzDistClientInterface> m_clients;
00350
00351
00352 gzMutex m_managerMessagesLocker;
00353
00354
00355 gzDistClientThreadPool m_clientThreadPool;
00356
00357
00358 gzRefDict<gzString, gzDistEvent> m_eventFactory;
00359
00360
00361 gzMutex m_eventFactoryLocker;
00362
00363
00364 gzRefDict<gzString, gzDistObject> m_objectFactory;
00365
00366
00367 gzMutex m_objectFactoryLocker;
00368
00369
00370 gzDistTrigger m_trigger;
00371
00372
00373 gzDistDebugClient* m_debugClient;
00374
00375
00376 gzBool m_closing;
00377
00378
00379 gzBool m_workerThreadActive;
00380
00381
00382 gzBool m_error;
00383
00384
00385 gzBool m_hasRemoteChannels;
00386 gzBool m_remoteChannelWarning;
00387
00388 gzRefList<gzDistManagerMessage> m_pendingManagerMessages;
00389
00390 gzDict<gzString, gzVoid> m_missedObjectFactories;
00391
00392 gzDict<gzString, gzVoid> m_missedEventFactories;
00393
00394
00395
00396
00397 static gzDistManagerPtr m_instance;
00398
00399
00400 static gzMutex m_instanceLocker;
00401 };
00402
00403
00404
00405
00406
00407 enum gzDistManagerMessageType
00408 {
00409 GZ_DIST_MANAGER_MESSAGE_TYPE_CREATE_SESSION = 1,
00410 GZ_DIST_MANAGER_MESSAGE_TYPE_REMOVE_SESSION,
00411 GZ_DIST_MANAGER_MESSAGE_TYPE_SUBSCRIBE_SESSIONS,
00412 GZ_DIST_MANAGER_MESSAGE_TYPE_UNSUBSCRIBE_SESSIONS,
00413 GZ_DIST_MANAGER_MESSAGE_TYPE_REGISTER_CLIENT,
00414 GZ_DIST_MANAGER_MESSAGE_TYPE_UNREGISTER_CLIENT,
00415 GZ_DIST_MANAGER_MESSAGE_TYPE_ENABLE_DEBUG,
00416 GZ_DIST_MANAGER_MESSAGE_TYPE_CHECK_PENDING_DATA
00417
00418
00419 };
00420
00421
00422
00423 class gzDistManagerMessage : public gzDistThreadSafeReference
00424 {
00425 public:
00426
00427
00428 gzDistManagerMessage(const gzDistManagerMessageType type);
00429
00430
00431 gzDistManagerMessage(const gzDistManagerMessageType type, const gzString& sessionName);
00432
00433
00434 gzDistManagerMessage(const gzDistManagerMessageType type, const gzString& sessionName, gzBool global, gzDistServerPriority prio);
00435
00436
00437 gzDistManagerMessage(const gzDistManagerMessageType type, gzDistClientInterface* client, gzULong poolId);
00438
00439
00440 gzDistManagerMessage(const gzDistManagerMessageType type, gzDistClientInterface* client, gzBool notifyExisting);
00441
00442
00443 virtual ~gzDistManagerMessage();
00444
00445
00446 gzDistThreadInterface* getThread();
00447
00448 gzVoid setThread(gzDistThreadInterface* thread);
00449
00450 gzVoid setDebugInterface(gzDistDebugClient* client);
00451
00452 gzDistDebugClient* getDebugInterface();
00453
00454
00455
00456 gzString m_sessionName;
00457
00458
00459 gzDistSessionPtr m_reference;
00460
00461
00462 gzDistClientInterface* m_client;
00463
00464
00465 gzVoid* m_void;
00466
00467
00468 gzDistManagerMessageType m_messageType;
00469
00470
00471 gzULong m_intData;
00472
00473
00474 gzULong m_threadId;
00475
00476
00477 gzDistServerPriority m_priority;
00478
00479
00480 gzBool m_notifyExisting;
00481
00482
00483 gzBool m_acknowledge;
00484
00485
00486 gzBool m_global;
00487
00488
00489 gzBool m_result;
00490 };
00491
00492
00493 #endif // __GZ_DIST_MANAGER_H__