/* * This method will pre-fetch all the necessary JNI ID's. It expects there to be * a valid JNIEnv in this->jnienv (so attachToJVM() should have been called first. * * This method will also create an instance of the java proxy class through which * RTIambassador calls will be routed. */ void JavaRTI::initialize() throw( RTIinternalError ) { ////////////////////////////////////////////////////////////// // get the proxy class id data and create an instance of it // ////////////////////////////////////////////////////////////// // find the ProxyRtiAmbassador class // // Get active environment JNIEnv* jnienv = getJniEnvironment(); this->jproxyClass = jnienv->FindClass( "org/portico/impl/cpp1516e/ProxyRtiAmbassador" ); if( jproxyClass != NULL ) { // mark the object as a global reference so that the GC doesn't suck it up on us this->jproxyClass = (jclass)jnienv->NewGlobalRef( this->jproxyClass ); } if( jproxyClass == NULL ) { logger->fatal( "Can't locate: org.portico.impl.cpp1516e.ProxyRtiAmbassador" ); exceptionCheck(); throw RTIinternalError( L"Can't locate: org.portico.impl.cpp1516e.ProxyRtiAmbassador" ); } // find the method id of the constructor // jmethodID constructor; constructor = jnienv->GetMethodID( jproxyClass, "<init>", "(I)V" ); if( constructor == NULL ) { logger->fatal( "Can't locate ProxyRtiAmbassador() constructor ID" ); exceptionCheck(); throw RTIinternalError( L"Can't locate ProxyRtiAmbassador() constructor ID" ); } // create the instance of the ambassador // logger->debug( "Creating new instance of ProxyRtiAmbassador" ); jobject localReference = jnienv->NewObject( jproxyClass, constructor, this->id ); // check for an exception // we have to use the plain old JNI method of exception detection as to work, the // exception manager requires that the JavaRTI instance be in the Runtime's map of // instances, and that won't happen until after the constructor, which this method // is a part of (in terms of method flow) if( jnienv->ExceptionOccurred() ) { jnienv->ExceptionDescribe(); jnienv->ExceptionClear(); throw RTIinternalError( L"Exception during ProxyRtiAmbassador() constructor" ); } // turn the reference into something more persistent (stop it from being garbage collected) jproxy = jnienv->NewGlobalRef( localReference ); if( jproxy == NULL ) { logger->fatal( "Could not instantiate ProxyRtiAmbassador" ); exceptionCheck(); } logger->info( "Initialized new JavaRTI (rti-%d)", this->id ); }
/* * The same as the cacheMethod(jmethodId,char*,char*) function, except that it also takes the * class on which the method should be located (where the other method will look for the id on * the ProxyRtiAmbassador class) */ void JavaRTI::cacheMethod( JNIEnv *jnienv, jmethodID *handle, jclass clazz, string method, string signature ) throw( RTIinternalError ) { logger->noisy( "Caching %s [%s]", method.c_str(), signature.c_str() ); // get the method and store it *handle = jnienv->GetMethodID( clazz, method.c_str(), signature.c_str() ); if( *handle == NULL ) { stringstream ss; ss << "(jni) Could not locate method " << method << "[" << signature << "]"; string message = ss.str(); logger->error( message ); throw RTIinternalError( StringUtils::toWideString(message) ); } }
void SocketEventDispatcher::timeout(const SharedPtr<AbstractSocketEvent>& socketEvent) { try { socketEvent->timeout(*this); } catch (const Exception& e) { Log(MessageCoding, Warning) << "Caught exception while processing socket output: " << e.what() << "\nClosing connection!" << std::endl; socketEvent->error(e); erase(socketEvent); } catch (const std::exception& e) { Log(MessageCoding, Warning) << "Caught exception while processing socket output: " << e.what() << "\nClosing connection!" << std::endl; socketEvent->error(RTIinternalError(e.what())); erase(socketEvent); } }
PORTICO1516E_NS_START ///////////////////////////////////////////////////////////////////////////////// // Federation Management Services /////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////// // 4.2 void PorticoRtiAmbassador::connect( FederateAmbassador& federateAmbassador, CallbackModel theCallbackModel, const std::wstring& localSettingsDesignator ) throw( ConnectionFailed, InvalidLocalSettingsDesignator, UnsupportedCallbackModel, AlreadyConnected, CallNotAllowedFromWithinCallback, RTIinternalError ) { logger->trace( "[Starting] connect(): callback=%d", theCallbackModel ); // get java versions of the parameters jstring jmodel = JniUtils::fromCallbackModel( jnienv, theCallbackModel ); // check the federate ambassador and associate the reference with our RTI if( &federateAmbassador != NULL ) javarti->fedamb = &federateAmbassador; else throw RTIinternalError( L"Null FederateAmbassador given to connect()" ); // call the method jnienv->CallVoidMethod( javarti->jproxy, javarti->CONNECT, jmodel ); // clean up and run the exception check jnienv->DeleteLocalRef( jmodel ); javarti->exceptionCheck(); logger->trace( "[Finished] connect(): callback=%d", theCallbackModel ); }
ssize_t SocketPacket::recv(SocketAddress& socketAddress, const BufferRange& bufferRange, bool peek) { throw RTIinternalError("No packet sockets on win32 so far!"); }
ssize_t SocketPacket::send(const SocketAddress& socketAddress, const ConstBufferRange& bufferRange) { throw RTIinternalError("No packet sockets on win32 so far!"); }