Re: [PATCH 2.3.1] MamaPublisher: Overloaded MamaPublisher create method


Chad Meyer
 

Hi Glenn,

 

I have applied the changes you recommended and created a new patch. Please see attached.

 

diff --git a/mama/jni/src/c/mamapublisherjni.c b/mama/jni/src/c/mamapublisherjni.c

index 518bacf..aa1c4c6 100644

--- a/mama/jni/src/c/mamapublisherjni.c

+++ b/mama/jni/src/c/mamapublisherjni.c

@@ -76,40 +76,47 @@ static void MAMACALLTYPE sendCompleteCB (mamaPublisher publisher,

/*

  * Class:     com_wombat_mama_MamaPublisher

  * Method:    _create

- * Signature: (Lcom/wombat/mama/Transport;Ljava/lang/String;)V

+ * Signature: (Lcom/wombat/mama/MamaTransport;Ljava/lang/String;Ljava/lang/String;)V

  */

JNIEXPORT void JNICALL Java_com_wombat_mama_MamaPublisher__1create

-  (JNIEnv* env, jobject this, jobject transport, jstring topic)

+  (JNIEnv* env, jobject this, jobject transport, jstring topic, jstring source)

{

-    mamaPublisher   cPublisher          =   NULL;

+             mamaPublisher   cPublisher          =   NULL;

     mamaTransport   cTransport          =   NULL;

-    const char*     cTopic              =   NULL;

+    const char*     cSource             =   NULL;

+             const char*     cTopic                                                       =   NULL;

     jlong           transportPointer    =   0;

     mama_status     status              =   MAMA_STATUS_OK;

     char errorString[UTILS_MAX_ERROR_STRING_LENGTH];

     /*Get the transport pointer*/

     assert(transport!=NULL);

     transportPointer = (*env)->GetLongField(env, transport,

             transportPointerFieldId_g);

+

     cTransport = CAST_JLONG_TO_POINTER(mamaTransport, transportPointer);

-    assert(transportPointer!=0);

+    assert(transportPointer!=0);

     /*Get the char* from the jstring*/

     if(NULL!=topic)

     {

          cTopic = (*env)->GetStringUTFChars(env,topic,0);

          if(!cTopic)return;

     }

-   

+             if(NULL!=source)

+    {

+         cSource = (*env)->GetStringUTFChars(env,source,0);

+         if(!cSource)return;

+    }

+

     if(MAMA_STATUS_OK!=(mamaPublisher_create(

                     &cPublisher,

                     cTransport,

                     cTopic,

-                    NULL,

+                    cSource,

                     NULL)))

     {

-        if(cTopic)(*env)->ReleaseStringUTFChars(env,topic, cTopic);

+                             if(cTopic)(*env)->ReleaseStringUTFChars(env,topic, cTopic);

+        if(cSource)(*env)->ReleaseStringUTFChars(env,source, cSource);

         utils_buildErrorStringForStatus(

                 errorString, UTILS_MAX_ERROR_STRING_LENGTH,

                 "Failed to create publisher.", status);

@@ -121,6 +128,7 @@ JNIEXPORT void JNICALL Java_com_wombat_mama_MamaPublisher__1create

                          CAST_POINTER_TO_JLONG(cPublisher));

        

     if(cTopic)(*env)->ReleaseStringUTFChars(env,topic, cTopic);

+             if(cSource)(*env)->ReleaseStringUTFChars(env,source, cSource);

    

     return;

}

diff --git a/mama/jni/src/com/wombat/mama/MamaPublisher.java b/mama/jni/src/com/wombat/mama/MamaPublisher.java

index 0146945..31bb1f5 100644

--- a/mama/jni/src/com/wombat/mama/MamaPublisher.java

+++ b/mama/jni/src/com/wombat/mama/MamaPublisher.java

@@ -34,10 +34,15 @@ public class MamaPublisher

     /*A long value containing a pointer to the underlying C publisher structure*/

     private long    publisherPointer_i   =   0;

+            

+             public void create (MamaTransport transport, String topic)

+    {

+        _create(transport,topic,null);

+    }

-    public void create (MamaTransport transport, String topic)

+             public void create (MamaTransport transport, String topic, String source)

     {

-        _create(transport,topic);

+        _create(transport,topic,source);

     }

     public void send (MamaMsg msg)

@@ -76,7 +81,7 @@ public class MamaPublisher

         _sendFromInbox(inbox,msg);

     }

-    private native void _create (MamaTransport transport, String topic);

+    private native void _create (MamaTransport transport, String topic, String source);

     private native void _send (MamaMsg msg);

--

1.8.4.msysgit.0

 

From: Glenn McClements [mailto:gmcclements@...]
Sent: Monday, September 08, 2014 7:14 AM
To: Meyer, Chad J; openmama-dev@...
Subject: Re: [Openmama-dev] [PATCH 2.3.1] MamaPublisher: Overloaded MamaPublisher create method

 

Thanks Chad.

 

For consistency though with the C++ interface, it should be (publisher, topic, source), not (publisher, source, topic).  

 

Also consider replacing/extending the existing JNI _create()

function rather than having two. This reduces code duplication and you already check for a NULL source being passed down so it should handle both Java methods. 

 

Glenn 

 

From: <Meyer>, Chad J <chad.j.meyer@...>
Date: Friday, 5 September 2014 22:42
To: "openmama-dev@..." <openmama-dev@...>
Subject: [Openmama-dev] [PATCH 2.3.1] MamaPublisher: Overloaded MamaPublisher create method

 

Hi,

 

Attached is a patch for OpenMAMA JNI that overloads the MamaPublisher create method. For consistency purposes, the new method requires two String parameters, source and symbol, as opposed to a single string currently found in the MamaPublisher class.  


diff --git a/mama/jni/src/c/mamapublisherjni.c b/mama/jni/src/c/mamapublisherjni.c

index 518bacf..629a51b 100644

--- a/mama/jni/src/c/mamapublisherjni.c

+++ b/mama/jni/src/c/mamapublisherjni.c

@@ -78,7 +78,7 @@ static void MAMACALLTYPE sendCompleteCB (mamaPublisher publisher,

  * Method:    _create

  * Signature: (Lcom/wombat/mama/Transport;Ljava/lang/String;)V

  */

-JNIEXPORT void JNICALL Java_com_wombat_mama_MamaPublisher__1create

+JNIEXPORT void JNICALL Java_com_wombat_mama_MamaPublisher__1create__Lcom_wombat_mama_MamaTransport_2Ljava_lang_String_2

   (JNIEnv* env, jobject this, jobject transport, jstring topic)

{

     mamaPublisher   cPublisher          =   NULL;

@@ -125,6 +125,66 @@ JNIEXPORT void JNICALL Java_com_wombat_mama_MamaPublisher__1create

     return;

}

 

+ /*

+ * Class:     com_wombat_mama_MamaPublisher

+ * Method:    _create

+ * Signature: (Lcom/wombat/mama/MamaTransport;Ljava/lang/String;Ljava/lang/String;)V

+ */

+JNIEXPORT void JNICALL Java_com_wombat_mama_MamaPublisher__1create__Lcom_wombat_mama_MamaTransport_2Ljava_lang_String_2Ljava_lang_String_2

+  (JNIEnv* env, jobject this, jobject transport, jstring source, jstring symbol)

+{

+             mamaPublisher   cPublisher          =   NULL;

+    mamaTransport   cTransport          =   NULL;

+    const char*     cSource             =   NULL;

+             const char*     cSymbol             =   NULL;

+    jlong           transportPointer    =   0;

+    mama_status     status              =   MAMA_STATUS_OK;

+    char errorString[UTILS_MAX_ERROR_STRING_LENGTH];

+            

+    /*Get the transport pointer*/

+    assert(transport!=NULL);

+    transportPointer = (*env)->GetLongField(env, transport,

+            transportPointerFieldId_g);

+    cTransport = CAST_JLONG_TO_POINTER(mamaTransport, transportPointer);

+    assert(transportPointer!=0);

+            

+    /*Get the char* from the jstring*/

+    if(NULL!=source)

+    {

+         cSource = (*env)->GetStringUTFChars(env,source,0);

+         if(!cSource)return;

+    }

+             if(NULL!=symbol)

+    {

+         cSymbol = (*env)->GetStringUTFChars(env,symbol,0);

+         if(!cSymbol)return;

+    }

+

+    if(MAMA_STATUS_OK!=(mamaPublisher_create(

+                    &cPublisher,

+                    cTransport,

+                    cSymbol,

+                    cSource,

+                    NULL)))

+    {

+        if(cSource)(*env)->ReleaseStringUTFChars(env,source, cSource);

+                             if(cSymbol)(*env)->ReleaseStringUTFChars(env,symbol, cSymbol);

+        utils_buildErrorStringForStatus(

+                errorString, UTILS_MAX_ERROR_STRING_LENGTH,

+                "Failed to create publisher.", status);

+        utils_throwMamaException(env,errorString);

+        return;

+    }

+

+    (*env)->SetLongField(env,this,publisherPointerFieldId_g,

+                         CAST_POINTER_TO_JLONG(cPublisher));

+       

+    if(cSource)(*env)->ReleaseStringUTFChars(env,source, cSource);

+             if(cSymbol)(*env)->ReleaseStringUTFChars(env,symbol, cSymbol);

+   

+    return;

+}

+

/*

  * Class:     com_wombat_mama_MamaPublisher

  * Method:    _send

diff --git a/mama/jni/src/com/wombat/mama/MamaPublisher.java b/mama/jni/src/com/wombat/mama/MamaPublisher.java

index 0146945..c1e8dc8 100644

--- a/mama/jni/src/com/wombat/mama/MamaPublisher.java

+++ b/mama/jni/src/com/wombat/mama/MamaPublisher.java

@@ -39,6 +39,11 @@ public class MamaPublisher

     {

         _create(transport,topic);

     }

+            

+             public void create (MamaTransport transport, String source, String symbol)

+    {

+        _create(transport,source,symbol);

+    }

     public void send (MamaMsg msg)

     {

@@ -77,6 +82,8 @@ public class MamaPublisher

     }

     private native void _create (MamaTransport transport, String topic);

+            

+             private native void _create (MamaTransport transport, String source, String symbol);

     private native void _send (MamaMsg msg);

--

1.8.4.msysgit.0

 

 

Chad Meyer| Corporate & Investment Bank | PIM Market Data Services | J.P. Morgan | 4 Metrotech Center 23rd Floor Brooklyn, NY 11201 | Tel: (718) 242-5165 | M: (215) 801-2606 | chad.j.meyer@...

 

This communication is for informational purposes only. It is not intended as an offer or solicitation for the purchase or sale of any financial instrument or as an official confirmation of any transaction. All market prices, data and other information are not warranted as to completeness or accuracy and are subject to change without notice. Any comments or statements made herein do not necessarily reflect those of JPMorgan Chase & Co., its subsidiaries and affiliates. This transmission may contain information that is proprietary, privileged, confidential and/or exempt from disclosure under applicable law. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution, or use of the information contained herein (including any reliance thereon) is STRICTLY PROHIBITED. Although this transmission and any attachments are believed to be free of any virus or other defect that might affect any computer system into which it is received and opened, it is the responsibility of the recipient to ensure that it is virus free and no responsibility is accepted by JPMorgan Chase & Co., its subsidiaries and affiliates, as applicable, for any loss or damage arising in any way from its use. If you received this transmission in error, please immediately contact the sender and destroy the material in its entirety, whether in electronic or hard copy format. Thank you. Please refer to http://www.jpmorgan.com/pages/disclosures for disclosures relating to European legal entities.


This message may contain confidential information and is intended for specific recipients unless explicitly noted otherwise. If you have reason to believe you are not an intended recipient of this message, please delete it and notify the sender. This message may not represent the opinion of Intercontinental Exchange, Inc. (ICE), Euronext or any of their subsidiaries or affiliates, and does not constitute a contract or guarantee. Unencrypted electronic mail is not secure and the recipient of this message is expected to provide safeguards from viruses and pursue alternate means of communication where privacy or a binding message is desired.


This communication is for informational purposes only. It is not intended as an offer or solicitation for the purchase or sale of any financial instrument or as an official confirmation of any transaction. All market prices, data and other information are not warranted as to completeness or accuracy and are subject to change without notice. Any comments or statements made herein do not necessarily reflect those of JPMorgan Chase & Co., its subsidiaries and affiliates. This transmission may contain information that is proprietary, privileged, confidential and/or exempt from disclosure under applicable law. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution, or use of the information contained herein (including any reliance thereon) is STRICTLY PROHIBITED. Although this transmission and any attachments are believed to be free of any virus or other defect that might affect any computer system into which it is received and opened, it is the responsibility of the recipient to ensure that it is virus free and no responsibility is accepted by JPMorgan Chase & Co., its subsidiaries and affiliates, as applicable, for any loss or damage arising in any way from its use. If you received this transmission in error, please immediately contact the sender and destroy the material in its entirety, whether in electronic or hard copy format. Thank you. Please refer to http://www.jpmorgan.com/pages/disclosures for disclosures relating to European legal entities.

Join Openmama-dev@lists.openmama.org to automatically receive all group messages.