00001 /*------------------------------------------------------------------------------ 00002 Name: CbQueueProperty.cpp 00003 Project: xmlBlaster.org 00004 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file 00005 Comment: Holding callback queue properties 00006 Version: $Id: CbQueueProperty.cpp 13445 2005-07-15 01:54:35Z ruff $ 00007 ------------------------------------------------------------------------------*/ 00008 00016 #include <util/qos/storage/CbQueueProperty.h> 00017 #include <util/lexical_cast.h> 00018 #include <ctype.h> // for toUpper 00019 #include <util/Global.h> 00020 00021 namespace org { namespace xmlBlaster { namespace util { namespace qos { namespace storage { 00022 00023 using namespace std; 00024 using namespace org::xmlBlaster::util; 00025 using namespace org::xmlBlaster::util::qos::address; 00026 00027 CbQueueProperty::CbQueueProperty(Global& global, 00028 const string& relating, 00029 const string& nodeId) 00030 : QueuePropertyBase(global, nodeId) 00031 { 00032 ME = "CbQueueProperty"; 00033 setRelating(relating); 00034 QueuePropertyBase::initialize(Constants::RELATING_CALLBACK); 00035 getCurrentCallbackAddress(); // Force creation, to read environment settings 00036 } 00037 00038 CbQueueProperty::CbQueueProperty(const QueuePropertyBase& prop) 00039 : QueuePropertyBase(prop) 00040 { 00041 } 00042 00043 CbQueueProperty& 00044 CbQueueProperty::operator =(const QueuePropertyBase& prop) 00045 { 00046 copy(prop); 00047 return *this; 00048 } 00049 00053 string CbQueueProperty::getSettings() 00054 { 00055 string ret; 00056 ret += string("type=") + getType() + string(" onOverflow=") + 00057 getOnOverflow() + string(" onFailure=") + getOnFailure() + 00058 string(" maxEntries=") + lexical_cast<std::string>(getMaxEntries()); 00059 if (!addressArr_.empty()) 00060 ret += string(" ") + getCurrentCallbackAddress()->getSettings(); 00061 return ret; 00062 } 00063 00064 00069 string& CbQueueProperty::toLowerCase(string& ref) 00070 { 00071 string::iterator iter = ref.begin(); 00072 while (iter != ref.end()) { 00073 *iter = tolower(*iter); 00074 iter++; 00075 } 00076 return ref; 00077 } 00078 00082 void CbQueueProperty::setRelating(const string& relating) 00083 { 00084 if (relating == "") { 00085 relating_ = Constants::RELATING_CALLBACK; 00086 return; 00087 } 00088 string help = relating; 00089 help = toLowerCase(help); 00090 00091 if (Constants::RELATING_CALLBACK == help) 00092 relating_ = Constants::RELATING_CALLBACK; 00093 else if (Constants::RELATING_SUBJECT == help) 00094 relating_ = Constants::RELATING_SUBJECT; 00095 else { 00096 log_.warn(ME, string("The queue relating attribute is invalid '") + relating + string("', setting to session scope")); 00097 relating_ = Constants::RELATING_CALLBACK; 00098 } 00099 } 00100 00101 bool CbQueueProperty::isSubjectRelated() 00102 { 00103 return Constants::RELATING_SUBJECT == getRelating(); 00104 } 00105 00106 bool CbQueueProperty::isSessionRelated() 00107 { 00108 return Constants::RELATING_CALLBACK == getRelating(); 00109 } 00110 00111 bool CbQueueProperty::onOverflowDeadMessage() 00112 { 00113 if (Constants::ONOVERFLOW_DEADMESSAGE == getOnOverflow()) 00114 return true; 00115 return false; 00116 } 00117 00118 00122 void CbQueueProperty::setCallbackAddress(const AddressBaseRef& address) 00123 { 00124 // addressArr_.insert(addressArr_.begin(), address); 00125 if (!addressArr_.empty()) addressArr_.erase(addressArr_.begin()); 00126 addressArr_.insert(addressArr_.begin(), address); 00127 } 00128 00131 void CbQueueProperty::setCallbackAddresses(const AddressVector& addresses) 00132 { 00133 addressArr_ = AddressVector(addresses); 00134 } 00135 00139 AddressVector CbQueueProperty::getCallbackAddresses() 00140 { 00141 return addressArr_; 00142 } 00143 00147 AddressBaseRef CbQueueProperty::getCurrentCallbackAddress() 00148 { 00149 if (addressArr_.empty()) { 00150 setCallbackAddress(new CallbackAddress(global_)); 00151 } 00152 return *addressArr_.begin(); 00153 } 00154 00158 string CbQueueProperty::usage() 00159 { 00160 string text; 00161 text += string("Control the callback queue properties (on server side):\n"); 00162 text += string(" -queue/callback/maxEntries [") + lexical_cast<std::string>(DEFAULT_maxEntriesDefault) + string("]\n"); 00163 text += string(" The maximum allowed number of messages in this queue.\n"); 00164 text += string(" -queue/callback/maxEntriesCache [") + lexical_cast<std::string>(DEFAULT_maxEntriesDefault) + string("]\n"); 00165 text += string(" The maximum allowed number of messages in the cache of this queue.\n"); 00166 text += string(" -queue/callback/maxBytes [") + lexical_cast<std::string>(DEFAULT_bytesDefault) + string("]\n"); 00167 text += string(" The maximum size in kBytes of this queue.\n"); 00168 text += string(" -queue/callback/maxBytesCache [") + lexical_cast<std::string>(DEFAULT_bytesDefault) + string("]\n"); 00169 text += string(" The maximum size in kBytes in the cache of this queue.\n"); 00170 //text += " -queue/callback/expires If not otherwise noted a queue dies after these milliseconds [" + DEFAULT_expiresDefault + "].\n"; 00171 //text += " -queue/callback/onOverflow What happens if queue is full. " + Constants.ONOVERFLOW_BLOCK + " | " + Constants.ONOVERFLOW_DEADMESSAGE + " [" + DEFAULT_onOverflow + "]\n"; 00172 //text += string(" -queue/callback/onOverflow What happens if queue is full [") + DEFAULT_onOverflow + string("]\n"); 00173 //text += string(" -queue/callback/onFailure Error handling when callback failed [") + DEFAULT_onFailure + string("]\n"); 00174 text += string(" -queue/callback/type [") + DEFAULT_type + string("]\n"); 00175 text += string(" The callback queue plugin type on server side\n"); 00176 //text += string(" -queue/callback/version The plugin version [") + DEFAULT_version + string("]\n"); 00177 return text; 00178 } 00179 00180 }}}}} // namespace 00181 00182 00183 #ifdef _XMLBLASTER_CLASSTEST 00184 00185 using namespace std; 00186 using namespace org::xmlBlaster::util::qos::storage; 00187 00189 int main(int args, char* argv[]) 00190 { 00191 Global& glob = Global::getInstance(); 00192 glob.initialize(args, argv); 00193 00194 CbQueueProperty prop(glob, "", ""); 00195 00196 cout << prop.toXml() << endl; 00197 CallbackAddress *adr = new CallbackAddress(glob, "EMAIL"); 00198 adr.setAddress("et@mars.sun"); 00199 prop.setCallbackAddress(adr); 00200 cout << prop.toXml() << endl; 00201 } 00202 00203 #endif 00204 00205