diff options
author | Benoit Foucher <benoit@zeroc.com> | 2005-09-19 11:30:42 +0000 |
---|---|---|
committer | Benoit Foucher <benoit@zeroc.com> | 2005-09-19 11:30:42 +0000 |
commit | 1634cdc345838ea72ea812df48bb998a70d40118 (patch) | |
tree | 9cf08ac084e939b7827d278acc472effa6bf974a /cpp/demo/IceGrid | |
parent | adding IceGrid slice to the makedist.py script (diff) | |
download | ice-1634cdc345838ea72ea812df48bb998a70d40118.tar.bz2 ice-1634cdc345838ea72ea812df48bb998a70d40118.tar.xz ice-1634cdc345838ea72ea812df48bb998a70d40118.zip |
Added simple demo
Diffstat (limited to 'cpp/demo/IceGrid')
-rw-r--r-- | cpp/demo/IceGrid/simple/Client.cpp | 102 | ||||
-rw-r--r-- | cpp/demo/IceGrid/simple/Hello.ice | 24 | ||||
-rw-r--r-- | cpp/demo/IceGrid/simple/HelloI.cpp | 30 | ||||
-rw-r--r-- | cpp/demo/IceGrid/simple/HelloI.h | 29 | ||||
-rw-r--r-- | cpp/demo/IceGrid/simple/Makefile | 43 | ||||
-rw-r--r-- | cpp/demo/IceGrid/simple/README | 33 | ||||
-rw-r--r-- | cpp/demo/IceGrid/simple/Server.cpp | 41 | ||||
-rw-r--r-- | cpp/demo/IceGrid/simple/application.xml | 27 | ||||
-rw-r--r-- | cpp/demo/IceGrid/simple/application_with_replication.xml | 37 | ||||
-rw-r--r-- | cpp/demo/IceGrid/simple/application_with_template.xml | 32 | ||||
-rw-r--r-- | cpp/demo/IceGrid/simple/db/node/.dummy | 0 | ||||
-rw-r--r-- | cpp/demo/IceGrid/simple/db/registry/.dummy | 0 |
12 files changed, 398 insertions, 0 deletions
diff --git a/cpp/demo/IceGrid/simple/Client.cpp b/cpp/demo/IceGrid/simple/Client.cpp new file mode 100644 index 00000000000..284d7c6554b --- /dev/null +++ b/cpp/demo/IceGrid/simple/Client.cpp @@ -0,0 +1,102 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2005 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 <Ice/Ice.h> +#include <Hello.h> + +using namespace std; +using namespace Demo; + +class HelloClient : public Ice::Application +{ +public: + + virtual int run(int, char*[]); + +private: + + void menu(); +}; + +int +main(int argc, char* argv[]) +{ + HelloClient app; + return app.main(argc, argv, "config"); +} + +void +HelloClient::menu() +{ + cout << + "usage:\n" + "t: send greeting\n" + "s: shutdown server\n" + "x: exit\n" + "?: help\n"; +} + +int +HelloClient::run(int argc, char* argv[]) +{ + Ice::PropertiesPtr properties = communicator()->getProperties(); + + Ice::StringSeq args = Ice::argsToStringSeq(argc, argv); + args = properties->parseCommandLineOptions("", args); + Ice::stringSeqToArgs(args, argc, argv); + + Ice::ObjectPrx base = communicator()->stringToProxy(properties->getPropertyWithDefault("Identity", "hello")); + HelloPrx twoway = HelloPrx::checkedCast(base); + if(!twoway) + { + cerr << argv[0] << ": invalid proxy" << endl; + return EXIT_FAILURE; + } + + menu(); + + char c; + do + { + try + { + cout << "==> "; + cin >> c; + if(c == 't') + { + twoway->sayHello(); + } + else if(c == 's') + { + twoway->shutdown(); + } + else if(c == 'x') + { + // Nothing to do + } + else if(c == '?') + { + menu(); + } + else + { + cout << "unknown command `" << c << "'" << endl; + menu(); + } + } + catch(const Ice::Exception& ex) + { + cerr << ex << endl; + } + } + while(cin.good() && c != 'x'); + + return EXIT_SUCCESS; +} + diff --git a/cpp/demo/IceGrid/simple/Hello.ice b/cpp/demo/IceGrid/simple/Hello.ice new file mode 100644 index 00000000000..176763722ce --- /dev/null +++ b/cpp/demo/IceGrid/simple/Hello.ice @@ -0,0 +1,24 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2005 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 HELLO_ICE +#define HELLO_ICE + +module Demo +{ + +interface Hello +{ + nonmutating void sayHello(); + idempotent void shutdown(); +}; + +}; + +#endif diff --git a/cpp/demo/IceGrid/simple/HelloI.cpp b/cpp/demo/IceGrid/simple/HelloI.cpp new file mode 100644 index 00000000000..bfd9f035498 --- /dev/null +++ b/cpp/demo/IceGrid/simple/HelloI.cpp @@ -0,0 +1,30 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2005 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 <Ice/Ice.h> +#include <HelloI.h> + +using namespace std; + +HelloI::HelloI(const string& name) : _name(name) +{ +} + +void +HelloI::sayHello(const Ice::Current&) const +{ + cout << _name << " says Hello World!" << endl; +} + +void +HelloI::shutdown(const Ice::Current& c) +{ + cout << _name << " shutting down..." << endl; + c.adapter->getCommunicator()->shutdown(); +} diff --git a/cpp/demo/IceGrid/simple/HelloI.h b/cpp/demo/IceGrid/simple/HelloI.h new file mode 100644 index 00000000000..7260a3914b9 --- /dev/null +++ b/cpp/demo/IceGrid/simple/HelloI.h @@ -0,0 +1,29 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2005 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 HELLO_I_H +#define HELLO_I_H + +#include <Hello.h> + +class HelloI : public Demo::Hello +{ +public: + + HelloI(const std::string&); + + virtual void sayHello(const Ice::Current&) const; + virtual void shutdown(const Ice::Current&); + +private: + + const std::string _name; +}; + +#endif diff --git a/cpp/demo/IceGrid/simple/Makefile b/cpp/demo/IceGrid/simple/Makefile new file mode 100644 index 00000000000..5581010a29b --- /dev/null +++ b/cpp/demo/IceGrid/simple/Makefile @@ -0,0 +1,43 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2005 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. +# +# ********************************************************************** + +top_srcdir = ../../.. + +CLIENT = client +SERVER = server + +TARGETS = $(CLIENT) $(SERVER) + +OBJS = Hello.o + +COBJS = Client.o + +SOBJS = HelloI.o \ + Server.o + +SRCS = $(OBJS:.o=.cpp) \ + $(COBJS:.o=.cpp) \ + $(SOBJS:.o=.cpp) \ + +SLICE_SRCS = Hello.ice + +include $(top_srcdir)/config/Make.rules + +CPPFLAGS := -I. $(CPPFLAGS) +LINKWITH := -lIce -lIceUtil + +$(CLIENT): $(OBJS) $(COBJS) + rm -f $@ + $(CXX) $(LDFLAGS) -o $@ $(OBJS) $(COBJS) $(LIBS) + +$(SERVER): $(OBJS) $(SOBJS) + rm -f $@ + $(CXX) $(LDFLAGS) -o $@ $(OBJS) $(SOBJS) $(LIBS) + +include .depend diff --git a/cpp/demo/IceGrid/simple/README b/cpp/demo/IceGrid/simple/README new file mode 100644 index 00000000000..3ab5067c9fc --- /dev/null +++ b/cpp/demo/IceGrid/simple/README @@ -0,0 +1,33 @@ +To run the demo, first start the IceGrid service: + +$ icegridnode --Ice.Config=config --warn + +In a separate window: + +$ icegridadmin --Ice.Config=config -e "application add 'application.xml'" +$ client + +This will deploy the servers described in the file "application.xml" +and start the client. + +Messages will be displayed in the IceGrid service window. + +To remove the application: + +$ icegridadmin --Ice.Config=config -e "application remove Simple" + +You can also use the following descriptors to deploy the application: + +- application_with_templates.xml: This descriptor demonstrates the use + of templates for the server definition. Templates make it easy to + deploy multiple instances of the same server. To deploy a new server + based on the template, use the following command: + + $ icegridadmin --Ice.Config=config -e "server template instantiate \ + Simple localhost SimpleServer index=2" + + This will deploy a new server based on the `SimpleServer' template. + +- application_with_replication.xml: This descriptor demonstrates the + use of replication to balance the load of the application over + several servers. diff --git a/cpp/demo/IceGrid/simple/Server.cpp b/cpp/demo/IceGrid/simple/Server.cpp new file mode 100644 index 00000000000..be48b4031cd --- /dev/null +++ b/cpp/demo/IceGrid/simple/Server.cpp @@ -0,0 +1,41 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2005 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 <Ice/Ice.h> +#include <HelloI.h> + +using namespace std; + +class Server : public Ice::Application +{ +public: + + virtual int run(int argc, char* argv[]); + +}; + +int +main(int argc, char* argv[]) +{ + Server app; + int status = app.main(argc, argv); + return status; +} + +int +Server::run(int argc, char* argv[]) +{ + Ice::PropertiesPtr properties = communicator()->getProperties(); + Ice::ObjectAdapterPtr adapter = communicator()->createObjectAdapter("Hello"); + Ice::Identity id = Ice::stringToIdentity(properties->getProperty("Identity")); + adapter->add(new HelloI(properties->getProperty("Ice.ServerId")), id); + adapter->activate(); + communicator()->waitForShutdown(); + return EXIT_SUCCESS; +} diff --git a/cpp/demo/IceGrid/simple/application.xml b/cpp/demo/IceGrid/simple/application.xml new file mode 100644 index 00000000000..9c10696b34c --- /dev/null +++ b/cpp/demo/IceGrid/simple/application.xml @@ -0,0 +1,27 @@ +<!-- + ********************************************************************** + + Copyright (c) 2003-2005 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. + + ********************************************************************** +--> + +<icegrid> + + <application name="Simple"> + + <node name="localhost"> + <server id="SimpleServer" exe="./server" pwd="."> + <adapter name="Hello" endpoints="tcp" register="true"> + <object identity="hello" type="::Hello"/> + </adapter> + <property name="Identity" value="hello"/> + </server> + </node> + + </application> + +</icegrid> diff --git a/cpp/demo/IceGrid/simple/application_with_replication.xml b/cpp/demo/IceGrid/simple/application_with_replication.xml new file mode 100644 index 00000000000..5fc537a6280 --- /dev/null +++ b/cpp/demo/IceGrid/simple/application_with_replication.xml @@ -0,0 +1,37 @@ +<!-- + ********************************************************************** + + Copyright (c) 2003-2005 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. + + ********************************************************************** +--> + +<icegrid> + + <application name="Simple"> + + <server-template id="SimpleServer"> + <parameter name="index"/> + <server id="SimpleServer-${index}" exe="./server" pwd="." activation="on-demand"> + <adapter name="Hello" endpoints="tcp" register="true" id="ReplicatedHelloAdapter"/> + <property name="Identity" value="hello"/> + </server> + </server-template> + + <replicated-adapter id="ReplicatedHelloAdapter"> + <load-balancing type="round-robin"/> + <object identity="hello" type="::Demo::Hello"/> + </replicated-adapter> + + <node name="localhost"> + <server-instance template="SimpleServer" index="1"/> + <server-instance template="SimpleServer" index="2"/> + <server-instance template="SimpleServer" index="3"/> + </node> + + </application> + +</icegrid> diff --git a/cpp/demo/IceGrid/simple/application_with_template.xml b/cpp/demo/IceGrid/simple/application_with_template.xml new file mode 100644 index 00000000000..6ef9acba0bd --- /dev/null +++ b/cpp/demo/IceGrid/simple/application_with_template.xml @@ -0,0 +1,32 @@ +<!-- + ********************************************************************** + + Copyright (c) 2003-2005 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. + + ********************************************************************** +--> + +<icegrid> + + <application name="Simple"> + + <server-template id="SimpleServer"> + <parameter name="index"/> + <server id="SimpleServer-${index}" exe="./server" pwd="."> + <adapter name="Hello" endpoints="tcp" register="true"> + <object identity="hello-${index}" type="::Hello"/> + </adapter> + <property name="Identity" value="hello-${index}"/> + </server> + </server-template> + + <node name="localhost"> + <server-instance template="SimpleServer" index="1"/> + </node> + + </application> + +</icegrid> diff --git a/cpp/demo/IceGrid/simple/db/node/.dummy b/cpp/demo/IceGrid/simple/db/node/.dummy new file mode 100644 index 00000000000..e69de29bb2d --- /dev/null +++ b/cpp/demo/IceGrid/simple/db/node/.dummy diff --git a/cpp/demo/IceGrid/simple/db/registry/.dummy b/cpp/demo/IceGrid/simple/db/registry/.dummy new file mode 100644 index 00000000000..e69de29bb2d --- /dev/null +++ b/cpp/demo/IceGrid/simple/db/registry/.dummy |