[mapguide-commits] r5580 - in sandbox/adsk/2.2gp:
Common/MapGuideCommon/System Common/PlatformBase/MapLayer
Server/src/Core Server/src/Services/Resource Server/src/UnitTesting
svn_mapguide at osgeo.org
svn_mapguide at osgeo.org
Wed Mar 2 00:17:02 EST 2011
Author: hubu
Date: 2011-03-01 21:17:02 -0800 (Tue, 01 Mar 2011)
New Revision: 5580
Modified:
sandbox/adsk/2.2gp/Common/MapGuideCommon/System/ConfigProperties.cpp
sandbox/adsk/2.2gp/Common/MapGuideCommon/System/ConfigProperties.h
sandbox/adsk/2.2gp/Common/MapGuideCommon/System/UserInformation.cpp
sandbox/adsk/2.2gp/Common/PlatformBase/MapLayer/LayerBase.cpp
sandbox/adsk/2.2gp/Server/src/Core/serverconfig.ini
sandbox/adsk/2.2gp/Server/src/Services/Resource/ApplicationRepository.cpp
sandbox/adsk/2.2gp/Server/src/Services/Resource/LibraryRepository.cpp
sandbox/adsk/2.2gp/Server/src/Services/Resource/Repository.cpp
sandbox/adsk/2.2gp/Server/src/Services/Resource/Repository.h
sandbox/adsk/2.2gp/Server/src/Services/Resource/RepositoryManager.cpp
sandbox/adsk/2.2gp/Server/src/Services/Resource/RepositoryManager.h
sandbox/adsk/2.2gp/Server/src/Services/Resource/ServerResourceService.cpp
sandbox/adsk/2.2gp/Server/src/Services/Resource/ServerResourceService.h
sandbox/adsk/2.2gp/Server/src/Services/Resource/SessionRepository.cpp
sandbox/adsk/2.2gp/Server/src/Services/Resource/SessionRepository.h
sandbox/adsk/2.2gp/Server/src/Services/Resource/SessionResourceContentManager.cpp
sandbox/adsk/2.2gp/Server/src/UnitTesting/TestResourceService.cpp
sandbox/adsk/2.2gp/Server/src/UnitTesting/TestResourceService.h
Log:
integrate submission r5455 from trunk to GrandPrix 2.3 branch
Modified: sandbox/adsk/2.2gp/Common/MapGuideCommon/System/ConfigProperties.cpp
===================================================================
--- sandbox/adsk/2.2gp/Common/MapGuideCommon/System/ConfigProperties.cpp 2011-03-01 15:08:14 UTC (rev 5579)
+++ sandbox/adsk/2.2gp/Common/MapGuideCommon/System/ConfigProperties.cpp 2011-03-02 05:17:02 UTC (rev 5580)
@@ -348,6 +348,10 @@
const INT32 MgConfigProperties::DefaultResourceServicePropertyRetryAttempts = 10;
const STRING MgConfigProperties::ResourceServicePropertyRetryInterval = L"RetryInterval"; // for internal use only
const INT32 MgConfigProperties::DefaultResourceServicePropertyRetryInterval = 10;
+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
@@ -646,6 +650,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: sandbox/adsk/2.2gp/Common/MapGuideCommon/System/ConfigProperties.h
===================================================================
--- sandbox/adsk/2.2gp/Common/MapGuideCommon/System/ConfigProperties.h 2011-03-01 15:08:14 UTC (rev 5579)
+++ sandbox/adsk/2.2gp/Common/MapGuideCommon/System/ConfigProperties.h 2011-03-02 05:17:02 UTC (rev 5580)
@@ -449,6 +449,14 @@
static const STRING ResourceServicePropertyRetryInterval; /// value("RetryInterval")
static const INT32 DefaultResourceServicePropertyRetryInterval; /// value(10)
+ /// 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: sandbox/adsk/2.2gp/Common/MapGuideCommon/System/UserInformation.cpp
===================================================================
--- sandbox/adsk/2.2gp/Common/MapGuideCommon/System/UserInformation.cpp 2011-03-01 15:08:14 UTC (rev 5579)
+++ sandbox/adsk/2.2gp/Common/MapGuideCommon/System/UserInformation.cpp 2011-03-02 05:17:02 UTC (rev 5580)
@@ -47,7 +47,7 @@
///</summary>
MgUserInformation::MgUserInformation(CREFSTRING sessionId)
{
- SetMgSessionId(sessionId);
+ SetMgSessionId(sessionId.c_str());
m_type = uitMgSession;
m_apiVersion = MG_API_VERSION(1,0,0);
}
@@ -69,8 +69,8 @@
{
MgUtil::CheckXss(userName);
- m_username = userName;
- m_password = password;
+ m_username = userName.c_str();
+ m_password = password.c_str();
m_type = uitMg;
m_apiVersion = MG_API_VERSION(1,0,0);
}
@@ -103,13 +103,13 @@
{
if (&userInfo != this)
{
- m_username = userInfo.m_username;
- m_password = userInfo.m_password;
- m_sessionId = userInfo.m_sessionId;
- m_locale = userInfo.m_locale;
+ m_username = userInfo.m_username.c_str();
+ m_password = userInfo.m_password.c_str();
+ m_sessionId = userInfo.m_sessionId.c_str();
+ m_locale = userInfo.m_locale.c_str();
m_type = userInfo.m_type;
- m_clientAgent = userInfo.m_clientAgent;
- m_clientIp = userInfo.m_clientIp;
+ m_clientAgent = userInfo.m_clientAgent.c_str();
+ m_clientIp = userInfo.m_clientIp.c_str();
m_apiVersion = userInfo.m_apiVersion;
}
@@ -134,8 +134,8 @@
{
MgUtil::CheckXss(userName);
- m_username = userName;
- m_password = password;
+ m_username = userName.c_str();
+ m_password = password.c_str();
m_type = uitMg;
}
@@ -156,7 +156,7 @@
///<returns>
/// Username stored
///</returns>
-STRING MgUserInformation::GetUserName() { return m_username; }
+STRING MgUserInformation::GetUserName() { return (STRING)m_username.c_str(); }
///////////////////////////////
///<summary>
@@ -165,7 +165,7 @@
///<returns>
/// password stored
///</returns>
-STRING MgUserInformation::GetPassword() { return m_password; }
+STRING MgUserInformation::GetPassword() { return (STRING)m_password.c_str(); }
///////////////////////////////
///<summary>
@@ -173,7 +173,7 @@
///</summary>
STRING MgUserInformation::GetMgSessionId()
{
- return m_sessionId;
+ return (STRING)m_sessionId.c_str();
}
///////////////////////////////
@@ -200,7 +200,7 @@
{
SetLocale(sessionId.substr(sepChar+1, MG_LOCALE_LENGTH));
}
- m_sessionId = sessionId;
+ m_sessionId = sessionId.c_str();
}
else
{
@@ -245,7 +245,7 @@
else
{
// two-character locales remain case insensitive for legacy behavior
- m_locale = locale;
+ m_locale = locale.c_str();
}
}
@@ -256,17 +256,17 @@
///</summary>
STRING MgUserInformation::GetLocale()
{
- return m_locale;
+ return (STRING)m_locale.c_str();
}
void MgUserInformation::SetClientAgent(CREFSTRING agent)
{
- m_clientAgent = agent;
+ m_clientAgent = agent.c_str();
}
STRING MgUserInformation::GetClientAgent()
{
- return m_clientAgent;
+ return (STRING)m_clientAgent.c_str();
}
void MgUserInformation::SetClientIp(CREFSTRING ip)
@@ -275,12 +275,12 @@
// Note that MgIpUtil::ValidateAddress is not used here because
// an IP look up will affect peformance.
MgUtil::CheckXss(ip);
- m_clientIp = ip;
+ m_clientIp = ip.c_str();
}
STRING MgUserInformation::GetClientIp()
{
- return m_clientIp;
+ return (STRING)m_clientIp.c_str();
}
///////////////////////////////
@@ -338,13 +338,19 @@
/// </summary>
/// <returns> Nothing
/// </returns>
-void MgUserInformation::Dispose() { delete this; }
+void MgUserInformation::Dispose()
+{
+ delete this;
+}
/////////////////////////////////////////////////////////////////
/// <summary>
/// Returns the classId.
/// </summary>
-INT32 MgUserInformation::GetClassId() { return m_cls_id; }
+INT32 MgUserInformation::GetClassId()
+{
+ return m_cls_id;
+}
MgByteReader* MgUserInformation::GetReader()
{
@@ -407,6 +413,8 @@
throw new MgConnectionNotOpenException(L"MgSiteConnection.GetCurrentUserInfo", __LINE__, __WFILE__, NULL, L"", NULL);
}
+ SAFE_ADDREF(userInfo);
+
return userInfo;
}
@@ -481,8 +489,8 @@
MgCryptographyUtil cryptoUtil;
string username, password;
- cryptoUtil.DecryptCredentials(MgUtil::WideCharToMultiByte(credentials),
- username, password);
+ string cred = MgUtil::WideCharToMultiByte(credentials);
+ cryptoUtil.DecryptCredentials(cred, username, password);
MgUtil::MultiByteToWideChar(username, m_username);
MgUtil::MultiByteToWideChar(password, m_password);
Modified: sandbox/adsk/2.2gp/Common/PlatformBase/MapLayer/LayerBase.cpp
===================================================================
--- sandbox/adsk/2.2gp/Common/PlatformBase/MapLayer/LayerBase.cpp 2011-03-01 15:08:14 UTC (rev 5579)
+++ sandbox/adsk/2.2gp/Common/PlatformBase/MapLayer/LayerBase.cpp 2011-03-02 05:17:02 UTC (rev 5580)
@@ -637,10 +637,33 @@
}
else
{
- ldf.reset(MgLayerBase::GetLayerDefinition(resourceService, m_definition));
+ Ptr<MgResourceIdentifier> resourceId = MgLayerBase::GetLayerDefinition();
+ // get and parse the layer definition
+ Ptr<MgByteReader> reader = resourceService->GetResourceContent(resourceId, L"");
+ Ptr<MgByteSink> sink = new MgByteSink(reader);
+ Ptr<MgByte> bytes = sink->ToBuffer();
+
+ assert(bytes->GetLength() > 0);
+
+ MdfParser::SAX2Parser parser;
+ parser.ParseString((const char*)bytes->Bytes(), bytes->GetLength());
+
+ if (!parser.GetSucceeded())
+ {
+ STRING errorMsg = parser.GetErrorMessage();
+ MgStringCollection arguments;
+ arguments.Add(errorMsg);
+ throw new MgInvalidLayerDefinitionException(L"MgLayerBase::GetLayerDefinition", __LINE__, __WFILE__, &arguments, L"", NULL);
+ }
+
+ MdfModel::LayerDefinition* ldef = parser.DetachLayerDefinition();
+ assert(ldef != NULL);
+
+ ldf.reset(ldef);
+
//cache the resource content
- MdfParser::SAX2Parser parser;
- std::string content = parser.SerializeToXML(ldf.get(), NULL);
+ std::string content;
+ content.assign((const char*) bytes->Bytes(), bytes->GetLength());
MgUtil::MultiByteToWideChar(content, m_resourceContent);
}
Modified: sandbox/adsk/2.2gp/Server/src/Core/serverconfig.ini
===================================================================
--- sandbox/adsk/2.2gp/Server/src/Core/serverconfig.ini 2011-03-01 15:08:14 UTC (rev 5579)
+++ sandbox/adsk/2.2gp/Server/src/Core/serverconfig.ini 2011-03-02 05:17:02 UTC (rev 5580)
@@ -366,6 +366,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
@@ -379,6 +385,8 @@
ResourceDataFileTrashFolderName = Trash
ResourcePermissionCacheSize = 1000
ResourceSchemaFilePath = Schema/
+SessionRepositoriesConfig = FilePerSession
+SessionRepositoriesLimit = 200
SessionRepositoryPath = Repositories/Session/
SessionResourceDataFilePath = Repositories/Session/DataFiles/
SiteRepositoryPath = Repositories/Site/
Modified: sandbox/adsk/2.2gp/Server/src/Services/Resource/ApplicationRepository.cpp
===================================================================
--- sandbox/adsk/2.2gp/Server/src/Services/Resource/ApplicationRepository.cpp 2011-03-01 15:08:14 UTC (rev 5579)
+++ sandbox/adsk/2.2gp/Server/src/Services/Resource/ApplicationRepository.cpp 2011-03-02 05:17:02 UTC (rev 5580)
@@ -41,5 +41,6 @@
MgApplicationRepository::~MgApplicationRepository()
{
- delete m_resourceDataStreamDatabase;
+ if(NULL != m_resourceDataStreamDatabase)
+ delete m_resourceDataStreamDatabase;
}
Modified: sandbox/adsk/2.2gp/Server/src/Services/Resource/LibraryRepository.cpp
===================================================================
--- sandbox/adsk/2.2gp/Server/src/Services/Resource/LibraryRepository.cpp 2011-03-01 15:08:14 UTC (rev 5579)
+++ sandbox/adsk/2.2gp/Server/src/Services/Resource/LibraryRepository.cpp 2011-03-02 05:17:02 UTC (rev 5580)
@@ -78,7 +78,8 @@
MgLibraryRepository::~MgLibraryRepository()
{
- delete m_resourceHeaderContainer;
+ if(NULL != m_resourceHeaderContainer)
+ delete m_resourceHeaderContainer;
}
///----------------------------------------------------------------------------
Modified: sandbox/adsk/2.2gp/Server/src/Services/Resource/Repository.cpp
===================================================================
--- sandbox/adsk/2.2gp/Server/src/Services/Resource/Repository.cpp 2011-03-01 15:08:14 UTC (rev 5579)
+++ sandbox/adsk/2.2gp/Server/src/Services/Resource/Repository.cpp 2011-03-02 05:17:02 UTC (rev 5580)
@@ -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: sandbox/adsk/2.2gp/Server/src/Services/Resource/Repository.h
===================================================================
--- sandbox/adsk/2.2gp/Server/src/Services/Resource/Repository.h 2011-03-01 15:08:14 UTC (rev 5579)
+++ sandbox/adsk/2.2gp/Server/src/Services/Resource/Repository.h 2011-03-02 05:17:02 UTC (rev 5580)
@@ -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: sandbox/adsk/2.2gp/Server/src/Services/Resource/RepositoryManager.cpp
===================================================================
--- sandbox/adsk/2.2gp/Server/src/Services/Resource/RepositoryManager.cpp 2011-03-01 15:08:14 UTC (rev 5579)
+++ sandbox/adsk/2.2gp/Server/src/Services/Resource/RepositoryManager.cpp 2011-03-02 05:17:02 UTC (rev 5580)
@@ -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: sandbox/adsk/2.2gp/Server/src/Services/Resource/RepositoryManager.h
===================================================================
--- sandbox/adsk/2.2gp/Server/src/Services/Resource/RepositoryManager.h 2011-03-01 15:08:14 UTC (rev 5579)
+++ sandbox/adsk/2.2gp/Server/src/Services/Resource/RepositoryManager.h 2011-03-02 05:17:02 UTC (rev 5580)
@@ -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: sandbox/adsk/2.2gp/Server/src/Services/Resource/ServerResourceService.cpp
===================================================================
--- sandbox/adsk/2.2gp/Server/src/Services/Resource/ServerResourceService.cpp 2011-03-01 15:08:14 UTC (rev 5579)
+++ sandbox/adsk/2.2gp/Server/src/Services/Resource/ServerResourceService.cpp 2011-03-02 05:17:02 UTC (rev 5580)
@@ -29,11 +29,14 @@
#include "LogDetail.h"
INT32 MgServerResourceService::sm_retryAttempts = 10;
+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;
@@ -124,6 +127,8 @@
// Initialize performance tuning settings.
INT32 retryInterval = 10; // in milliseconds
+ STRING sessionRepositoryPath;
+ STRING sessionRepositoriesConfig;
MgConfiguration* configuration = MgConfiguration::GetInstance();
assert(NULL != configuration);
@@ -139,16 +144,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.
@@ -189,11 +229,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;
}
///----------------------------------------------------------------------------
@@ -222,15 +272,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(false)
+ 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(false)
+ 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(false)
+
+ 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();
@@ -267,33 +404,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(true)
+ if ((NULL != content && !content->IsRewindable())
+ || (NULL != header && !header->IsRewindable()))
+ {
+ maxRetries = 0;
+ }
- if (NULL != content && content->IsRewindable())
- {
- content->Rewind();
+ MG_RESOURCE_SERVICE_BEGIN_OPERATION(true)
+
+ 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(true)
+
+ 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")
}
@@ -327,19 +559,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(true)
+ 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(true)
+
+ 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(true)
+
+ 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")
}
@@ -1183,12 +1482,31 @@
libraryRepositoryMan.Terminate();
}
- MgSessionRepositoryManager sessionRepositoryMan(*sm_sessionRepository);
+ if(sm_bSingleSessionRepository)
+ {
+ MgSessionRepositoryManager sessionRepositoryMan(*sm_sessionRepository);
- sessionRepositoryMan.Initialize(false);
- 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())
@@ -1566,7 +1884,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
{
@@ -2262,6 +2607,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: sandbox/adsk/2.2gp/Server/src/Services/Resource/ServerResourceService.h
===================================================================
--- sandbox/adsk/2.2gp/Server/src/Services/Resource/ServerResourceService.h 2011-03-01 15:08:14 UTC (rev 5579)
+++ sandbox/adsk/2.2gp/Server/src/Services/Resource/ServerResourceService.h 2011-03-02 05:17:02 UTC (rev 5580)
@@ -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: sandbox/adsk/2.2gp/Server/src/Services/Resource/SessionRepository.cpp
===================================================================
--- sandbox/adsk/2.2gp/Server/src/Services/Resource/SessionRepository.cpp 2011-03-01 15:08:14 UTC (rev 5579)
+++ sandbox/adsk/2.2gp/Server/src/Services/Resource/SessionRepository.cpp 2011-03-02 05:17:02 UTC (rev 5580)
@@ -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: sandbox/adsk/2.2gp/Server/src/Services/Resource/SessionRepository.h
===================================================================
--- sandbox/adsk/2.2gp/Server/src/Services/Resource/SessionRepository.h 2011-03-01 15:08:14 UTC (rev 5579)
+++ sandbox/adsk/2.2gp/Server/src/Services/Resource/SessionRepository.h 2011-03-02 05:17:02 UTC (rev 5580)
@@ -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: sandbox/adsk/2.2gp/Server/src/Services/Resource/SessionResourceContentManager.cpp
===================================================================
--- sandbox/adsk/2.2gp/Server/src/Services/Resource/SessionResourceContentManager.cpp 2011-03-01 15:08:14 UTC (rev 5579)
+++ sandbox/adsk/2.2gp/Server/src/Services/Resource/SessionResourceContentManager.cpp 2011-03-02 05:17:02 UTC (rev 5580)
@@ -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: sandbox/adsk/2.2gp/Server/src/UnitTesting/TestResourceService.cpp
===================================================================
--- sandbox/adsk/2.2gp/Server/src/UnitTesting/TestResourceService.cpp 2011-03-01 15:08:14 UTC (rev 5579)
+++ sandbox/adsk/2.2gp/Server/src/UnitTesting/TestResourceService.cpp 2011-03-02 05:17:02 UTC (rev 5580)
@@ -25,6 +25,13 @@
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(TestResourceService, "TestResourceService");
+// define thread group for tiling tests
+#define THREAD_GROUP 65530
+
+#define TESTREQUESTS 500
+
+static const INT32 MG_TEST_THREADS = 8; // Adjust this to get failures!
+
const STRING adminName = L"Administrator";
const STRING adminPass = L"admin";
const STRING userLocale = L"en";
@@ -1635,3 +1642,206 @@
CPPUNIT_FAIL(MG_WCHAR_TO_CHAR(message.c_str()));
}
}
+
+// data structure which is passed to each thread
+struct ResourceThreadData
+{
+ INT32 threadId;
+ INT32 command;
+ bool success;
+ bool done;
+ STRING session;
+};
+
+// the method which gets executed by the ACE worker thread
+ACE_THR_FUNC_RETURN RepositoryWorker(void* param)
+{
+ // get the data for this thread
+ 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
+ {
+ // 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
+ MgServiceManager* serviceManager = MgServiceManager::GetInstance();
+ Ptr<MgResourceService> svcResource = dynamic_cast<MgResourceService*>(
+ 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<MgByteSource> contentSource = new MgByteSource(resourceContentFileName);
+ Ptr<MgByteReader> contentReader = contentSource->GetReader();
+ svcResource->SetResource(resId, contentReader, NULL);
+ }
+ case 1:
+ {
+ //Set the resource data
+ Ptr<MgByteSource> dataSource = new MgByteSource(dataFileName);
+ Ptr<MgByteReader> dataReader = dataSource->GetReader();
+ svcResource->SetResourceData(resId, resourceDataName, L"File", dataReader);
+ }
+ // Need to add a case that updates the session with runtime map
+ }
+
+ MgUserInformation::SetCurrentUserInfo(NULL);
+ threadData->success = true;
+ }
+ catch (MgException* e)
+ {
+ STRING message = e->GetDetails(TEST_LOCALE);
+ message += L"\n";
+ message += e->GetStackTrace(TEST_LOCALE);
+ SAFE_RELEASE(e);
+ ACE_DEBUG((LM_INFO, ACE_TEXT("RepositoryWorker(%d) - Exception:\n%W\n"), threadId, message.c_str()));
+ }
+ catch (...)
+ {
+ throw;
+ }
+
+ // clear the user info to prevent leaks - if an exception happens and this is not called it leaks about 500 bytes!
+ MgUserInformation::SetCurrentUserInfo(NULL);
+
+ ACE_DEBUG((LM_INFO, ACE_TEXT("> thread %d done\n"), threadId));
+
+ threadData->done = true;
+ return 0;
+}
+
+void TestResourceService::TestCase_RepositoryBusy()
+{
+ // specify the number of threads to use
+ const INT32 numThreads = MG_TEST_THREADS;
+ ResourceThreadData threadData[numThreads];
+
+ try
+ {
+ long lStart = GetTickCount();
+
+ // get the tile service instance
+ MgServiceManager* serviceManager = MgServiceManager::GetInstance();
+ Ptr<MgResourceService> svcResource = dynamic_cast<MgResourceService*>(
+ serviceManager->RequestService(MgServiceType::ResourceService));
+ assert(svcResource != NULL);
+
+ // set user info
+ Ptr<MgUserInformation> userInfo = new MgUserInformation(L"Administrator", L"admin");
+ userInfo->SetLocale(TEST_LOCALE);
+ MgUserInformation::SetCurrentUserInfo(userInfo);
+
+ // 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));
+
+ INT32 nRequest = 0;
+ INT32 nSuccessful = 0;
+ bool bExceptionOcurred = false;
+ for (;;)
+ {
+ INT32 dc = 0;
+ for (INT32 i=0; i<numThreads; i++)
+ {
+ // check if the thread is available
+ if (threadData[i].done)
+ {
+ if(threadData[i].success)
+ nSuccessful++;
+
+ threadData[i].success = false;
+ threadData[i].done = false;
+ threadData[i].command = i%2;
+
+ // spawn a new thread using a specific group id
+ int thid = manager->spawn(ACE_THR_FUNC(RepositoryWorker), &threadData[i], 0, NULL, NULL, 0, THREAD_GROUP);
+ nRequest++;
+ }
+ }
+
+ // move on if all threads are done
+ if ((nRequest > TESTREQUESTS) || (bExceptionOcurred))
+ break;
+
+ // under Linux we get a deadlock if we don't call this every once in a while
+ if (nRequest % 25 == 0)
+ manager->wait_grp(THREAD_GROUP);
+ else
+ {
+ // pause briefly (10ms) before checking again
+ ACE_Time_Value t(0, 10000);
+ ACE_OS::sleep(t);
+ }
+ }
+
+ // make sure all threads in the group have completed
+ manager->wait_grp(THREAD_GROUP);
+
+ for (INT32 i=0; i<numThreads; i++)
+ {
+ if(threadData[i].success)
+ nSuccessful++;
+ }
+
+ ACE_DEBUG((LM_INFO, ACE_TEXT("\nRequests: %d/%d - Execution Time: = %6.4f (s)\n"), nSuccessful, nRequest, ((GetTickCount()-lStart)/1000.0)));
+ }
+ catch (MgException* e)
+ {
+ STRING message = e->GetDetails(TEST_LOCALE);
+ SAFE_RELEASE(e);
+ CPPUNIT_FAIL(MG_WCHAR_TO_CHAR(message.c_str()));
+ }
+ catch (...)
+ {
+ throw;
+ }
+}
Modified: sandbox/adsk/2.2gp/Server/src/UnitTesting/TestResourceService.h
===================================================================
--- sandbox/adsk/2.2gp/Server/src/UnitTesting/TestResourceService.h 2011-03-01 15:08:14 UTC (rev 5579)
+++ sandbox/adsk/2.2gp/Server/src/UnitTesting/TestResourceService.h 2011-03-02 05:17:02 UTC (rev 5580)
@@ -54,6 +54,7 @@
CPPUNIT_TEST(TestCase_DeleteResource);
CPPUNIT_TEST(TestCase_EnumerateUnmanagedData);
+ CPPUNIT_TEST(TestCase_RepositoryBusy);
CPPUNIT_TEST(TestEnd); // This must be the very last unit test
CPPUNIT_TEST_SUITE_END();
@@ -96,6 +97,7 @@
void TestCase_DeleteResource();
void TestCase_EnumerateUnmanagedData();
+ void TestCase_RepositoryBusy();
};
#endif // TESTRESOURCESERVICE_H_
More information about the mapguide-commits
mailing list