Baanboard.com

Go Back   Baanboard.com

User login

Frontpage Sponsor

Main

Google search


Poll
For ERP LN feature pack upgrade, what method of install are you using?
Installation Wizard into existing VRC
33%
Installation Wizard into new VRC
39%
Manual into existing VRC
6%
Manual into new VRC
22%
Total votes: 49

Baanboard at LinkedIn


Reference Content

 
Example of Java VM
By patvdv at 26 Feb 2008 - 21:57


Example of Java VM

Example of a custom implementation using the Java interfaces

Below is an example of a custom listener. The listener is installed from within the BaanERP program using the following program fragment (for clarity, all checks on return codes are omitted. This is not recommended in a real-life program!):

     long queue.fromJava
long queue.toJava
long ret

queue.fromJava = java.new.queue()
queue.toJava = java.new.queue()

| install a listener within baanERP; whenever a message arrives
| on the queue.fromJava, this program will receive a
| EVT_CHANNEL_EVENT event
| Note: listeners are optional, without a listener one will not
| be automatically informed about arriving buckets

ret = java.install.listener(queue.fromJava)

| install a listener at the Java side; whenever a message arrives
| on the queue.toJava the listener's onReceive() method will be
| called

ret = java.execute.static.method.async(
"com.baan.baanvm.test.TestListener",
"installListener",
queue.fromJava, queue.toJava)

The Java listener implementation in this case will look like:

 package com.baan.baanvm.test;   // package name
import com.baan.baanvm.*; // import the interface definitions

/** Test class which installs a listener on a java queue created in
* BaanERP.
*/

public class TestListener 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 TestListener (int p_idIn, int p_idOut)
{
m_queueFromERP = p_idIn;
m_queueToERP = p_idOut;
}

/** Called by BaanERP (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 QueuePinger(queueFrom4GL,queueTo4GL));
}
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)
{
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 BaanERP*/
s_iBaanVm.logMessage("Failed to bounce bucket,
ret = " + ret, 0);
}
}
else
{
/* no bucket received, log a debug message */
s_iBaanVm.logMessage("QueuePinger(" + m_queueFrom4GL
+ ") received: NULL bucket!!!", 0);
}
}
}

0
No votes yet


All times are GMT +2. The time now is 21:01.


©2001-2018 - Baanboard.com - Baanforums.com