00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include "EventChannelFactory.h"
00029
00030 #include "Orb.h"
00031 #include "EventChannel.h"
00032 #include "omniEventsLog.h"
00033
00034 #define DB(l,x) ((omniORB::traceLevel >= l) && (cerr << x << endl))
00035
00036 namespace OmniEvents {
00037
00038
00039
00040
00041 EventChannelFactory_i::EventChannelFactory_i(unsigned int port)
00042 : Servant(Orb::inst()._omniINSPOA.in()),
00043 _port(port)
00044 {
00045 activateObjectWithId("omniEvents");
00046 }
00047
00048
00049 EventChannelFactory_i::EventChannelFactory_i(
00050 unsigned int port,
00051 OepEcpsList& channels
00052 )
00053 : Servant(Orb::inst()._omniINSPOA.in()),
00054 _port(port)
00055 {
00056
00057 for(OepEcpsList::iterator i=channels.begin(); i!=channels.end(); i++)
00058 {
00059 EventChannel_i *channel =new EventChannel_i((*i)->getKey(),**i);
00060 channel->start();
00061 _eventChannels.insert(channel);
00062 }
00063 activateObjectWithId("omniEvents");
00064 }
00065
00066
00067 CORBA::Boolean
00068 EventChannelFactory_i::supports(const CosLifeCycle::Key &k)
00069 {
00070 if((k.length() == 1) &&
00071 (strcmp(k[0].id, "EventChannel") == 0) &&
00072 (strcmp(k[0].kind, "object interface") == 0))
00073 return 1;
00074 else
00075 return 0;
00076 }
00077
00078
00079 CORBA::Object_ptr
00080 EventChannelFactory_i::create_object(
00081 const CosLifeCycle::Key &k,
00082 const CosLifeCycle::Criteria &criteria
00083 )
00084 {
00085
00086 if (! this->supports(k))
00087 throw CosLifeCycle::NoFactory(k);
00088
00089 CORBA::String_var channelIdStr =newUniqueId();
00090 EventChannel_i* channel =new EventChannel_i(channelIdStr.in());
00091
00092
00093 for(CORBA::ULong i=0; i<criteria.length(); i++)
00094 {
00095 if(strcmp(criteria[i].name, "PullRetryPeriod") == 0)
00096 {
00097 CORBA::ULong pullRetryPeriod;
00098 if(! (criteria[i].value >>= pullRetryPeriod))
00099 throw CosLifeCycle::InvalidCriteria(criteria);
00100 if(pullRetryPeriod <= 0)
00101 throw CosLifeCycle::CannotMeetCriteria(criteria);
00102 channel->setPullRetryPeriod(pullRetryPeriod);
00103 }
00104 else if(strcmp(criteria[i].name, "MaxQueueLength") == 0)
00105 {
00106 CORBA::ULong maxQueueLength;
00107 if(! (criteria[i].value >>= maxQueueLength))
00108 throw CosLifeCycle::InvalidCriteria(criteria);
00109 if(maxQueueLength > 0)
00110 channel->setMaxQueueLength(maxQueueLength);
00111 else
00112 DB(1,"Ignoring CosLifeCycle criterion: MaxQueueLength=0");
00113 }
00114 else
00115 DB(1,"Ignoring unknown CosLifeCycle criterion: "<<criteria[i].name);
00116 }
00117
00118 channel->start();
00119 _eventChannels.insert(channel);
00120
00121 omniEventsLog::persist();
00122 return channel->_this();
00123 }
00124
00125
00126 void
00127 EventChannelFactory_i::output(ostream &os)
00128 {
00129 PortableServer::ObjectId_var oid=_poa->servant_to_id(this);
00130 CORBA::String_var oidStr =PortableServer::ObjectId_to_string(oid.in());
00131
00132 os << "channelFactory\n{\n"
00133 << "\tPORT\t" << _port << "\n"
00134 << "\tKEY\t" << oidStr.in() << "\n";
00135
00136 for(set<EventChannel_i*>::iterator i=_eventChannels.begin();
00137 i!=_eventChannels.end();
00138 ++i)
00139 {
00140 os << "\n";
00141 (*i)->output(os);
00142 }
00143
00144 os << "\n}\n";
00145 }
00146
00147
00148 };