mirror of https://gitee.com/bigwinds/arangodb
added RubyDispatcherThread
This commit is contained in:
parent
35ee4a3bff
commit
2a89e6e176
|
@ -5,7 +5,7 @@
|
|||
///
|
||||
/// DISCLAIMER
|
||||
///
|
||||
/// Copyright 2004-2012 triagens GmbH, Cologne, Germany
|
||||
/// Copyright 2004-2012 triAGENS GmbH, Cologne, Germany
|
||||
///
|
||||
/// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
/// you may not use this file except in compliance with the License.
|
||||
|
@ -57,5 +57,5 @@ ArangoHttpServer::ArangoHttpServer (Scheduler* scheduler, Dispatcher* dispatcher
|
|||
|
||||
// Local Variables:
|
||||
// mode: outline-minor
|
||||
// outline-regexp: "^\\(/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|// --SECTION--\\|/// @\\}\\)"
|
||||
// outline-regexp: "^\\(/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|/// @page\\|// --SECTION--\\|/// @\\}\\)"
|
||||
// End:
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
///
|
||||
/// DISCLAIMER
|
||||
///
|
||||
/// Copyright 2004-2012 triagens GmbH, Cologne, Germany
|
||||
/// Copyright 2004-2012 triAGENS GmbH, Cologne, Germany
|
||||
///
|
||||
/// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
/// you may not use this file except in compliance with the License.
|
||||
|
@ -80,5 +80,5 @@ namespace triagens {
|
|||
|
||||
// Local Variables:
|
||||
// mode: outline-minor
|
||||
// outline-regexp: "^\\(/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|// --SECTION--\\|/// @\\}\\)"
|
||||
// outline-regexp: "^\\(/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|/// @page\\|// --SECTION--\\|/// @\\}\\)"
|
||||
// End:
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
///
|
||||
/// DISCLAIMER
|
||||
///
|
||||
/// Copyright 2004-2012 triagens GmbH, Cologne, Germany
|
||||
/// Copyright 2004-2012 triAGENS GmbH, Cologne, Germany
|
||||
///
|
||||
/// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
/// you may not use this file except in compliance with the License.
|
||||
|
@ -80,6 +80,7 @@ using namespace triagens::arango;
|
|||
#include "MRuby/MRLineEditor.h"
|
||||
#include "MRuby/MRLoader.h"
|
||||
#include "MRuby/mr-actions.h"
|
||||
#include "RestServer/RubyDispatcherThread.h"
|
||||
|
||||
#include "mruby.h"
|
||||
#include "mruby/compile.h"
|
||||
|
@ -200,17 +201,13 @@ static DispatcherThread* SystemActionDispatcherThreadCreatorJS (DispatcherQueue*
|
|||
#ifdef TRI_ENABLE_MRUBY
|
||||
|
||||
static DispatcherThread* ClientActionDispatcherThreadCreatorMR (DispatcherQueue* queue) {
|
||||
return 0;
|
||||
#if 0
|
||||
return new ActionDispatcherThread(queue,
|
||||
Vocbase,
|
||||
GcIntervalJS,
|
||||
"CLIENT-RUBY",
|
||||
AllowedClientActions,
|
||||
StartupModulesJS,
|
||||
&StartupLoaderJS,
|
||||
&ActionLoaderJS);
|
||||
#endif
|
||||
return new RubyDispatcherThread(queue,
|
||||
Vocbase,
|
||||
"CLIENT-RUBY",
|
||||
AllowedClientActions,
|
||||
StartupModulesMR,
|
||||
&StartupLoaderMR,
|
||||
&ActionLoaderMR);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -222,17 +219,13 @@ static DispatcherThread* ClientActionDispatcherThreadCreatorMR (DispatcherQueue*
|
|||
#ifdef TRI_ENABLE_MRUBY
|
||||
|
||||
static DispatcherThread* SystemActionDispatcherThreadCreatorMR (DispatcherQueue* queue) {
|
||||
return 0;
|
||||
#if 0
|
||||
return new ActionDispatcherThread(queue,
|
||||
Vocbase,
|
||||
GcIntervalJS,
|
||||
"SYSTEM-RUBY",
|
||||
AllowedAdminActions,
|
||||
StartupModulesJS,
|
||||
&StartupLoaderJS,
|
||||
&ActionLoaderJS);
|
||||
#endif
|
||||
return new RubyDispatcherThread(queue,
|
||||
Vocbase,
|
||||
"SYSTEM-RUBY",
|
||||
AllowedAdminActions,
|
||||
StartupModulesMR,
|
||||
&StartupLoaderMR,
|
||||
&ActionLoaderMR);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -242,7 +235,7 @@ static DispatcherThread* SystemActionDispatcherThreadCreatorMR (DispatcherQueue*
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static void DefineApiHandlers (HttpHandlerFactory* factory,
|
||||
ApplicationAdminServer* admin,
|
||||
ApplicationAdminServer* admin,
|
||||
TRI_vocbase_t* vocbase) {
|
||||
|
||||
// add "/version" handler
|
||||
|
@ -340,7 +333,7 @@ ArangoServer::ArangoServer (int argc, char** argv)
|
|||
// .............................................................................
|
||||
|
||||
#ifdef TRI_ENABLE_RELATIVE_SYSTEM
|
||||
|
||||
|
||||
_workingDirectory = _binaryPath + "/../tmp";
|
||||
_actionPathJS = _binaryPath + "/../share/arango/js/actions/system";
|
||||
_startupModulesJS = _binaryPath + "/../share/arango/js/server/modules"
|
||||
|
@ -439,37 +432,37 @@ void ArangoServer::buildApplicationServer () {
|
|||
vector<right_t> rightsManager;
|
||||
rightsManager.push_back(RIGHT_TO_MANAGE_USER);
|
||||
rightsManager.push_back(RIGHT_TO_MANAGE_ADMIN);
|
||||
|
||||
|
||||
_applicationUserManager->createRole("manager", rightsManager, 0);
|
||||
|
||||
|
||||
// create admin role
|
||||
vector<right_t> rightsAdmin;
|
||||
rightsAdmin.push_back(RIGHT_TO_MANAGE_USER);
|
||||
rightsAdmin.push_back(RIGHT_TO_BE_DELETED);
|
||||
|
||||
|
||||
_applicationUserManager->createRole("admin", rightsAdmin, RIGHT_TO_MANAGE_ADMIN);
|
||||
|
||||
|
||||
// create user role
|
||||
vector<right_t> rightsUser;
|
||||
rightsUser.push_back(RIGHT_TO_BE_DELETED);
|
||||
|
||||
|
||||
_applicationUserManager->createRole("user", rightsUser, RIGHT_TO_MANAGE_USER);
|
||||
|
||||
|
||||
// create a standard user
|
||||
_applicationUserManager->createUser("manager", "manager");
|
||||
|
||||
|
||||
// added a anonymous right for session which are not logged in
|
||||
vector<right_t> rightsAnonymous;
|
||||
rightsAnonymous.push_back(RIGHT_TO_LOGIN);
|
||||
|
||||
|
||||
_applicationUserManager->setAnonymousRights(rightsAnonymous);
|
||||
|
||||
|
||||
// .............................................................................
|
||||
// use relative system paths
|
||||
// .............................................................................
|
||||
|
||||
#ifdef TRI_ENABLE_RELATIVE_SYSTEM
|
||||
|
||||
|
||||
_applicationServer->setSystemConfigFile("arango.conf", _binaryPath + "/../etc");
|
||||
_applicationAdminServer->allowAdminDirectory(_binaryPath + "/../share/arango/html/admin");
|
||||
|
||||
|
@ -736,7 +729,7 @@ int ArangoServer::startupServer () {
|
|||
|
||||
Vocbase = _vocbase;
|
||||
StartupModulesJS = _startupModulesJS;
|
||||
GcIntervalJS = _gcIntervalJS;
|
||||
GcIntervalJS = _gcIntervalJS;
|
||||
|
||||
// .............................................................................
|
||||
// create the various parts of the Arango server
|
||||
|
@ -763,7 +756,7 @@ int ArangoServer::startupServer () {
|
|||
|
||||
#if TRI_ENABLE_MRUBY
|
||||
if (0 < _actionThreadsMR) {
|
||||
// safe_cast<DispatcherImpl*>(dispatcher)->addQueue("CLIENT-RUBY", ClientActionDispatcherThreadCreatorMR, _actionThreadsMR);
|
||||
safe_cast<DispatcherImpl*>(dispatcher)->addQueue("CLIENT-RUBY", ClientActionDispatcherThreadCreatorMR, _actionThreadsMR);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -773,7 +766,7 @@ int ArangoServer::startupServer () {
|
|||
safe_cast<DispatcherImpl*>(dispatcher)->addQueue("SYSTEM-JAVASCRIPT", SystemActionDispatcherThreadCreatorJS, 2);
|
||||
|
||||
#if TRI_ENABLE_MRUBY
|
||||
// safe_cast<DispatcherImpl*>(dispatcher)->addQueue("SYSTEM-RUBY", SystemActionDispatcherThreadCreatorMR, 2);
|
||||
safe_cast<DispatcherImpl*>(dispatcher)->addQueue("SYSTEM-RUBY", SystemActionDispatcherThreadCreatorMR, 2);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
@ -805,7 +798,7 @@ int ArangoServer::startupServer () {
|
|||
}
|
||||
|
||||
// add action handler
|
||||
factory->addPrefixHandler("/",
|
||||
factory->addPrefixHandler("/",
|
||||
RestHandlerCreator<RestActionHandler>::createData<RestActionHandler::action_options_t*>,
|
||||
(void*) &httpOptions);
|
||||
|
||||
|
@ -833,7 +826,7 @@ int ArangoServer::startupServer () {
|
|||
DefineAdminHandlers(factory, _applicationAdminServer, _applicationUserManager, _vocbase);
|
||||
|
||||
// add action handler
|
||||
factory->addPrefixHandler("/",
|
||||
factory->addPrefixHandler("/",
|
||||
RestHandlerCreator<RestActionHandler>::createData<RestActionHandler::action_options_t*>,
|
||||
(void*) &adminOptions);
|
||||
|
||||
|
@ -984,7 +977,7 @@ int ArangoServer::executeShell (bool tests) {
|
|||
// run tests
|
||||
char const* input = "require(\"jsunity\").runCommandLineTests();";
|
||||
TRI_ExecuteJavaScriptString(context, v8::String::New(input), name, true);
|
||||
|
||||
|
||||
if (tryCatch.HasCaught()) {
|
||||
cout << TRI_StringifyV8Exception(&tryCatch);
|
||||
ok = false;
|
||||
|
@ -1026,7 +1019,7 @@ int ArangoServer::executeShell (bool tests) {
|
|||
|
||||
TRI_ExecuteJavaScriptString(context, v8::String::New(input), name, true);
|
||||
TRI_FreeString(TRI_UNKNOWN_MEM_ZONE, input);
|
||||
|
||||
|
||||
if (tryCatch.HasCaught()) {
|
||||
cout << TRI_StringifyV8Exception(&tryCatch);
|
||||
}
|
||||
|
@ -1097,7 +1090,7 @@ mrb_value MR_ArangoDatabase_Collection (mrb_state* mrb, mrb_value self) {
|
|||
return self;
|
||||
}
|
||||
|
||||
// check
|
||||
// check
|
||||
|
||||
printf("using collection '%s'\n", name);
|
||||
|
||||
|
@ -1110,7 +1103,7 @@ mrb_value MR_ArangoDatabase_Collection (mrb_state* mrb, mrb_value self) {
|
|||
printf("unknown collection (TODO raise error)\n");
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
return mrb_obj_value(Data_Wrap_Struct(mrb, ArangoCollectionClass, &MR_ArangoCollection_Type, (void*) collection));
|
||||
}
|
||||
|
||||
|
@ -1178,7 +1171,7 @@ int ArangoServer::executeRubyShell () {
|
|||
MRLineEditor* console = new MRLineEditor(mrs, ".arango-mrb");
|
||||
|
||||
console->open(false);
|
||||
|
||||
|
||||
while (true) {
|
||||
char* input = console->prompt("arangod> ");
|
||||
|
||||
|
@ -1222,7 +1215,7 @@ int ArangoServer::executeRubyShell () {
|
|||
mrb_p(&mrs->_mrb, result);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// close the console
|
||||
console->close();
|
||||
delete console;
|
||||
|
@ -1248,7 +1241,7 @@ void ArangoServer::openDatabase () {
|
|||
LOGGER_FATAL << "cannot open database '" << _databasePath << "'";
|
||||
LOGGER_INFO << "please use the '--database.directory' option";
|
||||
TRI_FlushLogging();
|
||||
|
||||
|
||||
ApplicationUserManager::unloadUsers();
|
||||
ApplicationUserManager::unloadRoles();
|
||||
exit(EXIT_FAILURE);
|
||||
|
@ -1282,5 +1275,5 @@ void ArangoServer::closeDatabase () {
|
|||
|
||||
// Local Variables:
|
||||
// mode: outline-minor
|
||||
// outline-regexp: "^\\(/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|// --SECTION--\\|/// @\\}\\)"
|
||||
// outline-regexp: "^\\(/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|/// @page\\|// --SECTION--\\|/// @\\}\\)"
|
||||
// End:
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
///
|
||||
/// DISCLAIMER
|
||||
///
|
||||
/// Copyright 2004-2012 triagens GmbH, Cologne, Germany
|
||||
/// Copyright 2004-2012 triAGENS GmbH, Cologne, Germany
|
||||
///
|
||||
/// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
/// you may not use this file except in compliance with the License.
|
||||
|
@ -270,8 +270,8 @@ namespace triagens {
|
|||
/// @CMDOPT{--javascript.directory @CA{directory}}
|
||||
///
|
||||
/// Specifies the @CA{directory} path to alternate startup Javascript files.
|
||||
/// Normally, the server will start using built-in Javascript core
|
||||
/// functionality. To override the core functionality with a different
|
||||
/// Normally, the server will start using built-in Javascript core
|
||||
/// functionality. To override the core functionality with a different
|
||||
/// implementation, this option can be used.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
@ -304,7 +304,7 @@ namespace triagens {
|
|||
///
|
||||
/// @CMDOPT{--javascript.action-threads @CA{number}}
|
||||
///
|
||||
/// Specifies the @CA{number} of threads that are spawned to handle action
|
||||
/// Specifies the @CA{number} of threads that are spawned to handle action
|
||||
/// requests using JavaScript.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
@ -315,7 +315,7 @@ namespace triagens {
|
|||
///
|
||||
/// @CMDOPT{--javascript.gc-interval @CA{interval}}
|
||||
///
|
||||
/// Specifies the interval (approximately in number of requests) that the
|
||||
/// Specifies the interval (approximately in number of requests) that the
|
||||
/// garbage collection for Javascript objects will be run in each thread.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
@ -341,7 +341,7 @@ namespace triagens {
|
|||
///
|
||||
/// @CMDOPT{--ruby.action-threads @CA{number}}
|
||||
///
|
||||
/// Specifies the @CA{number} of threads that are spawned to handle action
|
||||
/// Specifies the @CA{number} of threads that are spawned to handle action
|
||||
/// requests using MRuby.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
@ -441,5 +441,5 @@ namespace triagens {
|
|||
|
||||
// Local Variables:
|
||||
// mode: outline-minor
|
||||
// outline-regexp: "^\\(/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|// --SECTION--\\|/// @\\}\\)"
|
||||
// outline-regexp: "^\\(/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|/// @page\\|// --SECTION--\\|/// @\\}\\)"
|
||||
// End:
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
///
|
||||
/// DISCLAIMER
|
||||
///
|
||||
/// Copyright 2004-2012 triagens GmbH, Cologne, Germany
|
||||
/// Copyright 2004-2012 triAGENS GmbH, Cologne, Germany
|
||||
///
|
||||
/// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
/// you may not use this file except in compliance with the License.
|
||||
|
@ -161,7 +161,7 @@ void JavascriptDispatcherThread::run () {
|
|||
_context->Enter();
|
||||
|
||||
DispatcherThread::run();
|
||||
|
||||
|
||||
// free memory for this thread
|
||||
TRI_v8_global_t* v8g = (TRI_v8_global_t*) _isolate->GetData();
|
||||
|
||||
|
@ -171,7 +171,7 @@ void JavascriptDispatcherThread::run () {
|
|||
|
||||
_context->Exit();
|
||||
_context.Dispose();
|
||||
|
||||
|
||||
_isolate->Exit();
|
||||
_isolate->Dispose();
|
||||
}
|
||||
|
@ -251,7 +251,7 @@ void JavascriptDispatcherThread::initialise () {
|
|||
LOGGER_FATAL << "cannot load actions from directory '" << _actionLoader->getDirectory() << "'";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// and return from the context
|
||||
_context->Exit();
|
||||
_isolate->Exit();
|
||||
|
@ -267,5 +267,5 @@ void JavascriptDispatcherThread::initialise () {
|
|||
|
||||
// Local Variables:
|
||||
// mode: outline-minor
|
||||
// outline-regexp: "^\\(/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|// --SECTION--\\|/// @\\}\\)"
|
||||
// outline-regexp: "^\\(/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|/// @page\\|// --SECTION--\\|/// @\\}\\)"
|
||||
// End:
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
///
|
||||
/// DISCLAIMER
|
||||
///
|
||||
/// Copyright 2004-2012 triagens GmbH, Cologne, Germany
|
||||
/// Copyright 2004-2012 triAGENS GmbH, Cologne, Germany
|
||||
///
|
||||
/// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
/// you may not use this file except in compliance with the License.
|
||||
|
@ -199,7 +199,7 @@ namespace triagens {
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Javascript garbage collection interval (each x requests)
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
uint64_t _gcInterval;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -261,5 +261,5 @@ namespace triagens {
|
|||
|
||||
// Local Variables:
|
||||
// mode: outline-minor
|
||||
// outline-regexp: "^\\(/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|// --SECTION--\\|/// @\\}\\)"
|
||||
// outline-regexp: "^\\(/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|/// @page\\|// --SECTION--\\|/// @\\}\\)"
|
||||
// End:
|
||||
|
|
|
@ -0,0 +1,271 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief dispatcher thread for JavaScript actions
|
||||
///
|
||||
/// @file
|
||||
///
|
||||
/// DISCLAIMER
|
||||
///
|
||||
/// Copyright 2004-2012 triAGENS GmbH, Cologne, Germany
|
||||
///
|
||||
/// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
/// you may not use this file except in compliance with the License.
|
||||
/// You may obtain a copy of the License at
|
||||
///
|
||||
/// http://www.apache.org/licenses/LICENSE-2.0
|
||||
///
|
||||
/// Unless required by applicable law or agreed to in writing, software
|
||||
/// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
/// See the License for the specific language governing permissions and
|
||||
/// limitations under the License.
|
||||
///
|
||||
/// Copyright holder is triAGENS GmbH, Cologne, Germany
|
||||
///
|
||||
/// @author Dr. Frank Celler
|
||||
/// @author Copyright 2011-2012, triAGENS GmbH, Cologne, Germany
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "JavascriptDispatcherThread.h"
|
||||
|
||||
#include "Actions/actions.h"
|
||||
#include "Logger/Logger.h"
|
||||
#include "V8/v8-actions.h"
|
||||
#include "V8/v8-conv.h"
|
||||
#include "V8/v8-query.h"
|
||||
#include "V8/v8-shell.h"
|
||||
#include "V8/v8-utils.h"
|
||||
#include "V8/v8-vocbase.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace triagens::basics;
|
||||
using namespace triagens::rest;
|
||||
using namespace triagens::arango;
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- class ActionDispatcherThread
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- constructors and destructors
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @addtogroup ArangoDB
|
||||
/// @{
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief constructs a new dispatcher thread
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
JavascriptDispatcherThread::JavascriptDispatcherThread (rest::DispatcherQueue* queue,
|
||||
TRI_vocbase_t* vocbase,
|
||||
uint64_t gcInterval,
|
||||
string const& actionQueue,
|
||||
set<string> const& allowedContexts,
|
||||
string startupModules,
|
||||
JSLoader* startupLoader,
|
||||
JSLoader* actionLoader)
|
||||
: ActionDispatcherThread(queue),
|
||||
_vocbase(vocbase),
|
||||
_gcInterval(gcInterval),
|
||||
_gc(0),
|
||||
_isolate(0),
|
||||
_context(),
|
||||
_actionQueue(actionQueue),
|
||||
_allowedContexts(allowedContexts),
|
||||
_startupModules(startupModules),
|
||||
_startupLoader(startupLoader),
|
||||
_actionLoader(actionLoader) {
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @}
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- ActionDispatcherThread methods
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @addtogroup ArangoDB
|
||||
/// @{
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// {@inheritDoc}
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void* JavascriptDispatcherThread::context () {
|
||||
return (void*) _isolate; // the isolate is the execution context
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @}
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- DispatcherThread methods
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @addtogroup ArangoDB
|
||||
/// @{
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// {@inheritDoc}
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void JavascriptDispatcherThread::reportStatus () {
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// {@inheritDoc}
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void JavascriptDispatcherThread::tick (bool idle) {
|
||||
_gc += (idle ? 10 : 1);
|
||||
|
||||
if (_gc > _gcInterval) {
|
||||
LOGGER_TRACE << "collecting garbage...";
|
||||
|
||||
while (! v8::V8::IdleNotification()) {
|
||||
}
|
||||
|
||||
_gc = 0;
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @}
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- Thread methods
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @addtogroup ArangoDB
|
||||
/// @{
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// {@inheritDoc}
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void JavascriptDispatcherThread::run () {
|
||||
initialise();
|
||||
|
||||
_isolate->Enter();
|
||||
_context->Enter();
|
||||
|
||||
DispatcherThread::run();
|
||||
|
||||
// free memory for this thread
|
||||
TRI_v8_global_t* v8g = (TRI_v8_global_t*) _isolate->GetData();
|
||||
|
||||
if (v8g) {
|
||||
delete v8g;
|
||||
}
|
||||
|
||||
_context->Exit();
|
||||
_context.Dispose();
|
||||
|
||||
_isolate->Exit();
|
||||
_isolate->Dispose();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @}
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- private methods
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @addtogroup ArangoDB
|
||||
/// @{
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief initialises the isolate and context
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void JavascriptDispatcherThread::initialise () {
|
||||
bool ok;
|
||||
char const* files[] = { "common/bootstrap/modules.js",
|
||||
"common/bootstrap/print.js",
|
||||
"common/bootstrap/errors.js",
|
||||
"server/ahuacatl.js",
|
||||
"server/server.js"
|
||||
};
|
||||
size_t i;
|
||||
|
||||
// enter a new isolate
|
||||
_isolate = v8::Isolate::New();
|
||||
_isolate->Enter();
|
||||
|
||||
// create the context
|
||||
_context = v8::Context::New(0);
|
||||
|
||||
if (_context.IsEmpty()) {
|
||||
LOGGER_FATAL << "cannot initialize V8 engine";
|
||||
_isolate->Exit();
|
||||
TRI_FlushLogging();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
_context->Enter();
|
||||
|
||||
TRI_InitV8VocBridge(_context, _vocbase);
|
||||
TRI_InitV8Queries(_context);
|
||||
TRI_InitV8Actions(_context, _actionQueue, _allowedContexts);
|
||||
TRI_InitV8Conversions(_context);
|
||||
TRI_InitV8Utils(_context, _startupModules);
|
||||
TRI_InitV8Shell(_context);
|
||||
|
||||
// load all init files
|
||||
for (i = 0; i < sizeof(files) / sizeof(files[0]); ++i) {
|
||||
ok = _startupLoader->loadScript(_context, files[i]);
|
||||
|
||||
if (! ok) {
|
||||
LOGGER_FATAL << "cannot load json utilities from file '" << files[i] << "'";
|
||||
_context->Exit();
|
||||
_isolate->Exit();
|
||||
|
||||
TRI_FlushLogging();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
// load all actions
|
||||
if (_actionLoader == 0) {
|
||||
LOGGER_WARNING << "no action loader has been defined";
|
||||
}
|
||||
else {
|
||||
ok = _actionLoader->executeAllScripts(_context);
|
||||
|
||||
if (! ok) {
|
||||
LOGGER_FATAL << "cannot load actions from directory '" << _actionLoader->getDirectory() << "'";
|
||||
}
|
||||
}
|
||||
|
||||
// and return from the context
|
||||
_context->Exit();
|
||||
_isolate->Exit();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @}
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- END-OF-FILE
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// Local Variables:
|
||||
// mode: outline-minor
|
||||
// outline-regexp: "^\\(/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|/// @page\\|// --SECTION--\\|/// @\\}\\)"
|
||||
// End:
|
|
@ -0,0 +1,243 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief dispatcher thread for Ruby actions
|
||||
///
|
||||
/// @file
|
||||
///
|
||||
/// DISCLAIMER
|
||||
///
|
||||
/// Copyright 2004-2012 triAGENS GmbH, Cologne, Germany
|
||||
///
|
||||
/// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
/// you may not use this file except in compliance with the License.
|
||||
/// You may obtain a copy of the License at
|
||||
///
|
||||
/// http://www.apache.org/licenses/LICENSE-2.0
|
||||
///
|
||||
/// Unless required by applicable law or agreed to in writing, software
|
||||
/// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
/// See the License for the specific language governing permissions and
|
||||
/// limitations under the License.
|
||||
///
|
||||
/// Copyright holder is triAGENS GmbH, Cologne, Germany
|
||||
///
|
||||
/// @author Dr. Frank Celler
|
||||
/// @author Copyright 2011-2012, triAGENS GmbH, Cologne, Germany
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef TRIAGENS_REST_SERVER_RUBY_DISPATCHER_THREAD_H
|
||||
#define TRIAGENS_REST_SERVER_RUBY_DISPATCHER_THREAD_H 1
|
||||
|
||||
#include "Actions/ActionDispatcherThread.h"
|
||||
|
||||
#include "MRuby/MRLoader.h"
|
||||
#include "VocBase/vocbase.h"
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- class ActionDispatcherThread
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @addtogroup ArangoDB
|
||||
/// @{
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
namespace triagens {
|
||||
namespace arango {
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief dispatcher thread
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class RubyDispatcherThread : public ActionDispatcherThread {
|
||||
private:
|
||||
RubyDispatcherThread (RubyDispatcherThread const&);
|
||||
RubyDispatcherThread& operator= (RubyDispatcherThread const&);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @}
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- constructors and destructors
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @addtogroup ArangoDB
|
||||
/// @{
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public:
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief constructs a new dispatcher thread
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
RubyDispatcherThread (rest::DispatcherQueue*,
|
||||
TRI_vocbase_t*,
|
||||
string const& actionQueue,
|
||||
set<string> const& allowedContexts,
|
||||
std::string startupModules,
|
||||
MRLoader* startupLoader,
|
||||
MRLoader* actionLoader);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @}
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- ActionDispatcherThread methods
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @addtogroup ArangoDB
|
||||
/// @{
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public:
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// {@inheritDoc}
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void* context ();
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @}
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- DispatcherThread methods
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @addtogroup ArangoDB
|
||||
/// @{
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public:
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// {@inheritDoc}
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void reportStatus ();
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// {@inheritDoc}
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void tick (bool idle);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @}
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- Thread methods
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @addtogroup ArangoDB
|
||||
/// @{
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public:
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// {@inheritDoc}
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void run ();
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @}
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- private methods
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @addtogroup ArangoDB
|
||||
/// @{
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
private:
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief initialises the isolate and context
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void initialise ();
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @}
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- private variables
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @addtogroup ArangoDB
|
||||
/// @{
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
private:
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief vocbase
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
TRI_vocbase_t* _vocbase;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief V8 isolate
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
MR_state_t* _mrs;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief action queue
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::string _actionQueue;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief allowed action contexts
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::set<std::string> _allowedContexts;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief modules path
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
string _startupModules;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief startup path
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
MRLoader* _startupLoader;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief action path
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
MRLoader* _actionLoader;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @}
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endif
|
||||
|
||||
// Local Variables:
|
||||
// mode: outline-minor
|
||||
// outline-regexp: "^\\(/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|/// @page\\|// --SECTION--\\|/// @\\}\\)"
|
||||
// End:
|
|
@ -5,7 +5,7 @@
|
|||
///
|
||||
/// DISCLAIMER
|
||||
///
|
||||
/// Copyright 2004-2012 triagens GmbH, Cologne, Germany
|
||||
/// Copyright 2004-2012 triAGENS GmbH, Cologne, Germany
|
||||
///
|
||||
/// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
/// you may not use this file except in compliance with the License.
|
||||
|
@ -70,5 +70,5 @@ int main (int argc, char* argv[]) {
|
|||
|
||||
// Local Variables:
|
||||
// mode: outline-minor
|
||||
// outline-regexp: "^\\(/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|// --SECTION--\\|/// @page\\|/// @\\}\\)"
|
||||
// outline-regexp: "^\\(/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|/// @page\\|// --SECTION--\\|/// @\\}\\)"
|
||||
// End:
|
||||
|
|
|
@ -39,9 +39,9 @@ class ArangoError
|
|||
end
|
||||
end
|
||||
|
||||
################################################################################
|
||||
## -----------------------------------------------------------------------------
|
||||
## --SECTION-- END-OF-FILE
|
||||
################################################################################
|
||||
## -----------------------------------------------------------------------------
|
||||
|
||||
## Local Variables:
|
||||
## mode: outline-minor
|
||||
|
|
|
@ -40,9 +40,9 @@ static string MR_common_bootstrap_error =
|
|||
" end\n"
|
||||
"end\n"
|
||||
"\n"
|
||||
"################################################################################\n"
|
||||
"## -----------------------------------------------------------------------------\n"
|
||||
"## --SECTION-- END-OF-FILE\n"
|
||||
"################################################################################\n"
|
||||
"## -----------------------------------------------------------------------------\n"
|
||||
"\n"
|
||||
"## Local Variables:\n"
|
||||
"## mode: outline-minor\n"
|
||||
|
|
|
@ -77,9 +77,9 @@ static string MR_server_server =
|
|||
"\n"
|
||||
"end\n"
|
||||
"\n"
|
||||
"################################################################################\n"
|
||||
"## -----------------------------------------------------------------------------\n"
|
||||
"## --SECTION-- END-OF-FILE\n"
|
||||
"################################################################################\n"
|
||||
"## -----------------------------------------------------------------------------\n"
|
||||
"\n"
|
||||
"## Local Variables:\n"
|
||||
"## mode: outline-minor\n"
|
||||
|
|
|
@ -76,9 +76,9 @@ module Arango
|
|||
|
||||
end
|
||||
|
||||
################################################################################
|
||||
## -----------------------------------------------------------------------------
|
||||
## --SECTION-- END-OF-FILE
|
||||
################################################################################
|
||||
## -----------------------------------------------------------------------------
|
||||
|
||||
## Local Variables:
|
||||
## mode: outline-minor
|
||||
|
|
Loading…
Reference in New Issue