JClass* JProxy::getProxyClass(vector<JClass*>* interfaces){ JClass* pc=NULL; for (unsigned int i=0;i<interfaces->size();i++){ JClass* ci=interfaces->at(i); try{ JString proxyName(ci->getName()); proxyName<<"Proxy"; JClass* c=ci->getClassLoader()->loadClass(proxyName);//maybe define getProxyClass in interfaces ... if (JProxy::getClazz()->isAssignableFrom(c)){ pc=c; break; } }catch(JThrowable* th){ } } return pc; }
//----------------------------------------------------------------------------- void Consumer::createConsumer() { ACS_TRACE("Consumer::createConsumer"); try { // Get ConsumerAdmin object //CosNotifyChannelAdmin::AdminID adminid; consumerAdmin_m = notifyChannel_m->new_for_consumers(ifgop_m, adminid); if(CORBA::is_nil(consumerAdmin_m.in()) == true) { CORBAProblemExImpl err = CORBAProblemExImpl(__FILE__,__LINE__,"nc::Consumer::createConsumer"); throw err.getCORBAProblemEx(); } // get the the proxySupplier (named if possible) bool isAdminExt = false; try { NotifyMonitoringExt::ConsumerAdmin_var consumerAdminExt = NotifyMonitoringExt::ConsumerAdmin::_narrow(consumerAdmin_m); isAdminExt = (consumerAdminExt != 0); } catch(...) {} CosNotifyChannelAdmin::ProxySupplier_var proxySupplier = 0; if( isAdminExt && (callback_m->services_ != 0) ) { std::string name(callback_m->services_->getName().c_str()); std::string proxyName(createRandomizedClientName(name)); NotifyMonitoringExt::ConsumerAdmin_var consumerAdminExt = NotifyMonitoringExt::ConsumerAdmin::_narrow(consumerAdmin_m); while( proxySupplier == 0 ) { try { proxySupplier = consumerAdminExt->obtain_named_notification_push_supplier(CosNotifyChannelAdmin::STRUCTURED_EVENT, proxySupplierID, proxyName.c_str()); //ACS_SHORT_LOG((LM_INFO,"Consumer::createConsumer Got named proxy supplier '%s' with proxyID %d", proxyName.c_str(), proxySupplierID)); } catch (NotifyMonitoringExt::NameAlreadyUsed &ex) { // If the original name is already in use, append "-<tries>" and try again // until we find a free name proxyName = createRandomizedClientName(name); } catch (...) { // If any unexpected problem appears, try the unnamed version proxySupplier = consumerAdmin_m->obtain_notification_push_supplier(CosNotifyChannelAdmin::STRUCTURED_EVENT, proxySupplierID); //ACS_SHORT_LOG((LM_INFO,"Consumer::createConsumer Created unnamed proxy supplier")); } } } else { // Just the unnamed version if we don't have the TAO extensions proxySupplier = consumerAdmin_m->obtain_notification_push_supplier(CosNotifyChannelAdmin::STRUCTURED_EVENT, proxySupplierID); //ACS_SHORT_LOG((LM_INFO,"Consumer::createConsumer Created unnamed proxy supplier")); } if(CORBA::is_nil(proxySupplier.in()) == true) { CORBAProblemExImpl err = CORBAProblemExImpl(__FILE__,__LINE__,"nc::Consumer::createConsumer"); throw err.getCORBAProblemEx(); } //narrow to a STRUCTURED proxy supplier proxySupplier_m = CosNotifyChannelAdmin::StructuredProxyPushSupplier::_narrow(proxySupplier.in()); } catch(CORBAProblemEx) { ACS_SHORT_LOG((LM_ERROR,"Consumer::createConsumer failed for the '%s' channel due to a nil pointer!", channelName_mp)); throw; } catch(...) { ACS_SHORT_LOG((LM_ERROR,"Consumer::createConsumer failed for the '%s' channel due to some unknown reason!", channelName_mp)); CORBAProblemExImpl err = CORBAProblemExImpl(__FILE__,__LINE__,"nc::Consumer::createConsumer"); throw err.getCORBAProblemEx(); } //now the developer must call consumerReady() to receive events. }
//----------------------------------------------------------------------------- void Supplier::createSupplier() { ACS_TRACE("Supplier::createSupplier"); // TAO Developer's Guide p. 599 - Create Supplier Admin object if(CORBA::is_nil(notifyChannel_m.in()) == true) { ACS_SHORT_LOG((LM_ERROR, "Supplier::createSupplier error occured for the '%s' channel!", channelName_mp)); CORBAProblemExImpl err = CORBAProblemExImpl(__FILE__,__LINE__,"nc::Supplier::createSupplier"); throw err.getCORBAProblemEx(); } // CosNotifyChannelAdmin::AdminID adminid; // CosNotifyChannelAdmin::ProxyID proxyConsumerID; try { //get a supplier admin SupplierAdmin_m = notifyChannel_m->new_for_suppliers(ifgop_m, adminid); //sanity check on the supplier admin if(CORBA::is_nil(SupplierAdmin_m.in()) == true) { ACS_SHORT_LOG((LM_ERROR, "Supplier::createSupplier error occured for the '%s' channel!", channelName_mp)); CORBAProblemExImpl err = CORBAProblemExImpl(__FILE__,__LINE__,"nc::Supplier::createSupplier"); throw err.getCORBAProblemEx(); } // Check if our admin is a proper TAO extension // so we can create a named proxy consumer bool isAdminExt = false; try { NotifyMonitoringExt::SupplierAdmin_var supplierAdminExt = NotifyMonitoringExt::SupplierAdmin::_narrow(SupplierAdmin_m); isAdminExt = (supplierAdminExt != 0); } catch(...) {} //get a proxy consumer CosNotifyChannelAdmin::ProxyConsumer_var proxyconsumer = 0; if( isAdminExt ) { char *name = 0; if( component_mp != 0 ) name = component_mp->name(); else name = "Unknown"; std::string proxyName(createRandomizedClientName(name)); NotifyMonitoringExt::SupplierAdmin_var supplierAdminExt = NotifyMonitoringExt::SupplierAdmin::_narrow(SupplierAdmin_m); while( proxyconsumer == 0 ) { try { proxyconsumer = supplierAdminExt->obtain_named_notification_push_consumer(CosNotifyChannelAdmin::STRUCTURED_EVENT, proxyConsumerID, proxyName.c_str()); //ACS_SHORT_LOG((LM_INFO,"Consumer::createConsumer Got named proxy supplier '%s' with proxyID %d", proxyName.c_str(), proxyconsumerID)); } catch (NotifyMonitoringExt::NameAlreadyUsed &ex) { // If the original name is already in use, append "-<tries>" and try again // until we find a free name proxyName = createRandomizedClientName(name); } catch (...) { // If any unexpected problem appears, try the unnamed version proxyconsumer = SupplierAdmin_m->obtain_notification_push_consumer(CosNotifyChannelAdmin::STRUCTURED_EVENT, proxyConsumerID); //ACS_SHORT_LOG((LM_INFO,"Consumer::createConsumer Created unnamed proxy supplier")); } } } else { // Just the unnamed version if we don't have the TAO extensions proxyconsumer = SupplierAdmin_m->obtain_notification_push_consumer(CosNotifyChannelAdmin::STRUCTURED_EVENT, proxyConsumerID); } //sanity check on the consumer admin if(CORBA::is_nil(proxyconsumer.in()) == true) { ACS_SHORT_LOG((LM_ERROR, "Supplier::createSupplier error occured for the '%s' channel!", channelName_mp)); CORBAProblemExImpl err = CORBAProblemExImpl(__FILE__,__LINE__,"nc::Supplier::createSupplier"); throw err.getCORBAProblemEx(); } //narrow the consumer to a structured proxy proxyConsumer_m = CosNotifyChannelAdmin::StructuredProxyPushConsumer::_narrow(proxyconsumer.in()); //sanity check if(CORBA::is_nil(proxyConsumer_m.in()) == true) { ACS_SHORT_LOG((LM_ERROR, "Supplier::createSupplier error occured for the '%s' channel!", channelName_mp)); CORBAProblemExImpl err = CORBAProblemExImpl(__FILE__,__LINE__,"nc::Supplier::createSupplier"); throw err.getCORBAProblemEx(); } //activate ourself as a CORBA object reference_m = BACI_CORBA::ActivateTransientCORBAObject<CosNotifyComm::StructuredPushSupplier>(this); if (reference_m.in()==0) { reference_m = this->_this(); } //sanity check if(CORBA::is_nil(reference_m.in()) == true) { ACS_SHORT_LOG((LM_ERROR, "Supplier::createSupplier error occured for the '%s' channel!", channelName_mp)); CORBAProblemExImpl err = CORBAProblemExImpl(__FILE__,__LINE__,"nc::Supplier::createSupplier"); throw err.getCORBAProblemEx(); } //finally attach ourself to the proxy consumer proxyConsumer_m->connect_structured_push_supplier(reference_m.in()); } catch(CORBAProblemEx) { //exception thrown by us...OK to rethrow ACS_SHORT_LOG((LM_TRACE, "Supplier::createSupplier nil pointer error occured for the '%s' channel!", channelName_mp)); throw; } catch(...) { ACS_SHORT_LOG((LM_ERROR, "Supplier::createSupplier unknown error occured for the '%s' channel!", channelName_mp)); CORBAProblemExImpl err = CORBAProblemExImpl(__FILE__,__LINE__,"nc::Supplier::createSupplier"); throw err.getCORBAProblemEx(); } }