JNI Multithreading/Callback Function Design Issues

Ok, I have been working on this for quite some time now and I simply can not figure it out. So any ideas are more than welcome. :)
I have Java code that uses a DLL that I created in C++. My C++ code links with a library made by a 3rd party (don't have access to the source or anything). The 3rd party's code creates a new thread and calls a callback function that I define in my C++ code. This callback is called continuously until I perform some other code to stop it. Now for the tricky part. In my callback function I need to pass some data back in Java. Here is where my design falls apart. Since the callback function is technically part of the 3rd party's thread, I have to call AttachCurrentThread() in the callback to get the JNIEnv pointer in order to ultimately call my desired Java method. The problem is that my Java method (or even the C++ callback function) are only invoked if I do a sleep() in my C++ code after I start the 3rd party code which creates the thread. If I do a Thread.sleep() in Java after I call the native function code, it just sleeps and the callbacks never get called. It appears as though the thread dies as soon as I return from my C++ code.
So now I am stuck. I have tried creating a thread in Java which simply calls the C++ code and the C++ code just loops waiting for an updated flag, however, this causes the 3rd party's thread creation code to fail (not quite sure why). However, even if their code worked, I'm not convinced this is even proper design. I apologize if this is simply a threading design principle as my multithreading programming techniques are a bit rusty and I've never done a multithreaded application this complex (this is a simplified version, but the idea is the same).
I welcome any suggestions or even documentation that may lead me in the right direction. Thanks in advance.

I have a similar issue.
from java I call a dll I wrote, which calls a third party scanner dll (cyber.dll). Everything works ok, except, when an event in the scanner occurs, it calls the call backin my dll, which calls the callback in java, which kills the vm with an access violation. If I execute the call back to java from a c method which I just called from java, it works, but if it gets called outside of the java execution of the native code, it fails.
I havent done anything with treads or syncronisation. Do I need to do this AttachCurrentThread stuff? If so, where do I get the _jvm handle as Im not starting the vm from c?                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

Similar Messages

  • Import dll callback function

    Having trouble with this line "void   (*m_callback)(_t_pciCommand *cmd);" in PciApi.h file. I have replaced it with NULL and was able to import 2 functions, PciAllocCommand and PciSendCommand. I was then able to get valid information using GetValueByPointer.VI, but crash most of the time.
    typedef struct _t_pciCommand
                    t_pciCommandType                      m_command;
                    t_commandError                          m_error;
                    long                                               m_gpVal;
                    void                                                (*m_callback)(_t_pciCommand *cmd);
                    long                                              m_param[MAX_PCI_PARAMS];
                    int                                               m_state;
                    int                                               m_retries;
                    int                                               m_expected;           
                    long                                            m_origParam[MAX_PCI_PARAMS];
    } t_pciCommand;
    All files attached. Based on this callback funtion, I can't seem to resolve 2 functions, called PciAllocCommand and PciSendCommand.
    Thanks,
    John
    Solved!
    Go to Solution.
    Attachments:
    PciApiDll7.zip ‏630 KB

    The manual is "pci_api_manual_jb.doc", The funtion I care most about is PciAllocCommand and the #1 issue I have is how to pass "m_param[0]" , "m_param[1]" and "m_param[2]" to the dll. The original h file is "PciApp(original).h" . The second issue would be if removing the callback functionality I need a VI to poll the status of "t_PciCommand "Function without writing to it.
    For example, PciAllocCommand(c_baudrate, NULL, 0). How do I set baud = m_param[0]?
    Also I am adding a TestApp.exe example of what I want to do in Labview, focusing on the Param1 and Param2
    Attachments:
    PciApiDll7.zip ‏630 KB
    TestApp.zip ‏67 KB

  • External Function with a Pointer to a Callback Function Inside a DLL

    Hi.
    I'm loading a DLL and trying to call a function with the following prototype:
    Func1(HANDLE, hHandle, LPVOID (*pCallback)(UINT, UINT LPVOID), CHAR* sPath)
    Now, I have no problem with the variable types, because CVI 9.0.1 recognizes all of them and I have no problem with LoadLibrary() nor with GetProcAddress().
    But, how do I pass a pointer to a callback that is inside the DLL I'm trying to use.
    I've tried to declare the callback like this:
    LPVOID (CALLBACK Callback)(UINT iDevNo, UINT evEvent, LPVOID pData);
    and call the function Func1 like this:
    (Func1)(hHandle, &Callback, NULL);
    but this gets me:
     Undefined symbol '_Callback@12' referenced in "source.c".
    Hope I can get some help.
    I appreciate your time on this issue.
    Regards.
    Daniel Coelho
    VISToolkit - http://www.vistoolkit.com - Your Real Virtual Instrument Solution
    Controlar - Electronica Industrial e Sistemas, Lda
    Solved!
    Go to Solution.

    Hi Daniel,
    First, you have to make sure that the callback function is exported by the DLL, so that the program that uses the DLL can access the function name identifier. Then, you have to make sure that you call GetProcAddress not just on Func1, but also on the exported callback function. You need to store both function address values in their respective function pointers. You then can pass the callback function pointer as an argument to the Func1 call.
    It's probably cleaner if you define typedefs for all your function pointers, in the calling program:
    typedef LPVOID (__stdcall *CallbackType) (UINT , UINT, LPVOID);
    typedef ??? (__stdcall *Func1Type) (HANDLE, hHandle, CallbackType, CHAR*);
    CallbackType     CallbackPtr;
    Func1Type        Func1Ptr;
    dllHandle = LoadLibrary ("...");
    CallbackPtr = (CallbackType)GetProcAddress (dllHandle, "Callback");
    Func1Ptr = (Func1Type)GetProcAddress (dllHandle, "Func1");
    Func1Ptr (..., hHandle, CallbackPtr, NULL);
    Boa Sorte!
    Luis

  • Callback function as soon as animation complete

    Hi all,
    My question is very straight forward:
    I would like to fire up a function as soon as a symbol has finished playing, and i would like to write the code in the stage event.
    Ive created a very simple exmple for the matter:
    I have two symbols each with a very simple animation taking them out of the screen, and each with a trigger on 0ms - sym.stop();
    I start rect1 animation in the stage event and i would like to call a callback function as soon as rect1's playback is complete.
    screensohts attached:
    I think a lot of people would like to see a sulotion to this issue.
    thank you!
    Asafg84

    Hi Anne, thank you for your reply
    I generate children of a symbol dinamically, in very large numbers. The symbols playing could be brothers (children of the same symbol) and i want only one of their animation complete to trigger a callback function,
    additionally in the child symbols there are a lot of sequences of animation (I play them according to certain events), and it doesnt make good practice that i call a function at the end of each sequence.
    putting all my code at stage level gives me the most control and its the best practice, and sometimes necessary. i should be able to do that.
    Have a wonderful day and thanks again for the answer!
    Asafg84

  • Call Java Method from Callback function

    I am writing a JNI wrapper in c++ for a particular event driven DLL. The DLL makes a network connection to another device and then calls a callback function when events are raised on the device. The DLL has 3 basic functions: connect, disconnect, and registerEventListener. RegisterEventListener takes a function pointer which is called each time an event is raised on the device.
    My wrapper DLL exposes connect and disconnect functions via JNI. I can call these functions just fine from my Java code. Now the question... How do I call a Java method from my c++ callback function? I can call a Java method using env->CallXXXMethod(...) from within a function that is accessible to Java but I don't have access to the JNI parameters in my Callback function.
    So how do I call a Java method from a callback function? If this cannot be done then what is the "right way" to handle native event notification with JNI?

    jschell wrote:
    JNI parameters? Meaning what exactly?
    General outline of a callback
    1. Entry
    2. Get the VM, env - there are methods for this
    3. Attach the thread
    4. Get a java object - how depends on what you are doing, but create it or a static reference.
    5. Get the java method
    6. Call the java method.That is exactly correct. The callback function is called from a separate thread so using a cached pointer to JNIEnv, obtained from the original native method, crashes the JVM. The jmethodID and jclass objects (which are needed to call the static Java method) can be cached without problem. The following is the code I used to attach the current thread and call my static method.
    void MyClass::onEvent(int system_id, char* data)
         //get a pointer to the Java Environment
         JNIEnv *env;
         jvm->AttachCurrentThread((void **)&env, NULL);
         //Call the Java method with the newly aquired data
         jstring js = env->NewStringUTF(data);
         env->CallStaticVoidMethod(cls, mid, system_id, js);
    }My last question is about cleanup in this function. When I use NewStringUTF to "convert" my char* to jstring do I need to do anything special to clean up or will the Java garbage collector take care of it since the jstring is being passed to a Java method?
    Thanks for you help

  • NI DAQ and Arduino in Matlab (control obj in a callback function triggered by another obj)

    (I am aware that this may not be the most appropriate place to ask, but I'm pretty desperate...)
    I am writing a script to acquire online data from a DAQ card and to control an Arduino microcontroller based on the output of the DAQ card data.
    The acquiring of the DAQ card data works fine, but I'm having problems with (1) the online processing of these data and (2) the corresponding controlling of the Arduino microcontroller. I'll try to explain both problems as clear as possible, the matlab code that has already been written can be found at the bottom of this question.
    I'm using a 64-bit Matlab, so I can only use the Session-Based Interface.
    1) Online processing
    Data are collected at a rate of 1000 samples/s. Each time 250 new samples are available, a callback function is triggered to process these data (using a listener triggered by the 'DataAvailable' event). This processing consists of spectral analysis, using the 'spectrogram' function. The problem is that the spectrogram function should use a window of 500 samples and an overlap of 250 samples. So, new samples should be available for processing every 250 samples, but not only the new 250 samples but also the previous 250 samples are needed to accomplish the overlap. Basically, I need 500 samples for each callback function run, but this function has to be ran every 250 samples.
    2) Controlling the Arduino
    The biggest problem lies in the controlling of the Arduino. After spectral analysis, the calculated value is compared to a predefined treshold and if this value exceeds the treshold, the output of the Arduino should be put to one, else the output should be put to zero. The problem here is that, since the callback function is an external function, it doesn't recognize the Arduino object. The Arduino has been connected to Matlab at the start of the script, but is only available in the 'base' workspace. Connecting the Arduino on each function run isn't a possibility, since this should be done every 250 ms.
    Attempted solutions
    I have tried to make the function into a nested function, so that it can use the same variables as the ones in the script, but Matlab doesn't allow this. When I write a nested function, I get the following error: "A nested function cannot be defined inside a control statement (if, while, for, switch or try/catch)." However, I have never defined one of these statements, so the function isn't inside a control statement. I don't understand why this doesn't work.
    Matlab code
    Script
    %% Preparing Arduino
    % Connecting the arduino chip to Matlab
    a=arduino('COM4');
    % Defining the 13th pin as an output
    a.pinMode(13,'output')
    %% Preparing the DAQ card
    % Searching the DAQ card
    devices = daq.getDevices;
    % Create a session
    s = daq.createSession('ni');
    % Define the input channel
    s.addAnalogInputChannel('Dev1', 0, 'Voltage');
    % Define the total measuring and stimulation time
    s.DurationInSeconds = 4;
    % Define the interval for processing
    s.NotifyWhenDataAvailableExceeds = 500;
    % Loading the optimal stimulation parameters
    load('parameters.mat')
    setappdata(s,'freq',parameters(1))
    setappdata(s,'treshold',parameters(2))
    % Define a listener triggered by the DataAvailable event
    lh = s.addlistener('DataAvailable',@stimulation); 
    % Save the start time
    starttime=clock;
    % Start the measurements
    LFP=s.startForeground;
    Callback function
    function stimulation(src,event)
          freq=getappdata(src,'freq');
          treshold=getappdata(src,'treshold');
          LFP=event.Data;
          [S,F,T,P]=spectrogram(LFP,500,250,[],1000);
          PSD=log(P(freq));
          if PSD>=treshold
             a.digitalWrite(13,1)
          else
             a.digitalWrite(13,0)
          end
    end
    All comments/suggestions are welcome.
    Many thanks in advance!

    Hello hemm,
    As you noted this is most likely not the appropriate place to past these non-NI Development environment related questions.
    Especially since the issue does not seem to be related to the interface with the NI DAQ card.
    Maybe you could add some Message Tags so that people that are following specific tags might be able to  detect your question and help you.
    Would it be an option for you to use NI LabVIEW?
    If this is the case then it might be interesting to note that many of the Arduino users over here are using the NI LabVIEW Interface for Arduino Toolkit:
    http://sine.ni.com/nips/cds/view/p/lang/en/nid/212​478
    This is however being supported from the following page:
    https://decibel.ni.com/content/groups/labview-inte​rface-for-arduino
    Kind Regards,
    Thierry C - Applications Engineering Specialist Northern European Region - National Instruments
    CLD, CTA
    If someone helped you, let them know. Mark as solved and/or give a kudo.

  • SAPUI5 callback function paradigm

    I am missing callback functions in all controls and elements especially for loading and rendering.
    E.g.
    - I would like to know when a table (based on data binding) was rebuild.
    - When a dropdownbox was opened.
    - etc.
    there are so many events and states which would be helpful to know to control loading and rendering. How do you face this issue? How is your solution?

    Hi Sangeeta,
    CALLBACK modules basically return the u2018oldu2019 and u2018newu2019 memory of a dataset after an operation and thus give you a snapshot of what data changed in the process. They find use in event triggers, or to define a reaction based on some processing done in the transaction.
    E.g : say you want to send an Email to a supervisor everytime a user changes the BP name. The only way you can know if the BP name has changed is by comparing the database for BUT000-NAME_FIRST and BUT000-NAME_LAST between before and after the operation. To do this, you can just call module BUP_MEMORY_BUT000_CALLBACK, or BUPA_GENERAL_CALLBACK. This returns the BUT000 state before and after in 2 tables  - ET_BUT000_OLD and ET_BUT000_NEW. So you can easily compare the contents and react accordingly.
    The most classic use of Callback modules is in Data Exchange. The callback modules help the application decide what data has changed, and thus, what must be sent over to the other connected systems.
    Hope this helps you !
    Cheers,
    Rishu.

  • Testing asynchronous callback functions

    I have been creating a test suite for an API that my company has been developing and have run into a bit of a snag trying to create tests for a couple of our async callback functions. I have tested a number of our async events properly using the addEventListener and addAsync combination and they have worked brilliantly, but these last couple are slightly different.
    The issue I am running into now is that these problematic async callbacks are not firing an event but just returning a url and so the function signature doesn't match what is expected by the addEventListener/addAsync combination I had been using so far for testing. Is there a different approach required to test an asynchronous method that is not firing an event??
    Thanks in advance for your help.

    Geoff,
    Sorry this has gone unanswered. There are several new async methods that will be making an appearance in the upcoming beta 2. I think these will solve your issue.
    Mike

  • Design issue with the multiprovider

    Design issue with the multiprovider :
    I have the following problem when using my multiprovider.
    The data flow is like this. I have the info-objects IobjectA, IobjectB, IobjectCin my Cube.(Source for this data is s-systemA)
    And from another s-system I am also loading the masterdata for IobjectA
    Now I have created the multiprovider based on the cube and IobjectA.
    However, surprisingly join in not workign in multiprovider correctly.
    Scenario :
    Record from the Cube.
    IObjectA= 1AAA
    IObjectB = 2BBB
    IObjectC = 3CCC
    Records from IobjectA =1AAA.
    I expect the record should be like this :
    IObjectA : IObjectB: IObjectC
    1AAA       :2BBB       :3CCC
    However, I am getting the record like this:
    IObjectA : IObjectB: IObjectC
    1AAA       :2BBB       :3CCC
    1AAA         : #             :#
    In the Identification section I have selected both the entries for IobjectA still I am getting this error.
    My BW Version is 3.0B and the SP is 31.
    Thanks in advance for your suggestion.

    May be I was not clear enough in my first explanation, Let me try again to explain my scenario:
    My Expectation from Multi Provider is :
    IObjectA
    1AAA
    (From InfoObject)
    Union
    IObjectA     IObjectB     IObjectC
    1AAA     2BBB     3CCC
    (From Cube)
    The record in the multiprovider should be :
    IObjectA     IObjectB     IObjectC
    1AAA     2BBB     3CCC
    Because, this is what the Union says .. and the Definition of the multiprovider also says the same thing :
    http://help.sap.com/saphelp_bw30b/helpdata/EN/ad/6b023b6069d22ee10000000a11402f/frameset.htm
    Do you still think this is how the behaviour of the multiprovider.. if that is the case what would be the purpose of having an infoobject in the multiprovider.
    Thank you very much in advance for your responses.
    Best Regards.,
    Praveen.

  • Data mart from two DSOs to one - Loosing values - Design issue

    Dear BW experts,
    I´m dealing with a design issue for which I would really appreciate any help and suggestions.
    I will be as briefly as possible, and explain further based on the doubts , questions I received in order to make it easier go through this problem.
    I have two standard DSOs (DSO #1 and #2) feeding a third DSO (DSO #3), also standard.
    Each transformation DOES NOT include all fields, but only some of them.
    One of the source DSO (let´s call it DSO #1) is uploaded with a datasource that allows reverse type of records  (Record Mode = 'R'). Therefore some updates on DSO #1 comes with one entry with record mode 'R' and a 2nd entry with record mode = 'N' (new).
    Both feeds are delta mode, and not the same entries are updated through each of them, but the entries that are updated can differ (means an specific entry (unique key values)  could be update by one of the feeds, but no updates on the 2nd feed for that entry).
    Issue we have:  When a 'R' and 'N' entries happen in DSO #1 for any entry, that entry is also reversed and re created in the target DSO #3 (even being that not ALL fields are mapped in the transformation), and thefore we loose ALL the values that are exclusively updated through DSO #2, becoming blank.
    I don´t know it we are missing something in our design, or how should we fix this issue we have.
    Hope I was more or less clear with the description.
    ´d really appreciatted your feedback.
    Thanks!!
    Gustavo

    Hi Gustavo
    Two things I need to know.
    1. Do you have any End Routine in your DSO? If yes, what is the setting under "Update behavior of End Routine Display"....Option available right side of Delete Button ater End Rouine.
    2. Did you try with Full Load from DSO1 and DSO2 to DSO3? Do you face the same problem?
    Regards
    Anindya

  • How to create a callback function module

    Hi all,
    I am working in a requirement where we need to call a function module at a 'after change' event. So how to create a callback function module and register it with the crmvevent ?_
    I created a sample function module and try to create entries in table crmv_event_cust, but i got an error message saying that the function module name I provided is not in table CRMC_FUNC_ASSIGN. When I try to create entry there, I got a message that function module is not in CRMC_OBJ_FUNC and that table is a standard table with no maintanance options !!
    looks like i am going in wrong way ... can any one please help ??

    Looking at my system all you need to do is create the entry for the callback function in maint view: CRMV_FUNC_ASSIGN.
    Your entry should be as simple as Z-function name Object Function - <same as others in the segment you are assigning>
    IE for the partner it would be CRM_PARTNER as object function, for general order processing CRM_ORDER
    Take care,
    Stephen

  • Design issue with sharing LV2 style global between run-time executables

    Hi,
    Just when I though that I had everything figured out, I ran into this design issue.
    The application that I wrote is pretty much a client-server application where the server publishes data and the client subscribes data using data sockets. Once the client gets all the data in the mainClient.vi program, I use LV2 style (using shift registers) to make the data global to all the other sub-vi’s. So the LV2 is in initialize mode in the mainClient.vi program and then in the sub-vi’s the LV2 is in read mode. Also, I had built the run time menu for each sub-vi that when an item is selected from the menu, I would use the get menu selection to get the item tag which will be the file nam
    e of the sub-vi and open the selected sub-vi using vi server. This all worked great on my workstation where I have labVIEW 7.0 Express installed. But the final goal is to make exe’s for each of these sub-vi’s and install runtime on the PC’s that do not have labVIEW installed. Of course when I did that only the mainClient.exe program was getting the updated data from the server but the sub-vi’s were not getting the data from the mainClient.exe. I did realize that the reason for this is due to the fact that I had compiled all the sub-vi’s separately and so the LV2 vi is now local to each executable (i.e. all executables have their own memory location). Also, the run-time menu did not work because now I am trying to open an executable using vi server properties.
    To summarize, is there a way to share LV2 style global's between executables without compiling all of the sub-vi’s at one time? I tried using data-sockets (local-host) instead of LV2 st
    yle gloabls to communicate between the sub-vi’s but I ran into performance issues due to the large volume of data.
    I would really appreciate it if anyone can suggest a solution/alternative to this problem.
    Thanks
    Nish

    > 1)   How would I create a wrap-around for the LV2.vi which is
    > initialized in my mainClient.vi and then how would I use vi server in
    > my sub-vi to refer to that LV2.vi?
    > You mentioned that each sub-vi when opened will first connect to the
    > LV2.vi via via-server and will keep the connection in the shift
    > register of that sub-vi. Does this mean that the sub-vi is accessing
    > (pass-by-reference) the shared memory of the mainClient.vi? If this
    > is what you meant I think that this might work for my application.
    >
    If the LV2 global is loaded statically into your mainClient.vi, then any
    other application can connect to the exe and get a reference to the VI
    using the VI name. This gives you a VI reference you can use to call
    the VI. Ye
    s, the values will be copied between applications. That is
    why you need to add access operations to the global that returns just
    the info needed. If you need the average, do that in the global. If
    you need the array size, do that in the global. Returning the entire
    array shouldn't be a common operation on the LV2 style global anyway.
    > 2) Just to elaborate on my application, the data is
    > transferred via DataSockets from the mainServer.vi on another PC to
    > the client’s PC where the mainClient.vi program subscribes the
    > data (i.e. 5 arrays of double type and each arrays has about 50,000
    > elements). The sub-vi’s will have to access these arrays
    > located on the mainClient.vi every scan. Is there any limitation on
    > referencing the mainClient.vi data via vi-server from each sub-vi?
    Your app does need to watch both the amount of data being passed across
    the network, and the amount being shared between the apps. You might
    want to consider puttin
    g the VIs back into the main app. What is the
    reason you are breaking them apart for?
    Greg McKaskle

  • Calling a method from a callback function under ARC

    Hi All
    I previously wrote some HIDManager software. The HIDManager references were done in a Objective C class so within this object you have the code:
        IOHIDManagerRegisterDeviceMatchingCallback( k8055HIDManager, k8055BoardWasAdded, (__bridge void*)self );
    Which registers with the HIDManager
    The Callback function which is outside the class was as follows:
    static void k8055BoardWasAdded(void* inContext, IOReturn inResult, void* inSender, IOHIDDeviceRef k8055HIDDevice)
        IOHIDDeviceOpen(k8055HIDDevice, kIOHIDOptionsTypeNone);
        CCVellemanK8055Driver * k8055 = (__bridge CCVellemanK8055Driver *)inContext;
        [k8055 setHardwareConnectionStatus : YES];
    Any how my problem is in converting the code to ARC as under OS X 10.9 SDK and 64bit I'm now getting a EXC_BAD_ACCESS (Code=EXC_I386_GPFLT) at this line
        CCVellemanK8055Driver * k8055 = (__bridge CCVellemanK8055Driver *)inContext;
    although removing the method
    [k8055 setHardwareConnectionStatus : YES];
    will alow it to build but then obviously the app won't work as required.
    Could someone suggest a ARC safe way of accessing the passed instance so I can again call methods on it.
    Cheers
    Steve

    Try using blocks instead. This is the callback I am using for libcurl.
    static size_t callback(
      void * contents, size_t size, size_t nmemb, void * context)
      size_t (^block)(void *, size_t) =
        (__bridge size_t (^)(void *, size_t))context;
      size_t result = block(contents, size * nmemb);
      return result;

  • A web service design issue with patterns

    Hello,
    I�d like to ask for your help in the following design issue:
    I need to create an email sending web service (with Axis). Only just one method which returns with an integer return code. This handles the following:
    - based on the given parameters gets the email addresses from an
    LDAP server (with netscape ldap for java)
    -     makes a cache from them (only after a timeout period will be the cache
    refreshed) (don�t know what tool to use for this)
    -     selects html templates which to be sent based on the given parameters
    -     sends emails with the appropriate templates (with Velocity)
    -     the whole process is logged (with log4j)
    I have to write the code as generic as possible. I know that some design pattern should be used for this. (some from GoF , and I know there exists design patterns specially created for web services as well).
    Could you enumerate me which patterns (and for what part of the program) would be the best choice to solve this problem? I have read through some books about patterns, but don�t have the knowledge to pick up the right one for a concrete problem like this..
    Thank you in advance,
    nagybaly

    Hello,
    I�d like to ask for your help in the following design
    issue:
    I need to create an email sending web service (with
    Axis). Only just one method which returns with an
    integer return code. This handles the following:Lots of responsibilities here. You would do well to break this up into several classes that you can test separately.
    I would also advise that you not embed all this in a servlet. Make a service that collaborates with several objects to accomplish the task and let the serlvet just call it.
    .> - based on the given parameters gets the email
    addresses from an
    LDAP server (with netscape ldap for java)I'd recommend Spring's LDAP module. Pretty terrific stuff.
    cache from them (only after a timeout period will be
    the cache
    refreshed) (don�t know what tool to use for
    this)Maybe EhCache or OsCache or something like that.
    -     selects html templates which to be sent based on
    the given parametersWhere does this come from? Certainly not the LDAP. A relational database? Write a DAO for the document template.
    -     sends emails with the appropriate templates (with
    Velocity)Have an e-mail sender service using Java Mail.
    -     the whole process is logged (with log4j)Easily done.
    I have to write the code as generic as possible. I
    know that some design pattern should be used for
    this. No pattern. There might be patterns, if you say that the DAOs to access the LDAP and RDB are patterns.
    Stop thinking patterns and start thinking objects.
    (some from GoF , and I know there exists design
    patterns specially created for web services as
    well).Nope.
    Could you enumerate me which patterns (and for what
    part of the program) would be the best choice to
    solve this problem? I have read through some books
    about patterns, but don�t have the knowledge to pick
    up the right one for a concrete problem like this..
    Thank you in advance,
    nagybalyYou haven't read them because they aren't there. Your problem is pretty specific, even if it's common.
    %

  • How to change the Callback function of a GUI button?

    I would like to change the callback function associated with a GUI button dynamically in the programming way.
    Here is the code piece I tried, but it does not seem to work:
    const char* pstrLabelSaveJpeg = "SaveJpegCb";
    SetCtrlAttribute(pahel_id, ctrl_id ,ATTR_LABEL_TEXT, pstrLabelSaveJpeg);
    int CVICALLBACK SaveJpegCb(int panel, int control, int event, void *callbackData, int eventData1, int eventData2);
    Solved!
    Go to Solution.

    The attribute you used is about the "label" of the button.
    It is just an appearence attribute. You can write your own name on it, but that does not change the callback function.
    You should change the ATTR_CALLBACK_FUNCTION_POINTER attribute, and you should not pass the function name as a string.
    So your function call will look like this:
    SetCtrlAttribute(pahel_id, ctrl_id, ATTR_CALLBACK_FUNCTION_POINTER, SaveJpegCb);
    Of course, you have to declare the SaveJpegCb function somewhere above that line.
    I think you have already done that.
    S. Eren BALCI
    www.aselsan.com.tr

Maybe you are looking for

  • Brand new FIOS internet customer and...

    I signed up for the 50/25 and this morning I was easily getting that speed and a little more.  This evening on the verizon speed test I'll burst up to maybe 30 then drop in the single digits and the test wont even complete.  I've tried this every whi

  • MS word/excel

    Hopefully this is a good place to ask this question(s). I would like to "upgrade" my mom from a windows machine to a G3 imac. She has alot of existing MS word and excel files she would like to continue to use. What is the availability os MS software,

  • Someone hack my account

    I just receive an email (receipt of itunes) that indicates that i buy $43 dollars each by purshasing Ipad apps. I didnt have an Ipad... I need help!!!

  • Setup CD, WRT54G2

    I'm having quite a time getting an answer for this.  I have ordered a WRT54G2 router for my home network.  We have a satellite connection, 1 wired computer and 2 laptops and an Xbox 360 console with with wireless connections.  My 3 yr old WRT54G has

  • How to improve the wireless LAN coverage?

    Hi all, We are using Cisco 1200 access point in our small retail shops and use some wireless heldheld devices to connect the wireless network. Since the shops are inside the shopping plaza, there are many other wireless access point which interferenc