diff options
author | Bernard Normier <bernard@zeroc.com> | 2007-11-19 16:13:27 -0500 |
---|---|---|
committer | Bernard Normier <bernard@zeroc.com> | 2007-11-19 16:13:27 -0500 |
commit | 224d603f59e98951b7ee4b2fa1ca2953edb9d3d5 (patch) | |
tree | 78643cddbb841f0566e89999e99dd97f91d905d6 /cpp | |
parent | Fixed bug #2543 (diff) | |
parent | Minor fix, added CHANGES comment for bug 2368 (diff) | |
download | ice-224d603f59e98951b7ee4b2fa1ca2953edb9d3d5.tar.bz2 ice-224d603f59e98951b7ee4b2fa1ca2953edb9d3d5.tar.xz ice-224d603f59e98951b7ee4b2fa1ca2953edb9d3d5.zip |
Merge branch 'master' of ssh://cvs.zeroc.com/home/git/ice
Diffstat (limited to 'cpp')
-rw-r--r-- | cpp/CHANGES | 4 | ||||
-rw-r--r-- | cpp/config/Make.rules.mak.icesl | 107 | ||||
-rwxr-xr-x | cpp/iceslmakedist.py | 447 | ||||
-rw-r--r-- | cpp/src/IceGrid/LocatorI.cpp | 229 | ||||
-rw-r--r-- | cpp/src/IceGrid/LocatorI.h | 34 | ||||
-rw-r--r-- | cpp/test/IceGrid/deployer/Server.cpp | 10 | ||||
-rw-r--r-- | cpp/test/IceGrid/replicaGroup/AllTests.cpp | 13 |
7 files changed, 742 insertions, 102 deletions
diff --git a/cpp/CHANGES b/cpp/CHANGES index a4f4c564177..bc9d442f3d4 100644 --- a/cpp/CHANGES +++ b/cpp/CHANGES @@ -1,6 +1,10 @@ Changes since version 3.2.X (binary incompatible) ------------------------------------------------- +- While resolving replica group endpoints, the IceGrig locator + implementation does not wait anymore for adapter activation if + another adapter is already active. + - Fixed a bug in FreezeScript that caused a failure when a script attempted to access the 'length' member of a string value. diff --git a/cpp/config/Make.rules.mak.icesl b/cpp/config/Make.rules.mak.icesl new file mode 100644 index 00000000000..bc859fdb443 --- /dev/null +++ b/cpp/config/Make.rules.mak.icesl @@ -0,0 +1,107 @@ +# ********************************************************************** +# +# 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. +# +# ********************************************************************** + +# +# Select an installation base directory. The directory will be created +# if it does not exist. +# +prefix = C:\IceSL-$(VERSION) + +# +# Define OPTIMIZE as yes if you want to build with +# optimization. Otherwise build with debug information. +# +OPTIMIZE = yes + +# +# Specify your C++ compiler. Supported values are: +# VC80, VC80_EXPRESS +# +!if "$(CPP_COMPILER)" == "" +CPP_COMPILER = VC80 +!endif + +# +# For VC80 and VC80 Express it is necessary to set the location of the +# manifest tool. This must be the 6.x version of mt.exe, not the 5.x +# version! +# +# For VC80 Express mt.exe 6.x is provided by the Windows Platform SDK. +# It is necessary to set the location of the Platform SDK through the +# PDK_HOME environment variable (see INSTALL.WINDOWS for details). +# +!if "$(CPP_COMPILER)" == "VC80" +MT = "$(VS80COMNTOOLS)bin\mt.exe" +!elseif "$(CPP_COMPILER)" == "VC80_EXPRESS" +MT = "$(PDK_HOME)\bin\mt.exe" +!endif + + +# ---------------------------------------------------------------------- +# Don't change anything below this line! +# ---------------------------------------------------------------------- + +STATICLIBS = yes + +SHELL = /bin/sh + +bindir = $(top_srcdir)\bin +libdir = $(top_srcdir)\lib +includedir = $(top_srcdir)\include +slicedir = $(top_srcdir)\slice + +install_bindir = $(prefix)\bin + +OBJEXT = .obj + +SETARGV = setargv.obj + +!include $(top_srcdir)/config/Make.rules.msvc + + +libsubdir = lib + +!if "$(OPTIMIZE)" != "yes" +LIBSUFFIX = $(LIBSUFFIX)d +!endif + + +CPPFLAGS = $(CPPFLAGS) -I$(includedir) + + +LDFLAGS = $(LDFLAGS) $(LDPLATFORMFLAGS) $(CXXFLAGS) + +SLICEPARSERLIB = $(libdir)\slice$(LIBSUFFIX).lib + + +EVERYTHING = all clean install + +.SUFFIXES: +.SUFFIXES: .ice .cpp .c .obj + +.cpp.obj:: + $(CXX) /c $(CPPFLAGS) $(CXXFLAGS) $< + +.c.obj: + $(CC) /c $(CPPFLAGS) $(CFLAGS) $< + + +all:: $(SRCS) $(TARGETS) + +!if "$(TARGETS)" != "" + +clean:: + -del /q $(TARGETS) + +!endif + +clean:: + -del /q *.obj *.bak *.ilk *.exp *.pdb *.tds + +install:: diff --git a/cpp/iceslmakedist.py b/cpp/iceslmakedist.py new file mode 100755 index 00000000000..b04ba431ef5 --- /dev/null +++ b/cpp/iceslmakedist.py @@ -0,0 +1,447 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# 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. +# +# ********************************************************************** + +import os, sys, shutil, fnmatch, re, glob + +# +# Program usage. +# +def usage(): + print "Usage: " + sys.argv[0] + " [options] [tag]" + print + print "Options:" + print "-h Show this message." + print "-v Be verbose." + print + print "If no tag is specified, HEAD is used." + +# +# Find files matching a pattern. +# +def find(path, patt): + result = [ ] + files = os.listdir(path) + for x in files: + fullpath = os.path.join(path, x); + if os.path.isdir(fullpath) and not os.path.islink(fullpath): + result.extend(find(fullpath, patt)) + elif fnmatch.fnmatch(x, patt): + result.append(fullpath) + return result + +# +# Comment out rules in a Makefile. +# +def fixMakefile(file, target): + origfile = file + ".orig" + os.rename(file, origfile) + oldMakefile = open(origfile, "r") + newMakefile = open(file, "w") + origLines = oldMakefile.readlines() + + doComment = 0 + doCheck = 0 + newLines = [] + for x in origLines: + # + # If the rule contains the target string, then + # comment out this rule. + # + if not x.startswith("\t") and x.find(target) != -1 and x.find(target + ".o") == -1: + doComment = 1 + # + # If the line starts with "clean::", then check + # the following lines and comment out any that + # contain the target string. + # + elif x.startswith("clean::"): + doCheck = 1 + # + # Stop when we encounter an empty line. + # + elif len(x.strip()) == 0: + doComment = 0 + doCheck = 0 + + if doComment or (doCheck and x.find(target) != -1): + x = "#" + x + newLines.append(x) + + newMakefile.writelines(newLines) + newMakefile.close() + oldMakefile.close() + os.remove(origfile) + +# +# Remove lines containing a keyword from a file. +# +def editFile(file, target): + origfile = file + ".orig" + os.rename(file, origfile) + oldFile = open(origfile, "r") + newFile = open(file, "w") + origLines = oldFile.readlines() + + newLines = [] + for x in origLines: + if x.find(target) == -1: + newLines.append(x) + + newFile.writelines(newLines) + newFile.close() + oldFile.close() + os.remove(origfile) + +# +# Comment out implicit parser/scanner rules in config/Make.rules. +# +def fixMakeRules(file): + origfile = file + ".orig" + os.rename(file, origfile) + oldFile = open(origfile, "r") + newFile = open(file, "w") + origLines = oldFile.readlines() + + doComment = 0 + newLines = [] + for x in origLines: + if x.find("%.y") != -1 or x.find("%.l") != -1: + doComment = 1 + # + # Stop when we encounter an empty line. + # + elif len(x.strip()) == 0: + doComment = 0 + + if doComment: + x = "#" + x + newLines.append(x) + + newFile.writelines(newLines) + newFile.close() + oldFile.close() + os.remove(origfile) + +# +# Fix version in README, INSTALL files +# +def fixVersion(files, version): + for file in files: + origfile = file + ".orig" + os.rename(file, origfile) + oldFile = open(origfile, "r") + newFile = open(file, "w") + newFile.write(re.sub("@ver@", version, oldFile.read())) + newFile.close() + oldFile.close() + os.remove(origfile) + +# +# Check arguments +# +tag = "HEAD" +verbose = 0 +for x in sys.argv[1:]: + if x == "-h": + usage() + sys.exit(0) + elif x == "-v": + verbose = 1 + elif x.startswith("-"): + print sys.argv[0] + ": unknown option `" + x + "'" + print + usage() + sys.exit(1) + else: + tag = "-r" + x + +# +# Remove any existing "dist" directory and create a new one. +# +distdir = "dist" +if os.path.exists(distdir): + shutil.rmtree(distdir) +os.mkdir(distdir) +os.mkdir(os.path.join(distdir, "icesl")) +tmpdir = "tmp" +os.mkdir(os.path.join(distdir, tmpdir)) + +# +# Export sources from git. +# +print "Checking out sources " + tag + "..." +if verbose: + quiet = "-v" +else: + quiet = "" +os.system("git archive " + quiet + " " + tag + " . | (cd dist/icesl && tar xf -)") + +os.chdir(os.path.join("..", "sl", "src")) +os.system("git archive " + quiet + " " + tag + " . | (cd ../../cpp/dist/tmp && tar xf -)") + +os.chdir(os.path.join("..", "..", "distribution", "src", "icesl")) +os.system("git archive " + quiet + " " + tag + " . | (cd ../../../cpp/dist/tmp && tar xf -)") + +os.chdir(os.path.join("..", "..", "..", "cpp", distdir)) + +# +# Copy IceSL specific install files. +# +print "Copying icesl install files..." +shutil.copyfile(os.path.join("tmp", "ICE_LICENSE"), os.path.join("icesl", "ICE_LICENSE")) +shutil.copyfile(os.path.join("tmp", "README"), os.path.join("icesl", "README")) +shutil.copyfile(os.path.join("tmp", "INSTALL"), os.path.join("icesl", "INSTALL")) + +# +# Move Make.rules.mak.icesl +# +shutil.move(os.path.join("icesl", "config", "Make.rules.mak.icesl"), os.path.join("icesl", "config", "Make.rules.mak")) + +# +# Generate bison files. +# +print "Generating bison files..." +cwd = os.getcwd() +grammars = find("icesl", "*.y") +for x in grammars: + # + # Change to the directory containing the file. + # + (dir,file) = os.path.split(x) + os.chdir(dir) + (base,ext) = os.path.splitext(file) + # + # Run gmake to create the output files. + # + if verbose: + quiet = "" + else: + quiet = "-s" + if file == "cexp.y": + os.system("gmake " + quiet + " cexp.c") + else: + os.system("gmake " + quiet + " " + base + ".cpp") + # + # Edit the Makefile to comment out the grammar rules. + # + fixMakefile("Makefile.mak", base) + + os.chdir(cwd) + +# +# Generate flex files. +# +print "Generating flex files..." +scanners = find("icesl", "*.l") +for x in scanners: + # + # Change to the directory containing the file. + # + (dir,file) = os.path.split(x) + os.chdir(dir) + (base,ext) = os.path.splitext(file) + # + # Run gmake to create the output files. + # + if verbose: + quiet = "" + else: + quiet = "-s" + os.system("gmake " + quiet + " " + base + ".cpp") + # + # Edit the Makefile to comment out the flex rules. + # + fixMakefile("Makefile.mak", base) + + os.chdir(cwd) + +# +# Remove files. +# +print "Removing unnecessary files..." +filesToRemove = [ \ + os.path.join("icesl", "CHANGES"), \ + os.path.join("icesl", "INSTALL.HP-UX"), \ + os.path.join("icesl", "INSTALL.MACOSX"), \ + os.path.join("icesl", "INSTALL.SOLARIS"), \ + os.path.join("icesl", "INSTALL.WINDOWS"), \ + os.path.join("icesl", "INSTALL.LINUX"), \ + os.path.join("icesl", "iceemakedist.py"), \ + os.path.join("icesl", "iceslmakedist.py"), \ + os.path.join("icesl", "WINDOWS_SERVICE.txt"), \ + os.path.join("icesl", "makedist.py"), \ + os.path.join("icesl", "fixCopyright.py"), \ + os.path.join("icesl", "fixVersion.py"), \ + os.path.join("icesl", "allTests.py"), \ + os.path.join("icesl", "allDemos.py"), \ + os.path.join("icesl", "config", "convertssl.py"), \ + os.path.join("icesl", "config", "findSliceFiles.py"), \ + os.path.join("icesl", "config", "glacier2router.cfg"), \ + os.path.join("icesl", "config", "ice_ca.cnf"), \ + os.path.join("icesl", "config", "icegridnode.cfg"), \ + os.path.join("icesl", "config", "icegridregistry.cfg"), \ + os.path.join("icesl", "config", "icegrid-slice.3.1.ice.gz"), \ + os.path.join("icesl", "config", "makedepend.py"), \ + os.path.join("icesl", "config", "makegitignore.py"), \ + os.path.join("icesl", "config", "makeprops.py"), \ + os.path.join("icesl", "config", "Make.rules"), \ + os.path.join("icesl", "config", "Make.rules.AIX"), \ + os.path.join("icesl", "config", "Make.rules.bcc"), \ + os.path.join("icesl", "config", "Make.rules.Darwin"), \ + os.path.join("icesl", "config", "Make.rules.FreeBSD"), \ + os.path.join("icesl", "config", "Make.rules.HP-UX"), \ + os.path.join("icesl", "config", "Make.rules.Linux"), \ + os.path.join("icesl", "config", "Make.rules.OSF1"), \ + os.path.join("icesl", "config", "Make.rules.SunOS"), \ + os.path.join("icesl", "config", "Make.rules.icee"), \ + os.path.join("icesl", "config", "Make.rules.mak.icee"), \ + os.path.join("icesl", "config", "PropertyNames.xml"), \ + os.path.join("icesl", "config", "templates.xml"), \ + os.path.join("icesl", "config", "upgradeicegrid.py"), \ + os.path.join("icesl", "config", "upgradeicestorm.py"), \ + ] +filesToRemove.extend(find("icesl", ".gitignore")) +filesToRemove.extend(find("icesl", "Makefile")) +for x in filesToRemove: + os.remove(x) +shutil.rmtree(os.path.join("icesl", "demo")) +shutil.rmtree(os.path.join("icesl", "doc")) +shutil.rmtree(os.path.join("icesl", "test")) +shutil.rmtree(os.path.join("icesl", "include", "Freeze")) +shutil.rmtree(os.path.join("icesl", "include", "Glacier2")) +shutil.rmtree(os.path.join("icesl", "include", "Ice")) +shutil.rmtree(os.path.join("icesl", "include", "IceBox")) +shutil.rmtree(os.path.join("icesl", "include", "IceGrid")) +shutil.rmtree(os.path.join("icesl", "include", "IcePatch2")) +shutil.rmtree(os.path.join("icesl", "include", "IceSSL")) +shutil.rmtree(os.path.join("icesl", "include", "IceStorm")) +shutil.rmtree(os.path.join("icesl", "include", "IceXML")) +shutil.rmtree(os.path.join("icesl", "src", "ca")) +shutil.rmtree(os.path.join("icesl", "src", "Freeze")) +shutil.rmtree(os.path.join("icesl", "src", "FreezeScript")) +shutil.rmtree(os.path.join("icesl", "src", "Glacier2")) +shutil.rmtree(os.path.join("icesl", "src", "Ice")) +shutil.rmtree(os.path.join("icesl", "src", "IceBox")) +shutil.rmtree(os.path.join("icesl", "src", "IceGrid")) +shutil.rmtree(os.path.join("icesl", "src", "IcePatch2")) +shutil.rmtree(os.path.join("icesl", "src", "iceserviceinstall")) +shutil.rmtree(os.path.join("icesl", "src", "IceSSL")) +shutil.rmtree(os.path.join("icesl", "src", "IceStorm")) +shutil.rmtree(os.path.join("icesl", "src", "IceXML")) +shutil.rmtree(os.path.join("icesl", "src", "slice2cpp")) +shutil.rmtree(os.path.join("icesl", "src", "slice2cppe")) +shutil.rmtree(os.path.join("icesl", "src", "slice2cs")) +shutil.rmtree(os.path.join("icesl", "src", "slice2docbook")) +shutil.rmtree(os.path.join("icesl", "src", "slice2freeze")) +shutil.rmtree(os.path.join("icesl", "src", "slice2freezej")) +shutil.rmtree(os.path.join("icesl", "src", "slice2html")) +shutil.rmtree(os.path.join("icesl", "src", "slice2java")) +shutil.rmtree(os.path.join("icesl", "src", "slice2javae")) +shutil.rmtree(os.path.join("icesl", "src", "slice2py")) +shutil.rmtree(os.path.join("icesl", "src", "slice2rb")) + +# +# Get IceSL version. +# +config = open(os.path.join("tmp", "Ice", "AssemblyInfo.cs"), "r") +version = re.search("AssemblyVersion.*\"([0-9\.]*)\".*", config.read()).group(1) + +print "Fixing makefiles..." + +for makeRulesName in [os.path.join("icesl", "config", "Make.rules.mak")]: + fixMakeRules(makeRulesName) + makeRules = open(makeRulesName, "r") + lines = makeRules.readlines() + makeRules.close() + for i in range(len(lines)): + if lines[i].find("prefix") == 0: + lines[i] = lines[i].replace("IceE-$(VERSION)", "IceE-" + version) + makeRules = open(makeRulesName, "w") + makeRules.writelines(lines) + makeRules.close() + + +# +# Change SUBDIRS and INSTALL_SUBDIRS in top-level Makefile. +# +for makeFileName in [os.path.join("icesl", "Makefile.mak")]: + makeFile = open(makeFileName, "r") + lines = makeFile.readlines() + makeFile.close() + for i in range(len(lines)): + if lines[i].find("SUBDIRS") == 0: + lines[i] = "SUBDIRS = src\n" + if lines[i].find("INSTALL_SUBDIRS") == 0: + lines[i] = "INSTALL_SUBDIRS = $(install_bindir) $(install_libdir)\n" + makeFile = open(makeFileName, "w") + makeFile.writelines(lines) + makeFile.close() + +# +# Disable install targets for libIceUtil, libSlice. +# +for makeFileName in [os.path.join("icesl", "src", "IceUtil", "Makefile.mak"), \ + os.path.join("icesl", "src", "Slice", "Makefile.mak")]: + makeFile = open(makeFileName, "r") + lines = makeFile.readlines() + makeFile.close() + + doComment = 0 + for i in range(len(lines)): + if lines[i].find("install::") == 0: + doComment = 1 + elif len(lines[i].strip()) == 0: + doComment = 0 + elif doComment: + lines[i] = "#" + lines[i] + + makeFile = open(makeFileName, "w") + makeFile.writelines(lines) + makeFile.close() + +# +# Fix versions in README and INSTALL files. +# +print "Fixing version in README and INSTALL files..." +fixVersion(find("icesl", "README*"), version) +fixVersion(find("icesl", "INSTALL*"), version) + +# +# Create archives. +# +print "Creating distribution..." +icever = "IceSL-trans-" + version +os.rename("icesl", icever) +if verbose: + quiet = "v" +else: + quiet = "" +os.system("chmod -R u+rw,go+r . " + icever) +os.system("find " + icever + " -type d -exec chmod a+x {} \\;") +os.system("tar c" + quiet + "f " + icever + ".tar " + icever) +os.system("gzip -9 " + icever + ".tar") +if verbose: + quiet = "" +else: + quiet = "q" +os.system("zip -9r" + quiet + " " + icever + ".zip " + icever) + +# +# Copy files (README, etc.). +# +#shutil.copyfile(os.path.join(icever, "CHANGES"), "Ice-" + version + "-CHANGES") + +# +# Done. +# +print "Cleaning up..." +shutil.rmtree(icever) +shutil.rmtree(tmpdir) +print "Done." diff --git a/cpp/src/IceGrid/LocatorI.cpp b/cpp/src/IceGrid/LocatorI.cpp index 9158def55ff..b7361dce4a1 100644 --- a/cpp/src/IceGrid/LocatorI.cpp +++ b/cpp/src/IceGrid/LocatorI.cpp @@ -26,53 +26,67 @@ class AMI_Adapter_getDirectProxyI : public AMI_Adapter_getDirectProxy { public: - AMI_Adapter_getDirectProxyI(const LocatorIPtr& locator, const string& id, const LocatorAdapterInfo& adapter) : - _locator(locator), _id(id), _adapter(adapter) + AMI_Adapter_getDirectProxyI(const LocatorI::RequestPtr& request, const string& id) : + _request(request), _id(id) { } virtual void ice_response(const ::Ice::ObjectPrx& obj) { assert(obj); - _locator->getDirectProxyCallback(_adapter.proxy->ice_getIdentity(), obj); + _request->response(_id, obj); } - virtual void ice_exception(const ::Ice::Exception& ex) - { - _locator->getDirectProxyException(_adapter, _id, ex); + virtual void ice_exception(const ::Ice::Exception& e) + { + try + { + e.ice_throw(); + } + catch(const AdapterNotActiveException& ex) + { + if(ex.activatable) + { + _request->activate(_id); + return; + } + } + catch(const Ice::Exception&) + { + } + + _request->exception(_id, e); } private: - const LocatorIPtr _locator; + const LocatorI::RequestPtr _request; const string _id; - const LocatorAdapterInfo _adapter; }; class AMI_Adapter_activateI : public AMI_Adapter_activate { public: - AMI_Adapter_activateI(const LocatorIPtr& locator, const string& id, const LocatorAdapterInfo& adapter) : - _locator(locator), _id(id), _adapter(adapter) + AMI_Adapter_activateI(const LocatorIPtr& locator, const string& id) : + _locator(locator), _id(id) { } virtual void ice_response(const ::Ice::ObjectPrx& obj) { - _locator->getDirectProxyCallback(_adapter.proxy->ice_getIdentity(), obj); + _locator->activateFinished(_id, obj); } virtual void ice_exception(const ::Ice::Exception& ex) { - _locator->getDirectProxyException(_adapter, _id, ex); + _locator->activateException(_id, ex); } private: const LocatorIPtr _locator; const string _id; - const LocatorAdapterInfo _adapter; }; // @@ -205,29 +219,70 @@ LocatorI::Request::execute() ++_lastAdapter; } } - assert(!adapters.empty()); + for(LocatorAdapterInfoSeq::const_iterator p = adapters.begin(); p != adapters.end(); ++p) { - requestAdapter(*p); + p->proxy->getDirectProxy_async(new AMI_Adapter_getDirectProxyI(this, p->id)); + } +} + +void +LocatorI::Request::activate(const string& id) +{ + // + // Activate the adapter + // + // NOTE: we use a timeout large enough to ensure that the activate() call won't + // timeout if the server hangs in deactivation and/or activation. + // + for(LocatorAdapterInfoSeq::const_iterator p = _adapters.begin(); p != _adapters.end(); ++p) + { + if(p->id == id) + { + _locator->activate(*p, this); + _activating.insert(id); + } + } + + // + // If this is a request for a replica group, don't wait for the activation to + // complete. Instead, we query the next adapter which might be already active. + // + if(_replicaGroup) + { + LocatorAdapterInfo adapter; + { + Lock sync(*this); + if(_lastAdapter != _adapters.end()) + { + adapter = *_lastAdapter; + ++_lastAdapter; + } + } + if(adapter.proxy) + { + adapter.proxy->getDirectProxy_async(new AMI_Adapter_getDirectProxyI(this, adapter.id)); + } } } void -LocatorI::Request::exception(const Ice::Exception& ex) +LocatorI::Request::exception(const string& id, const Ice::Exception& ex) { LocatorAdapterInfo adapter; { Lock sync(*this); - if(!_exception.get()) { _exception.reset(ex.ice_clone()); } + + _activating.erase(id); if(_lastAdapter == _adapters.end()) { --_count; // Expect one less adapter proxy if there's no more adapters to query. - + // // If we received all the required proxies, it's time to send the // answer back to the client. @@ -236,7 +291,6 @@ LocatorI::Request::exception(const Ice::Exception& ex) { sendResponse(); } - return; } else { @@ -244,16 +298,28 @@ LocatorI::Request::exception(const Ice::Exception& ex) ++_lastAdapter; } } - requestAdapter(adapter); + + if(adapter.proxy) + { + adapter.proxy->getDirectProxy_async(new AMI_Adapter_getDirectProxyI(this, adapter.id)); + } } void -LocatorI::Request::response(const Ice::ObjectPrx& proxy) +LocatorI::Request::response(const string& id, const Ice::ObjectPrx& proxy) { + if(!proxy) + { + exception(id, AdapterNotActiveException()); + return; + } + Lock sync(*this); assert(proxy); - _proxies.push_back(proxy->ice_identity(_locator->getCommunicator()->stringToIdentity("dummy"))); + _activating.erase(id); + + _proxies[id] = proxy->ice_identity(_locator->getCommunicator()->stringToIdentity("dummy")); // // If we received all the required proxies, it's time to send the @@ -266,22 +332,11 @@ LocatorI::Request::response(const Ice::ObjectPrx& proxy) } void -LocatorI::Request::requestAdapter(const LocatorAdapterInfo& adapter) -{ - assert(adapter.proxy); - if(_locator->getDirectProxyRequest(this, adapter)) - { - AMI_Adapter_getDirectProxyPtr amiCB = new AMI_Adapter_getDirectProxyI(_locator, _id, adapter); - adapter.proxy->getDirectProxy_async(amiCB); - } -} - -void LocatorI::Request::sendResponse() { if(_proxies.size() == 1) { - _amdCB->ice_response(_proxies.back()); + _amdCB->ice_response(_proxies.begin()->second); } else if(_proxies.empty()) { @@ -304,10 +359,19 @@ LocatorI::Request::sendResponse() { Ice::EndpointSeq endpoints; endpoints.reserve(_proxies.size()); - for(vector<Ice::ObjectPrx>::const_iterator p = _proxies.begin(); p != _proxies.end(); ++p) + for(LocatorAdapterInfoSeq::const_iterator p = _adapters.begin(); p != _adapters.end(); ++p) { - Ice::EndpointSeq edpts = (*p)->ice_getEndpoints(); - endpoints.insert(endpoints.end(), edpts.begin(), edpts.end()); + map<string, Ice::ObjectPrx>::const_iterator q = _proxies.find(p->id); + if(q != _proxies.end()) + { + Ice::EndpointSeq edpts = q->second->ice_getEndpoints(); + endpoints.insert(endpoints.end(), edpts.begin(), edpts.end()); + } + } + + for(set<string>::const_iterator q = _activating.begin(); q != _activating.end(); ++q) + { + _locator->cancelActivate(*q, this); } Ice::ObjectPrx proxy = _locator->getCommunicator()->stringToProxy("dummy:default"); @@ -442,54 +506,55 @@ LocatorI::getLocalQuery(const Ice::Current&) const return _localQuery; } -bool -LocatorI::getDirectProxyRequest(const RequestPtr& request, const LocatorAdapterInfo& adapter) +const Ice::CommunicatorPtr& +LocatorI::getCommunicator() const { - Lock sync(*this); - - // - // Check if there's already pending requests for this adapter. If that's the case, - // we just add this one to the queue. If not, we add it to the queue and initiate - // a call on the adapter to get its direct proxy. - // - PendingRequestsMap::iterator p; - p = _pendingRequests.insert(make_pair(adapter.proxy->ice_getIdentity(), PendingRequests())).first; - p->second.push_back(request); - return p->second.size() == 1; + return _communicator; } void -LocatorI::getDirectProxyException(const LocatorAdapterInfo& adpt, const string& id, const Ice::Exception& ex) +LocatorI::activate(const LocatorAdapterInfo& adapter, const RequestPtr& request) { - try - { - ex.ice_throw(); - } - catch(const AdapterNotActiveException& ex) { - if(ex.activatable) + Lock sync(*this); + + // + // Check if there's already pending requests for this adapter. If that's the case, + // we just add this one to the queue. If not, we add it to the queue and initiate + // a call on the adapter to get its direct proxy. + // + PendingRequestsMap::iterator p; + p = _pendingRequests.insert(make_pair(adapter.id, PendingRequests())).first; + p->second.insert(request); + if(p->second.size() != 1) { - // - // Activate the adapter if it can be activated on demand. - // - // NOTE: we use a timeout large enough to ensure that the - // activate() call won't timeout if the server hangs in - // deactivation and/or activation. - // - AMI_Adapter_activatePtr amiCB = new AMI_Adapter_activateI(this, id, adpt); - int timeout = adpt.activationTimeout + adpt.deactivationTimeout; - AdapterPrx::uncheckedCast(adpt.proxy->ice_timeout(timeout * 1000))->activate_async(amiCB); return; } } - catch(const Ice::Exception&) + + AMI_Adapter_activatePtr amiCB = new AMI_Adapter_activateI(this, adapter.id); + int timeout = adapter.activationTimeout + adapter.deactivationTimeout; + AdapterPrx::uncheckedCast(adapter.proxy->ice_timeout(timeout * 1000))->activate_async(amiCB); +} + +void +LocatorI::cancelActivate(const string& id, const RequestPtr& request) +{ + Lock sync(*this); + PendingRequestsMap::iterator p = _pendingRequests.find(id); + if(p != _pendingRequests.end()) { + p->second.erase(request); } +} +void +LocatorI::activateFinished(const string& id, const Ice::ObjectPrx& proxy) +{ PendingRequests requests; { Lock sync(*this); - PendingRequestsMap::iterator p = _pendingRequests.find(adpt.proxy->ice_getIdentity()); + PendingRequestsMap::iterator p = _pendingRequests.find(id); assert(p != _pendingRequests.end()); requests.swap(p->second); _pendingRequests.erase(p); @@ -497,40 +562,24 @@ LocatorI::getDirectProxyException(const LocatorAdapterInfo& adpt, const string& for(PendingRequests::iterator q = requests.begin(); q != requests.end(); ++q) { - (*q)->exception(ex); + (*q)->response(id, proxy); } } void -LocatorI::getDirectProxyCallback(const Ice::Identity& adapterId, const Ice::ObjectPrx& proxy) +LocatorI::activateException(const string& id, const Ice::Exception& ex) { PendingRequests requests; { Lock sync(*this); - PendingRequestsMap::iterator p = _pendingRequests.find(adapterId); + PendingRequestsMap::iterator p = _pendingRequests.find(id); assert(p != _pendingRequests.end()); requests.swap(p->second); _pendingRequests.erase(p); } - if(proxy) - { - for(PendingRequests::const_iterator q = requests.begin(); q != requests.end(); ++q) - { - (*q)->response(proxy); - } - } - else + for(PendingRequests::iterator q = requests.begin(); q != requests.end(); ++q) { - for(PendingRequests::const_iterator q = requests.begin(); q != requests.end(); ++q) - { - (*q)->exception(AdapterNotActiveException()); - } + (*q)->exception(id, ex); } } - -const Ice::CommunicatorPtr& -LocatorI::getCommunicator() const -{ - return _communicator; -} diff --git a/cpp/src/IceGrid/LocatorI.h b/cpp/src/IceGrid/LocatorI.h index e36741631f9..f0f97239c83 100644 --- a/cpp/src/IceGrid/LocatorI.h +++ b/cpp/src/IceGrid/LocatorI.h @@ -13,6 +13,8 @@ #include <IceGrid/Internal.h> #include <IceGrid/Locator.h> +#include <set> + namespace IceGrid { @@ -30,6 +32,8 @@ typedef std::vector<LocatorAdapterInfo> LocatorAdapterInfoSeq; class LocatorI : public Locator, public IceUtil::Mutex { +public: + class Request : public IceUtil::Mutex, public IceUtil::Shared { public: @@ -38,8 +42,15 @@ class LocatorI : public Locator, public IceUtil::Mutex const LocatorAdapterInfoSeq&, int, const TraceLevelsPtr&); void execute(); - void response(const Ice::ObjectPrx&); - void exception(const Ice::Exception&); + void response(const std::string&, const Ice::ObjectPrx&); + void activate(const std::string&); + void exception(const std::string&, const Ice::Exception&); + + virtual bool + operator<(const Request& r) const + { + return this < &r; + } private: @@ -54,13 +65,12 @@ class LocatorI : public Locator, public IceUtil::Mutex const TraceLevelsPtr _traceLevels; unsigned int _count; LocatorAdapterInfoSeq::const_iterator _lastAdapter; - std::vector<Ice::ObjectPrx> _proxies; + std::map<std::string, Ice::ObjectPrx> _proxies; std::auto_ptr<Ice::Exception> _exception; + std::set<std::string> _activating; }; typedef IceUtil::Handle<Request> RequestPtr; -public: - LocatorI(const Ice::CommunicatorPtr&, const DatabasePtr&, const Ice::LocatorRegistryPrx&, const RegistryPrx&, const QueryPrx&); @@ -73,13 +83,15 @@ public: virtual Ice::LocatorRegistryPrx getRegistry(const Ice::Current&) const; virtual RegistryPrx getLocalRegistry(const Ice::Current&) const; virtual QueryPrx getLocalQuery(const Ice::Current&) const; - - bool getDirectProxyRequest(const RequestPtr&, const LocatorAdapterInfo&); - void getDirectProxyException(const LocatorAdapterInfo&, const std::string&, const Ice::Exception&); - void getDirectProxyCallback(const Ice::Identity&, const Ice::ObjectPrx&); const Ice::CommunicatorPtr& getCommunicator() const; + void activate(const LocatorAdapterInfo&, const RequestPtr&); + void cancelActivate(const std::string&, const RequestPtr&); + + void activateFinished(const std::string&, const Ice::ObjectPrx&); + void activateException(const std::string&, const Ice::Exception&); + protected: const Ice::CommunicatorPtr _communicator; @@ -88,8 +100,8 @@ protected: const RegistryPrx _localRegistry; const QueryPrx _localQuery; - typedef std::vector<RequestPtr> PendingRequests; - typedef std::map<Ice::Identity, PendingRequests> PendingRequestsMap; + typedef std::set<RequestPtr> PendingRequests; + typedef std::map<std::string, PendingRequests> PendingRequestsMap; PendingRequestsMap _pendingRequests; }; diff --git a/cpp/test/IceGrid/deployer/Server.cpp b/cpp/test/IceGrid/deployer/Server.cpp index 977c9270c1b..9762e0143e2 100644 --- a/cpp/test/IceGrid/deployer/Server.cpp +++ b/cpp/test/IceGrid/deployer/Server.cpp @@ -32,7 +32,15 @@ Server::run(int argc, char* argv[]) string name = properties->getProperty("Ice.ProgramName"); - Ice::ObjectAdapterPtr adapter = communicator()->createObjectAdapter("Server"); + Ice::ObjectAdapterPtr adapter; + + if(!properties->getProperty("ReplicatedAdapter").empty()) + { + adapter = communicator()->createObjectAdapter("ReplicatedAdapter"); + adapter->activate(); + } + + adapter = communicator()->createObjectAdapter("Server"); Ice::ObjectPtr object = new TestI(adapter, properties); adapter->add(object, communicator()->stringToIdentity(name)); diff --git a/cpp/test/IceGrid/replicaGroup/AllTests.cpp b/cpp/test/IceGrid/replicaGroup/AllTests.cpp index 1bef85f3b3d..866b5f23580 100644 --- a/cpp/test/IceGrid/replicaGroup/AllTests.cpp +++ b/cpp/test/IceGrid/replicaGroup/AllTests.cpp @@ -99,6 +99,19 @@ instantiateServer(const AdminPrx& admin, const string& templ, const string& node cerr << ex << endl; test(false); } + + assert(params.find("id") != params.end()); + try + { + admin->startServer(params.find("id")->second); + } + catch(const NodeUnreachableException&) + { + } + catch(const Ice::Exception&) + { + test(false); + } } void |