mirror of https://gitee.com/bigwinds/arangodb
233 lines
9.1 KiB
C++
233 lines
9.1 KiB
C++
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief batch request handler
|
|
///
|
|
/// @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 Jan Steemann
|
|
/// @author Copyright 2010-2012, triAGENS GmbH, Cologne, Germany
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
#ifndef TRIAGENS_REST_HANDLER_REST_BATCH_HANDLER_H
|
|
#define TRIAGENS_REST_HANDLER_REST_BATCH_HANDLER_H 1
|
|
|
|
#include "RestHandler/RestVocbaseBaseHandler.h"
|
|
#include "Rest/HttpRequest.h"
|
|
#include "Rest/HttpResponse.h"
|
|
#include "HttpServer/HttpHandler.h"
|
|
#include "HttpServer/HttpServer.h"
|
|
#include "HttpServer/HttpCommTask.h"
|
|
#include "GeneralServer/GeneralServerJob.h"
|
|
#include "Scheduler/Scheduler.h"
|
|
#include "Dispatcher/Dispatcher.h"
|
|
#include "ProtocolBuffers/arangodb.pb.h"
|
|
|
|
using namespace triagens::basics;
|
|
using namespace triagens::rest;
|
|
using namespace std;
|
|
|
|
// -----------------------------------------------------------------------------
|
|
// --SECTION-- RestBatchHandler
|
|
// -----------------------------------------------------------------------------
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @addtogroup ArangoDB
|
|
/// @{
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
namespace triagens {
|
|
namespace arango {
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief import request handler
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
class RestBatchHandler : public RestVocbaseBaseHandler {
|
|
using HttpHandler::createJob;
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @}
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// -----------------------------------------------------------------------------
|
|
// --SECTION-- constructors and destructors
|
|
// -----------------------------------------------------------------------------
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @addtogroup ArangoDB
|
|
/// @{
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
public:
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief constructor
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
RestBatchHandler (rest::HttpRequest* request, struct TRI_vocbase_s* vocbase);
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief destructor
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
~RestBatchHandler ();
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @}
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// -----------------------------------------------------------------------------
|
|
// --SECTION-- Handler methods
|
|
// -----------------------------------------------------------------------------
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @addtogroup ArangoDB
|
|
/// @{
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
public:
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// {@inheritDoc}
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
bool isDirect ();
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// {@inheritDoc}
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
string const& queue ();
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// {@inheritDoc}
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
status_e execute ();
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// notification routine called by async sub jobs
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
virtual void notify (Job*, const Job::notification_e);
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// {@inheritDoc}
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
virtual bool handleAsync ();
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @}
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// -----------------------------------------------------------------------------
|
|
// --SECTION-- private methods
|
|
// -----------------------------------------------------------------------------
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @addtogroup ArangoDB
|
|
/// @{
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
private:
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief add a single handler response to the output array
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
void addResponse (HttpHandler*);
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief create an overall protobuf response from the array of responses
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
void assembleResponse ();
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief convert a Job* to a GeneralServerJob*
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
static GeneralServerJob<HttpServer, HttpHandlerFactory::GeneralHandler>* toServerJob(Job*);
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief return the required content type string
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
static string const& getContentType ();
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @}
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// -----------------------------------------------------------------------------
|
|
// --SECTION-- private variables
|
|
// -----------------------------------------------------------------------------
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @addtogroup ArangoDB
|
|
/// @{
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief handlers created, ordered by their sequence in the input
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
vector<HttpHandler*> _handlers;
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief number of async handler responses still missing
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
sig_atomic_t _missingResponses;
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief flag that's set when the handler is fully finished
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
sig_atomic_t _reallyDone;
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief protobuffer container with all output messages
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
PB_ArangoMessage* _outputMessages;
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief mutex used to protected protobuffer and handlers structure
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
basics::Mutex _handlerLock;
|
|
|
|
};
|
|
}
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @}
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
#endif
|
|
|
|
// Local Variables:
|
|
// mode: outline-minor
|
|
// outline-regexp: "^\\(/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|// --SECTION--\\|/// @\\}\\)"
|
|
// End:
|