http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/492da34a/lang/cs/Org.Apache.REEF.Bridge/InteropLogger.cpp ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Bridge/InteropLogger.cpp b/lang/cs/Org.Apache.REEF.Bridge/InteropLogger.cpp new file mode 100644 index 0000000..418bd55 --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Bridge/InteropLogger.cpp @@ -0,0 +1,50 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +#include "InteropLogger.h" + +namespace Microsoft { + namespace Reef { + namespace Interop { + /// currently not being used + InteropLogger::InteropLogger (JNIEnv* env, jobject jobjectInteropLogger) { + _env = env; + _jobjectInteropLogger = jobjectInteropLogger; + _jclassInteropLogger = env->GetObjectClass(jobjectInteropLogger); + wchar_t formatBuf[1024]; + if (NULL == _jclassInteropLogger) { + swprintf_s (formatBuf, sizeof(formatBuf) / sizeof(wchar_t), L"_jclassInteropLogger %p\n", _jclassInteropLogger); + fwprintf (stdout, formatBuf); + fflush (stdout); + } + _jmidLog = env->GetMethodID(_jclassInteropLogger, "Log", "(ILjava/lang/String;)V"); + if (NULL == _jmidLog) { + swprintf_s (formatBuf, sizeof(formatBuf) / sizeof(wchar_t), L"_jmidLog %p\n", _jmidLog); + fwprintf (stdout, formatBuf); + fflush (stdout); + } + + } + void InteropLogger::Log(TraceLevel traceLevel, String^ message) { + pin_ptr<const wchar_t> wch = PtrToStringChars(message); + jstring msg = _env->NewString((const jchar*)wch, message->Length); + _env->CallObjectMethod(_jobjectInteropLogger, _jmidLog, (int)traceLevel, msg); + } + } + } +} \ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/492da34a/lang/cs/Org.Apache.REEF.Bridge/InteropLogger.h ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Bridge/InteropLogger.h b/lang/cs/Org.Apache.REEF.Bridge/InteropLogger.h new file mode 100644 index 0000000..0c0d162 --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Bridge/InteropLogger.h @@ -0,0 +1,47 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +#include "InteropUtil.h" +#include "org_apache_reef_javabridge_NativeInterop.h" +#include "JavaClrBridge.h" +#include "InteropAssemblies.h" +#using "Org.Apache.REEF.Driver.dll" + +using namespace System; +using namespace System::IO; +using namespace System::Collections::Generic; +using namespace System::Runtime::InteropServices; +using namespace System::Reflection; +using namespace Microsoft::Reef::Interop; + +namespace Microsoft { + namespace Reef { + namespace Interop { + public ref class InteropLogger : public ILogger { + jobject _jobjectInteropLogger; + jclass _jclassInteropLogger; + jmethodID _jmidLog; + JNIEnv* _env; + + public: + InteropLogger (JNIEnv* env, jobject jobjectInteropLogger); + virtual void Log(TraceLevel traceLevel, String^ message ); + }; + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/492da34a/lang/cs/Org.Apache.REEF.Bridge/InteropReturnInfo.cpp ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Bridge/InteropReturnInfo.cpp b/lang/cs/Org.Apache.REEF.Bridge/InteropReturnInfo.cpp new file mode 100644 index 0000000..821c0d1 --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Bridge/InteropReturnInfo.cpp @@ -0,0 +1,88 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +#include "InteropReturnInfo.h" + +namespace Microsoft { + namespace Reef { + namespace Interop { + // currently not being used + InteropReturnInfo::InteropReturnInfo ( + JNIEnv* env, + jobject jobjectInteropReturnInfo, + ILogger^ logger + ) { + _env = env; + _jobjectInteropReturnInfo = jobjectInteropReturnInfo; + jclass thisClass = env->GetObjectClass(jobjectInteropReturnInfo); + wchar_t formatBuf[1024]; + + swprintf_s (formatBuf, sizeof(formatBuf) / sizeof(wchar_t), L"zzzzzzz this should be printed by java jmid 00 %p\n", thisClass); + logger->Log(TraceLevel::Error, gcnew String(formatBuf)); + _jmidAddExceptionString = env->GetMethodID(thisClass, "addExceptionString", "(Ljava/lang/String;)V"); + if (NULL == _jmidAddExceptionString) { + swprintf_s (formatBuf, sizeof(formatBuf) / sizeof(wchar_t), L"_jmidAddExceptionString %p\n", _jmidAddExceptionString); + fwprintf (stdout, formatBuf); + fflush (stdout); + } + + _jmidHasExceptions = env->GetMethodID(thisClass, "hasExceptions", "()Z"); + if (NULL == _jmidHasExceptions) { + swprintf_s (formatBuf, sizeof(formatBuf) / sizeof(wchar_t), L"_jmidHasExceptions %p\n", _jmidHasExceptions); + fwprintf (stdout, formatBuf); + fflush (stdout); + } + + _jmidsetReturnCode = env->GetMethodID(thisClass, "setReturnCode", "(I)V"); + if (NULL == _jmidsetReturnCode) { + swprintf_s (formatBuf, sizeof(formatBuf) / sizeof(wchar_t), L"_jmidsetReturnCode %p\n", _jmidsetReturnCode); + fwprintf (stdout, formatBuf); + fflush (stdout); + } + + _jmidgetReturnCode = env->GetMethodID(thisClass, "getReturnCode", "()I"); + if (NULL == _jmidgetReturnCode) { + swprintf_s (formatBuf, sizeof(formatBuf) / sizeof(wchar_t), L"_jmidgetReturnCode %p\n", _jmidgetReturnCode); + fwprintf (stdout, formatBuf); + fflush (stdout); + } + } + + void InteropReturnInfo::AddExceptionString(String^ exceptionString) { + HasExceptions(); + pin_ptr<const wchar_t> wch = PtrToStringChars(exceptionString); + jstring ret = _env->NewString((const jchar*)wch, exceptionString->Length); + _env->CallObjectMethod(_jobjectInteropReturnInfo, _jmidAddExceptionString, ret); + HasExceptions(); + } + + Boolean InteropReturnInfo::HasExceptions() { + jobject obj = _env->CallObjectMethod(_jobjectInteropReturnInfo, _jmidHasExceptions); + return ((int)obj) != 0; + } + void InteropReturnInfo::SetReturnCode(int rc) { + _env->CallObjectMethod(_jobjectInteropReturnInfo, _jmidsetReturnCode, rc); + GetReturnCode(); + } + int InteropReturnInfo::GetReturnCode() { + jobject obj = _env->CallObjectMethod(_jobjectInteropReturnInfo, _jmidgetReturnCode); + return (int)obj; + } + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/492da34a/lang/cs/Org.Apache.REEF.Bridge/InteropReturnInfo.h ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Bridge/InteropReturnInfo.h b/lang/cs/Org.Apache.REEF.Bridge/InteropReturnInfo.h new file mode 100644 index 0000000..a79e85e --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Bridge/InteropReturnInfo.h @@ -0,0 +1,57 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +#include "InteropUtil.h" +#include "org_apache_reef_javabridge_NativeInterop.h" +#include "JavaClrBridge.h" +#include "InteropAssemblies.h" +#using "Org.Apache.REEF.Driver.dll" + +using namespace System; +using namespace System::IO; +using namespace System::Collections::Generic; +using namespace System::Runtime::InteropServices; +using namespace System::Reflection; +using namespace Microsoft::Reef::Interop; + +namespace Microsoft { + namespace Reef { + namespace Interop { + public ref class InteropReturnInfo : public IInteropReturnInfo { + JNIEnv* _env; + jobject _jobjectInteropReturnInfo; + + jmethodID _jmidAddExceptionString; + jmethodID _jmidHasExceptions; + jmethodID _jmidsetReturnCode; + jmethodID _jmidgetReturnCode; + + public: + InteropReturnInfo ( + JNIEnv* env, + jobject jobjectInteropReturnInfo, + ILogger^ logger + ); + virtual void AddExceptionString(String^ exceptionString); + virtual Boolean HasExceptions(); + virtual void SetReturnCode(int rc); + virtual int GetReturnCode(); + }; + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/492da34a/lang/cs/Org.Apache.REEF.Bridge/InteropUtil.cpp ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Bridge/InteropUtil.cpp b/lang/cs/Org.Apache.REEF.Bridge/InteropUtil.cpp new file mode 100644 index 0000000..be24f32 --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Bridge/InteropUtil.cpp @@ -0,0 +1,129 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +#include "InteropUtil.h" +#include "Clr2JavaImpl.h" + +using namespace System::Runtime::InteropServices; + +ref class ManagedLog { + internal: + static BridgeLogger^ LOGGER = BridgeLogger::GetLogger("<C++>InteropUtil"); +}; + +const wchar_t* UnicodeCppStringFromJavaString ( + JNIEnv *env, + jstring javaString) { + const wchar_t* cppString = NULL; + if (NULL != javaString) { + cppString = (const wchar_t* )env->GetStringChars( javaString, 0); + } + return cppString; +} + +void ReleaseUnicodeCppString ( + JNIEnv* env, + jstring javaString, + jchar* cppString) { + if (NULL != cppString) { + env->ReleaseStringChars(javaString, (jchar *)cppString); + } +} + +String^ ManagedStringFromJavaString ( + JNIEnv *env, + jstring javaString) { + if (javaString != NULL) { + int len = env->GetStringLength(javaString); + const wchar_t* wcsStr = UnicodeCppStringFromJavaString (env, javaString); + String^ managedStr = (NULL == wcsStr || 0 == len) ? nullptr : Marshal::PtrToStringUni((IntPtr)(unsigned short*)wcsStr, len); + ReleaseUnicodeCppString (env, javaString, (jchar*)wcsStr); + return managedStr; + } + return nullptr; +} + +jstring JavaStringFromManagedString( + JNIEnv *env, + String^ managedString) { + pin_ptr<const wchar_t> wch = PtrToStringChars(managedString); + return env->NewString((const jchar*)wch, managedString->Length); +} + +void HandleClr2JavaError( + JNIEnv *env, + String^ errorMessage, + jobject javaObject) { + ManagedLog::LOGGER->LogStart("InteropUtil::HandleClr2JavaError"); + + jclass javaClass = env->GetObjectClass (javaObject); + jmethodID jmidOnError = env->GetMethodID(javaClass, "onError", "(Ljava/lang/String;)V"); + + if (jmidOnError == NULL) { + ManagedLog::LOGGER->Log("jmidOnError is NULL"); + return; + } + env -> CallObjectMethod( + javaObject, + jmidOnError, + JavaStringFromManagedString(env, errorMessage)); + ManagedLog::LOGGER->LogStop("InteropUtil::HandleClr2JavaError"); +} + +array<byte>^ ManagedByteArrayFromJavaByteArray( + JNIEnv *env, + jbyteArray javaByteArray) { + if (javaByteArray != NULL) { + byte* bytes = (byte*)env->GetByteArrayElements (javaByteArray, FALSE); + int len = env->GetArrayLength(javaByteArray); + array<byte>^ managedByteArray = gcnew array<byte>(len); + //System::Array + for (int i = 0; i < len; i++) { + managedByteArray[i] = bytes[i]; + } + return managedByteArray; + } + return nullptr; +} + +jbyteArray JavaByteArrayFromManagedByteArray( + JNIEnv *env, + array<byte>^ managedByteArray) { + jbyteArray javaByteArray = env->NewByteArray(managedByteArray->Length); + pin_ptr<Byte> p = &managedByteArray[0]; + env->SetByteArrayRegion(javaByteArray, 0, managedByteArray->Length, (jbyte*) p); + return javaByteArray; +} + +jlongArray JavaLongArrayFromManagedLongArray( + JNIEnv *env, + array<unsigned long long>^ managedLongArray) { + jlongArray javaLongArray = env->NewLongArray(managedLongArray->Length); + pin_ptr<unsigned long long> p = &managedLongArray[0]; + env->SetLongArrayRegion(javaLongArray, 0, managedLongArray->Length, (jlong*) p); + return javaLongArray; +} + +JNIEnv* RetrieveEnv(JavaVM* jvm) { + JNIEnv *env; + if (jvm->AttachCurrentThread((void **) &env, NULL) != 0) { + ManagedLog::LOGGER->Log("cannot attach jni env to current jvm thread."); + throw; + } + return env; +} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/492da34a/lang/cs/Org.Apache.REEF.Bridge/InteropUtil.h ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Bridge/InteropUtil.h b/lang/cs/Org.Apache.REEF.Bridge/InteropUtil.h new file mode 100644 index 0000000..2d95bcc --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Bridge/InteropUtil.h @@ -0,0 +1,65 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +#pragma once +#define _USING_V110_SDK71_ + +#pragma warning( push ) +#pragma warning( disable : 4793 ) +#include <jni.h> +#pragma warning( pop ) +#include "mscoree.h" +#include "vcclr.h" + +using namespace System; + +const wchar_t* UnicodeCppStringFromJavaString ( + JNIEnv *env, + jstring javaString); + +void ReleaseUnicodeCppString ( + JNIEnv* env, + jstring javaString, + jchar* cppString); + +String^ ManagedStringFromJavaString ( + JNIEnv *env, + jstring javaString); + +jstring JavaStringFromManagedString( + JNIEnv *env, + String^ managedString); + +array<byte>^ ManagedByteArrayFromJavaByteArray( + JNIEnv *env, + jbyteArray javaByteArray); + +jbyteArray JavaByteArrayFromManagedByteArray( + JNIEnv *env, + array<byte>^ managedByteArray); + +jlongArray JavaLongArrayFromManagedLongArray( + JNIEnv *env, + array<unsigned long long>^ managedLongArray); + +JNIEnv* RetrieveEnv(JavaVM* jvm); + +void HandleClr2JavaError( + JNIEnv *env, + String^ errorMessage, + jobject javaObject); \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/492da34a/lang/cs/Org.Apache.REEF.Bridge/JavaClrBridge.cpp ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Bridge/JavaClrBridge.cpp b/lang/cs/Org.Apache.REEF.Bridge/JavaClrBridge.cpp new file mode 100644 index 0000000..2b8c7da --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Bridge/JavaClrBridge.cpp @@ -0,0 +1,492 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +#include "InteropUtil.h" +#include "org_apache_reef_javabridge_NativeInterop.h" +#include "JavaClrBridge.h" +#include "InteropAssemblies.h" +#include "InteropReturnInfo.h" +#include "Clr2JavaImpl.h" +#include "InteropLogger.h" +#include "BinaryUtil.h" +#include "malloc.h" + +using namespace System; +using namespace System::IO; +using namespace System::Collections::Generic; +using namespace System::Runtime::InteropServices; +using namespace System::Reflection; +using namespace Org::Apache::REEF::Driver::Bridge::Clr2java; + +ref class ManagedLog { + internal: + static BridgeLogger^ LOGGER = BridgeLogger::GetLogger("<C++>"); +}; + +static void MarshalErrorToJava ( + JNIEnv *env, + jobject jerrorInfo, + int errorNo, + String^ exceptionString +) { + jclass objectClass; + jfieldID fieldID; + + objectClass = env->GetObjectClass(jerrorInfo); + fieldID = env->GetFieldID(objectClass, "errorNo", "I"); + env->SetIntField (jerrorInfo, fieldID, errorNo); + + pin_ptr<const wchar_t> wchExceptionString = PtrToStringChars(exceptionString); + jstring jexceptionString = env->NewString((const jchar*)wchExceptionString, exceptionString->Length); + fieldID = env->GetFieldID(objectClass, "exceptionString", "Ljava/lang/String;"); + env->SetObjectField(jerrorInfo, fieldID, jexceptionString); +} + + +// Loading Clr Assembly. Note that we do not use ManagerLogger in this method since the +// logger assembly needs to be loaded by this method before it can be used. +JNIEXPORT void JNICALL Java_org_apache_reef_javabridge_NativeInterop_loadClrAssembly +( + JNIEnv *env, + jclass tobj, + jstring jfileName) { + try { + Console::Write("+Java_org_apache_reef_javabridge_NativeInterop_loadClrAssembly: "); + const wchar_t* charAsmName = UnicodeCppStringFromJavaString (env, jfileName); + int len = env->GetStringLength(jfileName); + wchar_t* fileName = (wchar_t* )_alloca((len + 2) * sizeof(wchar_t)); + memcpy(fileName, charAsmName, (len + 2)* sizeof(wchar_t)); + fileName[len] = 0; + String^ asmName = ManagedStringFromJavaString(env, jfileName); + Console::WriteLine("loading " + asmName); + + BINARY_TYPE binaryType = IsManagedBinary(fileName); + if (binaryType == BINARY_TYPE_CLR) { + System::Reflection::Assembly^ asm1 = Assembly::LoadFrom(asmName); + AssemblyUtil::Add(asm1); + } + else if (binaryType == BINARY_TYPE_NATIVE) { + HANDLE handle = LoadLibraryW(fileName); + } + } + catch (System::Exception^ ex) { + // We do not propagate the exception back to Java to stop driver here + // since failure to load an assembly is not necesary devastating + Console::Write("Exceptions in Java_org_apache_reef_javabridge_NativeInterop_loadClrAssembly"); + Console::Write(ex->Message); + Console::Write(ex->StackTrace); + } + +} + +/* + * Class: org_apache_reef_javabridge_NativeInterop + * Method: CallClrSystemOnStartHandler + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT jlongArray JNICALL Java_org_apache_reef_javabridge_NativeInterop_CallClrSystemOnStartHandler +(JNIEnv * env, jclass jclassx, jstring dateTimeString, jstring httpServerPort) { + try { + ManagedLog::LOGGER->Log("+Java_org_apache_reef_javabridge_NativeInterop_CallClrSystemOnStartHandler"); + const wchar_t* charConfig = UnicodeCppStringFromJavaString (env, dateTimeString); + int lenConfig = env->GetStringLength(dateTimeString); + String^ strConfig = Marshal::PtrToStringUni((IntPtr)(unsigned short*) charConfig, lenConfig); + DateTime dt = DateTime::Now; + + const wchar_t* charPort = UnicodeCppStringFromJavaString (env, httpServerPort); + int lenPort = env->GetStringLength(httpServerPort); + String^ strPort = Marshal::PtrToStringUni((IntPtr)(unsigned short*) charPort, lenPort); + + array<unsigned long long>^ handlers = ClrSystemHandlerWrapper::Call_ClrSystemStartHandler_OnStart(dt, strPort); + return JavaLongArrayFromManagedLongArray(env, handlers); + } + catch (System::Exception^ ex) { + // we cannot get error back to java here since we don't have an object to call back (although we idealy should...) + ManagedLog::LOGGER->LogError("Exceptions in Java_org_apache_reef_javabridge_NativeInterop_CallClrSystemOnStartHandler", ex); + return NULL; + } +} + +/* + * Class: org_apache_reef_javabridge_NativeInterop + * Method: ClrSystemAllocatedEvaluatorHandlerOnNext + * Signature: (JLorg/apache/reef/javabridge/AllocatedEvaluatorBridge;Lorg/apache/reef/javabridge/InteropLogger;)V + */ +JNIEXPORT void JNICALL Java_org_apache_reef_javabridge_NativeInterop_ClrSystemAllocatedEvaluatorHandlerOnNext +(JNIEnv *env, jclass cls, jlong handle, jobject jallocatedEvaluatorBridge, jobject jlogger) { + ManagedLog::LOGGER->Log("+Java_org_apache_reef_javabridge_NativeInterop_ClrSystemAllocatedEvaluatorHandlerOnNext:"); + AllocatedEvaluatorClr2Java^ allocatedEval = gcnew AllocatedEvaluatorClr2Java(env, jallocatedEvaluatorBridge); + try { + ClrSystemHandlerWrapper::Call_ClrSystemAllocatedEvaluatorHandler_OnNext(handle, allocatedEval); + } + catch (System::Exception^ ex) { + String^ errorMessage = "Exception in Call_ClrSystemAllocatedEvaluatorHandler_OnNext"; + ManagedLog::LOGGER->LogError(errorMessage, ex); + allocatedEval -> OnError(errorMessage); + } +} + +/* + * Class: org_apache_reef_javabridge_NativeInterop + * Method: ClrSystemActiveContextHandlerOnNext + * Signature: (JLorg/apache/reef/javabridge/ActiveContextBridge;Lorg/apache/reef/javabridge/InteropLogger;)V + */ +JNIEXPORT void JNICALL Java_org_apache_reef_javabridge_NativeInterop_ClrSystemActiveContextHandlerOnNext +(JNIEnv *env, jclass cls, jlong handle, jobject jactiveContextBridge, jobject jlogger) { + ManagedLog::LOGGER->Log("+Java_org_apache_reef_javabridge_NativeInterop_ClrSystemActiveContextHandlerOnNext"); + ActiveContextClr2Java^ activeContextBrdige = gcnew ActiveContextClr2Java(env, jactiveContextBridge); + try { + ClrSystemHandlerWrapper::Call_ClrSystemActiveContextHandler_OnNext(handle, activeContextBrdige); + } + catch (System::Exception^ ex) { + String^ errorMessage = "Exception in Call_ClrSystemActiveContextHandler_OnNext"; + ManagedLog::LOGGER->LogError(errorMessage, ex); + activeContextBrdige -> OnError(errorMessage); + } +} + +/* + * Class: org_apache_reef_javabridge_NativeInterop + * Method: ClrSystemEvaluatorRequstorHandlerOnNext + * Signature: (JLorg/apache/reef/javabridge/EvaluatorRequstorBridge;Lorg/apache/reef/javabridge/InteropLogger;)V + */ +JNIEXPORT void JNICALL Java_org_apache_reef_javabridge_NativeInterop_ClrSystemEvaluatorRequstorHandlerOnNext +(JNIEnv *env, jclass cls, jlong handle, jobject jevaluatorRequestorBridge, jobject jlogger) { + ManagedLog::LOGGER->Log("+Java_org_apache_reef_javabridge_NativeInterop_ClrSystemEvaluatorRequstorHandlerOnNext"); + EvaluatorRequestorClr2Java^ evaluatorRequestorBridge = gcnew EvaluatorRequestorClr2Java(env, jevaluatorRequestorBridge); + try { + ClrSystemHandlerWrapper::Call_ClrSystemEvaluatorRequestor_OnNext(handle, evaluatorRequestorBridge); + } + catch (System::Exception^ ex) { + String^ errorMessage = "Exception in Call_ClrSystemEvaluatorRequestor_OnNext"; + ManagedLog::LOGGER->LogError(errorMessage, ex); + evaluatorRequestorBridge -> OnError(errorMessage); + } +} + +/* + * Class: org_apache_reef_javabridge_NativeInterop + * Method: ClrSystemTaskMessageHandlerOnNext + * Signature: (J[BLorg/apache/reef/javabridge/TaskMessageBridge;Lorg/apache/reef/javabridge/InteropLogger;)V + */ +JNIEXPORT void JNICALL Java_org_apache_reef_javabridge_NativeInterop_ClrSystemTaskMessageHandlerOnNext +(JNIEnv *env, jclass cls, jlong handle, jbyteArray jmessage, jobject jtaskMessageBridge, jobject jlogger) { + ManagedLog::LOGGER->Log("+Java_org_apache_reef_javabridge_NativeInterop_ClrSystemTaskMessageHandlerOnNext"); + TaskMessageClr2Java^ taskMesageBridge = gcnew TaskMessageClr2Java(env, jtaskMessageBridge); + array<byte>^ message = ManagedByteArrayFromJavaByteArray(env, jmessage); + try { + ClrSystemHandlerWrapper::Call_ClrSystemTaskMessage_OnNext(handle, taskMesageBridge, message); + } + catch (System::Exception^ ex) { + String^ errorMessage = "Exception in Call_ClrSystemTaskMessage_OnNext"; + ManagedLog::LOGGER->LogError(errorMessage, ex); + taskMesageBridge -> OnError(errorMessage); + } +} + +/* + * Class: org_apache_reef_javabridge_NativeInterop + * Method: ClrSysteFailedTaskHandlerOnNext + * Signature: (JLorg/apache/reef/javabridge/FailedTaskBridge;Lorg/apache/reef/javabridge/InteropLogger;)V + */ +JNIEXPORT void JNICALL Java_org_apache_reef_javabridge_NativeInterop_ClrSystemFailedTaskHandlerOnNext +(JNIEnv *env , jclass cls, jlong handler, jobject jfailedTask, jobject jlogger) { + ManagedLog::LOGGER->Log("+Java_org_apache_reef_javabridge_NativeInterop_ClrSystemFailedTaskHandlerOnNext"); + FailedTaskClr2Java^ failedTaskBridge = gcnew FailedTaskClr2Java(env, jfailedTask); + try { + ClrSystemHandlerWrapper::Call_ClrSystemFailedTask_OnNext(handler, failedTaskBridge); + } + catch (System::Exception^ ex) { + String^ errorMessage = "Exception in Call_ClrSystemTaskMessage_OnNext"; + ManagedLog::LOGGER->LogError(errorMessage, ex); + failedTaskBridge -> OnError(errorMessage); + } +} + +/* + * Class: org_apache_reef_javabridge_NativeInterop + * Method: ClrSysteFailedTaskHandlerOnNext + * Signature: (JLorg.apache.reef.javabridge/FailedTaskBridge;Lorg.apache.reef.javabridge/InteropLogger;)V + */ +JNIEXPORT void JNICALL Java_org_apache_reef_javabridge_NativeInterop_ClrSystemRunningTaskHandlerOnNext +(JNIEnv *env , jclass cls, jlong handler, jobject jrunningTask, jobject jlogger) { + ManagedLog::LOGGER->Log("+Java_org_apache_reef_javabridge_NativeInterop_ClrSystemRunningTaskHandlerOnNext"); + RunningTaskClr2Java^ runningTaskBridge = gcnew RunningTaskClr2Java(env, jrunningTask); + try { + ClrSystemHandlerWrapper::Call_ClrSystemRunningTask_OnNext(handler, runningTaskBridge); + } + catch (System::Exception^ ex) { + String^ errorMessage = "Exception in Call_ClrSystemRunningTask_OnNext"; + ManagedLog::LOGGER->LogError(errorMessage, ex); + runningTaskBridge -> OnError(errorMessage); + } +} + +/* + * Class: org_apache_reef_javabridge_NativeInterop + * Method: ClrSystemFailedEvaluatorHandlerOnNext + * Signature: (JLorg/apache/reef/javabridge/FailedEvaluatorBridge;Lorg/apache/reef/javabridge/InteropLogger;)V + */ +JNIEXPORT void JNICALL Java_org_apache_reef_javabridge_NativeInterop_ClrSystemFailedEvaluatorHandlerOnNext +(JNIEnv *env , jclass cls, jlong handler, jobject jfailedEvaluator, jobject jlogger) { + ManagedLog::LOGGER->Log("+Java_org_apache_reef_javabridge_NativeInterop_ClrSystemFailedEvaluatorHandlerOnNext"); + FailedEvaluatorClr2Java^ failedEvaluatorBridge = gcnew FailedEvaluatorClr2Java(env, jfailedEvaluator); + try { + ClrSystemHandlerWrapper::Call_ClrSystemFailedEvaluator_OnNext(handler, failedEvaluatorBridge); + } + catch (System::Exception^ ex) { + String^ errorMessage = "Exception in Call_ClrSystemFailedEvaluator_OnNext"; + ManagedLog::LOGGER->LogError(errorMessage, ex); + failedEvaluatorBridge -> OnError(errorMessage); + } +} + +/* + * Class: org_apache_reef_javabridge_NativeInterop + * Method: ClrSystemHttpServerEventHandlerOnHttpRequest + * Signature: (JLorg/apache/reef/javabridge/HttpServerEventBridge;Lorg/apache/reef/javabridge/InteropLogger;)V + */ +JNIEXPORT void JNICALL Java_org_apache_reef_javabridge_NativeInterop_ClrSystemHttpServerHandlerOnNext +(JNIEnv *env , jclass cls, jlong handler, jobject jhttpServerEventBridge, jobject jlogger) { + ManagedLog::LOGGER->Log("+Java_org_apache_reef_javabridge_NativeInterop_ClrSystemHttpServerHandlerOnNext"); + HttpServerClr2Java^ httpServerClr2Java = gcnew HttpServerClr2Java(env, jhttpServerEventBridge); + try { + ClrSystemHandlerWrapper::Call_ClrSystemHttpServer_OnNext(handler, httpServerClr2Java); + } + catch (System::Exception^ ex) { + String^ errorMessage = "Exception in Call_ClrSystemHttpServer_OnNext"; + ManagedLog::LOGGER->LogError(errorMessage, ex); + httpServerClr2Java -> OnError(errorMessage); + } +} + +/* + * Class: org_apache_reef_javabridge_NativeInterop + * Method: ClrSystemCompletedTaskHandlerOnNext + * Signature: (JLorg/apache/reef/javabridge/CompletedTaskBridge;Lorg/apache/reef/javabridge/InteropLogger;)V + */ +JNIEXPORT void JNICALL Java_org_apache_reef_javabridge_NativeInterop_ClrSystemCompletedTaskHandlerOnNext +(JNIEnv *env , jclass cls, jlong handler, jobject jcompletedTask, jobject jlogger) { + ManagedLog::LOGGER->Log("+Java_org_apache_reef_javabridge_NativeInterop_ClrSystemCompletedTaskHandlerOnNext"); + CompletedTaskClr2Java^ completedTaskBridge = gcnew CompletedTaskClr2Java(env, jcompletedTask); + try { + ClrSystemHandlerWrapper::Call_ClrSystemCompletedTask_OnNext(handler, completedTaskBridge); + } + catch (System::Exception^ ex) { + String^ errorMessage = "Exception in Call_ClrSystemCompletedTask_OnNext"; + ManagedLog::LOGGER->LogError(errorMessage, ex); + completedTaskBridge -> OnError(errorMessage); + } +} + +/* + * Class: org_apache_reef_javabridge_NativeInterop + * Method: ClrBufferedLog + * Signature: (ILjava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_org_apache_reef_javabridge_NativeInterop_ClrBufferedLog +(JNIEnv *env, jclass cls, jint logLevel, jstring message) { + try { + if (!JavaClrBridge::LoggerWrapper::initialized) { + ManagedLog::LOGGER->Log("Initializing CLRBufferedLogHandler in java bridge..."); + JavaClrBridge::LoggerWrapper::logger->Listeners->Add(gcnew System::Diagnostics::ConsoleTraceListener()); + JavaClrBridge::LoggerWrapper::initialized = true; + } + + System::Diagnostics::TraceEventType eventType; + switch (logLevel) { + case 0: + eventType = System::Diagnostics::TraceEventType::Stop; + break; + case 1: + eventType = System::Diagnostics::TraceEventType::Error; + break; + case 2: + eventType = System::Diagnostics::TraceEventType::Warning; + break; + case 3: + eventType = System::Diagnostics::TraceEventType::Information; + break; + case 4: + eventType = System::Diagnostics::TraceEventType::Verbose; + break; + default: + eventType = System::Diagnostics::TraceEventType::Information; + break; + + } + + String^ msg = ManagedStringFromJavaString(env, message); + msg = System::String::Concat(System::DateTime::Now, msg); + JavaClrBridge::LoggerWrapper::logger->TraceEvent(eventType, 0, msg); + } + catch (System::Exception^ ex) { + ManagedLog::LOGGER->LogError("Exception in Java_javabridge_NativeInterop_ClrBufferedLog", ex); + } +} + +/* + * Class: org_apache_reef_javabridge_NativeInterop + * Method: ClrSystemSupendedTaskHandlerOnNext + * Signature: (JLorg/apache/reef/javabridge/SuspendedTaskBridge;)V + */ +JNIEXPORT void JNICALL Java_org_apache_reef_javabridge_NativeInterop_ClrSystemSupendedTaskHandlerOnNext +(JNIEnv *env , jclass cls, jlong handler, jobject jsuspendedTask) { + ManagedLog::LOGGER->Log("+Java_org_apache_reef_javabridge_NativeInterop_ClrSystemSupendedTaskHandlerOnNext"); + SuspendedTaskClr2Java^ suspendedTaskBridge = gcnew SuspendedTaskClr2Java(env, jsuspendedTask); + try { + ClrSystemHandlerWrapper::Call_ClrSystemSuspendedTask_OnNext(handler, suspendedTaskBridge); + } + catch (System::Exception^ ex) { + String^ errorMessage = "Exception in Call_ClrSystemSuspendedTask_OnNext"; + ManagedLog::LOGGER->LogError(errorMessage, ex); + suspendedTaskBridge -> OnError(errorMessage); + } +} + +/* + * Class: org_apache_reef_javabridge_NativeInterop + * Method: ClrSystemCompletdEvaluatorHandlerOnNext + * Signature: (JLorg/apache/reef/javabridge/CompletedEvaluatorBridge;)V + */ +JNIEXPORT void JNICALL Java_org_apache_reef_javabridge_NativeInterop_ClrSystemCompletdEvaluatorHandlerOnNext +(JNIEnv *env , jclass cls, jlong handler, jobject jcompletedEvaluator) { + ManagedLog::LOGGER->Log("+Java_org_apache_reef_javabridge_NativeInterop_ClrSystemCompletdEvaluatorHandlerOnNext"); + CompletedEvaluatorClr2Java^ completedEvaluatorBridge = gcnew CompletedEvaluatorClr2Java(env, jcompletedEvaluator); + try { + ClrSystemHandlerWrapper::Call_ClrSystemCompletedEvaluator_OnNext(handler, completedEvaluatorBridge); + } + catch (System::Exception^ ex) { + String^ errorMessage = "Exception in Call_ClrSystemSuspendedTask_OnNext"; + ManagedLog::LOGGER->LogError(errorMessage, ex); + completedEvaluatorBridge -> OnError(errorMessage); + } +} + +/* + * Class: org_apache_reef_javabridge_NativeInterop + * Method: ClrSystemClosedContextHandlerOnNext + * Signature: (JLorg/apache/reef/javabridge/ClosedContextBridge;)V + */ +JNIEXPORT void JNICALL Java_org_apache_reef_javabridge_NativeInterop_ClrSystemClosedContextHandlerOnNext +(JNIEnv *env , jclass cls, jlong handler, jobject jclosedContext) { + ManagedLog::LOGGER->Log("+Java_org_apache_reef_javabridge_NativeInterop_ClrSystemClosedContextHandlerOnNext"); + ClosedContextClr2Java^ closedContextBridge = gcnew ClosedContextClr2Java(env, jclosedContext); + try { + ClrSystemHandlerWrapper::Call_ClrSystemClosedContext_OnNext(handler, closedContextBridge); + } + catch (System::Exception^ ex) { + String^ errorMessage = "Exception in Call_ClrSystemClosedContext_OnNext"; + ManagedLog::LOGGER->LogError(errorMessage, ex); + closedContextBridge -> OnError(errorMessage); + } +} + +/* + * Class: org_apache_reef_javabridge_NativeInterop + * Method: ClrSystemFailedContextHandlerOnNext + * Signature: (JLorg/apache/reef/javabridge/FailedContextBridge;)V + */ +JNIEXPORT void JNICALL Java_org_apache_reef_javabridge_NativeInterop_ClrSystemFailedContextHandlerOnNext +(JNIEnv *env , jclass cls, jlong handler, jobject jfailedContext) { + ManagedLog::LOGGER->Log("+Java_org_apache_reef_javabridge_NativeInterop_ClrSystemFailedContextHandlerOnNext"); + FailedContextClr2Java^ failedContextBridge = gcnew FailedContextClr2Java(env, jfailedContext); + try { + ClrSystemHandlerWrapper::Call_ClrSystemFailedContext_OnNext(handler, failedContextBridge); + } + catch (System::Exception^ ex) { + String^ errorMessage = "Exception in Call_ClrSystemFailedContext_OnNext"; + ManagedLog::LOGGER->LogError(errorMessage, ex); + failedContextBridge -> OnError(errorMessage); + } +} + +/* + * Class: org_apache_reef_javabridge_NativeInterop + * Method: ClrSystemContextMessageHandlerOnNext + * Signature: (JLorg/apache/reef/javabridge/ContextMessageBridge;)V + */ +JNIEXPORT void JNICALL Java_org_apache_reef_javabridge_NativeInterop_ClrSystemContextMessageHandlerOnNext +(JNIEnv *env , jclass cls, jlong handler, jobject jcontextMessage) { + ManagedLog::LOGGER->Log("+Java_org_apache_reef_javabridge_NativeInterop_ClrSystemContextMessageHandlerOnNext"); + ContextMessageClr2Java^ contextMessageBridge = gcnew ContextMessageClr2Java(env, jcontextMessage); + try { + ClrSystemHandlerWrapper::Call_ClrSystemContextMessage_OnNext(handler, contextMessageBridge); + } + catch (System::Exception^ ex) { + String^ errorMessage = "Exception in Call_ClrSystemContextMessage_OnNext"; + ManagedLog::LOGGER->LogError(errorMessage, ex); + contextMessageBridge -> OnError(errorMessage); + } +} + +/* + * Class: org_apache_reef_javabridge_NativeInterop + * Method: ClrSystemDriverRestartHandlerOnNext + * Signature: (J)V + */ +JNIEXPORT void JNICALL Java_org_apache_reef_javabridge_NativeInterop_ClrSystemDriverRestartHandlerOnNext +(JNIEnv *env , jclass cls, jlong handler) { + ManagedLog::LOGGER->Log("+Java_org_apache_reef_javabridge_NativeInterop_ClrSystemDriverRestartHandlerOnNext"); + try { + ClrSystemHandlerWrapper::Call_ClrSystemDriverRestart_OnNext(handler); + } + catch (System::Exception^ ex) { + String^ errorMessage = "Exception in Call_ClrSystemContextMessage_OnNext"; + ManagedLog::LOGGER->LogError(errorMessage, ex); + // we do not call back to Java for exception in .NET restart handler + } +} + +/* + * Class: org_apache_reef_javabridge_NativeInterop + * Method: ClrSystemDriverRestartActiveContextHandlerOnNext + * Signature: (JLorg/apache/reef/javabridge/ActiveContextBridge;)V + */ +JNIEXPORT void JNICALL Java_org_apache_reef_javabridge_NativeInterop_ClrSystemDriverRestartActiveContextHandlerOnNext +(JNIEnv *env, jclass cls, jlong handle, jobject jactiveContextBridge) { + ManagedLog::LOGGER->Log("+Java_org_apache_reef_javabridge_NativeInterop_ClrSystemDriverRestartActiveContextHandlerOnNext"); + ActiveContextClr2Java^ activeContextBrdige = gcnew ActiveContextClr2Java(env, jactiveContextBridge); + try { + ClrSystemHandlerWrapper::Call_ClrSystemDriverRestartActiveContextHandler_OnNext(handle, activeContextBrdige); + } + catch (System::Exception^ ex) { + String^ errorMessage = "Exception in Call_ClrSystemDriverRestartActiveContextHandler_OnNext"; + ManagedLog::LOGGER -> LogError(errorMessage, ex); + activeContextBrdige -> OnError(errorMessage); + } +} + +/* + * Class: org_apache_reef_javabridge_NativeInterop + * Method: ClrSystemDriverRestartRunningTaskHandlerOnNext + * Signature: (JLorg/apache/reef/javabridge/RunningTaskBridge;)V + */ +JNIEXPORT void JNICALL Java_org_apache_reef_javabridge_NativeInterop_ClrSystemDriverRestartRunningTaskHandlerOnNext +(JNIEnv *env , jclass cls, jlong handler, jobject jrunningTask) { + ManagedLog::LOGGER->Log("+Java_org_apache_reef_javabridge_NativeInterop_ClrSystemDriverRestartRunningTaskHandlerOnNext"); + RunningTaskClr2Java^ runningTaskBridge = gcnew RunningTaskClr2Java(env, jrunningTask); + try { + ClrSystemHandlerWrapper::Call_ClrSystemDriverRestartRunningTask_OnNext(handler, runningTaskBridge); + } + catch (System::Exception^ ex) { + String^ errorMessage = "Exception in Call_ClrSystemDriverRestartRunningTask_OnNext"; + ManagedLog::LOGGER->LogError(errorMessage, ex); + runningTaskBridge -> OnError(errorMessage); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/492da34a/lang/cs/Org.Apache.REEF.Bridge/JavaClrBridge.h ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Bridge/JavaClrBridge.h b/lang/cs/Org.Apache.REEF.Bridge/JavaClrBridge.h new file mode 100644 index 0000000..61d9d0a --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Bridge/JavaClrBridge.h @@ -0,0 +1,33 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +// JavaClrBridge.h + +#pragma once + +using namespace System; + +namespace JavaClrBridge { + ref class LoggerWrapper + { + public: + static System::Diagnostics::TraceSource^ logger = + gcnew System::Diagnostics::TraceSource("JavaCLRBridgeLogger", System::Diagnostics::SourceLevels::All); + static bool initialized = false; + }; +} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/492da34a/lang/cs/Org.Apache.REEF.Bridge/Org.Apache.REEF.Bridge.nuspec ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Bridge/Org.Apache.REEF.Bridge.nuspec b/lang/cs/Org.Apache.REEF.Bridge/Org.Apache.REEF.Bridge.nuspec new file mode 100644 index 0000000..2c869e2 --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Bridge/Org.Apache.REEF.Bridge.nuspec @@ -0,0 +1,22 @@ +<?xml version="1.0"?> +<package > + <metadata> + <id>Org.Apache.REEF.Bridge</id> + <version>$version$</version> + <title>Org.Apache.REEF.Bridge</title> + <authors>The Apache REEF project</authors> + <owners>The Apache REEF project</owners> + <licenseUrl>http://www.apache.org/licenses/LICENSE-2.0</licenseUrl> + <projectUrl>http://reef.incubator.apache.org/</projectUrl> + <requireLicenseAcceptance>false</requireLicenseAcceptance> + <description>Clr Bridge for REEF.NET</description> + <copyright>The Apache Software Foundation</copyright> + <dependencies> + <dependency id="Org.Apache.REEF.Driver" version="$version$" /> + </dependencies> + </metadata> + <files> + <file src="..\bin\$Platform$\$Configuration$\Org.Apache.REEF.Bridge\Org.Apache.REEF.Bridge.dll" target="lib\net45" /> + <file src="..\bin\$Platform$\$Configuration$\Org.Apache.REEF.Bridge\Org.Apache.REEF.Bridge.pdb" target="lib\net45" /> + </files> +</package> http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/492da34a/lang/cs/Org.Apache.REEF.Bridge/Org.Apache.REEF.Bridge.vcxproj ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Bridge/Org.Apache.REEF.Bridge.vcxproj b/lang/cs/Org.Apache.REEF.Bridge/Org.Apache.REEF.Bridge.vcxproj new file mode 100644 index 0000000..88446b6 --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Bridge/Org.Apache.REEF.Bridge.vcxproj @@ -0,0 +1,180 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at +http://www.apache.org/licenses/LICENSE-2.0 +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +--> +<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <PropertyGroup> + <BuildInParallel>false</BuildInParallel> + <Configuration Condition="'$(Configuration)' == '' ">Debug</Configuration> + <Platform Condition="'$(Platform)' == ''">x64</Platform> + <SolutionDir Condition="'$(SolutionDir)' == ''">..</SolutionDir> + <RestorePackages>true</RestorePackages> + </PropertyGroup> + <Import Project="$(SolutionDir)\build.props" /> + <ItemGroup Label="ProjectConfigurations"> + <ProjectConfiguration Include="Debug|x64"> + <Configuration>Debug</Configuration> + <Platform>x64</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Release|x64"> + <Configuration>Release</Configuration> + <Platform>x64</Platform> + </ProjectConfiguration> + </ItemGroup> + <PropertyGroup Label="Globals"> + <ProjectGuid>{4E69D40A-26D6-4D4A-B96D-729946C07FE1}</ProjectGuid> + <TargetFrameworkVersion>v4.5</TargetFrameworkVersion> + <Keyword>ManagedCProj</Keyword> + <RootNamespace>OrgApacheREEFBridge</RootNamespace> + </PropertyGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> + <ConfigurationType>DynamicLibrary</ConfigurationType> + <UseDebugLibraries>true</UseDebugLibraries> + <PlatformToolset>v120</PlatformToolset> + <CLRSupport>true</CLRSupport> + <CharacterSet>Unicode</CharacterSet> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> + <ConfigurationType>DynamicLibrary</ConfigurationType> + <UseDebugLibraries>false</UseDebugLibraries> + <PlatformToolset>v120</PlatformToolset> + <CLRSupport>true</CLRSupport> + <CharacterSet>Unicode</CharacterSet> + <RestorePackages>true</RestorePackages> + </PropertyGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> + <ImportGroup Label="ExtensionSettings"> + </ImportGroup> + <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <PropertyGroup Label="UserMacros" /> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> + <LinkIncremental>true</LinkIncremental> + <ReferencePath>..\bin\$(Platform)\$(Configuration)\Org.Apache.REEF.Driver;..\bin\x64\Release\Org.Apache.REEF.Driver;$(ReferencePath)</ReferencePath> + <OutDir>$(SolutionDir)bin\$(Platform)\$(Configuration)\$(ProjectName)\</OutDir> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> + <LinkIncremental>false</LinkIncremental> + <ReferencePath>..\bin\$(Platform)\$(Configuration)\Org.Apache.REEF.Driver;..\bin\x64\Release\Org.Apache.REEF.Driver;$(ReferencePath)</ReferencePath> + <OutDir>$(SolutionDir)bin\$(Platform)\$(Configuration)\$(ProjectName)\</OutDir> + </PropertyGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> + <ClCompile> + <WarningLevel>Level3</WarningLevel> + <Optimization>Disabled</Optimization> + <PreprocessorDefinitions>WIN32;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <PrecompiledHeader>NotUsing</PrecompiledHeader> + <AdditionalIncludeDirectories>..\..\java\reef-bridge-java\target\classes;$(JAVA_HOME)\include;$(JAVA_HOME)\include\win32;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + </ClCompile> + <Link> + <GenerateDebugInformation>true</GenerateDebugInformation> + <AdditionalDependencies> + </AdditionalDependencies> + <AdditionalLibraryDirectories>..\bin\$(Platform)\$(Configuration)\Org.Apache.REEF.Driver;..\bin\x64\$(Configuration)\Org.Apache.REEF.Driver;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> + <AdditionalOptions>/ignore:4248 %(AdditionalOptions)</AdditionalOptions> + </Link> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> + <ClCompile> + <WarningLevel>Level3</WarningLevel> + <PreprocessorDefinitions>WIN32;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <PrecompiledHeader>NotUsing</PrecompiledHeader> + <AdditionalIncludeDirectories>..\..\java\reef-bridge-java\target\classes;$(JAVA_HOME)\include;$(JAVA_HOME)\include\win32;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + </ClCompile> + <Link> + <GenerateDebugInformation>true</GenerateDebugInformation> + <AdditionalDependencies> + </AdditionalDependencies> + <AdditionalLibraryDirectories>..\bin\$(Platform)\$(Configuration)\Org.Apache.REEF.Driver;..\bin\x64\$(Configuration)\Org.Apache.REEF.Driver;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> + <AdditionalOptions>/ignore:4248 %(AdditionalOptions)</AdditionalOptions> + </Link> + </ItemDefinitionGroup> + <ItemGroup> + <Reference Include="System" /> + <Reference Include="System.Data" /> + <Reference Include="System.Xml" /> + </ItemGroup> + <ItemGroup> + <ClInclude Include="BinaryUtil.h" /> + <ClInclude Include="Clr2JavaImpl.h" /> + <ClInclude Include="InteropAssemblies.h" /> + <ClInclude Include="InteropLogger.h" /> + <ClInclude Include="InteropReturnInfo.h" /> + <ClInclude Include="InteropUtil.h" /> + <ClInclude Include="JavaClrBridge.h" /> + <ClInclude Include="resource.h" /> + <ClInclude Include="Stdafx.h" /> + </ItemGroup> + <ItemGroup> + <ClCompile Include="ActiveContextClr2Java.cpp" /> + <ClCompile Include="AllocatedEvaluatorClr2Java.cpp" /> + <ClCompile Include="AssemblyInfo.cpp" /> + <ClCompile Include="AssemblyUtil.cpp" /> + <ClCompile Include="BinaryUtil.cpp" /> + <ClCompile Include="ClosedContextClr2Java.cpp" /> + <ClCompile Include="CommonUtilities.cpp" /> + <ClCompile Include="CompletedEvaluatorClr2Java.cpp" /> + <ClCompile Include="CompletedTaskClr2Java.cpp" /> + <ClCompile Include="ContextMessageClr2Java.cpp" /> + <ClCompile Include="EvaluatorRequestorClr2Java.cpp" /> + <ClCompile Include="FailedContextClr2Java.cpp" /> + <ClCompile Include="FailedEvaluatorClr2Java.cpp" /> + <ClCompile Include="FailedTaskClr2Java.cpp" /> + <ClCompile Include="HttpServerClr2Java.cpp" /> + <ClCompile Include="InteropLogger.cpp" /> + <ClCompile Include="InteropReturnInfo.cpp" /> + <ClCompile Include="InteropUtil.cpp" /> + <ClCompile Include="JavaClrBridge.cpp" /> + <ClCompile Include="RunningTaskClr2Java.cpp" /> + <ClCompile Include="Stdafx.cpp"> + <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader> + <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader> + </ClCompile> + <ClCompile Include="SuspendedTaskClr2Java.cpp" /> + <ClCompile Include="TaskMessageClr2Java.cpp" /> + </ItemGroup> + <ItemGroup> + <Text Include="ReadMe.txt" /> + </ItemGroup> + <ItemGroup> + <ResourceCompile Include="app.rc" /> + </ItemGroup> + <ItemGroup> + <Image Include="app.ico" /> + </ItemGroup> + <ItemGroup> + <ProjectReference Include="..\Org.Apache.REEF.Bridge.JAR\Org.Apache.REEF.Bridge.JAR.csproj"> + <Project>{62905c7c-1a7e-4923-b78d-1bf42d7fad40}</Project> + <Private>false</Private> + <ReferenceOutputAssembly>false</ReferenceOutputAssembly> + <CopyLocalSatelliteAssemblies>false</CopyLocalSatelliteAssemblies> + <LinkLibraryDependencies>false</LinkLibraryDependencies> + <UseLibraryDependencyInputs>false</UseLibraryDependencyInputs> + </ProjectReference> + <ProjectReference Include="..\Org.Apache.REEF.Driver\Org.Apache.REEF.Driver.csproj"> + <Project>{a6baa2a7-f52f-4329-884e-1bcf711d6805}</Project> + </ProjectReference> + </ItemGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> + <Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" /> + <ImportGroup Label="ExtensionTargets"> + </ImportGroup> +</Project> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/492da34a/lang/cs/Org.Apache.REEF.Bridge/Org.Apache.REEF.Bridge.vcxproj.filters ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Bridge/Org.Apache.REEF.Bridge.vcxproj.filters b/lang/cs/Org.Apache.REEF.Bridge/Org.Apache.REEF.Bridge.vcxproj.filters new file mode 100644 index 0000000..2bb0932 --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Bridge/Org.Apache.REEF.Bridge.vcxproj.filters @@ -0,0 +1,136 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <ItemGroup> + <Filter Include="Source Files"> + <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier> + <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions> + </Filter> + <Filter Include="Header Files"> + <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier> + <Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions> + </Filter> + <Filter Include="Resource Files"> + <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier> + <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions> + </Filter> + </ItemGroup> + <ItemGroup> + <ClInclude Include="Org.Apache.REEF.JavaClrBridge.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="Stdafx.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="resource.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="BinaryUtil.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="Clr2JavaImpl.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="InteropAssemblies.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="InteropLogger.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="InteropReturnInfo.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="InteropUtil.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="JavaClrBridge.h"> + <Filter>Header Files</Filter> + </ClInclude> + </ItemGroup> + <ItemGroup> + <ClCompile Include="Org.Apache.REEF.JavaClrBridge.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="AssemblyInfo.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="Stdafx.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="ActiveContextClr2Java.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="AllocatedEvaluatorClr2Java.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="AssemblyUtil.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="BinaryUtil.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="ClosedContextClr2Java.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="CommonUtilities.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="CompletedEvaluatorClr2Java.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="CompletedTaskClr2Java.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="ContextMessageClr2Java.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="EvaluatorRequestorClr2Java.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="FailedContextClr2Java.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="FailedEvaluatorClr2Java.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="FailedTaskClr2Java.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="HttpServerClr2Java.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="InteropLogger.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="InteropReturnInfo.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="InteropUtil.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="JavaClrBridge.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="RunningTaskClr2Java.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="SuspendedTaskClr2Java.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="TaskMessageClr2Java.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + </ItemGroup> + <ItemGroup> + <Text Include="ReadMe.txt" /> + </ItemGroup> + <ItemGroup> + <ResourceCompile Include="app.rc"> + <Filter>Resource Files</Filter> + </ResourceCompile> + </ItemGroup> + <ItemGroup> + <Image Include="app.ico"> + <Filter>Resource Files</Filter> + </Image> + </ItemGroup> +</Project> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/492da34a/lang/cs/Org.Apache.REEF.Bridge/ReadMe.txt ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Bridge/ReadMe.txt b/lang/cs/Org.Apache.REEF.Bridge/ReadMe.txt new file mode 100644 index 0000000..804fb33 --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Bridge/ReadMe.txt @@ -0,0 +1,57 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +======================================================================== + DYNAMIC LINK LIBRARY : Org.Apache.REEF.JavaClrBridge Project Overview +======================================================================== + +AppWizard has created this Org.Apache.REEF.JavaClrBridge DLL for you. + +This file contains a summary of what you will find in each of the files that +make up your Org.Apache.REEF.JavaClrBridge application. + +Org.Apache.REEF.JavaClrBridge.vcxproj + This is the main project file for VC++ projects generated using an Application Wizard. + It contains information about the version of Visual C++ that generated the file, and + information about the platforms, configurations, and project features selected with the + Application Wizard. + +Org.Apache.REEF.JavaClrBridge.vcxproj.filters + This is the filters file for VC++ projects generated using an Application Wizard. + It contains information about the association between the files in your project + and the filters. This association is used in the IDE to show grouping of files with + similar extensions under a specific node (for e.g. ".cpp" files are associated with the + "Source Files" filter). + +Org.Apache.REEF.JavaClrBridge.cpp + This is the main DLL source file. + +Org.Apache.REEF.JavaClrBridge.h + This file contains a class declaration. + +AssemblyInfo.cpp + Contains custom attributes for modifying assembly metadata. + +///////////////////////////////////////////////////////////////////////////// +Other notes: + +AppWizard uses "TODO:" to indicate parts of the source code you +should add to or customize. + +///////////////////////////////////////////////////////////////////////////// http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/492da34a/lang/cs/Org.Apache.REEF.Bridge/RunningTaskClr2Java.cpp ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Bridge/RunningTaskClr2Java.cpp b/lang/cs/Org.Apache.REEF.Bridge/RunningTaskClr2Java.cpp new file mode 100644 index 0000000..dfc8ae3 --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Bridge/RunningTaskClr2Java.cpp @@ -0,0 +1,94 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +#include "Clr2JavaImpl.h" + +namespace Org { + namespace Apache { + namespace REEF { + namespace Driver { + namespace Bridge { + namespace Clr2java { + ref class ManagedLog { + internal: + static BridgeLogger^ LOGGER = BridgeLogger::GetLogger("<C++>"); + }; + RunningTaskClr2Java::RunningTaskClr2Java(JNIEnv *env, jobject jobjectRunningTask) { + ManagedLog::LOGGER->LogStart("RunningTaskClr2Java::RunningTaskClr2Java"); + + pin_ptr<JavaVM*> pJavaVm = &_jvm; + if (env->GetJavaVM(pJavaVm) != 0) { + ManagedLog::LOGGER->LogError("Failed to get JavaVM", nullptr); + } + _jobjectRunningTask = reinterpret_cast<jobject>(env->NewGlobalRef(jobjectRunningTask)); + + jclass jclassRunningTask = env->GetObjectClass(_jobjectRunningTask); + jmethodID jmidGetId = env->GetMethodID(jclassRunningTask, "getId", "()Ljava/lang/String;"); + + _jstringId = reinterpret_cast<jstring>(env->NewGlobalRef(env->CallObjectMethod(_jobjectRunningTask, jmidGetId))); + ManagedLog::LOGGER->LogStop("RunningTaskClr2Java::RunningTaskClr2Java"); + } + + IActiveContextClr2Java^ RunningTaskClr2Java::GetActiveContext() { + ManagedLog::LOGGER->LogStart("RunningTaskClr2Java::GetActiveContext"); + + JNIEnv *env = RetrieveEnv(_jvm); + + jclass jclassRunningTask = env->GetObjectClass(_jobjectRunningTask); + jfieldID jidActiveContext = env->GetFieldID(jclassRunningTask, "jactiveContext", "Lorg/apache/reef/javabridge/ActiveContextBridge;"); + jobject jobjectActiveContext = env->GetObjectField(_jobjectRunningTask, jidActiveContext); + ManagedLog::LOGGER->LogStop("RunningTaskClr2Java::GetActiveContext"); + + return gcnew ActiveContextClr2Java(env, jobjectActiveContext); + } + + String^ RunningTaskClr2Java::GetId() { + ManagedLog::LOGGER->Log("RunningTaskClr2Java::GetId"); + JNIEnv *env = RetrieveEnv(_jvm); + return ManagedStringFromJavaString(env, _jstringId); + } + + void RunningTaskClr2Java::Send(array<byte>^ message) { + ManagedLog::LOGGER->LogStart("RunningTaskClr2Java::Send"); + JNIEnv *env = RetrieveEnv(_jvm); + jclass jclassRunningTask = env->GetObjectClass(_jobjectRunningTask); + jmethodID jmidSend = env->GetMethodID(jclassRunningTask, "send", "([B)V"); + + + if (jmidSend == NULL) { + ManagedLog::LOGGER->Log("jmidSend is NULL"); + return; + } + env->CallObjectMethod( + _jobjectRunningTask, + jmidSend, + JavaByteArrayFromManagedByteArray(env, message)); + ManagedLog::LOGGER->LogStop("RunningTaskClr2Java::Send"); + } + + void RunningTaskClr2Java::OnError(String^ message) { + ManagedLog::LOGGER->Log("RunningTaskClr2Java::OnError"); + JNIEnv *env = RetrieveEnv(_jvm); + HandleClr2JavaError(env, message, _jobjectRunningTask); + } + } + } + } + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/492da34a/lang/cs/Org.Apache.REEF.Bridge/Stdafx.cpp ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Bridge/Stdafx.cpp b/lang/cs/Org.Apache.REEF.Bridge/Stdafx.cpp new file mode 100644 index 0000000..9a10a6e --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Bridge/Stdafx.cpp @@ -0,0 +1,24 @@ +/** +* Licensed to the Apache Software Foundation (ASF) under one +* or more contributor license agreements. See the NOTICE file +* distributed with this work for additional information +* regarding copyright ownership. The ASF licenses this file +* to you under the Apache License, Version 2.0 (the +* "License"); you may not use this file except in compliance +* with the License. You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* KIND, either express or implied. See the License for the +* specific language governing permissions and limitations +* under the License. +*/ + +// stdafx.cpp : source file that includes just the standard includes +// Org.Apache.REEF.JavaClrBridge.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/492da34a/lang/cs/Org.Apache.REEF.Bridge/Stdafx.h ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Bridge/Stdafx.h b/lang/cs/Org.Apache.REEF.Bridge/Stdafx.h new file mode 100644 index 0000000..add9279 --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Bridge/Stdafx.h @@ -0,0 +1,25 @@ +/** +* Licensed to the Apache Software Foundation (ASF) under one +* or more contributor license agreements. See the NOTICE file +* distributed with this work for additional information +* regarding copyright ownership. The ASF licenses this file +* to you under the Apache License, Version 2.0 (the +* "License"); you may not use this file except in compliance +* with the License. You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* KIND, either express or implied. See the License for the +* specific language governing permissions and limitations +* under the License. +*/ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, +// but are changed infrequently + +#pragma once + + http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/492da34a/lang/cs/Org.Apache.REEF.Bridge/SuspendedTaskClr2Java.cpp ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Bridge/SuspendedTaskClr2Java.cpp b/lang/cs/Org.Apache.REEF.Bridge/SuspendedTaskClr2Java.cpp new file mode 100644 index 0000000..e052d24 --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Bridge/SuspendedTaskClr2Java.cpp @@ -0,0 +1,87 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +#include "Clr2JavaImpl.h" + +namespace Org { + namespace Apache { + namespace REEF { + namespace Driver { + namespace Bridge { + namespace Clr2java { + ref class ManagedLog { + internal: + static BridgeLogger^ LOGGER = BridgeLogger::GetLogger("<C++>"); + }; + + SuspendedTaskClr2Java::SuspendedTaskClr2Java(JNIEnv *env, jobject jobjectSuspendedTask) { + ManagedLog::LOGGER->LogStart("SuspendedTaskClr2Java::SuspendedTaskClr2Java"); + pin_ptr<JavaVM*> pJavaVm = &_jvm; + if (env->GetJavaVM(pJavaVm) != 0) { + ManagedLog::LOGGER->LogError("Failed to get JavaVM", nullptr); + } + _jobjectSuspendedTask = reinterpret_cast<jobject>(env->NewGlobalRef(jobjectSuspendedTask)); + + jclass jclassSuspendedTask = env->GetObjectClass(_jobjectSuspendedTask); + jfieldID jidTaskId = env->GetFieldID(jclassSuspendedTask, "taskId", "Ljava/lang/String;"); + _jstringId = reinterpret_cast<jstring>(env->NewGlobalRef(env->GetObjectField(_jobjectSuspendedTask, jidTaskId))); + ManagedLog::LOGGER->LogStop("SuspendedTaskClr2Java::SuspendedTaskClr2Java"); + } + + IActiveContextClr2Java^ SuspendedTaskClr2Java::GetActiveContext() { + ManagedLog::LOGGER->LogStart("SuspendedTaskClr2Java::GetActiveContext"); + JNIEnv *env = RetrieveEnv(_jvm); + + jclass jclassSuspendedTask = env->GetObjectClass(_jobjectSuspendedTask); + jfieldID jidActiveContext = env->GetFieldID(jclassSuspendedTask, "jactiveContext", "Lorg/apache/reef/javabridge/ActiveContextBridge;"); + jobject jobjectActiveContext = env->GetObjectField(_jobjectSuspendedTask, jidActiveContext); + ManagedLog::LOGGER->LogStop("SuspendedTaskClr2Java::GetActiveContext"); + return gcnew ActiveContextClr2Java(env, jobjectActiveContext); + } + + String^ SuspendedTaskClr2Java::GetId() { + ManagedLog::LOGGER->Log("SuspendedTaskClr2Java::GetId"); + JNIEnv *env = RetrieveEnv(_jvm); + return ManagedStringFromJavaString(env, _jstringId); + } + + array<byte>^ SuspendedTaskClr2Java::Get() { + ManagedLog::LOGGER->Log("SuspendedTaskClr2Java::Get"); + JNIEnv *env = RetrieveEnv(_jvm); + jclass jclassSuspendedTask = env->GetObjectClass(_jobjectSuspendedTask); + jmethodID jmidGet = env->GetMethodID(jclassSuspendedTask, "get", "()[B"); + + if (jmidGet == NULL) { + ManagedLog::LOGGER->Log("jmidGet is NULL"); + return nullptr; + } + jbyteArray jMessage = (jbyteArray)env->CallObjectMethod(_jobjectSuspendedTask, jmidGet); + return ManagedByteArrayFromJavaByteArray(env, jMessage); + } + + void SuspendedTaskClr2Java::OnError(String^ message) { + ManagedLog::LOGGER->Log("SuspendedTaskClr2Java::OnError"); + JNIEnv *env = RetrieveEnv(_jvm); + HandleClr2JavaError(env, message, _jobjectSuspendedTask); + } + } + } + } + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/492da34a/lang/cs/Org.Apache.REEF.Bridge/TaskMessageClr2Java.cpp ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Bridge/TaskMessageClr2Java.cpp b/lang/cs/Org.Apache.REEF.Bridge/TaskMessageClr2Java.cpp new file mode 100644 index 0000000..1ee79e9 --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Bridge/TaskMessageClr2Java.cpp @@ -0,0 +1,62 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +#include "Clr2JavaImpl.h" + +namespace Org { + namespace Apache { + namespace REEF { + namespace Driver { + namespace Bridge { + namespace Clr2java { + ref class ManagedLog { + internal: + static BridgeLogger^ LOGGER = BridgeLogger::GetLogger("<C++>"); + }; + + TaskMessageClr2Java::TaskMessageClr2Java(JNIEnv *env, jobject jtaskMessage) { + ManagedLog::LOGGER->LogStart("TaskMessageClr2Java::TaskMessageClr2Java"); + pin_ptr<JavaVM*> pJavaVm = &_jvm; + if (env->GetJavaVM(pJavaVm) != 0) { + ManagedLog::LOGGER->LogError("Failed to get JavaVM", nullptr); + } + _jobjectTaskMessage = reinterpret_cast<jobject>(env->NewGlobalRef(jtaskMessage)); + + jclass jclassTaskMessage = env->GetObjectClass(_jobjectTaskMessage); + jfieldID jidTaskId = env->GetFieldID(jclassTaskMessage, "taskId", "Ljava/lang/String;"); + _jstringId = reinterpret_cast<jstring>(env->NewGlobalRef(env->GetObjectField(_jobjectTaskMessage, jidTaskId))); + ManagedLog::LOGGER->LogStop("TaskMessageClr2Java::TaskMessageClr2Java"); + } + + void TaskMessageClr2Java::OnError(String^ message) { + ManagedLog::LOGGER->Log("TaskMessageClr2Java::OnError"); + JNIEnv *env = RetrieveEnv(_jvm); + HandleClr2JavaError(env, message, _jobjectTaskMessage); + } + + String^ TaskMessageClr2Java::GetId() { + ManagedLog::LOGGER->Log("TaskMessageClr2Java::GetId"); + JNIEnv *env = RetrieveEnv(_jvm); + return ManagedStringFromJavaString(env, _jstringId); + } + } + } + } + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/492da34a/lang/cs/Org.Apache.REEF.Bridge/app.ico ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Bridge/app.ico b/lang/cs/Org.Apache.REEF.Bridge/app.ico new file mode 100644 index 0000000..d06d92b Binary files /dev/null and b/lang/cs/Org.Apache.REEF.Bridge/app.ico differ http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/492da34a/lang/cs/Org.Apache.REEF.Bridge/app.rc ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Bridge/app.rc b/lang/cs/Org.Apache.REEF.Bridge/app.rc new file mode 100644 index 0000000..eab4306 Binary files /dev/null and b/lang/cs/Org.Apache.REEF.Bridge/app.rc differ http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/492da34a/lang/cs/Org.Apache.REEF.Bridge/resource.h ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Bridge/resource.h b/lang/cs/Org.Apache.REEF.Bridge/resource.h new file mode 100644 index 0000000..a0daa2a --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Bridge/resource.h @@ -0,0 +1,22 @@ +/** +* Licensed to the Apache Software Foundation (ASF) under one +* or more contributor license agreements. See the NOTICE file +* distributed with this work for additional information +* regarding copyright ownership. The ASF licenses this file +* to you under the Apache License, Version 2.0 (the +* "License"); you may not use this file except in compliance +* with the License. You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* KIND, either express or implied. See the License for the +* specific language governing permissions and limitations +* under the License. +*/ + +//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ generated include file. +// Used by app.rc http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/492da34a/lang/cs/Org.Apache.REEF.Client/CLRBridgeClient.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Client/CLRBridgeClient.cs b/lang/cs/Org.Apache.REEF.Client/CLRBridgeClient.cs index 00b0a9a..5ec77c6 100644 --- a/lang/cs/Org.Apache.REEF.Client/CLRBridgeClient.cs +++ b/lang/cs/Org.Apache.REEF.Client/CLRBridgeClient.cs @@ -36,8 +36,8 @@ namespace Org.Apache.REEF.Client public class CLRBridgeClient { public const string ReefHome = "REEF_HOME"; - public const string DefaultClrFolder = @"lang\reef-bridge\dotnetHello"; - public const string DefaultReefJar = @"lang\reef-bridge\target\" + Constants.BridgeJarFileName; + public const string DefaultClrFolder = @"lang\java\reef-bridge-java\dotnetHello"; + public const string DefaultReefJar = @"lang\java\reef-bridge-java\target\" + Constants.JavaBridgeJarFileName; public const string DefaultRunCommand = "run.cmd"; private static string _clrFolder = null; http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/492da34a/lang/cs/Org.Apache.REEF.Client/Org.Apache.REEF.Client.csproj ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Client/Org.Apache.REEF.Client.csproj b/lang/cs/Org.Apache.REEF.Client/Org.Apache.REEF.Client.csproj index 9eac07f..9410aea 100644 --- a/lang/cs/Org.Apache.REEF.Client/Org.Apache.REEF.Client.csproj +++ b/lang/cs/Org.Apache.REEF.Client/Org.Apache.REEF.Client.csproj @@ -74,6 +74,10 @@ under the License. <Project>{75503f90-7b82-4762-9997-94b5c68f15db}</Project> <Name>Org.Apache.REEF.Examples</Name> </ProjectReference> + <ProjectReference Include="..\Org.Apache.REEF.Bridge\Org.Apache.REEF.Bridge.vcxproj"> + <Project>{4e69d40a-26d6-4d4a-b96d-729946c07fe1}</Project> + <Name>Org.Apache.REEF.Bridge</Name> + </ProjectReference> </ItemGroup> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <!-- To modify your build process, add your task inside one of the targets below and uncomment it. http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/492da34a/lang/cs/Org.Apache.REEF.Driver/Bridge/ClrClientHelper.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Driver/Bridge/ClrClientHelper.cs b/lang/cs/Org.Apache.REEF.Driver/Bridge/ClrClientHelper.cs index 8ccade9..d032241 100644 --- a/lang/cs/Org.Apache.REEF.Driver/Bridge/ClrClientHelper.cs +++ b/lang/cs/Org.Apache.REEF.Driver/Bridge/ClrClientHelper.cs @@ -32,7 +32,7 @@ namespace Org.Apache.REEF.Driver.Bridge { private static readonly Logger LOGGER = Logger.GetLogger(typeof(ClrClientHelper)); - public static void Run(HashSet<string> appDlls, IConfiguration driverBridgeConfig, DriverSubmissionSettings driverSubmissionSettings, string reefJar = Constants.BridgeJarFileName, string runCommand = "run.cmd", string clrFolder = ".", string className = Constants.BridgeLaunchClass) + public static void Run(HashSet<string> appDlls, IConfiguration driverBridgeConfig, DriverSubmissionSettings driverSubmissionSettings, string reefJar = Constants.JavaBridgeJarFileName, string runCommand = "run.cmd", string clrFolder = ".", string className = Constants.BridgeLaunchClass) { using (LOGGER.LogFunction("ClrHandlerHelper::Run")) { http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/492da34a/lang/cs/Org.Apache.REEF.Driver/Constants.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Driver/Constants.cs b/lang/cs/Org.Apache.REEF.Driver/Constants.cs index efbe999..0ec5659 100644 --- a/lang/cs/Org.Apache.REEF.Driver/Constants.cs +++ b/lang/cs/Org.Apache.REEF.Driver/Constants.cs @@ -71,7 +71,7 @@ namespace Org.Apache.REEF.Driver public const string DriverAppDirectory = "ReefDriverAppDlls"; - public const string BridgeJarFileName = "reef-bridge-0.11.0-incubating-SNAPSHOT-shaded.jar"; + public const string JavaBridgeJarFileName = "reef-bridge-java-0.11.0-incubating-SNAPSHOT-shaded.jar"; public const string BridgeLaunchClass = "org.apache.reef.javabridge.generic.Launch"; http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/492da34a/lang/cs/Org.Apache.REEF.Driver/DriverConfigGenerator.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Driver/DriverConfigGenerator.cs b/lang/cs/Org.Apache.REEF.Driver/DriverConfigGenerator.cs index ec4aa37..c0e1691 100644 --- a/lang/cs/Org.Apache.REEF.Driver/DriverConfigGenerator.cs +++ b/lang/cs/Org.Apache.REEF.Driver/DriverConfigGenerator.cs @@ -140,7 +140,7 @@ namespace Org.Apache.REEF.Driver private static void ExtractConfigFromJar(string jarfileFolder) { - string jarfile = jarfileFolder + Constants.BridgeJarFileName; + string jarfile = jarfileFolder + Constants.JavaBridgeJarFileName; List<string> files = new List<string>(); files.Add(DriverConfigGenerator.HttpServerConfigFile); files.Add(DriverConfigGenerator.JobDriverConfigFile); http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/492da34a/lang/cs/Org.Apache.REEF.Driver/InteropInterface/IInteropReturnInfo.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Driver/InteropInterface/IInteropReturnInfo.cs b/lang/cs/Org.Apache.REEF.Driver/InteropInterface/IInteropReturnInfo.cs new file mode 100644 index 0000000..b3b930a --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Driver/InteropInterface/IInteropReturnInfo.cs @@ -0,0 +1,30 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +using System; + +namespace Microsoft.Reef.Interop +{ + public interface IInteropReturnInfo + { + void AddExceptionString(String exceptionString); + Boolean HasExceptions(); + void SetReturnCode(int rc); + int GetReturnCode(); + } +} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/492da34a/lang/cs/Org.Apache.REEF.Driver/InteropInterface/ILogger.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Driver/InteropInterface/ILogger.cs b/lang/cs/Org.Apache.REEF.Driver/InteropInterface/ILogger.cs new file mode 100644 index 0000000..4a7f9b2 --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Driver/InteropInterface/ILogger.cs @@ -0,0 +1,37 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +using System; + +namespace Microsoft.Reef.Interop +{ + public enum TraceLevel : int + { + NoTrace = Int32.MaxValue, + + Error = 1000, + Warning = 900, + Info = 800, + Verbose = 300, + } + + public interface ILogger + { + void Log(TraceLevel traceLevel, String message); + } +} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/492da34a/lang/cs/Org.Apache.REEF.Driver/Org.Apache.REEF.Driver.csproj ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Driver/Org.Apache.REEF.Driver.csproj b/lang/cs/Org.Apache.REEF.Driver/Org.Apache.REEF.Driver.csproj index c50dab8..443a3d5 100644 --- a/lang/cs/Org.Apache.REEF.Driver/Org.Apache.REEF.Driver.csproj +++ b/lang/cs/Org.Apache.REEF.Driver/Org.Apache.REEF.Driver.csproj @@ -135,6 +135,8 @@ under the License. <Compile Include="Evaluator\IFailedEvaluator.cs" /> <Compile Include="FailedJob.cs" /> <Compile Include="IDriver.cs" /> + <Compile Include="InteropInterface\IInteropReturnInfo.cs" /> + <Compile Include="InteropInterface\ILogger.cs" /> <Compile Include="IStartHandler.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Task\ICompletedTask.cs" />
