Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / examples / CSD_Strategy / ThreadPool3 / OrbTask.cpp
blobd304e57961e0921083961df9427c36fc55eb67b5
1 // This may look like C, but it's really -*- C++ -*-
3 //=============================================================================
4 /**
5 * @file OrbTask.cpp
7 * @author Tim Bradley <bradley_t@ociweb.com>
8 */
9 //=============================================================================
11 #include "OrbTask.h"
13 namespace { enum { MAX_ORB_TASK_WORKER_THREADS = 20 }; }
16 OrbTask::OrbTask(CORBA::ORB_ptr orb, unsigned num_threads)
17 : orb_ (CORBA::ORB::_duplicate(orb)),
18 num_threads_(num_threads)
23 OrbTask::~OrbTask()
28 int
29 OrbTask::open(void*)
31 if (this->num_threads_ < 1)
33 ACE_ERROR_RETURN((LM_ERROR,
34 "(%P|%t) OrbTask failed to open. "
35 "num_threads_ (%d) is less-than 1.\n",
36 this->num_threads_),
37 -1);
40 if (this->num_threads_ > MAX_ORB_TASK_WORKER_THREADS)
42 ACE_ERROR_RETURN((LM_ERROR,
43 "(%P|%t) OrbTask failed to open. "
44 "num_threads_ (%d) is too large. Max is %d.\n",
45 this->num_threads_, MAX_ORB_TASK_WORKER_THREADS),
46 -1);
49 if (CORBA::is_nil(this->orb_.in()))
51 ACE_ERROR_RETURN((LM_ERROR,
52 "(%P|%t) OrbTask failed to open. "
53 "ORB object reference is nil.\n"),
54 -1);
57 if (this->activate(THR_NEW_LWP | THR_JOINABLE, this->num_threads_) != 0)
59 // Assumes that when activate returns non-zero return code that
60 // no threads were activated.
61 ACE_ERROR_RETURN((LM_ERROR,
62 "(%P|%t) OrbTask failed to activate "
63 "(%d) worker threads.\n",
64 this->num_threads_),
65 -1);
68 return 0;
72 int
73 OrbTask::svc()
75 try
77 this->orb_->run();
79 catch (...)
81 ACE_ERROR((LM_ERROR,
82 "(%P|%t) Exception raised by ORB::run() method. "
83 "OrbTask is stopping.\n"));
86 return 0;
90 int
91 OrbTask::close(u_long)
93 return 0;