Skip to content

Commit

Permalink
Update tests and demos to use ValueFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
externl committed Dec 10, 2015
1 parent 3ff0f0e commit 497bf0a
Show file tree
Hide file tree
Showing 28 changed files with 107 additions and 208 deletions.
7 changes: 1 addition & 6 deletions cpp/demo/Freeze/bench/Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ TestApp::IntIntMapReadTest(const string& mapName, T*)
*/
}

class MyFactory : public Ice::ObjectFactory
class MyFactory : public Ice::ValueFactory
{
public:

Expand All @@ -690,11 +690,6 @@ class MyFactory : public Ice::ObjectFactory
}
return 0;
}

void
destroy()
{
}
};
typedef IceUtil::Handle<MyFactory> MyFactoryPtr;

Expand Down
13 changes: 4 additions & 9 deletions cpp/demo/Freeze/casino/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ main(int argc, char* argv[])
}

template<class T>
class ObjectFactory : public Ice::ObjectFactory
class ValueFactory : public Ice::ValueFactory
{
public:

Expand All @@ -52,11 +52,6 @@ class ObjectFactory : public Ice::ObjectFactory
{
return new T;
}

virtual void
destroy()
{
}
};

int
Expand Down Expand Up @@ -90,9 +85,9 @@ CasinoServer::run(int argc, char*[])
//
// Register factories
//
communicator()->addObjectFactory(new ObjectFactory<BankI>, CasinoStore::PersistentBank::ice_staticId());
communicator()->addObjectFactory(new ObjectFactory<PlayerI>, CasinoStore::PersistentPlayer::ice_staticId());
communicator()->addObjectFactory(new ObjectFactory<BetI>, CasinoStore::PersistentBet::ice_staticId());
communicator()->addValueFactory(new ValueFactory<BankI>, CasinoStore::PersistentBank::ice_staticId());
communicator()->addValueFactory(new ValueFactory<PlayerI>, CasinoStore::PersistentPlayer::ice_staticId());
communicator()->addValueFactory(new ValueFactory<BetI>, CasinoStore::PersistentBet::ice_staticId());

//
// Create evictors; each type gets its own type-specific evictor
Expand Down
9 changes: 0 additions & 9 deletions cpp/demo/Freeze/library/BookFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,3 @@ BookFactory::create(const string&)
assert(type == "::Demo::Book");
return new BookI(_library);
}

void
BookFactory::destroy()
{
//
// Break cyclic object dependencies
//
_library = 0;
}
5 changes: 2 additions & 3 deletions cpp/demo/Freeze/library/BookFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,16 @@

#include <LibraryI.h>

class BookFactory : public Ice::ObjectFactory
class BookFactory : public Ice::ValueFactory
{
public:

BookFactory(const LibraryIPtr&);

//
// Operations from ObjectFactory
// Operations from ValueFactory
//
virtual Ice::ObjectPtr create(const std::string&);
virtual void destroy();

private:

Expand Down
14 changes: 7 additions & 7 deletions cpp/demo/Freeze/library/Collocated.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ using namespace std;
class LibraryCollocated : public Ice::Application
{
public:

LibraryCollocated(const string&);

virtual int run(int argc, char* argv[]);
Expand Down Expand Up @@ -45,7 +45,7 @@ int
LibraryCollocated::run(int argc, char* argv[])
{
Ice::PropertiesPtr properties = communicator()->getProperties();

//
// Create an object adapter
//
Expand All @@ -60,23 +60,23 @@ LibraryCollocated::run(int argc, char* argv[])
{
evictor->setSize(evictorSize);
}

//
// Use the evictor as servant Locator.
//
adapter->addServantLocator(evictor, "book");

//
// Create the library, and add it to the Object Adapter.
//
LibraryIPtr library = new LibraryI(communicator(), _envName, "authors", evictor);
adapter->add(library, communicator()->stringToIdentity("library"));

//
// Create and install a factory for books.
//
Ice::ObjectFactoryPtr bookFactory = new BookFactory(library);
communicator()->addObjectFactory(bookFactory, Demo::Book::ice_staticId());
Ice::ValueFactoryPtr bookFactory = new BookFactory(library);
communicator()->addValueFactory(bookFactory, Demo::Book::ice_staticId());

//
// Everything ok, let's go.
Expand Down
14 changes: 7 additions & 7 deletions cpp/demo/Freeze/library/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ using namespace std;
class LibraryServer : public Ice::Application
{
public:

LibraryServer(const string& envName) :
_envName(envName)
{
Expand Down Expand Up @@ -58,25 +58,25 @@ LibraryServer::run(int argc, char*[])
{
evictor->setSize(evictorSize);
}

//
// Use the evictor as servant Locator.
//
adapter->addServantLocator(evictor, "book");


//
// Create the library, and add it to the object adapter.
//
LibraryIPtr library = new LibraryI(communicator(), _envName, "authors", evictor);
adapter->add(library, communicator()->stringToIdentity("library"));

//
// Create and install a factory for books.
//
Ice::ObjectFactoryPtr bookFactory = new BookFactory(library);
communicator()->addObjectFactory(bookFactory, Demo::Book::ice_staticId());
Ice::ValueFactoryPtr bookFactory = new BookFactory(library);
communicator()->addValueFactory(bookFactory, Demo::Book::ice_staticId());

//
// Everything ok, let's go.
//
Expand Down
8 changes: 4 additions & 4 deletions cpp/demo/Freeze/phonebook/Collocated.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ using namespace std;
class PhoneBookCollocated : public Ice::Application
{
public:

PhoneBookCollocated(const string&);
virtual int run(int argc, char* argv[]);

Expand Down Expand Up @@ -49,7 +49,7 @@ PhoneBookCollocated::run(int argc, char* argv[])
// Create and install a factory for contacts.
//
ContactFactoryPtr contactFactory = new ContactFactory();
communicator()->addObjectFactory(contactFactory, Demo::Contact::ice_staticId());
communicator()->addValueFactory(contactFactory, Demo::Contact::ice_staticId());

//
// Create the name index.
Expand Down Expand Up @@ -87,13 +87,13 @@ PhoneBookCollocated::run(int argc, char* argv[])
// which cannot happen during createXXXEvictor().
//
contactFactory->setEvictor(evictor);

//
// Create the phonebook, and add it to the Object Adapter.
//
PhoneBookIPtr phoneBook = new PhoneBookI(evictor, contactFactory, index);
adapter->add(phoneBook, communicator()->stringToIdentity("phonebook"));

//
// Everything ok, let's go.
//
Expand Down
11 changes: 1 addition & 10 deletions cpp/demo/Freeze/phonebook/ContactFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,12 @@ ContactFactory::create(const string&)
return new ContactI(this);
}

void
ContactFactory::destroy()
{
//
// Break cyclic object dependencies
//
_evictor = 0;
}

void
ContactFactory::setEvictor(const Freeze::EvictorPtr& evictor)
{
_evictor = evictor;
}

Freeze::EvictorPtr
ContactFactory::getEvictor() const
{
Expand Down
7 changes: 3 additions & 4 deletions cpp/demo/Freeze/phonebook/ContactFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,20 @@

#include <Freeze/Freeze.h>

class ContactFactory : public Ice::ObjectFactory
class ContactFactory : public Ice::ValueFactory
{
public:

ContactFactory();

//
// Operations from ObjectFactory
// Operations from ValueFactory
//
virtual Ice::ObjectPtr create(const std::string&);
virtual void destroy();

void
setEvictor(const Freeze::EvictorPtr&);

Freeze::EvictorPtr
getEvictor() const;

Expand Down
12 changes: 6 additions & 6 deletions cpp/demo/Freeze/phonebook/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ using namespace Freeze;
class PhoneBookServer : public Ice::Application
{
public:

PhoneBookServer(const string& envName) :
_envName(envName)
{
Expand Down Expand Up @@ -44,13 +44,13 @@ PhoneBookServer::run(int argc, char*[])
}

Ice::PropertiesPtr properties = communicator()->getProperties();

//
// Create and install a factory for contacts.
//
ContactFactoryPtr contactFactory = new ContactFactory();
communicator()->addObjectFactory(contactFactory, Demo::Contact::ice_staticId());
communicator()->addValueFactory(contactFactory, Demo::Contact::ice_staticId());

//
// Create the name index.
//
Expand Down Expand Up @@ -86,13 +86,13 @@ PhoneBookServer::run(int argc, char*[])
// which cannot happen during createXXXEvictor().
//
contactFactory->setEvictor(evictor);

//
// Create the phonebook, and add it to the object adapter.
//
PhoneBookIPtr phoneBook = new PhoneBookI(evictor, contactFactory, index);
adapter->add(phoneBook, communicator()->stringToIdentity("phonebook"));

//
// Everything ok, let's go.
//
Expand Down
14 changes: 7 additions & 7 deletions cpp/test/Freeze/complex/Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ validate(const Complex::ComplexDict& m)
return EXIT_SUCCESS;
}

static const char* expressions[] =
static const char* expressions[] =
{
"2",
"10",
Expand Down Expand Up @@ -84,7 +84,7 @@ static void
usage(const char* name)
{
cerr << "Usage: " << name << " [options] validate|populate\n";
cerr <<
cerr <<
"Options:\n"
"--dbdir Location of the database directory.\n";
}
Expand All @@ -95,10 +95,10 @@ run(int argc, char* argv[], const Ice::CommunicatorPtr& communicator, Complex::C
//
// Register a factory for the node types.
//
Ice::ObjectFactoryPtr factory = new Complex::ObjectFactoryI;
communicator->addObjectFactory(factory, "::Complex::NumberNode");
communicator->addObjectFactory(factory, "::Complex::AddNode");
communicator->addObjectFactory(factory, "::Complex::MultiplyNode");
Ice::ValueFactoryPtr factory = new Complex::ValueFactoryI;
communicator->addValueFactory(factory, "::Complex::NumberNode");
communicator->addValueFactory(factory, "::Complex::AddNode");
communicator->addValueFactory(factory, "::Complex::MultiplyNode");

if(argc > 1 && strcmp(argv[1], "populate") == 0)
{
Expand All @@ -118,7 +118,7 @@ main(int argc, char* argv[])
{
int status;
Ice::CommunicatorPtr communicator;

string envName = "db";

try
Expand Down
9 changes: 2 additions & 7 deletions cpp/test/Freeze/complex/NodeI.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#define NODE_I_H

#include <Complex.h>
#include <Ice/ObjectFactory.h>
#include <Ice/ValueFactory.h>

namespace Complex
{
Expand Down Expand Up @@ -72,7 +72,7 @@ class MultiplyNodeI : public MultiplyNode
}
};

class ObjectFactoryI : public Ice::ObjectFactory
class ValueFactoryI : public Ice::ValueFactory
{
public:

Expand All @@ -94,11 +94,6 @@ class ObjectFactoryI : public Ice::ObjectFactory
assert(false);
return 0;
}

virtual void destroy()
{
// Nothing to do
}
};

} // End namespace Complex
Expand Down
Loading

0 comments on commit 497bf0a

Please sign in to comment.