![]() |
![]() |
Welcome to the February 2005 edition of Riverace's ACE News and Tips newsletter. This issue contains a helpful review of how to customize the ACE_Acceptor class to create new service handlers in a specialized way (and differently from last month), news about what's coming up in the next ACE release, and a note about the latest ACE Fix Kit releases. Please forward this newsletter to anyone you think may be interested! Anyone who wishes to receive their own copy of this newsletter can subscribe at http://www.riverace.com/subscribe2/index.mv. If you no longer wish to subscribe, removal directions are at the bottom of this page. Please reply with any feedback you have on this newsletter, as well as ideas for information you'd like to see in upcoming newsletters. We want to be as helpful as possible, so please let us know how we can do that. ACE Tip: Customizing Service Handler Creation When Accepting ConnectionsLast month we looked at a way to customize creation of an ACE_Svc_Handler-derived class when accepting new connections using the ACE_Acceptor class. That method involved deriving a new class from ACE_Acceptor and reimplementing the make_svc_handler() method. A different way to customize this behavior is to use the ACE_Strategy_Acceptor class instead of ACE_Acceptor. ACE_Strategy_Acceptor uses programmer-supplied strategy classes to perform the major steps that ACE_Acceptor implements internally (and allows users to override). When is this capability preferred?
Like ACE_Acceptor, ACE_Strategy_Acceptor is a class template (the complete reference for this class is at http://www.dre.vanderbilt.edu/Doxygen/Stable/ace/classACE__Strategy__Acceptor.html). The first template argument to ACE_Acceptor is the class representing the service handler for each new connected service. The strategies used with ACE_Strategy_Acceptor are also class templates that take one or both of ACE_Strategy_Acceptor's template arguments. For our example, we're interested in the ACE_Creation_Strategy<SVC_HANDLER> class. ACE_Creation_Strategy is described at http://www.dre.vanderbilt.edu/Doxygen/Stable/ace/classACE__Creation__Strategy.html, and as with the ACE_Acceptor, you need to reimplement the make_svc_handler() method. It has the same signature, but its default implementation is slightly different than that of ACE_Acceptor: template <class SVC_HANDLER> ACE_INLINE int
ACE_Creation_Strategy<SVC_HANDLER>::make_svc_handler (SVC_HANDLER *&sh)
{
ACE_TRACE ("ACE_Creation_Strategy<SVC_HANDLER>::make_svc_handler");
if (sh == 0)
ACE_NEW_RETURN (sh, SVC_HANDLER (this->thr_mgr_), -1);
sh->reactor (this->reactor_);
return 0;
}
Note that the new handler gets the ACE_Thread_Manager and ACE_Reactor pointers from members in the ACE_Strategy_Acceptor object. If your objective is simply to set a thread manager and/or a reactor different from the acceptor's, you can use the default ACE_Creation_Strategy and open it with the pointers you want. Of course, they default to process singletons. Continuing the example from last month, let's say our new handlers need to have a pointer to a central processor for all messages that the service handler receives. The processor is represented by a Processor class, and each new handler requires a pointer to the central Processor class. Rather than keep a globally-accessible pointer to a Processor, we can derive a new class from ACE_Creation_Strategy that has the Processor pointer and passes it to each new service handler. The new strategy class could be defined thusly: class My_Strategy : public ACE_Creation_Strategy<Service>
{
public:
My_Strategy (Processor *processor,
ACE_Thread_Manager *thr_mgr = 0,
ACE_Reactor *r = ACE_Reactor::instance ())
: ACE_Creation_Strategy<Service> (thr_mgr, r),
processor_ (processor) { };
int make_svc_handler (Service *&sh)
{
if (sh == 0)
ACE_NEW_RETURN (sh,
Service (this->processor_,
this->thr_mgr_),
-1);
// Set the reactor of the newly created <SVC_HANDLER> to the
// one specified for this strategy.
sh->reactor (this->reactor_);
return 0;
}
private:
Processor *processor_;
}
After an instance of My_Strategy is created, its pointer can be passed to either the constructor or the open() method of ACE_Strategy_Acceptor object. Then, when ACE_Strategy_Acceptor accepts a new connection for the service, the My_Strategy::make_svc_handler() hook allocates a new Service, passing the Processor* to it. Note that although the Service(Processor*) constructor is used, Service must still define a default constructor to satisfy the template requirements of ACE_Creation_Strategy. Section 7.3 in C++NPv2 discusses the entire sequence of steps involved in ACE_Acceptor's acceptance sequence. If you have more questions about this aspect of the ACE Acceptor-Connector framework, please feel free to file a support request to get further clarification and information. If you're not a Riverace support customer, you can learn more about our support services at http://www.riverace.com/support.htm. ACE.next: What's New?The ACE development community is hard at work on the next version of ACE. Here are some of the things you can look forward to (items in bold are new or changed since last month):
As you can see, the pace of changes is slowing and the ACE development team is beginning to focus more on testing in preparation for the release of ACE 5.5. New ACE Fix Kits Released!Riverace released ACE versions 5.3e and 5.4b, containing lots of new fixes and improvements to the ACE 5.3 and 5.4 release series, respectively. These kits provide fixes to previously released ACE versions, and are not beta test kits in the ACE develoment stream. The small price for these kits provides you with tremendous value in the ability to maintain stability in your projects while picking up important fixes to ACE. New Project Coming Up?If you're planning a new project to start soon, or find yourself grappling with how to apply ACE to your current project, remember that Riverace provides world-class development and consulting services with special expertise in ACE. We can help you be sure that your new system is designed to take full advantage of ACE's power and flexibility, getting your system delivered in the shortest possible time and with the highest level of quality. Please contact Steve Huston at 888-384-8154 (toll-free in the US) or +1 508-541-9180 to discuss how Riverace can help you. |
Useful ACE Information
Quotables"I also wanted to take this opportunity to express my appreciation for the quality and responsiveness of your organization. It is a very rare pleasure to work with an organization that provides in-depth technical support while remaining strongly customer focused - a fact you clearly demonstrate on every interaction. With your help, we have been able to dramatically improve our development schedule while reducing the overall cost and resources required. Riverace has exceeded our expectations without exception." Christopher W. Midgley This Newsletter...... is produced by Riverace Corporation to educate the ACE user community about ACE and available ACE resources, give tips on how to use ACE more effectively, and explain how Riverace can help you make the most of this powerful toolkit. About UsRiverace Corporation is the premier support service provider for the ACE toolkit worldwide. Steve Huston, Riverace's President/CEO and founder, has over 20 years' experience developing network protocols and applications. He has coauthored three books on ACE's design and usage and is considered an expert by ACE users around the world. Riverace has been focused on providing world-class technical support and consulting services for ACE since 1997. |