B Using the Java Connector Solution for Classic Events

This appendix contains the following topics:

Note:

This chapter is applicable only if you use classic event delivery. Classic event delivery is available when you use JD Edwards EnterpriseOne 8.93 or earlier releases, or if you use JD Edwards EnterpriseOne Tools 8.94 with JD Edwards EnterpriseOne Applications 8.10 or earlier releases of the JD Edwards EnterpriseOne Applications.

Refer to the Guaranteed Events chapters if you use JD Edwards EnterpriseOne Tools 8.94 with JD Edwards EnterpriseOne Applications 8.11 or JD Edwards EnterpriseOne Tools 8.95 or a later Tools release with JD Edwards EnterpriseOne Applications 8.10 or a later Applications release.

B.1 Understanding Java Connector Events

The Java connector outbound event source architecture enables Java clients to use either the Java connector or the dynamic Java connector to subscribe to various transaction types in JD Edwards EnterpriseOne and receive notification upon completion of those transactions. For example, a client can subscribe to the event JDESOOUT and then receive notification when a sales order transaction is complete in JD Edwards EnterpriseOne.

This diagram illustrates the subscription and notification process:

Figure B-1 Subscription and notification process

Description of Figure B-1 follows
Description of "Figure B-1 Subscription and notification process"

  1. JD Edwards EnterpriseOne clients create different types of EventListeners.

  2. JD Edwards EnterpriseOne clients subscribe to various event types with the Java connector.

  3. When the Java connector receives a subscription for a given event, it subscribes to the same event type with the event distribution kernel.

  4. JD Edwards EnterpriseOne events originate from the real-time events kernel or from callback functions in Uses.

    When the event distribution kernel receives an event to which the Java connector has subscribed, it sends the event to the Java connector.

  5. The Java connector sends the event to all subscribers for that event.

    The EventListener callback function is executed to receive the subscribed event.

    Note:

    The outbound events architecture is the same for the Java connector and the dynamic Java connector. The difference is that corresponding package location for the dynamic Java connector is comjdedwards.system.connector.dynamic.* and com.jdedwards.system.connector.dynamic.events.*.

    For purposes of discussion in this document, the Java connector is used to illustrate the outbound events architecture. Special notes are added to discuss any API differences between the Java connector and dynamic Java connector.

    Do not mix the usage of APIs from the two connectors in one application.

B.2 Developing the Java Client to Use the Java Connector Event Source

You use the Java connector outbound event source to subscribe to an outbound event. This list identifies the tasks for setting up and using the Java client to subscribe to JD Edwards EnterpriseOne transaction types and notify you upon completion of the transaction:

  • Create a Java class to implement an interface.

  • Create a Java client application to subscribe to an event.

  • Compile the Java client.

  • Run the Java client.

B.2.1 Creating a Java Class to Implement an Interface

You create a Java class to implement an interface to JD Edwards EnterpriseOne. Depending on the purpose for which you are using the Java class, implement one of these interfaces:

  • com.jdedwards.system.connector.events.CountedListener

    Implement this interface if you want to know the subscription count, when the subscription count is reached, and when the subscribed event is dropped.

  • com.jdedwards.system.connector.events.PersistentListener

    Implement this interface if you want the real-time event kernel to persist the subscription when the kernel goes down and comes up, and the connection to the Java connector is reestablished.

  • com.jdedwards.system.connector.events.EventListener

    Implement this interface for most other situations.

No matter which interface you implement, the implementation Java class must contain these five methods:

//set the event type to subscribe
void setEventType( String type );
String getEventType();

//stop/start the event coming in the Java connector
void setPause( boolean pause );
boolean isPaused();

//the callback function when the event arrives
void onOneWorldEvent( EventObject event );

B.2.2 Creating a Java Client Application to Subscribe to an Event

You create a Java client application to subscribe to an event. The Java client application must:

  1. Create a new instance of the Connector class.

  2. Use the connector object to verify the client's user ID, password, and environment, and then log the client into JD Edwards EnterpriseOne.

  3. Do one of these:

    • For Java connector, create an EventSource object by calling the CreateBusinessObject method of the Connector class, passing in an Events::EventSource string identifier.

    • For dynamic Java connector, Get EventSource instance by using this command:

      com.jdedwards.system.connector.dynamic.connector.events.EventSource. 
      getInstance()
      
  4. Create an EventListener object.

  5. Specify the specific event type to which to subscribe.

  6. Register the EventListener object with the EventSrc object.

  7. Develop a callback function.

    When the subscribed to event arrives, the EventListener calls this callback function. This step is optional.

B.2.2.1 Example: Using the Java Client to Subscribe to an Event Using the Java Connector Outbound Event Source

This example illustrates how to write code for a Java client to subscribe to an event using the Java connector outbound event source.

import java.io.*;
import javax.swing.*;
import com.jdedwards.system.connector.*;
import com.jdedwards.system.connector.events.*;

        

... //Declare Class             
{
        Connector m_connector = null;
        EventSource m_theSource = null;
        ListenerImpl_Page132 m_listener = null;
                try
                {
                                m_connector = new Connector();
                                int m_Access = 0;
                m_Access = m_connector.Login("user", "pwd", "env");
                
                // passing in an "Events::EventSource" string identifier.
                m_theSource = (EventSource)m_connector.CreateBusinessObject
("Events::EventSource", m_Access);
                
                m_listener = new ListenerImpl(this);
                
                m_listener.setEventType("JDESOOUT");
                
                m_theSource.addListener( m_listener, m_Access );
                }
                catch(Exception e)
                {
                System.out.println(e.toString());
                System.out.println(e.getMessage());
                e.printStackTrace();
                }
        }

        public synchronized void executeCallBack(EventObject event)
        {
                System.out.println("Getting the event:"+event.getData());
//execute the call back function;
        }
}

class ListenerImpl_Page132 implements EventListener
{
        String m_eventType;
        boolean m_paused = false;
        EventClient_Page132 m_client;
        /** Creates new Listener*/
        public ListenerImpl()
        { }
        public ListenerImpl(EventClient
        { this.m_client=client;
        }
        public synchronized String getEventType()
        {
        return m_eventType;
        }
        public void setEventType(java.lang.String eventType)
        {
        this.m_eventType = eventType;
        }
        public synchronized boolean isPaused()
        {
        return m_paused;
        }
        public synchronized void setPause(boolean pause)
        {
        m_paused = pause;
        }
        public synchronized void onOneWorldEvent(EventObject p1)
        {
        System.out.println("Received event: " + p1.getType());
        // if the arrival event is the one that client subscribes,
        // the EventListner can trigger the call back function in the client
        if (p1.getType().equalsIgnoreCase(m_eventType)) {
        m_client.executeCallBack(p1);
        }
        }

B.2.3 Compiling the Java Client

To compile the Java client, use this command:

set JAVA_HOME = <the path of JDK>
set OneWorld_HOME = <the installation path>
set CLASSPATH=%OneWorld_HOME%\system\classes\base_JAR.jar
set CLASSPATH=%OneWorld_HOME%\system\classes\jdeNet_JAR.jar
set CLASSPATH=%OneWorld_HOME%\system\classes\system_JAR.jar
set CLASSPATH=%CLASSPATH%;%OneWorld_HOME%\system\classes\Connector.jar
set CLASSPATH=%CLASSPATH%;%OneWorld_Home%\system\classes\log4j.jar
set CLASSPATH=%CLASSPATH%;%OneWorld_HOME%\system\classes\xalan.jar
set CLASSPATH=%CLASSPATH%;%OneWorld_HOME%\system\classes\xerces.jar
%JAVA_HOME%\bin\javac -classpath %CLASSPATH% EventClient.java
EventListenerImpl

B.2.4 Running the Java Client

To run the Java client, use this command:

set JAVA_HOME = <the path of JDK>
set OneWorld_HOME = <the installation path>
set CLASSPATH=%OneWorld_HOME%\system\classes\base_JAR.jar
set CLASSPATH=%OneWorld_HOME%\system\classes\jdeNet_JAR.jar
set CLASSPATH=%OneWorld_HOME%\system\classes\system_JAR.jar
set CLASSPATH=%CLASSPATH%;%OneWorld_HOME%\system\classes\Connector.jar
set CLASSPATH=%CLASSPATH%;%OneWorld_Home%\system\classes\log4j.jar
set CLASSPATH=%CLASSPATH%;%OneWorld_HOME%\system\classes\xalan.jar
set CLASSPATH=%CLASSPATH%;%OneWorld_HOME%\system\classes\xerces.jar
set CLASSPATH=%CLASSPATH%;%OneWorld_HOME%\system\classes\castor.jar
%JAVA_HOME%\bin\java -classpath %cp%
EventClient