util/qos/storage/ClientQueueProperty.cpp

Go to the documentation of this file.
00001 /*------------------------------------------------------------------------------
00002 Name:      ClientQueueProperty.cpp
00003 Project:   xmlBlaster.org
00004 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file
00005 Comment:   Holding callback queue properties
00006 ------------------------------------------------------------------------------*/
00007 
00008 #include <util/qos/storage/ClientQueueProperty.h>
00009 #include <util/lexical_cast.h>
00010 #include <util/Global.h>
00011 
00012 namespace org { namespace xmlBlaster { namespace util { namespace qos { namespace storage {
00013 
00014 using namespace std;
00015 using namespace org::xmlBlaster::util;
00016 using namespace org::xmlBlaster::util::qos::address;
00017 
00018    ClientQueueProperty::ClientQueueProperty(Global& global, const string& nodeId) :
00019       QueuePropertyBase(global, nodeId)
00020    {
00021       ME = "ClientQueueProperty";
00022       relating_ = Constants::RELATING_CLIENT;  // == "connection"
00023       QueuePropertyBase::initialize(Constants::RELATING_CLIENT); // == "connection"
00024 
00025       /*
00026 #     ifndef XMLBLASTER_PERSISTENT_QUEUE
00027       // TODO !!!: Hack: We need to force default to RAM instead of CACHE
00028       // as we have no C++ CACHE implementation  (see QueueFactory.cpp for the other workaround)
00029       string envType = global_.getProperty().getStringProperty("queue/connection/type", "");
00030       if (envType == "") {
00031          setType("RAM");
00032       }
00033 #    endif
00034 */
00035    }
00036 
00037    ClientQueueProperty::ClientQueueProperty(const QueuePropertyBase& prop)
00038       : QueuePropertyBase(prop)
00039    {
00040    }
00041 
00042    ClientQueueProperty& ClientQueueProperty::operator =(const QueuePropertyBase& prop)
00043    {
00044       copy(prop);
00045       return *this;
00046    }
00047 
00051    string ClientQueueProperty::getSettings()
00052    {
00053       string ret;
00054       ret += string("type=") + getType() + string(" onOverflow=") +
00055              getOnOverflow() + string(" onFailure=") + getOnFailure() +
00056              string(" maxEntries=") + lexical_cast<std::string>(getMaxEntries());
00057       if (!addressArr_.empty())
00058          ret += string(" ") + getCurrentAddress()->getSettings();
00059       return ret;
00060    }
00061 
00064    void ClientQueueProperty::setAddress(const AddressBaseRef& address)
00065    {
00066       // this differes from the current java code (2002-12-07) since it allows
00067       // multiple addresses
00068       addressArr_.insert(addressArr_.begin(), address);
00069    }
00070 
00074    void ClientQueueProperty::setAddresses(const AddressVector& addresses)
00075    {
00076       addressArr_ = AddressVector(addresses);
00077    }
00078 
00079 
00083    AddressBaseRef ClientQueueProperty::getCurrentAddress()
00084    {
00085       if (addressArr_.empty()) {
00086          addressArr_.push_back(new Address(global_));
00087       }
00088       // otherwise get the last one added
00089       return *addressArr_.begin();
00090    }
00091 
00095    string ClientQueueProperty::usage()
00096    {
00097       string text = "";
00098       text += string("Control client side failsafe queue properties (message recorder):\n");
00099       text += string("   -queue/connection/maxEntries [") + lexical_cast<std::string>(DEFAULT_maxEntriesDefault) + string("]\n");
00100       text += string("                       The maximum allowed number of messages in this queue.\n");
00101       text += string("                       0 switches recording of invocations off, -1 sets it to unlimited.\n");
00102       text += string("   -queue/connection/type [CACHE].\n");
00103       text += string("                       The C++ client side queue plugin type, choose 'RAM' for a pure memory based queue.\n");
00104 #     ifdef XMLBLASTER_PERSISTENT_QUEUE
00105       text += string("                       Choose 'SQLite' for a pure persistent client side queue.\n");
00106 #     else
00107       text += string("                       Please recompile with -DXMLBLASTER_PERSISTENT_QUEUE=1 defined\n");
00108       text += string("                       to have a persistent client side queue 'SQLite'.\n");
00109 #     endif
00110       text += string("   -queue/connection/version ") + DEFAULT_version + string("].\n");
00111       text += string("                       The queue plugin type.\n");
00112       text += string("   -queue/connection/maxBytes [" + lexical_cast<std::string>(DEFAULT_bytesDefault) + "].\n");
00113       text += string("                       The maximum size in bytes of this queue.\n");
00114 #     ifdef XMLBLASTER_PERSISTENT_QUEUE
00115       text += string("SQLite specific setting:\n");
00116       text += string("   -queue/connection/url [xmlBlasterClientCpp.db].\n");
00117       text += string("                       The location and file name of the database.\n");
00118 #     endif
00119     //text += string("   -queue/connection/expires      If not otherwise noted a queue dies after these milliseconds [" + DEFAULT_expiresDefault + "].\n";
00120     //text += string("   -queue/connection/onOverflow   What happens if queue is full. " + Constants.ONOVERFLOW_BLOCK + " | " + Constants.ONOVERFLOW_DEADMESSAGE + " [" + DEFAULT_onOverflow + "]\n";
00121     //text += string("   -queue/connection/onFailure    What happens if the data sink connection has a failure [" + DEFAULT_onFailure + "]\n";
00122       return text;
00123    }
00124 
00125 }}}}} // namespace
00126 
00127 #ifdef _XMLBLASTER_CLASSTEST
00128 
00129 using namespace std;
00130 using namespace org::xmlBlaster::util::qos::storage;
00131 
00133 int main(int args, char* argv[])
00134 {
00135    Global& glob = Global::getInstance();
00136    glob.initialize(args, argv);
00137    ClientQueueProperty prop(glob, "");
00138    cout << prop.toXml() << endl;
00139    Address adr(glob, "EMAIL");
00140    adr.setAddress("et@mars.sun");
00141    prop.setAddress(adr);
00142    cout << prop.toXml() << endl;
00143 }
00144 
00145 #endif