1
0
Fork 0
arangodb/js/server/bootstrap/module-internal.js

341 lines
12 KiB
JavaScript

/*jshint globalstrict:true, -W051:true */
/*global global, require */
'use strict';
////////////////////////////////////////////////////////////////////////////////
/// @brief module "internal"
///
/// @file
///
/// DISCLAIMER
///
/// Copyright 2004-2013 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 2010-2013, triAGENS GmbH, Cologne, Germany
////////////////////////////////////////////////////////////////////////////////
// -----------------------------------------------------------------------------
// --SECTION-- Module "internal"
// -----------------------------------------------------------------------------
var exports = require("internal");
var fs = require("fs");
var console = require("console");
// -----------------------------------------------------------------------------
// --SECTION-- private variables
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @brief db
////////////////////////////////////////////////////////////////////////////////
exports.db = global.db;
delete global.db;
////////////////////////////////////////////////////////////////////////////////
/// @brief ArangoCollection
////////////////////////////////////////////////////////////////////////////////
exports.ArangoCollection = global.ArangoCollection;
delete global.ArangoCollection;
////////////////////////////////////////////////////////////////////////////////
/// @brief ArangoDatabase
////////////////////////////////////////////////////////////////////////////////
exports.ArangoDatabase = global.ArangoDatabase;
delete global.ArangoDatabase;
////////////////////////////////////////////////////////////////////////////////
/// @brief ShapedJson
////////////////////////////////////////////////////////////////////////////////
exports.ShapedJson = global.ShapedJson;
delete global.ShapedJson;
////////////////////////////////////////////////////////////////////////////////
/// @brief enableStatistics
////////////////////////////////////////////////////////////////////////////////
exports.enableStatistics = global.ENABLE_STATISTICS;
delete global.ENABLE_STATISTICS;
////////////////////////////////////////////////////////////////////////////////
/// @brief dispatcherThreads
////////////////////////////////////////////////////////////////////////////////
exports.dispatcherThreads = global.DISPATCHER_THREADS;
delete global.DISPATCHER_THREADS;
////////////////////////////////////////////////////////////////////////////////
/// @brief frontendVersionCheck
////////////////////////////////////////////////////////////////////////////////
exports.frontendVersionCheck = global.FE_VERSION_CHECK;
delete global.FE_VERSION_CHECK;
// -----------------------------------------------------------------------------
// --SECTION-- private functions
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @brief resets engine in development mode
////////////////////////////////////////////////////////////////////////////////
exports.resetEngine = function () {
require("org/arangodb/actions").reloadRouting();
};
////////////////////////////////////////////////////////////////////////////////
/// @brief rebuilds the authentication cache
////////////////////////////////////////////////////////////////////////////////
exports.reloadAuth = global.RELOAD_AUTH;
delete global.RELOAD_AUTH;
////////////////////////////////////////////////////////////////////////////////
/// @brief write-ahead log object
////////////////////////////////////////////////////////////////////////////////
exports.wal = {
flush: function () {
return global.WAL_FLUSH.apply(null, arguments);
},
properties: function () {
return global.WAL_PROPERTIES.apply(null, arguments);
}
};
////////////////////////////////////////////////////////////////////////////////
/// @brief defines an action
////////////////////////////////////////////////////////////////////////////////
if (global.SYS_DEFINE_ACTION) {
exports.defineAction = global.SYS_DEFINE_ACTION;
delete global.SYS_DEFINE_ACTION;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief autoload modules from database
////////////////////////////////////////////////////////////////////////////////
// autoload specific modules
exports.autoloadModules = function () {
console.debug("autoloading actions");
var modules = exports.db._collection("_modules");
if (modules !== null) {
modules = modules.byExample({ autoload: true }).toArray();
modules.forEach(function(module) {
// this module is only meant to be executed in one thread
if (exports.threadNumber !== 0 && ! module.perThread) {
return;
}
console.debug("autoloading module: %s", module.path);
try {
// require a module
if (module.path !== undefined) {
require(module.path);
}
// execute a user function
else if (module.func !== undefined) {
/*jshint evil: true */
var func = new Function(module.func);
func();
}
}
catch (err) {
console.error("error while loading startup module '%s': %s", module.name || module.path, String(err));
}
});
}
console.debug("autoloading actions finished");
};
////////////////////////////////////////////////////////////////////////////////
/// @brief executes a string in all V8 contexts
////////////////////////////////////////////////////////////////////////////////
if (global.SYS_EXECUTE_GLOBAL_CONTEXT_FUNCTION) {
exports.executeGlobalContextFunction = global.SYS_EXECUTE_GLOBAL_CONTEXT_FUNCTION;
}
else {
exports.executeGlobalContextFunction = function() {
// nothing to do. we're probably in --no-server mode
};
}
////////////////////////////////////////////////////////////////////////////////
/// @brief reloads the AQL user functions
////////////////////////////////////////////////////////////////////////////////
if (global.SYS_EXECUTE_GLOBAL_CONTEXT_FUNCTION) {
exports.reloadAqlFunctions = function () {
exports.executeGlobalContextFunction("reloadAql");
require("org/arangodb/aql").reload();
};
delete global.SYS_EXECUTE_GLOBAL_CONTEXT_FUNCTION;
}
else {
exports.reloadAqlFunctions = function () {
require("org/arangodb/aql").reload();
};
}
////////////////////////////////////////////////////////////////////////////////
/// @brief getStateReplicationLogger
////////////////////////////////////////////////////////////////////////////////
if (global.REPLICATION_LOGGER_STATE) {
exports.getStateReplicationLogger = global.REPLICATION_LOGGER_STATE;
delete global.REPLICATION_LOGGER_STATE;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief configureReplicationApplier
////////////////////////////////////////////////////////////////////////////////
if (global.REPLICATION_APPLIER_CONFIGURE) {
exports.configureReplicationApplier = global.REPLICATION_APPLIER_CONFIGURE;
delete global.REPLICATION_APPLIER_CONFIGURE;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief startReplicationApplier
////////////////////////////////////////////////////////////////////////////////
if (global.REPLICATION_APPLIER_START) {
exports.startReplicationApplier = global.REPLICATION_APPLIER_START;
delete global.REPLICATION_APPLIER_START;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief shutdownReplicationApplier
////////////////////////////////////////////////////////////////////////////////
if (global.REPLICATION_APPLIER_SHUTDOWN) {
exports.shutdownReplicationApplier = global.REPLICATION_APPLIER_SHUTDOWN;
delete global.REPLICATION_APPLIER_SHUTDOWN;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief getStateReplicationApplier
////////////////////////////////////////////////////////////////////////////////
if (global.REPLICATION_APPLIER_STATE) {
exports.getStateReplicationApplier = global.REPLICATION_APPLIER_STATE;
delete global.REPLICATION_APPLIER_STATE;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief forgetStateReplicationApplier
////////////////////////////////////////////////////////////////////////////////
if (global.REPLICATION_APPLIER_FORGET) {
exports.forgetStateReplicationApplier = global.REPLICATION_APPLIER_FORGET;
delete global.REPLICATION_APPLIER_FORGET;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief sychroniseReplication
////////////////////////////////////////////////////////////////////////////////
if (global.REPLICATION_SYNCHRONISE) {
exports.synchroniseReplication = global.REPLICATION_SYNCHRONISE;
delete global.REPLICATION_SYNCHRONISE;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief serverId
////////////////////////////////////////////////////////////////////////////////
if (global.REPLICATION_SERVER_ID) {
exports.serverId = global.REPLICATION_SERVER_ID;
delete global.REPLICATION_SERVER_ID;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief loadStartup
////////////////////////////////////////////////////////////////////////////////
exports.loadStartup = function (path) {
return exports.load(fs.join(exports.startupPath, path));
};
////////////////////////////////////////////////////////////////////////////////
/// @brief createNamedQueue
////////////////////////////////////////////////////////////////////////////////
if (global.SYS_CREATE_NAMED_QUEUE) {
exports.createNamedQueue = global.SYS_CREATE_NAMED_QUEUE;
delete global.SYS_CREATE_NAMED_QUEUE;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief addJob
////////////////////////////////////////////////////////////////////////////////
if (global.SYS_ADD_JOB) {
exports.addJob = global.SYS_ADD_JOB;
delete global.SYS_ADD_JOB;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief raw request body
////////////////////////////////////////////////////////////////////////////////
if (global.SYS_RAW_REQUEST_BODY) {
exports.rawRequestBody = global.SYS_RAW_REQUEST_BODY;
delete global.SYS_RAW_REQUEST_BODY;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief request parts
////////////////////////////////////////////////////////////////////////////////
if (global.SYS_REQUEST_PARTS) {
exports.requestParts = global.SYS_REQUEST_PARTS;
delete global.SYS_REQUEST_PARTS;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief send chunks
////////////////////////////////////////////////////////////////////////////////
if (global.SYS_SEND_CHUNK) {
exports.sendChunk = global.SYS_SEND_CHUNK;
delete global.SYS_SEND_CHUNK;
}
// -----------------------------------------------------------------------------
// --SECTION-- END-OF-FILE
// -----------------------------------------------------------------------------
// Local Variables:
// mode: outline-minor
// outline-regexp: "/// @brief\\|/// @addtogroup\\|/// @page\\|// --SECTION--\\|/// @\\}\\|/\\*jslint"
// End: