diff options
author | Matthew Newhook <matthew@zeroc.com> | 2007-06-12 10:10:27 +0800 |
---|---|---|
committer | Matthew Newhook <matthew@zeroc.com> | 2007-06-12 10:10:27 +0800 |
commit | dad94809b45711bfcc23f33f2ac7ad89c6460c8c (patch) | |
tree | 26747d77dd0f225418ca45c5c265c552ebfa6ba6 /cpp/demo | |
parent | added .gitignore updates. (diff) | |
download | ice-dad94809b45711bfcc23f33f2ac7ad89c6460c8c.tar.bz2 ice-dad94809b45711bfcc23f33f2ac7ad89c6460c8c.tar.xz ice-dad94809b45711bfcc23f33f2ac7ad89c6460c8c.zip |
http://bugzilla.zeroc.com/bugzilla/show_bug.cgi?id=2231
Diffstat (limited to 'cpp/demo')
-rw-r--r-- | cpp/demo/Freeze/customEvictor/Client.cpp | 71 | ||||
-rw-r--r-- | cpp/demo/Freeze/customEvictor/CurrentDatabase.cpp | 19 | ||||
-rw-r--r-- | cpp/demo/Freeze/customEvictor/CurrentDatabase.h | 1 | ||||
-rw-r--r-- | cpp/demo/Freeze/customEvictor/Evictor.cpp | 36 | ||||
-rw-r--r-- | cpp/demo/Freeze/customEvictor/Evictor.h | 3 | ||||
-rw-r--r-- | cpp/demo/Freeze/customEvictor/EvictorBase.cpp | 13 | ||||
-rw-r--r-- | cpp/demo/Freeze/customEvictor/EvictorBase.h | 14 | ||||
-rw-r--r-- | cpp/demo/Freeze/customEvictor/ItemI.cpp | 10 | ||||
-rwxr-xr-x | cpp/demo/Freeze/customEvictor/Makefile.mak | 4 | ||||
-rw-r--r-- | cpp/demo/Freeze/customEvictor/Server.cpp | 4 | ||||
-rw-r--r-- | cpp/demo/Freeze/customEvictor/SimpleEvictor.cpp | 2 | ||||
-rw-r--r-- | cpp/demo/Freeze/customEvictor/SimpleEvictor.h | 3 | ||||
-rw-r--r-- | cpp/demo/Freeze/customEvictor/config.client | 4 | ||||
-rw-r--r-- | cpp/demo/Freeze/customEvictor/config.server | 8 |
14 files changed, 87 insertions, 105 deletions
diff --git a/cpp/demo/Freeze/customEvictor/Client.cpp b/cpp/demo/Freeze/customEvictor/Client.cpp index aa28debb0c9..e11ab96f351 100644 --- a/cpp/demo/Freeze/customEvictor/Client.cpp +++ b/cpp/demo/Freeze/customEvictor/Client.cpp @@ -33,43 +33,13 @@ main(int argc, char* argv[]) return app.main(argc, argv, "config.client"); } -class StopWatch -{ -public: - - void - start() - { - _stopped = false; - _start = IceUtil::Time::now(); - } - - IceUtil::Time - stop() - { - if(!_stopped) - { - _stopped = true; - _stop = IceUtil::Time::now(); - } - - return _stop - _start; - } - -private: - - bool _stopped; - IceUtil::Time _start; - IceUtil::Time _stop; -}; - class ReaderThread : public IceUtil::Thread { public: - ReaderThread(ItemPrx anItem) - : _anItem(anItem), - _requestsPerSecond(-1) + ReaderThread(const ItemPrx& anItem) : + _anItem(anItem), + _requestsPerSecond(-1) { } @@ -78,8 +48,7 @@ public: // // Measures how long it takes to read 'readCount' items at random // - StopWatch stopWatch; - stopWatch.start(); + IceUtil::Time start = IceUtil::Time::now(); try { @@ -95,7 +64,7 @@ public: ItemPrx item = ItemPrx::uncheckedCast(_anItem->ice_identity(identity)); item->getDescription(); } - _requestsPerSecond = static_cast<int>(readCount / stopWatch.stop().toSecondsDouble()); + _requestsPerSecond = static_cast<int>(readCount / (IceUtil::Time::now() - start).toSecondsDouble()); } catch(const IceUtil::Exception& e) { @@ -110,20 +79,18 @@ public: private: - ItemPrx _anItem; + const ItemPrx _anItem; int _requestsPerSecond; }; - typedef IceUtil::Handle<ReaderThread> ReaderThreadPtr; - class WriterThread : public IceUtil::Thread { public: - WriterThread(ItemPrx anItem) - : _anItem(anItem), - _requestsPerSecond(-1) + WriterThread(const ItemPrx& anItem) : + _anItem(anItem), + _requestsPerSecond(-1) { } @@ -132,8 +99,7 @@ public: // // Measure how long it takes to write 'writeCount' items at random // - StopWatch stopWatch; - stopWatch.start(); + IceUtil::Time start = IceUtil::Time::now(); try { @@ -151,7 +117,7 @@ public: item->adjustStock(1); } - _requestsPerSecond = static_cast<int>(writeCount / stopWatch.stop().toSecondsDouble()); + _requestsPerSecond = static_cast<int>(writeCount / (IceUtil::Time::now() - start).toSecondsDouble()); } catch(const IceUtil::Exception& e) { @@ -166,13 +132,11 @@ public: private: - ItemPrx _anItem; + const ItemPrx _anItem; int _requestsPerSecond; }; - typedef IceUtil::Handle<WriterThread> WriterThreadPtr; - int WarehouseClient::run(int argc, char* argv[]) { @@ -189,7 +153,6 @@ WarehouseClient::run(int argc, char* argv[]) const int readerCount = 5; - ReaderThreadPtr rt[readerCount]; int i; for(i = 0; i < readerCount; ++i) @@ -198,9 +161,7 @@ WarehouseClient::run(int argc, char* argv[]) rt[i]->start(); } - wt->getThreadControl().join(); - for(i = 0; i < readerCount; ++i) { rt[i]->getThreadControl().join(); @@ -209,24 +170,22 @@ WarehouseClient::run(int argc, char* argv[]) // // Display results: // - cout.precision(3); int rpt = wt->getRequestsPerSecond(); if(rpt > 0) { cout << "Writer: " << rpt << " requests per second (" << 1000.0 / rpt << " ms per request)" << endl; } - + for(i = 0; i < readerCount; ++i) { rpt = rt[i]->getRequestsPerSecond(); if(rpt > 0) { - cout << "Reader " << i << ": " << rt[i]->getRequestsPerSecond() - << " requests per second (" << 1000.0 / rpt << " ms per request)" << endl; + cout << "Reader " << i << ": " << rpt << " requests per second (" << 1000.0 / rpt + << " ms per request)" << endl; } } return EXIT_SUCCESS; } - diff --git a/cpp/demo/Freeze/customEvictor/CurrentDatabase.cpp b/cpp/demo/Freeze/customEvictor/CurrentDatabase.cpp index 9bd8f601760..357cfa69d56 100644 --- a/cpp/demo/Freeze/customEvictor/CurrentDatabase.cpp +++ b/cpp/demo/Freeze/customEvictor/CurrentDatabase.cpp @@ -11,10 +11,11 @@ #include <CurrentDatabase.h> using namespace std; +using namespace IceUtil; // -// This implementation is very simple but not restartable, i.e. -// you can only create and destroy one CurrentDatabase per process run. +// This implementation is very simple but not restartable, i.e. you +// can only create and destroy one CurrentDatabase per process run. // #ifdef _MSC_VER @@ -32,11 +33,10 @@ __thread Database* db = 0; } - -CurrentDatabase::CurrentDatabase(const Ice::CommunicatorPtr& communicator, const string& envName, const string& dbName) - : _communicator(communicator), - _envName(envName), - _dbName(dbName) +CurrentDatabase::CurrentDatabase(const Ice::CommunicatorPtr& comm, const string& envName, const string& dbName) : + _communicator(comm), + _envName(envName), + _dbName(dbName) { } @@ -56,10 +56,9 @@ CurrentDatabase::get() { Freeze::ConnectionPtr connection = Freeze::createConnection(_communicator, _envName); db = new Database(connection, _dbName); + + Mutex::Lock sync(_dbListMutex); _dbList.push_back(db); } return *db; } - - - diff --git a/cpp/demo/Freeze/customEvictor/CurrentDatabase.h b/cpp/demo/Freeze/customEvictor/CurrentDatabase.h index 4e67a089ac9..dcc0231ce9d 100644 --- a/cpp/demo/Freeze/customEvictor/CurrentDatabase.h +++ b/cpp/demo/Freeze/customEvictor/CurrentDatabase.h @@ -32,6 +32,7 @@ private: const Ice::CommunicatorPtr _communicator; const std::string _envName; const std::string _dbName; + IceUtil::Mutex _dbListMutex; std::list<Database*> _dbList; }; diff --git a/cpp/demo/Freeze/customEvictor/Evictor.cpp b/cpp/demo/Freeze/customEvictor/Evictor.cpp index 0f624f7b6fa..a4b93688396 100644 --- a/cpp/demo/Freeze/customEvictor/Evictor.cpp +++ b/cpp/demo/Freeze/customEvictor/Evictor.cpp @@ -20,9 +20,8 @@ int cacheMisses = 0; // // Cache // - -EvictorCache::EvictorCache(CurrentDatabase& currentDb) - : _currentDb(currentDb) +EvictorCache::EvictorCache(CurrentDatabase& currentDb) : + _currentDb(currentDb) { } @@ -63,12 +62,13 @@ EvictorCache::load(const Ice::Identity& itemId) } // -// Finish to initialize the entry after it has been inserted in the Cache map, -// but before any other thread can find it. -// pinned() is called while IceUtil::Cache's internal mutex is locked, so -// we must be careful with lock acquisition order. For example we cannot acquire -// the Evictor mutex here, since we also call IceUtil::Cache with the Evictor mutex -// locked. +// Finish to initialize the entry after it has been inserted in the +// Cache map, but before any other thread can find it. +// +// pinned() is called while IceUtil::Cache's internal mutex is locked, +// so we must be careful with lock acquisition order. For example we +// cannot acquire the Evictor mutex here, since we also call +// IceUtil::Cache with the Evictor mutex locked. // void EvictorCache::pinned(const EvictorEntryPtr& entry, EvictorCache::Position cp) @@ -77,15 +77,14 @@ EvictorCache::pinned(const EvictorEntryPtr& entry, EvictorCache::Position cp) entry->cachePosition = cp; } - // // EvictorEntry // -EvictorEntry::EvictorEntry(const ItemIPtr& item) - : servant(item), - useCount(-1), - stale(true) +EvictorEntry::EvictorEntry(const ItemIPtr& item) : + servant(item), + useCount(-1), + stale(true) { } @@ -93,10 +92,10 @@ EvictorEntry::EvictorEntry(const ItemIPtr& item) // Evictor // -Evictor::Evictor(CurrentDatabase& currentDb, int size) - : _cache(currentDb), - _queueSize(0), - _size(size) +Evictor::Evictor(CurrentDatabase& currentDb, int size) : + _cache(currentDb), + _queueSize(0), + _size(size) { } @@ -180,7 +179,6 @@ Evictor::finished(const Ice::Current& current, const Ice::ObjectPtr& servant, } } - void Evictor::deactivate(const string& category) { diff --git a/cpp/demo/Freeze/customEvictor/Evictor.h b/cpp/demo/Freeze/customEvictor/Evictor.h index 05189afed1b..d091309a4e2 100644 --- a/cpp/demo/Freeze/customEvictor/Evictor.h +++ b/cpp/demo/Freeze/customEvictor/Evictor.h @@ -16,7 +16,6 @@ #include <ItemI.h> #include <list> - struct EvictorEntry; typedef IceUtil::Handle<EvictorEntry> EvictorEntryPtr; @@ -62,13 +61,11 @@ struct EvictorEntry : public Ice::LocalObject bool stale; // stale is true when the entry is no longer (or not yet) in the Cache map }; - class Evictor : public Ice::ServantLocator { public: Evictor(CurrentDatabase&, int); - virtual Ice::ObjectPtr locate(const Ice::Current&, Ice::LocalObjectPtr&); virtual void finished(const Ice::Current&, const Ice::ObjectPtr&, const Ice::LocalObjectPtr&); diff --git a/cpp/demo/Freeze/customEvictor/EvictorBase.cpp b/cpp/demo/Freeze/customEvictor/EvictorBase.cpp index ed41cfbaba4..e8e2d7bccf3 100644 --- a/cpp/demo/Freeze/customEvictor/EvictorBase.cpp +++ b/cpp/demo/Freeze/customEvictor/EvictorBase.cpp @@ -1,7 +1,16 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2007 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + #include <EvictorBase.h> -EvictorBase::EvictorBase(Ice::Int size) - : _size(size) +EvictorBase::EvictorBase(Ice::Int size) : + _size(size) { if (_size < 0) { diff --git a/cpp/demo/Freeze/customEvictor/EvictorBase.h b/cpp/demo/Freeze/customEvictor/EvictorBase.h index 79a6a5b22b6..2f1cfa3fd69 100644 --- a/cpp/demo/Freeze/customEvictor/EvictorBase.h +++ b/cpp/demo/Freeze/customEvictor/EvictorBase.h @@ -1,5 +1,14 @@ -#ifndef EVICTORBASE_H -#define EVICTORBASE_H +// ********************************************************************** +// +// Copyright (c) 2003-2007 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#ifndef EVICTOR_BASE_H +#define EVICTOR_BASE_H #include <Ice/ServantLocator.h> #include <IceUtil/Handle.h> @@ -46,7 +55,6 @@ private: void evictServants(); }; - typedef IceUtil::Handle<EvictorBase> EvictorBasePtr; #endif diff --git a/cpp/demo/Freeze/customEvictor/ItemI.cpp b/cpp/demo/Freeze/customEvictor/ItemI.cpp index 02f750fec8b..3f7e7d3b282 100644 --- a/cpp/demo/Freeze/customEvictor/ItemI.cpp +++ b/cpp/demo/Freeze/customEvictor/ItemI.cpp @@ -11,11 +11,11 @@ using namespace std; using namespace IceUtil; +using namespace Warehouse; - -ItemI::ItemI(CurrentDatabase& currentDb, const Warehouse::ItemInfo& info) - : _currentDb(currentDb), - _cachedInfo(info) +ItemI::ItemI(CurrentDatabase& currentDb, const ItemInfo& info) : + _currentDb(currentDb), + _cachedInfo(info) { } @@ -63,7 +63,7 @@ ItemI::adjustStock(int value, const Ice::Current& current) int newQuantity = _cachedInfo.quantityInStock + value; if(newQuantity < 0) { - throw Warehouse::OutOfStock(); + throw OutOfStock(); } _cachedInfo.quantityInStock = newQuantity; save(current); diff --git a/cpp/demo/Freeze/customEvictor/Makefile.mak b/cpp/demo/Freeze/customEvictor/Makefile.mak index bc5cd44bb2a..6acd6a92801 100755 --- a/cpp/demo/Freeze/customEvictor/Makefile.mak +++ b/cpp/demo/Freeze/customEvictor/Makefile.mak @@ -43,7 +43,6 @@ SPDBFLAGS = /pdb:$(SERVER:.exe=.pdb) COPDBFLAGS = /pdb:$(COLLOCATED:.exe=.pdb) !endif - $(CLIENT): $(OBJS) $(COBJS) $(LINK) $(LD_EXEFLAGS) $(CPDBFLAGS) $(SETARGV) $(OBJS) $(COBJS) $(PREOUT)$@ $(PRELIBS)$(LIBS) @if exist $@.manifest echo ^ ^ ^ Embedding manifest using $(MT) && \ @@ -54,7 +53,6 @@ $(SERVER): $(OBJS) $(SOBJS) @if exist $@.manifest echo ^ ^ ^ Embedding manifest using $(MT) && \ $(MT) -nologo -manifest $@.manifest -outputresource:$@;#1 && del /q $@.manifest - Database.h Database.cpp: ItemInfo.ice $(SLICE2FREEZE) del /q Database.h Database.cpp $(SLICE2FREEZE) -I$(slicedir) --dict Database,string,Warehouse::ItemInfo Database ItemInfo.ice @@ -66,5 +64,7 @@ clean:: cleandb del /q Item.h Item.cpp del /q ItemInfo.h ItemInfo.cpp del /q Database.h Database.cpp + del /q Item.cpp Item.h + del /q ItemInfo.cpp ItemInfo.h include .depend diff --git a/cpp/demo/Freeze/customEvictor/Server.cpp b/cpp/demo/Freeze/customEvictor/Server.cpp index 81ece9ace69..190f684e4e1 100644 --- a/cpp/demo/Freeze/customEvictor/Server.cpp +++ b/cpp/demo/Freeze/customEvictor/Server.cpp @@ -16,6 +16,7 @@ #include <SimpleEvictor.h> using namespace std; +using namespace Warehouse; const int objectCount = 10000; const int evictorSize = 8000; @@ -34,7 +35,6 @@ main(int argc, char* argv[]) return app.main(argc, argv, "config.server"); } - int WarehouseServer::run(int argc, char* argv[]) { @@ -67,7 +67,7 @@ WarehouseServer::run(int argc, char* argv[]) // // Populate database with objectCount entries // - Warehouse::ItemInfo info; + ItemInfo info; connection->beginTransaction(); diff --git a/cpp/demo/Freeze/customEvictor/SimpleEvictor.cpp b/cpp/demo/Freeze/customEvictor/SimpleEvictor.cpp index 3b872d5025f..18b01e1d78f 100644 --- a/cpp/demo/Freeze/customEvictor/SimpleEvictor.cpp +++ b/cpp/demo/Freeze/customEvictor/SimpleEvictor.cpp @@ -61,7 +61,7 @@ SimpleEvictor::add(const Ice::Current& current, Ice::LocalObjectPtr& cookie) } void -SimpleEvictor::evict(const Ice::ObjectPtr& current, const Ice::LocalObjectPtr&) +SimpleEvictor::evict(const Ice::ObjectPtr&, const Ice::LocalObjectPtr&) { // // Nothing to do diff --git a/cpp/demo/Freeze/customEvictor/SimpleEvictor.h b/cpp/demo/Freeze/customEvictor/SimpleEvictor.h index c0737e79dfe..0c270cc0fa9 100644 --- a/cpp/demo/Freeze/customEvictor/SimpleEvictor.h +++ b/cpp/demo/Freeze/customEvictor/SimpleEvictor.h @@ -18,7 +18,7 @@ class SimpleEvictor : public EvictorBase { public: - SimpleEvictor(CurrentDatabase& db, int size); + SimpleEvictor(CurrentDatabase&, int); protected: @@ -28,7 +28,6 @@ protected: private: CurrentDatabase& _currentDb; - int _size; }; #endif diff --git a/cpp/demo/Freeze/customEvictor/config.client b/cpp/demo/Freeze/customEvictor/config.client index 0931f742fd0..85af0e37fae 100644 --- a/cpp/demo/Freeze/customEvictor/config.client +++ b/cpp/demo/Freeze/customEvictor/config.client @@ -1 +1,5 @@ +# +# The client reads this property to create the reference to an +# "item" object in the server. +# Item.Proxy="P\/N 5":tcp -p 10000 diff --git a/cpp/demo/Freeze/customEvictor/config.server b/cpp/demo/Freeze/customEvictor/config.server index 59bd7ed130e..b77445b9d93 100644 --- a/cpp/demo/Freeze/customEvictor/config.server +++ b/cpp/demo/Freeze/customEvictor/config.server @@ -1,5 +1,13 @@ +# +# The server creates one single object adapter with the name +# "Warehouse". The following line sets the endpoints for this adapter. +# Warehouse.Endpoints=tcp -p 10000 +# +# Configure 10 threads in the server side thread pool. Setting +# SizeWarn to -1 disables warnings if we start to run out of threads. +# Ice.ThreadPool.Server.Size=10 Ice.ThreadPool.Server.SizeWarn=-1 |