[mapguide-commits] r5455 - in trunk/MgDev:
Common/MapGuideCommon/System Server/src/Core
Server/src/Services/Resource Server/src/UnitTesting
svn_mapguide at osgeo.org
svn_mapguide at osgeo.org
Thu Dec 9 15:51:18 EST 2010
Author: brucedechant
Date: 2010-12-09 12:51:18 -0800 (Thu, 09 Dec 2010)
New Revision: 5455
Modified:
trunk/MgDev/Common/MapGuideCommon/System/ConfigProperties.cpp
trunk/MgDev/Common/MapGuideCommon/System/ConfigProperties.h
trunk/MgDev/Server/src/Core/serverconfig.ini
trunk/MgDev/Server/src/Services/Resource/ApplicationRepository.cpp
trunk/MgDev/Server/src/Services/Resource/LibraryRepository.cpp
trunk/MgDev/Server/src/Services/Resource/Repository.cpp
trunk/MgDev/Server/src/Services/Resource/Repository.h
trunk/MgDev/Server/src/Services/Resource/RepositoryManager.cpp
trunk/MgDev/Server/src/Services/Resource/RepositoryManager.h
trunk/MgDev/Server/src/Services/Resource/ServerResourceService.cpp
trunk/MgDev/Server/src/Services/Resource/ServerResourceService.h
trunk/MgDev/Server/src/Services/Resource/SessionRepository.cpp
trunk/MgDev/Server/src/Services/Resource/SessionRepository.h
trunk/MgDev/Server/src/Services/Resource/SessionResourceContentManager.cpp
trunk/MgDev/Server/src/UnitTesting/TestResourceService.cpp
Log:
Fix for trac ticket 1552 - DB_BUSY errors generated under load
http://trac.osgeo.org/mapguide/ticket/1552
Notes:
- Added support for either single session repository file for all sessions (original design) or a session repository file per session. The session repository file per session scales much better at the cost of memory resources.
Modified: trunk/MgDev/Common/MapGuideCommon/System/ConfigProperties.cpp
===================================================================
--- trunk/MgDev/Common/MapGuideCommon/System/ConfigProperties.cpp 2010-12-09 18:27:15 UTC (rev 5454)
+++ trunk/MgDev/Common/MapGuideCommon/System/ConfigProperties.cpp 2010-12-09 20:51:18 UTC (rev 5455)
@@ -352,6 +352,10 @@
const INT32 MgConfigProperties::DefaultResourceServicePropertyRetryAttempts = 50;
const STRING MgConfigProperties::ResourceServicePropertyRetryInterval = L"RetryInterval"; // for internal use only
const INT32 MgConfigProperties::DefaultResourceServicePropertyRetryInterval = 25;
+const STRING MgConfigProperties::ResourceServicePropertySessionRepositoriesConfig = L"SessionRepositoriesConfig";
+const STRING MgConfigProperties::DefaultResourceServicePropertySessionRepositoriesConfig = L"FilePerSession";
+const STRING MgConfigProperties::ResourceServicePropertySessionRepositoriesLimit = L"SessionRepositoriesLimit";
+const INT32 MgConfigProperties::DefaultResourceServicePropertySessionRepositoriesLimit = 200;
// ******************************************************************
// Site Service Properties
@@ -655,6 +659,7 @@
{ MgConfigProperties::ResourceServicePropertyResourceValidationEnabled , MgPropertyType::Boolean , 0 , 1 , L"" },
{ MgConfigProperties::ResourceServicePropertyRetryAttempts , MgPropertyType::Int32 , 0 , 1000 , L"" },
{ MgConfigProperties::ResourceServicePropertyRetryInterval , MgPropertyType::Int32 , 0 , 60000 , L"" },
+ { MgConfigProperties::ResourceServicePropertySessionRepositoriesLimit , MgPropertyType::Int32 , 0 , 60000 , L"" },
{ L"" , 0 , 0.0 , 0.0 , L"" }
};
Modified: trunk/MgDev/Common/MapGuideCommon/System/ConfigProperties.h
===================================================================
--- trunk/MgDev/Common/MapGuideCommon/System/ConfigProperties.h 2010-12-09 18:27:15 UTC (rev 5454)
+++ trunk/MgDev/Common/MapGuideCommon/System/ConfigProperties.h 2010-12-09 20:51:18 UTC (rev 5455)
@@ -457,6 +457,14 @@
static const STRING ResourceServicePropertyRetryInterval; /// value("RetryInterval")
static const INT32 DefaultResourceServicePropertyRetryInterval; /// value(25)
+ /// Sets whether to use a single file session repository or a session repository file per session
+ static const STRING ResourceServicePropertySessionRepositoriesConfig; /// value("SessionRepositoriesConfig")
+ static const STRING DefaultResourceServicePropertySessionRepositoriesConfig;/// value("FilePerSession")
+
+ /// Sets the maximum number of allowed active sessions
+ static const STRING ResourceServicePropertySessionRepositoriesLimit; /// value("SessionRepositoriesLimit")
+ static const INT32 DefaultResourceServicePropertySessionRepositoriesLimit; /// value(200)
+
EXTERNAL_API:
/// Sets the root of the session repository
Modified: trunk/MgDev/Server/src/Core/serverconfig.ini
===================================================================
--- trunk/MgDev/Server/src/Core/serverconfig.ini 2010-12-09 18:27:15 UTC (rev 5454)
+++ trunk/MgDev/Server/src/Core/serverconfig.ini 2010-12-09 20:51:18 UTC (rev 5455)
@@ -372,6 +372,12 @@
# 0 <= Value <= 2147483647
# ResourceSchemaFilePath Path where the resource schema files are
# stored
+# SessionRepositoriesConfig Sets whether to use a single file session
+# repository or a session repository file per session.
+# SingleFile or FilePerSession
+# SessionRepositoriesLimit The total number of active session files allowed.
+# This setting only works when FilePerSession
+# is used.
# SessionRepositoryPath Path where the Session repository is stored
# SessionResourceDataFilePath Path where the Session resource data files
# are stored
@@ -385,6 +391,8 @@
ResourceDataFileTrashFolderName = Trash
ResourcePermissionCacheSize = 1000
ResourceSchemaFilePath = Schema/
+SessionRepositoriesConfig = FilePerSession
+SessionRepositoriesLimit = 200
SessionRepositoryPath = Repositories/Session/
SessionResourceDataFilePath = Repositories/Session/DataFiles/
SiteRepositoryPath = Repositories/Site/
Modified: trunk/MgDev/Server/src/Services/Resource/ApplicationRepository.cpp
===================================================================
--- trunk/MgDev/Server/src/Services/Resource/ApplicationRepository.cpp 2010-12-09 18:27:15 UTC (rev 5454)
+++ trunk/MgDev/Server/src/Services/Resource/ApplicationRepository.cpp 2010-12-09 20:51:18 UTC (rev 5455)
@@ -41,5 +41,6 @@
MgApplicationRepository::~MgApplicationRepository()
{
- delete m_resourceDataStreamDatabase;
+ if(NULL != m_resourceDataStreamDatabase)
+ delete m_resourceDataStreamDatabase;
}
Modified: trunk/MgDev/Server/src/Services/Resource/LibraryRepository.cpp
===================================================================
--- trunk/MgDev/Server/src/Services/Resource/LibraryRepository.cpp 2010-12-09 18:27:15 UTC (rev 5454)
+++ trunk/MgDev/Server/src/Services/Resource/LibraryRepository.cpp 2010-12-09 20:51:18 UTC (rev 5455)
@@ -78,7 +78,8 @@
MgLibraryRepository::~MgLibraryRepository()
{
- delete m_resourceHeaderContainer;
+ if(NULL != m_resourceHeaderContainer)
+ delete m_resourceHeaderContainer;
}
///----------------------------------------------------------------------------
Modified: trunk/MgDev/Server/src/Services/Resource/Repository.cpp
===================================================================
--- trunk/MgDev/Server/src/Services/Resource/Repository.cpp 2010-12-09 18:27:15 UTC (rev 5454)
+++ trunk/MgDev/Server/src/Services/Resource/Repository.cpp 2010-12-09 20:51:18 UTC (rev 5455)
@@ -27,6 +27,8 @@
const string MgRepository::SessionResourceContentContainerName = "MgSessionResourceContents.dbxml";
const string MgRepository::SessionResourceDataStreamDatabaseName = "MgSessionResourceData.db";
const string MgRepository::SiteResourceContentContainerName = "MgSiteResourceContents.dbxml";
+const string MgRepository::SessionResourceContentContainerExt = ".dbxml";
+const string MgRepository::SessionResourceDataStreamDatabaseExt = ".db";
///----------------------------------------------------------------------------
/// <summary>
@@ -53,8 +55,11 @@
MgRepository::~MgRepository()
{
- delete m_resourceContentContainer;
- delete m_environment;
+ if(NULL != m_resourceContentContainer)
+ delete m_resourceContentContainer;
+
+ if(NULL != m_environment)
+ delete m_environment;
}
///----------------------------------------------------------------------------
Modified: trunk/MgDev/Server/src/Services/Resource/Repository.h
===================================================================
--- trunk/MgDev/Server/src/Services/Resource/Repository.h 2010-12-09 18:27:15 UTC (rev 5454)
+++ trunk/MgDev/Server/src/Services/Resource/Repository.h 2010-12-09 20:51:18 UTC (rev 5455)
@@ -69,6 +69,8 @@
static const string SessionResourceContentContainerName;
static const string SessionResourceDataStreamDatabaseName;
static const string SiteResourceContentContainerName;
+ static const string SessionResourceContentContainerExt;
+ static const string SessionResourceDataStreamDatabaseExt;
protected:
Modified: trunk/MgDev/Server/src/Services/Resource/RepositoryManager.cpp
===================================================================
--- trunk/MgDev/Server/src/Services/Resource/RepositoryManager.cpp 2010-12-09 18:27:15 UTC (rev 5454)
+++ trunk/MgDev/Server/src/Services/Resource/RepositoryManager.cpp 2010-12-09 20:51:18 UTC (rev 5455)
@@ -80,306 +80,6 @@
return XmlValue(XmlValue::DATE_TIME, dateTime.ToXmlStringUtf8());
}
-///----------------------------------------------------------------------------
-/// <summary>
-/// Returns all the database or log files in the specified environment.
-/// </summary>
-///----------------------------------------------------------------------------
-
-MgStringCollection* MgRepositoryManager::GetFiles(CREFSTRING repositoryType,
- DbEnv& dbEnv, u_int32_t flags)
-{
- Ptr<MgStringCollection> files;
- char **begin = NULL;
-
- MG_RESOURCE_SERVICE_TRY()
-
- char **list = NULL;
-
- try
- {
- dbEnv.log_archive(&list, flags);
- }
- catch (DbException& e)
- {
- if (DB_NOTFOUND == e.get_errno())
- {
- // There is no database or log file.
- return NULL;
- }
- else
- {
- throw e;
- }
- }
-
- if (NULL != list)
- {
- STRING wcFile;
-
- files = new MgStringCollection;
-
- for (begin = list; *list != NULL; ++list)
- {
- string mbFile = *list;
-
- if (flags & DB_ARCH_DATA)
- {
- bool valid = false;
-
- if (MgRepositoryType::Session == repositoryType)
- {
- valid = (MgRepository::SessionResourceContentContainerName == mbFile
- || MgRepository::SessionResourceDataStreamDatabaseName == mbFile);
- }
- else if (MgRepositoryType::Site == repositoryType)
- {
- valid = (MgRepository::SiteResourceContentContainerName == mbFile);
- }
- else if (MgRepositoryType::Library == repositoryType)
- {
- valid = (MgRepository::LibraryResourceContentContainerName == mbFile
- || MgRepository::LibraryResourceHeaderContainerName == mbFile
- || MgRepository::LibraryResourceDataStreamDatabaseName == mbFile);
- }
-
- if (!valid)
- {
- throw new MgInvalidRepositoryTypeException(
- L"MgRepositoryManager.GetFiles", __LINE__, __WFILE__, NULL, L"", NULL);
- }
- }
-
- MgUtil::MultiByteToWideChar(mbFile, wcFile);
- files->Add(wcFile);
- }
-
- }
-
- MG_RESOURCE_SERVICE_CATCH(L"MgRepositoryManager.GetFiles")
-
- ::free(begin);
-
- MG_RESOURCE_SERVICE_THROW()
-
- return files.Detach();
-}
-
-///----------------------------------------------------------------------------
-/// <summary>
-/// Returns all the database files from the specified repository.
-/// </summary>
-///----------------------------------------------------------------------------
-
-MgStringCollection* MgRepositoryManager::GetDatabaseFiles(CREFSTRING repositoryType,
- CREFSTRING repositoryPath, bool fullPath)
-{
- Ptr<MgStringCollection> files = new MgStringCollection;
- STRING dir = repositoryPath;
-
- MgFileUtil::AppendSlashToEndOfPath(dir);
-
- if (MgRepositoryType::Session == repositoryType)
- {
- STRING file, pathname;
-
- MgUtil::MultiByteToWideChar(
- MgRepository::SessionResourceContentContainerName, file);
- pathname = dir + file;
-
- if (MgFileUtil::PathnameExists(pathname))
- {
- files->Add(fullPath ? pathname : file);
- }
-
- MgUtil::MultiByteToWideChar(
- MgRepository::SessionResourceDataStreamDatabaseName, file);
- pathname = dir + file;
-
- if (MgFileUtil::PathnameExists(pathname))
- {
- files->Add(fullPath ? pathname : file);
- }
- }
- else
- {
- assert(false);
- }
-
- return files.Detach();
-}
-
-///----------------------------------------------------------------------------
-/// <summary>
-/// Returns all the database files in the specified environment.
-/// </summary>
-///----------------------------------------------------------------------------
-
-MgStringCollection* MgRepositoryManager::GetDatabaseFiles(CREFSTRING repositoryType,
- DbEnv& dbEnv, bool fullPath)
-{
- u_int32_t flags = DB_ARCH_DATA;
-
- if (fullPath)
- {
- flags |= DB_ARCH_ABS;
- }
-
- return GetFiles(repositoryType, dbEnv, flags);
-}
-
-///----------------------------------------------------------------------------
-/// <summary>
-/// Returns all the log files in the specified environment.
-/// </summary>
-///----------------------------------------------------------------------------
-
-MgStringCollection* MgRepositoryManager::GetLogFiles(CREFSTRING repositoryType,
- DbEnv& dbEnv, bool fullPath)
-{
- u_int32_t flags = DB_ARCH_LOG;
-
- if (fullPath)
- {
- flags |= DB_ARCH_ABS;
- }
-
- return GetFiles(repositoryType, dbEnv, flags);
-}
-
-///----------------------------------------------------------------------------
-/// <summary>
-/// Cleans up a repository. All database files, log files, backing files, and
-/// data files will be removed.
-/// </summary>
-///----------------------------------------------------------------------------
-
-void MgRepositoryManager::CleanRepository(CREFSTRING repositoryType)
-{
- if (MgRepositoryType::Session != repositoryType)
- {
- throw new MgInvalidRepositoryTypeException(
- L"MgRepositoryManager.CleanRepository", __LINE__, __WFILE__, NULL, L"", NULL);
- }
-
- STRING repositoryPath, resourceDataFilePath;
- MgConfiguration* configuration = MgConfiguration::GetInstance();
- assert(NULL != configuration);
-
- configuration->GetStringValue(
- MgConfigProperties::ResourceServicePropertiesSection,
- MgConfigProperties::ResourceServicePropertySessionRepositoryPath,
- repositoryPath,
- MgConfigProperties::DefaultResourceServicePropertySessionRepositoryPath);
-
- configuration->GetStringValue(
- MgConfigProperties::ResourceServicePropertiesSection,
- MgConfigProperties::ResourceServicePropertySessionResourceDataFilePath,
- resourceDataFilePath,
- MgConfigProperties::DefaultResourceServicePropertySessionResourceDataFilePath);
-
- // Check to see whether or not it is safe to open the database.
-
- MgSessionRepository::VerifyAccess(repositoryPath, resourceDataFilePath);
-
- // Remove all the database files.
-
- string home;
- MgUtil::WideCharToMultiByte(repositoryPath, home);
- Ptr<MgStringCollection> logFiles;
-
- {
- MgDbEnvironment environment(repositoryType, home);
- DbTxn* dbTxn = NULL;
-
- MG_RESOURCE_SERVICE_TRY()
-
- DbEnv& dbEnv = environment.GetDbEnv();
-
- if (environment.IsTransacted())
- {
- dbEnv.txn_begin(0, &dbTxn, 0);
- assert(NULL != dbTxn);
- }
-
- logFiles = GetLogFiles(repositoryType, dbEnv, true);
- Ptr<MgStringCollection> databaseFiles = GetDatabaseFiles(
- repositoryType, dbEnv, false);
-
- if (databaseFiles == NULL)
- {
- databaseFiles = GetDatabaseFiles(repositoryType, repositoryPath, false);
- }
-
- if (databaseFiles != NULL)
- {
- for (INT32 i = 0; i < databaseFiles->GetCount(); ++i)
- {
- string file;
-
- MgUtil::WideCharToMultiByte(databaseFiles->GetItem(i), file);
- dbEnv.dbremove(dbTxn, file.c_str(), NULL, 0);
- }
- }
-
- if (NULL != dbTxn)
- {
- dbTxn->commit(0);
- }
-
- MG_RESOURCE_SERVICE_CATCH(L"MgRepositoryManager.CleanRepository")
-
- if (mgException != NULL)
- {
- try
- {
- if (NULL != dbTxn)
- {
- dbTxn->abort();
- }
- }
- catch (...)
- {
- assert(false);
- }
- }
-
- MG_RESOURCE_SERVICE_THROW()
- }
-
- // Remove all the backing files if they exist.
-
- {
- MG_RESOURCE_SERVICE_TRY()
-
- DbEnv dbEnv(0);
-
- dbEnv.remove(home.c_str(), 0);
-
- MG_RESOURCE_SERVICE_CATCH_AND_THROW(L"MgRepositoryManager.CleanRepository")
- }
-
- // Remove all the log files.
-
- if (logFiles != NULL)
- {
- for (INT32 i = 0; i < logFiles->GetCount(); ++i)
- {
- MgFileUtil::DeleteFile(logFiles->GetItem(i));
- }
- }
-
- // Remove all the data files.
-
- {
- MG_RESOURCE_SERVICE_TRY()
-
- MgFileUtil::CleanDirectory(resourceDataFilePath);
-
- MG_RESOURCE_SERVICE_CATCH_AND_THROW(L"MgRepositoryManager.CleanRepository")
- }
-}
-
///////////////////////////////////////////////////////////////////////////////
/// \brief
/// Initialize the repository manager.
Modified: trunk/MgDev/Server/src/Services/Resource/RepositoryManager.h
===================================================================
--- trunk/MgDev/Server/src/Services/Resource/RepositoryManager.h 2010-12-09 18:27:15 UTC (rev 5454)
+++ trunk/MgDev/Server/src/Services/Resource/RepositoryManager.h 2010-12-09 20:51:18 UTC (rev 5455)
@@ -45,20 +45,8 @@
private:
- static MgStringCollection* GetFiles(CREFSTRING repositoryType,
- DbEnv& dbEnv, u_int32_t flags);
-
public:
- static MgStringCollection* GetDatabaseFiles(CREFSTRING repositoryType,
- CREFSTRING repositoryPath, bool fullPath);
- static MgStringCollection* GetDatabaseFiles(CREFSTRING repositoryType,
- DbEnv& dbEnv, bool fullPath);
- static MgStringCollection* GetLogFiles(CREFSTRING repositoryType,
- DbEnv& dbEnv, bool fullPath);
-
- static void CleanRepository(CREFSTRING repositoryType);
-
void Initialize(bool transacted);
void Terminate();
Modified: trunk/MgDev/Server/src/Services/Resource/ServerResourceService.cpp
===================================================================
--- trunk/MgDev/Server/src/Services/Resource/ServerResourceService.cpp 2010-12-09 18:27:15 UTC (rev 5454)
+++ trunk/MgDev/Server/src/Services/Resource/ServerResourceService.cpp 2010-12-09 20:51:18 UTC (rev 5455)
@@ -29,11 +29,14 @@
#include "LogDetail.h"
INT32 MgServerResourceService::sm_retryAttempts = 50;
+INT32 MgServerResourceService::sm_sessionRepositoriesLimit = MgConfigProperties::DefaultResourceServicePropertySessionRepositoriesLimit;
ACE_Time_Value MgServerResourceService::sm_retryInterval;
MgSiteRepository* MgServerResourceService::sm_siteRepository = NULL;
MgSessionRepository* MgServerResourceService::sm_sessionRepository = NULL;
MgLibraryRepository* MgServerResourceService::sm_libraryRepository = NULL;
+std::map<STRING, MgSessionRepository* > MgServerResourceService::sm_sessionRepositories;
+bool MgServerResourceService::sm_bSingleSessionRepository = false;
ACE_Recursive_Thread_Mutex MgServerResourceService::sm_mutex;
set<STRING> MgServerResourceService::sm_changedResources;
@@ -136,6 +139,8 @@
// Initialize performance tuning settings.
INT32 retryInterval = 25; // in milliseconds
+ STRING sessionRepositoryPath;
+ STRING sessionRepositoriesConfig;
MgConfiguration* configuration = MgConfiguration::GetInstance();
assert(NULL != configuration);
@@ -151,16 +156,51 @@
retryInterval,
MgConfigProperties::DefaultResourceServicePropertyRetryInterval);
+ configuration->GetStringValue(
+ MgConfigProperties::ResourceServicePropertiesSection,
+ MgConfigProperties::ResourceServicePropertySessionRepositoriesConfig,
+ sessionRepositoriesConfig,
+ MgConfigProperties::DefaultResourceServicePropertySessionRepositoriesConfig);
+
+ configuration->GetIntValue(
+ MgConfigProperties::ResourceServicePropertiesSection,
+ MgConfigProperties::ResourceServicePropertySessionRepositoriesLimit,
+ sm_sessionRepositoriesLimit,
+ MgConfigProperties::DefaultResourceServicePropertySessionRepositoriesLimit);
+
+ configuration->GetStringValue(
+ MgConfigProperties::ResourceServicePropertiesSection,
+ MgConfigProperties::ResourceServicePropertySessionRepositoryPath,
+ sessionRepositoryPath,
+ MgConfigProperties::DefaultResourceServicePropertySessionRepositoryPath);
+
sm_retryInterval.msec((long)retryInterval);
+ // Set the session repository configuration
+ if(_wcsicmp(sessionRepositoriesConfig.c_str(), MgConfigProperties::DefaultResourceServicePropertySessionRepositoriesConfig.c_str()) == 0)
+ {
+ // FilePerSession
+ sm_bSingleSessionRepository = false;
+ }
+ else
+ {
+ // SingleFile
+ sm_bSingleSessionRepository = true;
+ }
+
// Clean up the Session repository.
+ MgFileUtil::CleanDirectory(sessionRepositoryPath);
- MgRepositoryManager::CleanRepository(MgRepositoryType::Session);
-
+ // The session repository configuration depends on the serverconfig.ini SessionRepositoriesConfig setting.
+ // If it is "SingleFile" then it uses a single file to hold all of the session information for all sessions.
+ // If it is "FilePerSession" then it uses a file per session.
// Initialize the Session repository.
- sm_sessionRepository = new MgSessionRepository();
- sm_sessionRepository->Initialize();
+ if(sm_bSingleSessionRepository)
+ {
+ sm_sessionRepository = new MgSessionRepository(L"");
+ sm_sessionRepository->Initialize();
+ }
// Initialize the Site repository.
@@ -201,11 +241,21 @@
delete sm_siteRepository;
sm_siteRepository = NULL;
- delete sm_sessionRepository;
- sm_sessionRepository = NULL;
+ for (std::map<STRING, MgSessionRepository* >::iterator i = sm_sessionRepositories.begin();i != sm_sessionRepositories.end(); ++i)
+ {
+ MgSessionRepository* sessionRepository = i->second;
+ if(NULL != sessionRepository)
+ {
+ delete sessionRepository;
+ sessionRepository = NULL;
+ }
+ }
delete sm_libraryRepository;
sm_libraryRepository = NULL;
+
+ delete sm_sessionRepository;
+ sm_sessionRepository = NULL;
}
///----------------------------------------------------------------------------
@@ -234,15 +284,102 @@
__LINE__, __WFILE__, NULL, L"", NULL);
}
- auto_ptr<MgSessionRepositoryManager> repositoryMan(
- new MgSessionRepositoryManager(*sm_sessionRepository));
+ string list = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
- MG_RESOURCE_SERVICE_BEGIN_OPERATION()
+ list += "<RepositoryList xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"RepositoryList-1.0.0.xsd\">\n";
- byteReader = repositoryMan->EnumerateRepositories();
+ if(sm_bSingleSessionRepository)
+ {
+ auto_ptr<MgSessionRepositoryManager> repositoryMan(
+ new MgSessionRepositoryManager(*sm_sessionRepository));
- MG_RESOURCE_SERVICE_END_OPERATION(sm_retryAttempts)
+ MG_RESOURCE_SERVICE_BEGIN_OPERATION()
+ byteReader = repositoryMan->EnumerateRepositories();
+
+ MG_RESOURCE_SERVICE_END_OPERATION(sm_retryAttempts)
+
+ // Need to combine the results from all of the session repositories
+ STRING sessionContents = byteReader->ToString();
+ string content;
+ MgUtil::WideCharToMultiByte(sessionContents, content);
+ list += content;
+ }
+ else
+ {
+ if(0 == sm_sessionRepositories.size())
+ {
+ // Since there are no sessions yet we will need to check access rights ourselves
+ auto_ptr<MgSecurityManager> securityMan;
+ securityMan.reset(new MgSecurityManager());
+
+ Ptr<MgUserInformation> currUserInfo = MgUserInformation::GetCurrentUserInfo();
+ assert(NULL != currUserInfo);
+ STRING sessionId = currUserInfo->GetMgSessionId();
+ STRING userName = currUserInfo->GetUserName();
+ STRING password = currUserInfo->GetPassword();
+
+ if (!sessionId.empty())
+ {
+ if (userName.empty())
+ {
+ userName = securityMan->GetUserName(sessionId);
+ password = securityMan->GetPassword(userName);
+ }
+ }
+
+ if (userName.empty())
+ {
+ MG_LOG_AUTHENTICATION_ENTRY(MgResources::UnauthorizedAccess.c_str());
+
+ throw new MgUnauthorizedAccessException(
+ L"MgServerResourceService.EnumerateRepositories",
+ __LINE__, __WFILE__, NULL, L"", NULL);
+ }
+
+ if (!securityMan->IsUserAnAdministrator(userName))
+ {
+ MG_LOG_AUTHENTICATION_ENTRY(MgResources::UnauthorizedAccess.c_str());
+
+ throw new MgUnauthorizedAccessException(
+ L"MgServerResourceService.EnumerateRepositories",
+ __LINE__, __WFILE__, NULL, L"", NULL);
+ }
+ }
+
+ for (std::map<STRING, MgSessionRepository* >::iterator i = sm_sessionRepositories.begin();i != sm_sessionRepositories.end(); ++i)
+ {
+ MgSessionRepository* sessionRepository = i->second;
+ if(NULL != sessionRepository)
+ {
+ auto_ptr<MgSessionRepositoryManager> repositoryMan(
+ new MgSessionRepositoryManager(*sessionRepository));
+
+ MG_RESOURCE_SERVICE_BEGIN_OPERATION()
+
+ byteReader = repositoryMan->EnumerateRepositories();
+
+ MG_RESOURCE_SERVICE_END_OPERATION(sm_retryAttempts)
+
+ // Need to combine the results from all of the session repositories
+ STRING sessionContents = byteReader->ToString();
+ string content;
+ MgUtil::WideCharToMultiByte(sessionContents, content);
+ list += content;
+ }
+ }
+ }
+
+ list += "</RepositoryList>";
+
+ // Create a byte reader.
+
+ Ptr<MgByteSource> byteSource = new MgByteSource(
+ (unsigned char*)list.c_str(), (INT32)list.length());
+
+ byteSource->SetMimeType(MgMimeType::Xml);
+ byteReader = byteSource->GetReader();
+
MG_RESOURCE_SERVICE_CATCH_AND_THROW(L"MgServerResourceService.EnumerateRepositories")
return byteReader.Detach();
@@ -279,33 +416,128 @@
L"MgServerResourceService.CreateRepository", __LINE__, __WFILE__, NULL, L"", NULL);
}
- ACE_ASSERT(!resource->GetRepositoryName().empty());
- auto_ptr<MgSessionRepositoryManager> repositoryMan(
- new MgSessionRepositoryManager(*sm_sessionRepository));
- int maxRetries = sm_retryAttempts;
-
- if ((NULL != content && !content->IsRewindable())
- || (NULL != header && !header->IsRewindable()))
+ if(sm_bSingleSessionRepository)
{
- maxRetries = 0;
- }
+ auto_ptr<MgSessionRepositoryManager> repositoryMan(
+ new MgSessionRepositoryManager(*sm_sessionRepository));
+ int maxRetries = sm_retryAttempts;
- MG_RESOURCE_SERVICE_BEGIN_OPERATION()
+ if ((NULL != content && !content->IsRewindable())
+ || (NULL != header && !header->IsRewindable()))
+ {
+ maxRetries = 0;
+ }
- if (NULL != content && content->IsRewindable())
- {
- content->Rewind();
+ MG_RESOURCE_SERVICE_BEGIN_OPERATION()
+
+ if (NULL != content && content->IsRewindable())
+ {
+ content->Rewind();
+ }
+
+ if (NULL != header && header->IsRewindable())
+ {
+ header->Rewind();
+ }
+
+ repositoryMan->CreateRepository(resource, content, header);
+
+ MG_RESOURCE_SERVICE_END_OPERATION(maxRetries)
}
-
- if (NULL != header && header->IsRewindable())
+ else
{
- header->Rewind();
- }
+ auto_ptr<MgSecurityManager> securityMan;
+ securityMan.reset(new MgSecurityManager());
- repositoryMan->CreateRepository(resource, content, header);
+ Ptr<MgUserInformation> currUserInfo = MgUserInformation::GetCurrentUserInfo();
+ assert(NULL != currUserInfo);
+ STRING sessionId = currUserInfo->GetMgSessionId();
+ STRING userName = currUserInfo->GetUserName();
+ STRING password = currUserInfo->GetPassword();
- MG_RESOURCE_SERVICE_END_OPERATION(maxRetries)
+ if (!sessionId.empty())
+ {
+ if (userName.empty())
+ {
+ userName = securityMan->GetUserName(sessionId);
+ password = securityMan->GetPassword(userName);
+ }
+ }
+ if (userName.empty())
+ {
+ MG_LOG_AUTHENTICATION_ENTRY(MgResources::UnauthorizedAccess.c_str());
+
+ throw new MgUnauthorizedAccessException(
+ L"MgServerResourceService.CreateRepository",
+ __LINE__, __WFILE__, NULL, L"", NULL);
+ }
+
+ ACE_ASSERT(!resource->GetRepositoryName().empty());
+ STRING name = resource->GetRepositoryName();
+ std::map<STRING, MgSessionRepository* >::iterator iter = sm_sessionRepositories.find(name);
+ if(sm_sessionRepositories.end() == iter)
+ {
+ // ACE_DEBUG((LM_INFO, ACE_TEXT("CreateRepository: %W\n"), name.c_str()));
+ MgSessionRepository* sessionRepository = NULL;
+
+ // Check to see if there is room. If not we need to throw an exception.
+ if(sm_sessionRepositories.size() >= sm_sessionRepositoriesLimit)
+ {
+ MgStringCollection arguments;
+ arguments.Add(resource->ToString());
+
+ throw new MgRepositoryCreationFailedException(
+ L"MgServerResourceService.CreateRepository", __LINE__, __WFILE__, &arguments, L"", NULL);
+ }
+
+ sessionRepository = new MgSessionRepository(name);
+ if(NULL != sessionRepository)
+ {
+ // Add this NEW session repository to the map
+ sm_sessionRepositories.insert(std::pair<STRING, MgSessionRepository* >(name, sessionRepository));
+ ACE_DEBUG((LM_INFO, ACE_TEXT("%d/%d ++ %W\n"), sm_sessionRepositories.size(), sm_sessionRepositoriesLimit, name.c_str()));
+
+ // Initialize the session repository
+ sessionRepository->Initialize();
+
+ auto_ptr<MgSessionRepositoryManager> repositoryMan(
+ new MgSessionRepositoryManager(*sessionRepository));
+ int maxRetries = sm_retryAttempts;
+
+ if ((NULL != content && !content->IsRewindable())
+ || (NULL != header && !header->IsRewindable()))
+ {
+ maxRetries = 0;
+ }
+
+ MG_RESOURCE_SERVICE_BEGIN_OPERATION()
+
+ if (NULL != content && content->IsRewindable())
+ {
+ content->Rewind();
+ }
+
+ if (NULL != header && header->IsRewindable())
+ {
+ header->Rewind();
+ }
+
+ repositoryMan->CreateRepository(resource, content, header);
+
+ MG_RESOURCE_SERVICE_END_OPERATION(maxRetries)
+ }
+ }
+ else
+ {
+ MgStringCollection arguments;
+ arguments.Add(resource->ToString());
+
+ throw new MgDuplicateRepositoryException(
+ L"MgServerResourceService.CreateRepository", __LINE__, __WFILE__, &arguments, L"", NULL);
+ }
+ }
+
MG_RESOURCE_SERVICE_CATCH_AND_THROW(L"MgServerResourceService.CreateRepository")
}
@@ -339,19 +571,86 @@
L"MgServerResourceService.DeleteRepository", __LINE__, __WFILE__, NULL, L"", NULL);
}
- ACE_ASSERT(!resource->GetRepositoryName().empty());
- auto_ptr<MgSessionRepositoryManager> repositoryMan(
- new MgSessionRepositoryManager(*sm_sessionRepository));
+ auto_ptr<MgSecurityManager> securityMan;
+ securityMan.reset(new MgSecurityManager());
- MG_RESOURCE_SERVICE_BEGIN_OPERATION()
+ Ptr<MgUserInformation> currUserInfo = MgUserInformation::GetCurrentUserInfo();
+ assert(NULL != currUserInfo);
+ STRING sessionId = currUserInfo->GetMgSessionId();
+ STRING userName = currUserInfo->GetUserName();
+ STRING password = currUserInfo->GetPassword();
- repositoryMan->DeleteRepository(resource);
+ if (!sessionId.empty())
+ {
+ if (userName.empty())
+ {
+ userName = securityMan->GetUserName(sessionId);
+ password = securityMan->GetPassword(userName);
+ }
+ }
- MG_RESOURCE_SERVICE_END_OPERATION(sm_retryAttempts)
+ if (userName.empty())
+ {
+ MG_LOG_AUTHENTICATION_ENTRY(MgResources::UnauthorizedAccess.c_str());
- // Update the current set of changed resources.
- UpdateChangedResources(repositoryMan->GetChangedResources());
+ throw new MgUnauthorizedAccessException(
+ L"MgServerResourceService.CreateRepository",
+ __LINE__, __WFILE__, NULL, L"", NULL);
+ }
+ if(sm_bSingleSessionRepository)
+ {
+ auto_ptr<MgSessionRepositoryManager> repositoryMan(
+ new MgSessionRepositoryManager(*sm_sessionRepository));
+
+ MG_RESOURCE_SERVICE_BEGIN_OPERATION()
+
+ repositoryMan->DeleteRepository(resource);
+
+ MG_RESOURCE_SERVICE_END_OPERATION(sm_retryAttempts)
+
+ // Update the current set of changed resources.
+ UpdateChangedResources(repositoryMan->GetChangedResources());
+ }
+ else
+ {
+ ACE_ASSERT(!resource->GetRepositoryName().empty());
+ STRING name = resource->GetRepositoryName();
+ std::map<STRING, MgSessionRepository* >::iterator iter = sm_sessionRepositories.find(name);
+ if(sm_sessionRepositories.end() != iter)
+ {
+ ACE_DEBUG((LM_INFO, ACE_TEXT("%d/%d -- %W\n"), sm_sessionRepositories.size(), sm_sessionRepositoriesLimit, name.c_str()));
+ MgSessionRepository* sessionRepository = iter->second;
+ if(NULL != sessionRepository)
+ {
+ auto_ptr<MgSessionRepositoryManager> repositoryMan(
+ new MgSessionRepositoryManager(*sessionRepository));
+
+ MG_RESOURCE_SERVICE_BEGIN_OPERATION()
+
+ repositoryMan->DeleteRepository(resource);
+
+ MG_RESOURCE_SERVICE_END_OPERATION(sm_retryAttempts)
+
+ // Update the current set of changed resources.
+ UpdateChangedResources(repositoryMan->GetChangedResources());
+
+ sm_sessionRepositories.erase(iter);
+ delete sessionRepository;
+ sessionRepository = NULL;
+ }
+ }
+ else
+ {
+ MgStringCollection arguments;
+ arguments.Add(name);
+
+ throw new MgRepositoryNotFoundException(
+ L"MgServerResourceService.DeleteRepository",
+ __LINE__, __WFILE__, &arguments, L"", NULL);
+ }
+ }
+
MG_RESOURCE_SERVICE_CATCH_AND_THROW(L"MgServerResourceService.DeleteRepository")
}
@@ -1197,12 +1496,31 @@
libraryRepositoryMan.Terminate();
}
- MgSessionRepositoryManager sessionRepositoryMan(*sm_sessionRepository);
+ if(sm_bSingleSessionRepository)
+ {
+ MgSessionRepositoryManager sessionRepositoryMan(*sm_sessionRepository);
- sessionRepositoryMan.Initialize(true);
- sessionRepositoryMan.EnumerateParentMapDefinitions(childResources,
- parentResources);
- sessionRepositoryMan.Terminate();
+ sessionRepositoryMan.Initialize(true);
+ sessionRepositoryMan.EnumerateParentMapDefinitions(childResources,
+ parentResources);
+ sessionRepositoryMan.Terminate();
+ }
+ else
+ {
+ for (std::map<STRING, MgSessionRepository* >::iterator i = sm_sessionRepositories.begin();i != sm_sessionRepositories.end(); ++i)
+ {
+ MgSessionRepository* sessionRepository = i->second;
+ if(NULL != sessionRepository)
+ {
+ MgSessionRepositoryManager sessionRepositoryMan(*sessionRepository);
+
+ sessionRepositoryMan.Initialize(true);
+ sessionRepositoryMan.EnumerateParentMapDefinitions(childResources,
+ parentResources);
+ sessionRepositoryMan.Terminate();
+ }
+ }
+ }
}
if (!parentResources.empty())
@@ -1580,7 +1898,34 @@
else if (MgRepositoryType::Session == repositoryType)
{
ACE_ASSERT(!resource->GetRepositoryName().empty());
- repositoryMan.reset(new MgSessionRepositoryManager(*sm_sessionRepository));
+
+ if(sm_bSingleSessionRepository)
+ {
+ repositoryMan.reset(new MgSessionRepositoryManager(*sm_sessionRepository));
+ }
+ else
+ {
+ // Find the session repository associated with this resource
+ STRING name = resource->GetRepositoryName();
+ std::map<STRING, MgSessionRepository* >::iterator iter = sm_sessionRepositories.find(name);
+ if(sm_sessionRepositories.end() != iter)
+ {
+ MgSessionRepository* sessionRepository = iter->second;
+ if(NULL != sessionRepository)
+ {
+ repositoryMan.reset(new MgSessionRepositoryManager(*sessionRepository));
+ }
+ }
+ else
+ {
+ MgStringCollection arguments;
+ arguments.Add(name);
+
+ throw new MgRepositoryNotFoundException(
+ L"MgServerResourceService.CreateApplicationRepositoryManager",
+ __LINE__, __WFILE__, &arguments, L"", NULL);
+ }
+ }
}
else
{
@@ -2288,6 +2633,18 @@
sm_sessionRepository->PerformCheckpoint(flags);
}
+ if (0 > sm_sessionRepositories.size())
+ {
+ for (std::map<STRING, MgSessionRepository* >::iterator i = sm_sessionRepositories.begin();i != sm_sessionRepositories.end(); ++i)
+ {
+ MgSessionRepository* sessionRepository = i->second;
+ if(NULL != sessionRepository)
+ {
+ sessionRepository->PerformCheckpoint(flags);
+ }
+ }
+ }
+
MG_RESOURCE_SERVICE_CATCH_AND_THROW(L"MgServerResourceService.PerformCheckpoint")
}
Modified: trunk/MgDev/Server/src/Services/Resource/ServerResourceService.h
===================================================================
--- trunk/MgDev/Server/src/Services/Resource/ServerResourceService.h 2010-12-09 18:27:15 UTC (rev 5454)
+++ trunk/MgDev/Server/src/Services/Resource/ServerResourceService.h 2010-12-09 20:51:18 UTC (rev 5455)
@@ -193,9 +193,12 @@
static MgSiteRepository* sm_siteRepository;
static MgSessionRepository* sm_sessionRepository;
static MgLibraryRepository* sm_libraryRepository;
+ static std::map<STRING, MgSessionRepository* > sm_sessionRepositories;
+ static INT32 sm_sessionRepositoriesLimit;
static ACE_Recursive_Thread_Mutex sm_mutex;
static set<STRING> sm_changedResources;
+ static bool sm_bSingleSessionRepository;
};
#endif
Modified: trunk/MgDev/Server/src/Services/Resource/SessionRepository.cpp
===================================================================
--- trunk/MgDev/Server/src/Services/Resource/SessionRepository.cpp 2010-12-09 18:27:15 UTC (rev 5454)
+++ trunk/MgDev/Server/src/Services/Resource/SessionRepository.cpp 2010-12-09 20:51:18 UTC (rev 5455)
@@ -28,19 +28,18 @@
/// </exceptions>
///----------------------------------------------------------------------------
-MgSessionRepository::MgSessionRepository()
+MgSessionRepository::MgSessionRepository(CREFSTRING name)
{
MG_RESOURCE_SERVICE_TRY()
// Get the repositry and data file paths.
- STRING repositoryPath;
MgConfiguration* configuration = MgConfiguration::GetInstance();
configuration->GetStringValue(
MgConfigProperties::ResourceServicePropertiesSection,
MgConfigProperties::ResourceServicePropertySessionRepositoryPath,
- repositoryPath,
+ m_repositoryPath,
MgConfigProperties::DefaultResourceServicePropertySessionRepositoryPath);
configuration->GetStringValue(
@@ -49,19 +48,31 @@
m_resourceDataFilePath,
MgConfigProperties::DefaultResourceServicePropertySessionResourceDataFilePath);
+ m_sessionName = name;
+
// Check to see whether or not it is safe to open the database.
+ m_dbVersion = VerifyAccess(m_repositoryPath, m_resourceDataFilePath);
- m_dbVersion = VerifyAccess(repositoryPath, m_resourceDataFilePath);
-
// Open the repository.
-
m_environment = new MgDbEnvironment(MgRepositoryType::Session,
- MgUtil::WideCharToMultiByte(repositoryPath));
- m_resourceContentContainer = new MgResourceContainer(*m_environment,
- MgRepository::SessionResourceContentContainerName);
- m_resourceDataStreamDatabase = new MgResourceDatabase(*m_environment,
- MgRepository::SessionResourceDataStreamDatabaseName);
+ MgUtil::WideCharToMultiByte(m_repositoryPath));
+ if(m_sessionName.empty())
+ {
+ m_resourceContentContainer = new MgResourceContainer(*m_environment,
+ MgRepository::SessionResourceContentContainerName);
+ m_resourceDataStreamDatabase = new MgResourceDatabase(*m_environment,
+ MgRepository::SessionResourceDataStreamDatabaseName);
+ }
+ else
+ {
+ std::string containerName = MgUtil::WideCharToMultiByte(m_sessionName) + MgRepository::SessionResourceContentContainerExt;
+ m_resourceContentContainer = new MgResourceContainer(*m_environment, containerName);
+
+ std::string databaseName = MgUtil::WideCharToMultiByte(m_sessionName) + MgRepository::SessionResourceDataStreamDatabaseExt;
+ m_resourceDataStreamDatabase = new MgResourceDatabase(*m_environment, databaseName);
+ }
+
MG_RESOURCE_SERVICE_CATCH_AND_THROW(L"MgSessionRepository.MgSessionRepository")
}
@@ -73,6 +84,36 @@
MgSessionRepository::~MgSessionRepository()
{
+
+ MG_RESOURCE_SERVICE_TRY()
+
+ delete m_resourceDataStreamDatabase;
+ m_resourceDataStreamDatabase = NULL;
+
+ delete m_resourceContentContainer;
+ m_resourceContentContainer = NULL;
+
+ delete m_environment;
+ m_environment = NULL;
+
+ // Now that the above have been deleted we can delete the associated files
+ STRING containerName = L"";
+ STRING databaseName = L"";
+ if(m_sessionName.empty())
+ {
+ containerName = m_repositoryPath + MgUtil::MultiByteToWideChar(MgRepository::SessionResourceContentContainerName);
+ databaseName = m_repositoryPath + MgUtil::MultiByteToWideChar(MgRepository::SessionResourceDataStreamDatabaseName);
+ }
+ else
+ {
+ containerName = m_repositoryPath + m_sessionName + MgUtil::MultiByteToWideChar(MgRepository::SessionResourceContentContainerExt);
+ databaseName = m_repositoryPath + m_sessionName + MgUtil::MultiByteToWideChar(MgRepository::SessionResourceDataStreamDatabaseExt);
+ }
+
+ MgFileUtil::DeleteFile(containerName);
+ MgFileUtil::DeleteFile(databaseName);
+
+ MG_RESOURCE_SERVICE_CATCH(L"MgSessionRepository.~MgSessionRepository")
}
///----------------------------------------------------------------------------
@@ -86,13 +127,16 @@
MgFileUtil::CreateDirectory(repositoryPath, false, true);
MgFileUtil::CreateDirectory(resourceDataFilePath, false, true);
+ STRING containerName = m_sessionName + MgUtil::MultiByteToWideChar(MgRepository::SessionResourceContentContainerExt);
int dbVersion = MgRepository::VerifyAccess(
repositoryPath,
- MgUtil::MultiByteToWideChar(MgRepository::SessionResourceContentContainerName),
+ containerName,
true);
+
+ STRING databaseName = m_sessionName + MgUtil::MultiByteToWideChar(MgRepository::SessionResourceDataStreamDatabaseExt);
MgRepository::VerifyAccess(
repositoryPath,
- MgUtil::MultiByteToWideChar(MgRepository::SessionResourceDataStreamDatabaseName),
+ databaseName,
false);
return dbVersion;
Modified: trunk/MgDev/Server/src/Services/Resource/SessionRepository.h
===================================================================
--- trunk/MgDev/Server/src/Services/Resource/SessionRepository.h 2010-12-09 18:27:15 UTC (rev 5454)
+++ trunk/MgDev/Server/src/Services/Resource/SessionRepository.h 2010-12-09 20:51:18 UTC (rev 5455)
@@ -26,7 +26,7 @@
public:
- MgSessionRepository();
+ MgSessionRepository(CREFSTRING name);
virtual ~MgSessionRepository();
private:
@@ -40,7 +40,7 @@
public:
- static int VerifyAccess(CREFSTRING repositoryPath, CREFSTRING resourceDataFilePath);
+ int VerifyAccess(CREFSTRING repositoryPath, CREFSTRING resourceDataFilePath);
virtual void Initialize();
private:
@@ -50,7 +50,8 @@
/// Data Members
private:
-
+ STRING m_sessionName;
+ STRING m_repositoryPath;
};
#endif
Modified: trunk/MgDev/Server/src/Services/Resource/SessionResourceContentManager.cpp
===================================================================
--- trunk/MgDev/Server/src/Services/Resource/SessionResourceContentManager.cpp 2010-12-09 18:27:15 UTC (rev 5454)
+++ trunk/MgDev/Server/src/Services/Resource/SessionResourceContentManager.cpp 2010-12-09 20:51:18 UTC (rev 5455)
@@ -82,10 +82,8 @@
// this XML follows the RepositoryList-1.0.0.xsd schema
XmlValue xmlValue;
- string list = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
+ string list;
- list += "<RepositoryList xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"RepositoryList-1.0.0.xsd\">\n";
-
while (results.next(xmlValue)) // TODO: Need an XML writer
{
const XmlDocument& xmlDoc = xmlValue.asDocument();
@@ -123,8 +121,6 @@
list += "\t</Repository>\n";
}
- list += "</RepositoryList>";
-
// Create a byte reader.
Ptr<MgByteSource> byteSource = new MgByteSource(
Modified: trunk/MgDev/Server/src/UnitTesting/TestResourceService.cpp
===================================================================
--- trunk/MgDev/Server/src/UnitTesting/TestResourceService.cpp 2010-12-09 18:27:15 UTC (rev 5454)
+++ trunk/MgDev/Server/src/UnitTesting/TestResourceService.cpp 2010-12-09 20:51:18 UTC (rev 5455)
@@ -1650,6 +1650,7 @@
INT32 command;
bool success;
bool done;
+ STRING session;
};
// the method which gets executed by the ACE worker thread
@@ -1659,6 +1660,8 @@
ResourceThreadData* threadData = (ResourceThreadData*)param;
INT32 threadId = threadData->threadId;
INT32 command = threadData->command;
+ STRING session = threadData->session;
+
ACE_DEBUG((LM_INFO, ACE_TEXT("> thread %d started\n"), threadId));
try
@@ -1666,6 +1669,7 @@
// set user info
Ptr<MgUserInformation> userInfo = new MgUserInformation(L"Administrator", L"admin");
userInfo->SetLocale(TEST_LOCALE);
+ userInfo->SetMgSessionId(session);
MgUserInformation::SetCurrentUserInfo(userInfo);
// get the tile service instance
@@ -1674,12 +1678,16 @@
serviceManager->RequestService(MgServiceType::ResourceService));
assert(svcResource != NULL);
+ STRING resource = L"Session:";
+ resource += session;
+ resource += L"//UnitTests/Data/test-1.FeatureSource";
+ Ptr<MgResourceIdentifier> resId = new MgResourceIdentifier(resource);
+
switch (command)
{
case 0:
{
//Set the resource
- Ptr<MgResourceIdentifier> resId = new MgResourceIdentifier(L"Library://UnitTests/Data/test-1.FeatureSource");
Ptr<MgByteSource> contentSource = new MgByteSource(resourceContentFileName);
Ptr<MgByteReader> contentReader = contentSource->GetReader();
svcResource->SetResource(resId, contentReader, NULL);
@@ -1687,7 +1695,6 @@
case 1:
{
//Set the resource data
- Ptr<MgResourceIdentifier> resId = new MgResourceIdentifier(L"Library://UnitTests/Data/test-1.FeatureSource");
Ptr<MgByteSource> dataSource = new MgByteSource(dataFileName);
Ptr<MgByteReader> dataReader = dataSource->GetReader();
svcResource->SetResourceData(resId, resourceDataName, L"File", dataReader);
@@ -1741,21 +1748,38 @@
userInfo->SetLocale(TEST_LOCALE);
MgUserInformation::SetCurrentUserInfo(userInfo);
- // Initialize the resource
- Ptr<MgResourceIdentifier> resId = new MgResourceIdentifier(L"Library://UnitTests/Data/test-1.FeatureSource");
- Ptr<MgByteSource> contentSource = new MgByteSource(resourceContentFileName);
- Ptr<MgByteReader> contentReader = contentSource->GetReader();
- svcResource->SetResource(resId, contentReader, NULL);
-
// need a thread manager
ACE_Thread_Manager* manager = ACE_Thread_Manager::instance();
// initialize the thread data
for (INT32 i=0; i<numThreads; i++)
{
+ // Initialize the resource
+ wchar_t wszBuffer[255];
+ swprintf(wszBuffer, 255, L"48cb0286-%04d-1000-8001-005056c00008_en_6F7A8590045708AE0D05", i);
+
+ // Session format: 48cb0286-0000-1000-8001-005056c00008_en_6F7A8590045708AE0D05
+ STRING session = wszBuffer;
+ STRING resource = L"Session:";
+ resource += session;
+ resource += L"//";
+
+ // Create session resource
+ Ptr<MgResourceIdentifier> resIdSession = new MgResourceIdentifier(resource);
+ svcResource->CreateRepository(resIdSession, NULL, NULL);
+
+ // Create feature source resource
+ resource += L"UnitTests/Data/test-1.FeatureSource";
+ Ptr<MgResourceIdentifier> resId = new MgResourceIdentifier(resource);
+ Ptr<MgByteSource> contentSource = new MgByteSource(resourceContentFileName);
+ Ptr<MgByteReader> contentReader = contentSource->GetReader();
+ svcResource->SetResource(resId, contentReader, NULL);
+
+ // Set the thread specific data
threadData[i].threadId = i;
threadData[i].success = false;
threadData[i].done = true;
+ threadData[i].session = session;
}
ACE_DEBUG((LM_INFO, ACE_TEXT("\nTestCase_RepositoryBusy\nThreads: %d Requests: %d\n\n"), numThreads, TESTREQUESTS));
More information about the mapguide-commits
mailing list