EventSyncApp.java

The three ways to receive an event, along with an explanation of functionality, are illustrated in this EventSyncApp.java class sample code. This sample code uses the AUTO_ACKNOWLEDGE acknowledgement mode:

import com.jdedwards.system.connector.dynamic.Connector;
import com.jdedwards.system.connector.dynamic.newevents.EventObject;
import com.jdedwards.system.connector.dynamic.newevents.EventService;
import com.jdedwards.system.connector.dynamic.newevents.EventSession;
import com.jdedwards.system.connector.dynamic.newevents.SyncEventSession;

Sample Java Connector Synchronous Events application.

public class EventSyncApp {

    public static void main(String[] args) {
        
		try {
		    

Instantiate a Connector object.

            Connector con = Connector.getInstance();

Login from the Connector to JD Edwards EnterpriseOne.

            int sessionID = con.login("username", "password", 
            "environment", "role");

Instantiate an EventService object.

            EventService service = EventService.getInstance();

Create a synchronous event session in AUTO_ACKNOWLEDGE mode.

            SyncEventSession eventSession = 
            service.getSyncEventSession(sessionID,
EventSession.AUTO_ACKNOWLEDGE);

Start the delivery of events.

            eventSession.start();

The receive() method will not return control to the caller until an event is delivered.

            EventObject event1 = eventSession.receive();

Do some processing of the event data here. Refer to the sample class (MyListener.java) for a list of the methods that can be called on the EventObject class.

The receive(long timeout) method will return control to the caller if the timeout value (in milliseconds) elapses without an event being delivered. Of course, if an event is delivered before the timeout value elapses, the EventObject will be returned to the caller.

            EventObject event2 = eventSession.receive(5000);

Do some processing of the event data here. Refer to the sample 'MyListener.java' class for a list of the methods that can be called on the EventObject class.

The receiveNoWait() method either immediately returns an EventObject to the caller if an event is waiting to be delivered or returns null if no event is waiting.

            EventObject event3 = eventSession.receiveNoWait();

Do some processing of the event data here. Refer to the sample 'MyListener.java' class for a list of the methods that can be called on the EventObjectclass.

Stop the delivery of events. Note that you can continuously alternate between calls to start() and stop() as long as you do not call the close() method.

            eventSession.stop();

Close the event session. No other operations on the event session are possible at this point.

            eventSession.close();

Logoff the user from JD Edwards EnterpriseOne

            con.logoff(sessionID);

Shut the Connector down.

            con.shutDown();
            
        } catch (Exception e) {
            
            e.printStackTrace();
            System.exit(-1);
            
        }
        
        System.exit(0);
	   }
}