Skip to Content
0
Former Member
Mar 17, 2008 at 09:56 PM

How do I implement a listener using new MDM Java API?

57 Views

I checked this thread () and it indicates that there may be missing functionality to the MDM listener event model. However, the problems described in this thread are not the ones I encounter. Here is some sample code:

public class ListenerTest implements DataListener {

...

public static void main(String[] args) {
	ListenerTest app = new ListenerTest();
	try {
		// get connection
		ConnectionPool connections = null;
		connections = ConnectionPoolFactory.getInstance(props.getServerName());
		RepositoryIdentifier repId = new RepositoryIdentifier(props.getRepositoryName(),
				props.getDbmsName(), DBMSType.ORACLE);

		// get list of available regions for the repository
		final GetRepositoryRegionListCommand regionListCommand = 
			new GetRepositoryRegionListCommand(connections);
		regionListCommand.setRepositoryIdentifier(repId);
		regionListCommand.execute();
		final RegionProperties[] regions = regionListCommand.getRegions();

		// set up event dispatcher
		EventDispatcher ed = new EventDispatcher(props.getServerName());
		ed.addListener(app);
		ed.registerDataNotifications(props.getUserName(), 
			props.getPassword(), repId, regions[0]);
		ed.registerRepositoryNotifications(props.getUserName(), 
			props.getPassword(), repId);
		ed.registerGlobalNotifications();

		while (true) {
			Thread.yield();
			try {
				Thread.sleep(500);
			} catch (InterruptedException ex) {
				System.out.println(ex);
			}
		}
	} catch (ConnectionException e) {
		e.printStackTrace();
	} catch (CommandException e) {
		e.printStackTrace();
	}
}

// implement events
public void recordAdded(RecordEvent evt) {
	System.out.println(evt.getServerName());
}

...
}

Whenever I generate a data event in the repository, I get this error message:

Mar 17, 2008 5:28:26 PM com.sap.mdm.internal.net.ConnectionImpl finalize
INFO: Disconnect was not called. Cleaning up connection in finalize.

I have tried to find code samples for the new API but only found the one linked to at the top of this posting. My questions are:

1. Why am I getting the finalize error whenever an event is generated?

2. Are there any working code samples for MDM listeners using the new Java API that I am unaware of?

I am able to use the MDM4J API to create listeners, but the event model is very limited compared to the new API.

Any help is greatly appreciated.