00001 // request.h 00002 /* 00003 * Copyright (C) 2010 10gen Inc. 00004 * 00005 * This program is free software: you can redistribute it and/or modify 00006 * it under the terms of the GNU Affero General Public License, version 3, 00007 * as published by the Free Software Foundation. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU Affero General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU Affero General Public License 00015 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00016 */ 00017 00018 00019 #pragma once 00020 00021 #include "../pch.h" 00022 #include "../util/message.h" 00023 #include "../db/dbmessage.h" 00024 #include "config.h" 00025 #include "util.h" 00026 00027 namespace mongo { 00028 00029 00030 class OpCounters; 00031 class ClientInfo; 00032 00033 class Request : boost::noncopyable { 00034 public: 00035 Request( Message& m, AbstractMessagingPort* p ); 00036 00037 // ---- message info ----- 00038 00039 00040 const char * getns() const { 00041 return _d.getns(); 00042 } 00043 int op() const { 00044 return _m.operation(); 00045 } 00046 bool expectResponse() const { 00047 return op() == dbQuery || op() == dbGetMore; 00048 } 00049 bool isCommand() const; 00050 00051 MSGID id() const { 00052 return _id; 00053 } 00054 00055 DBConfigPtr getConfig() const { 00056 assert( _didInit ); 00057 return _config; 00058 } 00059 bool isShardingEnabled() const { 00060 assert( _didInit ); 00061 return _config->isShardingEnabled(); 00062 } 00063 00064 ChunkManagerPtr getChunkManager() const { 00065 assert( _didInit ); 00066 return _chunkManager; 00067 } 00068 00069 ClientInfo * getClientInfo() const { 00070 return _clientInfo; 00071 } 00072 00073 // ---- remote location info ----- 00074 00075 00076 Shard primaryShard() const ; 00077 00078 // ---- low level access ---- 00079 00080 void reply( Message & response , const string& fromServer ); 00081 00082 Message& m() { return _m; } 00083 DbMessage& d() { return _d; } 00084 AbstractMessagingPort* p() const { return _p; } 00085 00086 void process( int attempt = 0 ); 00087 00088 void gotInsert(); 00089 00090 void init(); 00091 00092 void reset( bool reload=false ); 00093 00094 private: 00095 Message& _m; 00096 DbMessage _d; 00097 AbstractMessagingPort* _p; 00098 00099 MSGID _id; 00100 DBConfigPtr _config; 00101 ChunkManagerPtr _chunkManager; 00102 00103 ClientInfo * _clientInfo; 00104 00105 OpCounters* _counter; 00106 00107 bool _didInit; 00108 }; 00109 00110 } 00111 00112 #include "strategy.h"