2009-02-06 20:11:31 +01:00
|
|
|
// request.h
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2009-02-06 20:25:06 +01:00
|
|
|
#include "../stdafx.h"
|
2009-02-06 20:11:31 +01:00
|
|
|
#include "../util/message.h"
|
|
|
|
#include "../db/dbmessage.h"
|
2009-02-13 03:03:46 +01:00
|
|
|
#include "config.h"
|
2009-02-06 20:11:31 +01:00
|
|
|
|
|
|
|
namespace mongo {
|
|
|
|
|
2009-02-20 16:46:42 +01:00
|
|
|
class Request : boost::noncopyable {
|
2009-02-06 20:11:31 +01:00
|
|
|
public:
|
2009-03-02 05:43:00 +01:00
|
|
|
Request( Message& m, AbstractMessagingPort* p );
|
2009-02-06 20:11:31 +01:00
|
|
|
|
2009-02-19 19:26:25 +01:00
|
|
|
// ---- message info -----
|
|
|
|
|
|
|
|
|
2009-02-06 20:11:31 +01:00
|
|
|
const char * getns(){
|
|
|
|
return _d.getns();
|
|
|
|
}
|
2009-02-19 18:55:01 +01:00
|
|
|
int op(){
|
|
|
|
return _m.data->operation();
|
|
|
|
}
|
|
|
|
bool expectResponse(){
|
|
|
|
return op() == dbQuery || op() == dbGetMore;
|
|
|
|
}
|
2009-02-06 20:11:31 +01:00
|
|
|
|
|
|
|
MSGID id(){
|
|
|
|
return _id;
|
|
|
|
}
|
|
|
|
|
2009-02-06 21:44:21 +01:00
|
|
|
DBConfig * getConfig(){
|
|
|
|
return _config;
|
|
|
|
}
|
2009-09-01 22:30:20 +02:00
|
|
|
bool isShardingEnabled(){
|
|
|
|
return _config->isShardingEnabled();
|
|
|
|
}
|
2009-02-19 19:26:25 +01:00
|
|
|
|
2009-08-31 22:31:50 +02:00
|
|
|
ChunkManager * getChunkManager(){
|
2009-09-01 22:30:20 +02:00
|
|
|
return _chunkManager;
|
2009-02-20 16:46:42 +01:00
|
|
|
}
|
|
|
|
|
2009-02-19 19:26:25 +01:00
|
|
|
// ---- remote location info -----
|
2009-02-06 21:44:21 +01:00
|
|
|
|
2009-02-19 19:26:25 +01:00
|
|
|
|
|
|
|
string singleServerName();
|
|
|
|
|
2009-02-06 21:44:21 +01:00
|
|
|
const char * primaryName(){
|
2009-02-08 20:36:01 +01:00
|
|
|
return _config->getPrimary().c_str();
|
2009-02-06 21:44:21 +01:00
|
|
|
}
|
|
|
|
|
2009-02-19 19:26:25 +01:00
|
|
|
// ---- low level access ----
|
2009-02-17 17:41:34 +01:00
|
|
|
|
2009-02-06 20:11:31 +01:00
|
|
|
void reply( Message & response ){
|
2009-03-02 05:43:00 +01:00
|
|
|
_p->reply( _m , response , _id );
|
2009-02-06 20:11:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Message& m(){ return _m; }
|
|
|
|
DbMessage& d(){ return _d; }
|
2009-03-02 05:43:00 +01:00
|
|
|
AbstractMessagingPort* p(){ return _p; }
|
2009-02-06 20:11:31 +01:00
|
|
|
|
2009-04-07 21:19:27 +02:00
|
|
|
void process( int attempt = 0 );
|
|
|
|
|
2009-02-06 20:11:31 +01:00
|
|
|
private:
|
2009-04-07 21:19:27 +02:00
|
|
|
|
2009-04-13 04:19:41 +02:00
|
|
|
void reset( bool reload=false );
|
2009-04-07 21:19:27 +02:00
|
|
|
|
2009-02-06 20:11:31 +01:00
|
|
|
Message& _m;
|
|
|
|
DbMessage _d;
|
2009-03-02 05:43:00 +01:00
|
|
|
AbstractMessagingPort* _p;
|
2009-02-19 19:26:25 +01:00
|
|
|
|
2009-02-06 20:11:31 +01:00
|
|
|
MSGID _id;
|
2009-02-06 21:44:21 +01:00
|
|
|
DBConfig * _config;
|
2009-09-01 22:30:20 +02:00
|
|
|
ChunkManager * _chunkManager;
|
2009-02-06 20:11:31 +01:00
|
|
|
};
|
2009-04-07 21:19:27 +02:00
|
|
|
|
|
|
|
class StaleConfigException : public std::exception {
|
2009-04-13 04:19:41 +02:00
|
|
|
public:
|
|
|
|
StaleConfigException( const string& ns , const string& msg){
|
|
|
|
stringstream s;
|
|
|
|
s << "StaleConfigException ns: " << ns << " " << msg;
|
|
|
|
_msg = s.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~StaleConfigException() throw(){}
|
2009-04-07 21:19:27 +02:00
|
|
|
|
2009-04-13 04:19:41 +02:00
|
|
|
virtual const char* what() const throw(){
|
|
|
|
return _msg.c_str();
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
string _msg;
|
2009-04-07 21:19:27 +02:00
|
|
|
};
|
2009-02-06 20:11:31 +01:00
|
|
|
}
|
2009-02-23 19:56:54 +01:00
|
|
|
|
|
|
|
#include "strategy.h"
|