toolswizard
18th July 2010, 23:06
I have a need to call some Java routines from LN. I have tried to get the JVMI interface example working that is found in the programmers manual.

I have successfully created the session, and created the Java listener, but I have not been able to pass a message between them. If you have a working version, could you please post the Java code, or contact me.

hessenmob
10th September 2010, 20:28
Doesn't work here either. The code in the programmers guide is broken. Some referenced variables are not there. The quality of the product and the corresponding documentation is very flawed. There are copy'n paste errors and so on, many information is missing.

toolswizard
12th September 2010, 16:10
Thank you for your reply. I did get it working. It looks similar to yours. I will be posting both the LN script and the Java script.

hessenmob
13th September 2010, 11:04
I fixed it too, here is my JAVA Code, stripped the not working QueuePinger by putting in a Instance of the Programm itsself now i can handle the message in the onReceive Event (Just putting the Message back, no function there).
Problem is, that I am not able to capture the events on the LN side. I want to call async and then I want to be called back. Does anyone know how to implement a Listener on the LN side? Information on this is non existent.



package de.lti.PlcGenerator;

import com.baan.baanvm.BaanVMImpl;
import com.baan.baanvm.IBaanVM;
import com.baan.baanvm.IBucket;
import com.baan.baanvm.IQueueListener;
import com.baan.baanvm.test.queue.QueuePinger;

public class PlcBucketListener implements IQueueListener
{
private int m_queueFromERP;
private int m_queueToERP;
private static IBaanVM s_iBaanVm = new BaanVMImpl();

/** constructor of an instance of the listener */
public PlcBucketListener(int p_idIn, int p_idOut) {
m_queueFromERP = p_idIn;
m_queueToERP = p_idOut;
}

/**
* Called by Infor ERP LN (java.execute.static.method.async). Its main
* function is to install an instance of the listener on the queue, and to
* initialize all variables
*/
public static void installListener(int queueToERP, int queueFromERP)
{
try {
/* install an instance of the listener */
s_iBaanVm.installListener(queueFromERP, new PlcBucketListener(queueFromERP, queueToERP));
} catch (Exception e) {
/* failed to install listener, log error message */
s_iBaanVm.logMessage(e.toString(), 0);
}
}

/**
* This listener method will be called whenever a new bucket appears on the
* m_queueFromERP queue
*/
public void onReceive(IBucket p_bucket)
{
int ret;

if ( p_bucket != null )
{
/* we have received data, do something (using the
* IBucket interface to set and retrieve the
* contents) !
*/

/* for this example, just bounce the bucket back */

/* place bucket on the queue m_queueToERP */
if ( (ret = s_iBaanVm.putBucket(m_queueToERP,p_bucket)) < 0 )
{
/* failed to place bucket on queue to Infor ERP LN*/
s_iBaanVm.logMessage("Failed to bounce bucket, ret = " + ret, 0);
}
}
else
{
/* no bucket received, log a debug message */
s_iBaanVm.logMessage("QueuePinger(" + m_queueFromERP + ") received: NULL bucket!!!", 0);
}
}
}





Baan side


function call.java.async()
{
queue.fromJava = java.new.queue()
queue.toJava = java.new.queue()

string header(30)
string body(30)

return.long = java.install.listener(queue.fromJava)

return.long = java.execute.static.method.sync(
"de.lti.PlcGenerator.PlcBucketListener",
"installListener",
queue.fromJava, queue.toJava)

return.long = java.put.bucket(queue.toJava, "BODY1", 30, "HEAD1")

while true
return.long = java.get.bucket(queue.fromJava, body, 30, header)

if (return.long > 0) then
message(header & body)
break
endif
endwhile
}

FrenkR
16th March 2016, 02:41
For those trying this path. I succeeded implementing listener in 3GL only. AFAIK, 4GL(UI) script has no event defined for "EVTCHANNELEVENT". In the beginning of 3GL "main" loop you should configure JVMI queues, install listener and start java app (script as proposed in previous post). After that you implement "message pump" as follows(this is a sample that shows "ping" response from JVMI):

| event message loop
long event(EVTMAXSIZE)

while TRUE
next.event(event) | read event

on case evt.type(event)
case EVTCHANNELEVENT:
ret = java.get.bucket( queue.to.erp, body, 8000)
if ret >= 0 then
message(body)
else
message("Error get bucket(Err=%d)", ret)
endif
|ToDO: put your logic for processing messages
endcase
endwhile

Inside 4GL session, you can start 3GL using "activate/kill" command

jeffersyuan
9th October 2018, 09:37
Hi,

Any ideas about Synchronous & asynchronous via JVM method?

Thanks.
Jeffers

I fixed it too, here is my JAVA Code, stripped the not working QueuePinger by putting in a Instance of the Programm itsself now i can handle the message in the onReceive Event (Just putting the Message back, no function there).
Problem is, that I am not able to capture the events on the LN side. I want to call async and then I want to be called back. Does anyone know how to implement a Listener on the LN side? Information on this is non existent.



package de.lti.PlcGenerator;

import com.baan.baanvm.BaanVMImpl;
import com.baan.baanvm.IBaanVM;
import com.baan.baanvm.IBucket;
import com.baan.baanvm.IQueueListener;
import com.baan.baanvm.test.queue.QueuePinger;

public class PlcBucketListener implements IQueueListener
{
private int m_queueFromERP;
private int m_queueToERP;
private static IBaanVM s_iBaanVm = new BaanVMImpl();

/** constructor of an instance of the listener */
public PlcBucketListener(int p_idIn, int p_idOut) {
m_queueFromERP = p_idIn;
m_queueToERP = p_idOut;
}

/**
* Called by Infor ERP LN (java.execute.static.method.async). Its main
* function is to install an instance of the listener on the queue, and to
* initialize all variables
*/
public static void installListener(int queueToERP, int queueFromERP)
{
try {
/* install an instance of the listener */
s_iBaanVm.installListener(queueFromERP, new PlcBucketListener(queueFromERP, queueToERP));
} catch (Exception e) {
/* failed to install listener, log error message */
s_iBaanVm.logMessage(e.toString(), 0);
}
}

/**
* This listener method will be called whenever a new bucket appears on the
* m_queueFromERP queue
*/
public void onReceive(IBucket p_bucket)
{
int ret;

if ( p_bucket != null )
{
/* we have received data, do something (using the
* IBucket interface to set and retrieve the
* contents) !
*/

/* for this example, just bounce the bucket back */

/* place bucket on the queue m_queueToERP */
if ( (ret = s_iBaanVm.putBucket(m_queueToERP,p_bucket)) < 0 )
{
/* failed to place bucket on queue to Infor ERP LN*/
s_iBaanVm.logMessage("Failed to bounce bucket, ret = " + ret, 0);
}
}
else
{
/* no bucket received, log a debug message */
s_iBaanVm.logMessage("QueuePinger(" + m_queueFromERP + ") received: NULL bucket!!!", 0);
}
}
}





Baan side


function call.java.async()
{
queue.fromJava = java.new.queue()
queue.toJava = java.new.queue()

string header(30)
string body(30)

return.long = java.install.listener(queue.fromJava)

return.long = java.execute.static.method.sync(
"de.lti.PlcGenerator.PlcBucketListener",
"installListener",
queue.fromJava, queue.toJava)

return.long = java.put.bucket(queue.toJava, "BODY1", 30, "HEAD1")

while true
return.long = java.get.bucket(queue.fromJava, body, 30, header)

if (return.long > 0) then
message(header & body)
break
endif
endwhile
}

giggty
12th October 2018, 09:22
What about it? Can you give more details about what are you struggling with?

baanware
17th September 2021, 10:26
Hi,

3 years later I have also tried to make the Listener work. I do have issues compiling on the Java side though. Java does not find the "com.baan.baanvm" package.

My source code is placed in the {BSE}\java directory, from where I execute the java compilation. Does any of you have an idea what I am doing wrong?

(I am working on a LN 10.5 system)

Thanks!