NativeMethods.h File Reference

Go to the source code of this file.

Functions

JNIEXPORT jlong JNICALL Java_net_sf_farrago_fennel_FennelStorage_newObjectHandle (JNIEnv *, jclass, jobject)
JNIEXPORT void JNICALL Java_net_sf_farrago_fennel_FennelStorage_deleteObjectHandle (JNIEnv *, jclass, jlong)
JNIEXPORT void JNICALL Java_net_sf_farrago_fennel_FennelStorage_setObjectHandle (JNIEnv *, jclass, jlong, jobject)
JNIEXPORT jint JNICALL Java_net_sf_farrago_fennel_FennelStorage_getHandleCount (JNIEnv *, jclass)
JNIEXPORT jstring JNICALL Java_net_sf_farrago_fennel_FennelStorage_getAccessorXmiForTupleDescriptor (JNIEnv *, jclass, jobject)
JNIEXPORT jlong JNICALL Java_net_sf_farrago_fennel_FennelStorage_executeJavaCmd (JNIEnv *, jclass, jobject, jlong)
JNIEXPORT void JNICALL Java_net_sf_farrago_fennel_FennelStorage_tupleStreamGraphGetInputStreams (JNIEnv *, jclass, jlong, jstring, jobject)
JNIEXPORT void JNICALL Java_net_sf_farrago_fennel_FennelStorage_tupleStreamGraphOpen (JNIEnv *, jclass, jlong, jlong, jobject, jobject)
JNIEXPORT jint JNICALL Java_net_sf_farrago_fennel_FennelStorage_tupleStreamFetch (JNIEnv *, jclass, jlong, jbyteArray)
JNIEXPORT jint JNICALL Java_net_sf_farrago_fennel_FennelStorage_tupleStreamTransformFetch (JNIEnv *, jclass, jlong, jint, jbyteArray)
JNIEXPORT void JNICALL Java_net_sf_farrago_fennel_FennelStorage_tupleStreamRestart (JNIEnv *, jclass, jlong)
JNIEXPORT void JNICALL Java_net_sf_farrago_fennel_FennelStorage_tupleStreamGraphClose (JNIEnv *, jclass, jlong, jint)
JNIEXPORT jlong JNICALL Java_net_sf_farrago_fennel_FennelStorage_newExecutionHandle (JNIEnv *, jclass)
JNIEXPORT void JNICALL Java_net_sf_farrago_fennel_FennelStorage_deleteExecutionHandle (JNIEnv *, jclass, jlong)
JNIEXPORT void JNICALL Java_net_sf_farrago_fennel_FennelStorage_cancelExecution (JNIEnv *, jclass, jlong)


Function Documentation

JNIEXPORT void JNICALL Java_net_sf_farrago_fennel_FennelStorage_cancelExecution ( JNIEnv *  ,
jclass  ,
jlong   
)

Definition at line 489 of file NativeMethods.cpp.

References CmdInterpreter::ExecutionHandle::aborted, and CmdInterpreter::getExecutionHandleFromLong().

00491 {
00492     CmdInterpreter::ExecutionHandle &execHandle =
00493         CmdInterpreter::getExecutionHandleFromLong(handle);
00494     execHandle.aborted = true;
00495 }

JNIEXPORT void JNICALL Java_net_sf_farrago_fennel_FennelStorage_deleteExecutionHandle ( JNIEnv *  ,
jclass  ,
jlong   
)

Definition at line 478 of file NativeMethods.cpp.

References JniUtil::decrementHandleCount(), deleteAndNullify(), and CmdInterpreter::getExecutionHandleFromLong().

00480 {
00481     CmdInterpreter::ExecutionHandle &execHandle =
00482         CmdInterpreter::getExecutionHandleFromLong(handle);
00483     CmdInterpreter::ExecutionHandle *pExecHandle = &execHandle;
00484     JniUtil::decrementHandleCount(EXECHANDLE_TRACE_TYPE_STR, pExecHandle);
00485     deleteAndNullify(pExecHandle);
00486 }

JNIEXPORT void JNICALL Java_net_sf_farrago_fennel_FennelStorage_deleteObjectHandle ( JNIEnv *  ,
jclass  ,
jlong   
)

Definition at line 421 of file NativeMethods.cpp.

References JniUtil::decrementHandleCount().

00423 {
00424     // TODO:  excn handling?
00425 
00426     JniEnvRef pEnv(pEnvInit);
00427     jobject *pGlobalRef = reinterpret_cast<jobject *>(handle);
00428     jobject jGlobalRef = *pGlobalRef;
00429     if (jGlobalRef) {
00430         pEnv->DeleteGlobalRef(jGlobalRef);
00431     }
00432     delete pGlobalRef;
00433     JniUtil::decrementHandleCount(JAVAOBJECTHANDLE_TYPE_STR, pGlobalRef);
00434 }

JNIEXPORT jlong JNICALL Java_net_sf_farrago_fennel_FennelStorage_executeJavaCmd ( JNIEnv *  ,
jclass  ,
jobject  ,
jlong   
)

Definition at line 94 of file NativeMethods.cpp.

References CmdInterpreter::executeCommand(), CmdInterpreter::getExecutionHandleFromLong(), JniEnvRef::handleExcn(), and CmdInterpreter::pExecHandle.

00096 {
00097     JniEnvRef pEnv(pEnvInit);
00098     try {
00099         ProxyCmd cmd;
00100         cmd.init(pEnv,jCmd);
00101         CmdInterpreter cmdInterpreter;
00102         if (jExecHandle == 0) {
00103             cmdInterpreter.pExecHandle = NULL;
00104         } else {
00105             CmdInterpreter::ExecutionHandle &execHandle =
00106                 CmdInterpreter::getExecutionHandleFromLong(jExecHandle);
00107             cmdInterpreter.pExecHandle = &execHandle;
00108         }
00109         return cmdInterpreter.executeCommand(cmd);
00110     } catch (std::exception &ex) {
00111         pEnv.handleExcn(ex);
00112         return 0;
00113     }
00114 }

JNIEXPORT jstring JNICALL Java_net_sf_farrago_fennel_FennelStorage_getAccessorXmiForTupleDescriptor ( JNIEnv *  ,
jclass  ,
jobject   
)

Definition at line 320 of file NativeMethods.cpp.

References TupleAccessor::compute(), TupleAccessor::getAttributeAccessor(), TupleAccessor::getBitFieldOffset(), TupleAccessor::getMinByteCount(), JniProxy::init(), AttributeAccessor::iNullBit, isMAXU(), and CmdInterpreter::readTupleDescriptor().

00322 {
00323     JniEnvRef pEnv(pEnvInit);
00324 
00325     // NOTE: Since JniProxies are currently read-only, generate XMI
00326     // representation instead.  If more of this kind of thing starts to
00327     // accumulate, making the JniProxies read-write would be a good idea.
00328 
00329     ProxyTupleDescriptor proxyTupleDesc;
00330     proxyTupleDesc.init(pEnv,jTupleDesc);
00331 
00332     // TODO:  excn handling?
00333 
00334     // TODO:  should take database handle and use its factory instead
00335     StandardTypeDescriptorFactory typeFactory;
00336     TupleDescriptor tupleDescriptor;
00337     CmdInterpreter::readTupleDescriptor(
00338         tupleDescriptor,
00339         proxyTupleDesc,
00340         typeFactory);
00341     TupleAccessor tupleAccessor;
00342     tupleAccessor.compute(tupleDescriptor);
00343     std::ostringstream oss;
00344     oss << "<XMI xmi.version = '1.2' "
00345         << "xmlns:FEMFennel = 'org.omg.xmi.namespace.FEMFennel'>" << std::endl;
00346     oss << "<XMI.content>" << std::endl;
00347     oss << "<FEMFennel:TupleAccessor minByteLength='";
00348     oss << tupleAccessor.getMinByteCount();
00349     oss << "' bitFieldOffset='";
00350     if (!isMAXU(tupleAccessor.getBitFieldOffset())) {
00351         oss << tupleAccessor.getBitFieldOffset();
00352     } else {
00353         oss << "-1";
00354     }
00355     oss << "'>" << std::endl;
00356     for (uint i = 0; i < tupleDescriptor.size(); ++i) {
00357         AttributeAccessor const &attrAccessor =
00358             tupleAccessor.getAttributeAccessor(i);
00359         oss << "<FEMFennel:TupleAccessor.AttrAccessor>";
00360         oss << "<FEMFennel:TupleAttrAccessor ";
00361         oss << "nullBitIndex='";
00362         if (!isMAXU(attrAccessor.iNullBit)) {
00363             oss << attrAccessor.iNullBit;
00364         } else {
00365             oss << "-1";
00366         }
00367         oss << "' ";
00368         oss << "fixedOffset='";
00369         if (!isMAXU(attrAccessor.iFixedOffset)) {
00370             oss << attrAccessor.iFixedOffset;
00371         } else {
00372             oss << "-1";
00373         }
00374         oss << "' ";
00375         oss << "endIndirectOffset='";
00376         if (!isMAXU(attrAccessor.iEndIndirectOffset)) {
00377             oss << attrAccessor.iEndIndirectOffset;
00378         } else {
00379             oss << "-1";
00380         }
00381         oss << "' ";
00382         oss << "bitValueIndex='";
00383         if (!isMAXU(attrAccessor.iValueBit)) {
00384             oss << attrAccessor.iValueBit;
00385         } else {
00386             oss << "-1";
00387         }
00388         oss << "' ";
00389         oss << "/>" << std::endl;
00390         oss << "</FEMFennel:TupleAccessor.AttrAccessor>";
00391     }
00392     oss << "</FEMFennel:TupleAccessor>" << std::endl;
00393     oss << "</XMI.content>" << std::endl;
00394     oss << "</XMI>" << std::endl;
00395     std::string s = oss.str();
00396     return pEnv->NewStringUTF(s.c_str());
00397 }

JNIEXPORT jint JNICALL Java_net_sf_farrago_fennel_FennelStorage_getHandleCount ( JNIEnv *  ,
jclass   
)

Definition at line 461 of file NativeMethods.cpp.

References JniUtil::getHandleCount().

00463 {
00464     return JniUtil::getHandleCount();
00465 }

JNIEXPORT jlong JNICALL Java_net_sf_farrago_fennel_FennelStorage_newExecutionHandle ( JNIEnv *  ,
jclass   
)

Definition at line 468 of file NativeMethods.cpp.

References JniUtil::incrementHandleCount().

00470 {
00471     CmdInterpreter::ExecutionHandle *pExecHandle =
00472         new CmdInterpreter::ExecutionHandle();
00473     JniUtil::incrementHandleCount(EXECHANDLE_TRACE_TYPE_STR, pExecHandle);
00474     return reinterpret_cast<int64_t>(pExecHandle);
00475 }

JNIEXPORT jlong JNICALL Java_net_sf_farrago_fennel_FennelStorage_newObjectHandle ( JNIEnv *  ,
jclass  ,
jobject   
)

Definition at line 400 of file NativeMethods.cpp.

References JniUtil::incrementHandleCount().

00402 {
00403     // TODO:  excn handling?
00404 
00405     JniEnvRef pEnv(pEnvInit);
00406     jobject jGlobalRef;
00407     if (obj) {
00408         jGlobalRef = pEnv->NewGlobalRef(obj);
00409         // TODO:  convert to Java excn instead
00410         assert(jGlobalRef);
00411     } else {
00412         jGlobalRef = NULL;
00413     }
00414     jobject *pGlobalRef = new jobject;
00415     JniUtil::incrementHandleCount(JAVAOBJECTHANDLE_TYPE_STR, pGlobalRef);
00416     *pGlobalRef = jGlobalRef;
00417     return reinterpret_cast<jlong>(pGlobalRef);
00418 }

JNIEXPORT void JNICALL Java_net_sf_farrago_fennel_FennelStorage_setObjectHandle ( JNIEnv *  ,
jclass  ,
jlong  ,
jobject   
)

Definition at line 439 of file NativeMethods.cpp.

00441 {
00442     // TODO:  excn handling?
00443 
00444     JniEnvRef pEnv(pEnvInit);
00445     jobject *pGlobalRef = reinterpret_cast<jobject *>(handle);
00446     jobject jGlobalRef = *pGlobalRef;
00447     if (jGlobalRef) {
00448         pEnv->DeleteGlobalRef(jGlobalRef);
00449     }
00450     if (obj) {
00451         jGlobalRef = pEnv->NewGlobalRef(obj);
00452         // TODO:  convert to Java excn instead
00453         assert(jGlobalRef);
00454     } else {
00455         jGlobalRef = NULL;
00456     }
00457     *pGlobalRef = jGlobalRef;
00458 }

JNIEXPORT jint JNICALL Java_net_sf_farrago_fennel_FennelStorage_tupleStreamFetch ( JNIEnv *  ,
jclass  ,
jlong  ,
jbyteArray   
)

Definition at line 117 of file NativeMethods.cpp.

References ExecStreamBufAccessor::consumeData(), EXECBUF_EOS, ExecStreamBufAccessor::getConsumptionAvailableBounded(), ExecStreamBufAccessor::getConsumptionStart(), CmdInterpreter::getExecStreamFromLong(), ExecStream::getGraph(), ExecStreamGraph::getScheduler(), ExecStreamBufAccessor::getState(), JniEnvRef::handleExcn(), ExecStreamBufAccessor::isConsumptionPossible(), and ExecStreamScheduler::readStream().

00119 {
00120     JniEnvRef pEnv(pEnvInit);
00121     try {
00122         ExecStream &stream =
00123             CmdInterpreter::getExecStreamFromLong(hStream);
00124         ExecStreamScheduler *scheduler = stream.getGraph().getScheduler();
00125         assert(scheduler);
00126         ExecStreamBufAccessor &bufAccessor = scheduler->readStream(stream);
00127         if (bufAccessor.getState() == EXECBUF_EOS) {
00128             return 0;
00129         }
00130         assert(bufAccessor.isConsumptionPossible());
00131         uint cbLimit = uint(pEnv->GetArrayLength(byteArray));
00132         uint cbActual = bufAccessor.getConsumptionAvailableBounded(cbLimit);
00133         assert(cbActual);
00134         PConstBuffer pBuffer = bufAccessor.getConsumptionStart();
00135         assert(cbLimit >= cbActual);
00136         pEnv->SetByteArrayRegion(
00137             byteArray,0,cbActual,(jbyte *)(pBuffer));
00138         bufAccessor.consumeData(pBuffer + cbActual);
00139         return cbActual;
00140     } catch (std::exception &ex) {
00141         pEnv.handleExcn(ex);
00142         return 0;
00143     }
00144 }

JNIEXPORT void JNICALL Java_net_sf_farrago_fennel_FennelStorage_tupleStreamGraphClose ( JNIEnv *  ,
jclass  ,
jlong  ,
jint   
)

Definition at line 277 of file NativeMethods.cpp.

References CmdInterpreter::getStreamGraphHandleFromLong(), JniEnvRef::handleExcn(), CmdInterpreter::StreamGraphHandle::pExecStreamGraph, and CmdInterpreter::StreamGraphHandle::pScheduler.

00279 {
00280     JniEnvRef pEnv(pEnvInit);
00281     try {
00282         CmdInterpreter::StreamGraphHandle &streamGraphHandle =
00283             CmdInterpreter::getStreamGraphHandleFromLong(hStreamGraph);
00284         switch (action) {
00285         case net_sf_farrago_fennel_FennelStorage_CLOSE_RESULT:
00286             if (streamGraphHandle.pScheduler.unique()) {
00287                 streamGraphHandle.pScheduler->stop();
00288             }
00289             if (streamGraphHandle.pExecStreamGraph) {
00290                 streamGraphHandle.pExecStreamGraph->close();
00291             }
00292             break;
00293         case net_sf_farrago_fennel_FennelStorage_CLOSE_ABORT:
00294             if (streamGraphHandle.pScheduler) {
00295                 if (streamGraphHandle.pExecStreamGraph) {
00296                     streamGraphHandle.pScheduler->abort(
00297                         *(streamGraphHandle.pExecStreamGraph));
00298                 }
00299             }
00300             break;
00301         case net_sf_farrago_fennel_FennelStorage_CLOSE_DEALLOCATE:
00302             if (streamGraphHandle.pScheduler) {
00303                 if (streamGraphHandle.pScheduler.unique()) {
00304                     streamGraphHandle.pScheduler->stop();
00305                 }
00306                 streamGraphHandle.pScheduler->removeGraph(
00307                     streamGraphHandle.pExecStreamGraph);
00308             }
00309             delete &streamGraphHandle;
00310             break;
00311         default:
00312             permAssert(false);
00313         }
00314     } catch (std::exception &ex) {
00315         pEnv.handleExcn(ex);
00316     }
00317 }

JNIEXPORT void JNICALL Java_net_sf_farrago_fennel_FennelStorage_tupleStreamGraphGetInputStreams ( JNIEnv *  ,
jclass  ,
jlong  ,
jstring  ,
jobject   
)

Definition at line 186 of file NativeMethods.cpp.

References CmdInterpreter::getStreamGraphHandleFromLong(), JniEnvRef::handleExcn(), CmdInterpreter::StreamGraphHandle::pExecStreamGraph, and JniUtil::toStdString().

00189 {
00190     JniEnvRef pEnv(pEnvInit);
00191     try {
00192         // TODO lift these to JniUtil:
00193         jclass classList = pEnv->FindClass("java/util/List");
00194         jmethodID methListAdd = pEnv->GetMethodID(classList, "add", "(Ljava/lang/Object;)Z");
00195         CmdInterpreter::StreamGraphHandle &streamGraphHandle =
00196             CmdInterpreter::getStreamGraphHandleFromLong(hStreamGraph);
00197         SharedExecStreamGraph pgraph = streamGraphHandle.pExecStreamGraph;
00198         assert(pgraph);
00199 
00200         SharedExecStream base =
00201             pgraph->findStream(JniUtil::toStdString(pEnv, baseName));
00202         assert(base);
00203         uint ct = pgraph->getInputCount(base->getStreamId());
00204         for (uint i = 0; i < ct; i++) {
00205             SharedExecStream input =
00206                 pgraph->getStreamInput(base->getStreamId(), i);
00207             assert(input);
00208             jstring inputName = pEnv->NewStringUTF(input->getName().c_str());
00209             pEnv->CallObjectMethod(inputStreamNameList, methListAdd, inputName);
00210         }
00211     } catch (std::exception &ex) {
00212         pEnv.handleExcn(ex);
00213     }
00214 }

JNIEXPORT void JNICALL Java_net_sf_farrago_fennel_FennelStorage_tupleStreamGraphOpen ( JNIEnv *  ,
jclass  ,
jlong  ,
jlong  ,
jobject  ,
jobject   
)

Definition at line 231 of file NativeMethods.cpp.

References CmdInterpreter::getStreamGraphHandleFromLong(), CmdInterpreter::getTxnHandleFromLong(), JniEnvRef::handleExcn(), CmdInterpreter::StreamGraphHandle::javaRuntimeContext, CmdInterpreter::newErrorTarget(), CmdInterpreter::TxnHandle::pDb, CmdInterpreter::StreamGraphHandle::pExecStreamGraph, CmdInterpreter::StreamGraphHandle::pReadCommittedSegment, CmdInterpreter::TxnHandle::pReadCommittedSnapshotSegment, CmdInterpreter::TxnHandle::pResourceGovernor, CmdInterpreter::StreamGraphHandle::pScheduler, CmdInterpreter::StreamGraphHandle::pSegment, CmdInterpreter::TxnHandle::pSnapshotSegment, and CmdInterpreter::TxnHandle::pTxn.

00234 {
00235     JniEnvRef pEnv(pEnvInit);
00236     try {
00237         CmdInterpreter::StreamGraphHandle &streamGraphHandle =
00238             CmdInterpreter::getStreamGraphHandleFromLong(hStreamGraph);
00239         CmdInterpreter::TxnHandle &txnHandle =
00240             CmdInterpreter::getTxnHandleFromLong(hTxn);
00241         // Provide runtime context for stream open(), which a scheduler may
00242         // defer til after out java caller returns: hence the global ref.
00243         streamGraphHandle.javaRuntimeContext =
00244             pEnv->NewGlobalRef(hJavaStreamMap);
00245         streamGraphHandle.pExecStreamGraph->setTxn(txnHandle.pTxn);
00246 
00247         // When snapshots are enabled, switch the delegating segment so
00248         // the stream graph accesses the snapshot segment associated with
00249         // the current txn
00250         SharedDatabase pDb = txnHandle.pDb;
00251         if (pDb->areSnapshotsEnabled()) {
00252             DynamicDelegatingSegment *pSegment =
00253                 SegmentFactory::dynamicCast<DynamicDelegatingSegment *>(
00254                     streamGraphHandle.pSegment);
00255             pSegment->setDelegatingSegment(
00256                 WeakSegment(txnHandle.pSnapshotSegment));
00257             pSegment =
00258                 SegmentFactory::dynamicCast<DynamicDelegatingSegment *>(
00259                     streamGraphHandle.pReadCommittedSegment);
00260             pSegment->setDelegatingSegment(
00261                 WeakSegment(txnHandle.pReadCommittedSnapshotSegment));
00262         }
00263         streamGraphHandle.pExecStreamGraph->setErrorTarget(
00264             CmdInterpreter::newErrorTarget(hJavaErrorTarget));
00265         txnHandle.pResourceGovernor->requestResources(
00266             *(streamGraphHandle.pExecStreamGraph));
00267         streamGraphHandle.pExecStreamGraph->open();
00268         if (streamGraphHandle.pScheduler.unique()) {
00269             streamGraphHandle.pScheduler->start();
00270         }
00271     } catch (std::exception &ex) {
00272         pEnv.handleExcn(ex);
00273     }
00274 }

JNIEXPORT void JNICALL Java_net_sf_farrago_fennel_FennelStorage_tupleStreamRestart ( JNIEnv *  ,
jclass  ,
jlong   
)

Definition at line 217 of file NativeMethods.cpp.

References CmdInterpreter::getExecStreamFromLong(), JniEnvRef::handleExcn(), and ExecStream::open().

00219 {
00220     JniEnvRef pEnv(pEnvInit);
00221     try {
00222         ExecStream &stream =
00223             CmdInterpreter::getExecStreamFromLong(hStream);
00224         stream.open(true);
00225     } catch (std::exception &ex) {
00226         pEnv.handleExcn(ex);
00227     }
00228 }

JNIEXPORT jint JNICALL Java_net_sf_farrago_fennel_FennelStorage_tupleStreamTransformFetch ( JNIEnv *  ,
jclass  ,
jlong  ,
jint  ,
jbyteArray   
)

Definition at line 147 of file NativeMethods.cpp.

References EXECBUF_EOS, CmdInterpreter::getExecStreamFromLong(), ExecStream::getGraph(), ExecStream::getStreamId(), ExecStreamGraph::getStreamInputAccessor(), and JniEnvRef::handleExcn().

00150 {
00151     JniEnvRef pEnv(pEnvInit);
00152     try {
00153         ExecStream &stream =
00154             CmdInterpreter::getExecStreamFromLong(hStream);
00155 
00156         uint iInput = static_cast<uint>(inputOrdinal);
00157 
00158         SharedExecStreamBufAccessor bufAccessor =
00159             stream.getGraph().getStreamInputAccessor(
00160                 stream.getStreamId(), iInput);
00161 
00162         if (bufAccessor->getState() == EXECBUF_EOS) {
00163             return 0;
00164         }
00165 
00166         if (!bufAccessor->isConsumptionPossible()) {
00167             return -1;
00168         }
00169 
00170         uint cbLimit = uint(pEnv->GetArrayLength(byteArray));
00171         uint cbActual = bufAccessor->getConsumptionAvailableBounded(cbLimit);
00172         assert(cbActual);
00173         PConstBuffer pBuffer = bufAccessor->getConsumptionStart();
00174         assert(cbLimit >= cbActual);
00175         pEnv->SetByteArrayRegion(
00176             byteArray,0,cbActual,(jbyte *)(pBuffer));
00177         bufAccessor->consumeData(pBuffer + cbActual);
00178         return cbActual;
00179     } catch (std::exception &ex) {
00180         pEnv.handleExcn(ex);
00181         return 0;
00182     }
00183 }


Generated on Mon Jun 22 04:00:22 2009 for Fennel by  doxygen 1.5.1