cancel
Showing results for 
Search instead for 
Did you mean: 

ConcurrentModificationException - com.sap. eventlistener

Former Member
0 Kudos

Hello

I'm using the com.sap eventlisteners, The process modfies a lots of fields in the main table on record added, and I have to process something on records modified event too. Whenever a record gets added, the desired processing happens and after the add event method ends, I get the following exception, After this exception occurs, the listener is not listening anymore. Any suggestions, why this error occurs? After the exception stack trace, I have pasted my code snippet.

My API and MDM versions are 5.5.62.56. A prompt response, will be greatly appreciated.

java.util.ConcurrentModificationException

at java.util.LinkedList$ListItr.checkForComodification(LinkedList.java:617)

at java.util.LinkedList$ListItr.next(LinkedList.java:552)

at com.sap.mdm.internal.notification.DataEventHandler.handleEvent(DataEventHandler.java:61)

at com.sap.mdm.notification.EventDispatcher$AllEventListener.eventOccur(EventDispatcher.java:55)

at com.sap.mdm.internal.notification.DataNotificationResolver.event_ModifiedNotification(DataNotificationResolver.java:74)

at com.sap.mdm.internal.protocol.notification.web.AbstractWebClientNotificationResolver.unpack(AbstractWebClientNotificationResolver.java:60)

at com.sap.mdm.internal.protocol.manual.notification.NotificationHandler.handleMessage(NotificationHandler.java:65)

at com.sap.mdm.internal.net.ConnectionImpl.receiveMessage(ConnectionImpl.java:566)

at com.sap.mdm.internal.net.ConnectionImpl.send(ConnectionImpl.java:229)

at com.sap.mdm.internal.protocol.manual.notification.NotificationHandler.retrieveNotification(NotificationHandler.java:29)

at com.sap.mdm.internal.notification.NotificationDispatcher.run(NotificationDispatcher.java:104)

at java.lang.Thread.run(Thread.java:595)

Exception in thread "class com.sap.mdm.notification.EventDispatchercom.sap.mdm.notification.EventDispatcher@1f31652" java.util.ConcurrentModificationException

at java.util.LinkedList$ListItr.checkForComodification(LinkedList.java:617)

at java.util.LinkedList$ListItr.next(LinkedList.java:552)

at com.sap.mdm.internal.notification.DataEventHandler.handleEvent(DataEventHandler.java:61)

at com.sap.mdm.notification.EventDispatcher$AllEventListener.eventOccur(EventDispatcher.java:55)

at com.sap.mdm.internal.notification.DataNotificationResolver.event_ModifiedNotification(DataNotificationResolver.java:74)

at com.sap.mdm.internal.protocol.notification.web.AbstractWebClientNotificationResolver.unpack(AbstractWebClientNotificationResolver.java:60)

at com.sap.mdm.internal.protocol.manual.notification.NotificationHandler.handleMessage(NotificationHandler.java:65)

at com.sap.mdm.internal.net.ConnectionImpl.receiveMessage(ConnectionImpl.java:566)

at com.sap.mdm.internal.net.ConnectionImpl.send(ConnectionImpl.java:229)

at com.sap.mdm.internal.protocol.manual.notification.NotificationHandler.retrieveNotification(NotificationHandler.java:29)

at com.sap.mdm.internal.notification.NotificationDispatcher.run(NotificationDispatcher.java:104)

at java.lang.Thread.run(Thread.java:595)

public class EventListener implements DataListener {

private static String encryptionKey = "123456789012345678901234567890";

private static String encryptionScheme = Encrypter.DESEDE_ENCRYPTION_SCHEME;

String regionName = "English [US]";

public static void main(String[] args) {

EventListener app = new EventListener();

String regionName = "English [US]";

try {

Settings settings = new Settings();

Encrypter encrypter = new Encrypter( encryptionScheme, encryptionKey );

UserSessionContext context = new UserSessionContext(SettingsValues.getMDMServer(), SettingsValues.getRepository(), regionName, SettingsValues.getUserId());

SessionManager sessionManager = SessionManager.getInstance();

sessionManager.createSession(context, SessionTypes.USER_SESSION_TYPE, encrypter.decrypt(SettingsValues.Encrypted_Pwd));

RepositorySchemaEx rsx = MetadataManager.getInstance().getRepositorySchema(context);

RepositoryIdentifier repId = rsx.getRepositoryIdentifier();

rsx.getRegion(regionName);

EventDispatcherManager edm = EventDispatcherManager.getInstance();

EventDispatcher ed = edm.getEventDispatcher(SettingsValues.getMDMServer());

ed.addListener(app);

ed.registerDataNotifications(SettingsValues.getUserId(), encrypter.decrypt(SettingsValues.Encrypted_Pwd), repId, rsx.getRegion(regionName));

//ed.registerRepositoryNotifications(SettingsValues.getUserId(), encrypter.decrypt(SettingsValues.Encrypted_Pwd), repId);

//ed.registerGlobalNotifications();

System.out.println("Connected and listening on Server - " + SettingsValues.MDMServer);

while (true) {

Thread.yield();

try {

Thread.sleep(500);

} catch (InterruptedException ex) {

System.out.println(ex);

}

}

} catch (Exception e){

e.printStackTrace();

}

}

public void recordAdded(RecordEvent arg0) {

if (arg0.getTableId().toString().equalsIgnoreCase("T1")){

System.out.println("Record: added to table Products");

Settings settings = new Settings();

try{

Encrypter encrypter = new Encrypter( encryptionScheme, encryptionKey );

RecordId[] recId = new RecordId[1];

recId[0] = arg0.getRecordId();

UserSessionContext context = new UserSessionContext(SettingsValues.getMDMServer(), SettingsValues.getRepository(), regionName, SettingsValues.getUserId());

SessionManager sessionManager = SessionManager.getInstance();

sessionManager.createSession(context, SessionTypes.USER_SESSION_TYPE, encrypter.decrypt(SettingsValues.Encrypted_Pwd));

RepositorySchemaEx rsx = MetadataManager.getInstance().getRepositorySchema(context);

FieldId[] fields = new FieldId[1];

fields[0] = rsx.getFieldId("Products", "PH1_Class");

ResultDefinition rd = new ResultDefinition(arg0.getTableId());

rd.setSelectFields(fields);

ResultDefinition[] suppRd = getSupportingResultDefinitions(rsx.getTableSchema("Products"),context);

Record[] rec = RecordDAO.getRecordsByID(context,rd,suppRd,recId);

if (rec.length > 0) {

//MdmValue ph1ClassVal = (LookupValue)rec[0].getFieldValue(rsx.getFieldId("Products","PH1_Class"));

if(!rec[0].getFieldValue(rsx.getFieldId("Products","PH1_Class")).isNull()){

Application app = new Application();

app.execute(arg0.getRecordId().id,"A",true,false,"PH1_A");

}else{

Application app = new Application();

app.execute(arg0.getRecordId().id,"A",true,false,"PH1_NA");

}

}

System.out.println("Stop here");

}catch(Exception e){

e.printStackTrace();

}

}

}

public void recordsModified(RecordsEvent arg0) {

if (arg0.getTableId().toString().equalsIgnoreCase("T1")){

System.out.println("Record: updated to table Products");

Settings settings = new Settings();

try{

Encrypter encrypter = new Encrypter( encryptionScheme, encryptionKey );

RecordId[] recId = arg0.getRecordIds();

UserSessionContext context = new UserSessionContext(SettingsValues.getMDMServer(), SettingsValues.getRepository(), regionName, SettingsValues.getUserId());

SessionManager sessionManager = SessionManager.getInstance();

sessionManager.createSession(context, SessionTypes.USER_SESSION_TYPE, encrypter.decrypt(SettingsValues.Encrypted_Pwd));

RepositorySchemaEx rsx = MetadataManager.getInstance().getRepositorySchema(context);

FieldId[] fields = new FieldId[1];

fields[0] = rsx.getFieldId("Products", "PH1_Class");

ResultDefinition rd = new ResultDefinition(arg0.getTableId());

rd.setSelectFields(fields);

ResultDefinition[] suppRd = getSupportingResultDefinitions(rsx.getTableSchema("Products"),context);

Record[] rec = RecordDAO.getRecordsByID(context,rd,suppRd,recId);

if (rec.length > 0) {

//MdmValue ph1ClassVal = (LookupValue)rec[0].getFieldValue(rsx.getFieldId("Products","PH1_Class"));

for(int i = 0; i < rec.length;i++){

if(!rec<i>.getFieldValue(rsx.getFieldId("Products","PH1_Class")).isNull()){

Application app = new Application();

app.execute(rec<i>.getId().id,"U",true,false,"PH1_A");

}else{

Application app = new Application();

app.execute(rec<i>.getId().id,"U",true,false,"PH1_NA");

}

}

}

//sessionManager.destroyAllSessions();

}catch(Exception e){

e.printStackTrace();

}

}

}

public void recordsRemoved(RecordsEvent arg0) {

// TODO Auto-generated method stub

}

public void recordsCheckedOut(RecordsCheckOutEvent arg0) {

// TODO Auto-generated method stub

}

public void recordsCheckedIn(RecordEvent arg0) {

// TODO Auto-generated method stub

}

public void recordsRolledBack(RecordEvent arg0) {

// TODO Auto-generated method stub

}

public void recordsProtectionChanged(RecordsEvent arg0) {

// TODO Auto-generated method stub

}

public void attributeAdded(AttributeEvent arg0) {

// TODO Auto-generated method stub

}

public void attributeModified(AttributeEvent arg0) {

// TODO Auto-generated method stub

}

public void attributesRemoved(AttributesEvent arg0) {

// TODO Auto-generated method stub

}

public void attributesLinked(LinkedAttributesEvent arg0) {

// TODO Auto-generated method stub

}

public void attributesUnlinked(CategoryAttributesEvent arg0) {

// TODO Auto-generated method stub

}

public void attributesLinkModified(LinkedAttributesEvent arg0) {

// TODO Auto-generated method stub

}

public void attributeSetKeyMapable(AttributesKeyMapableEvent arg0) {

// TODO Auto-generated method stub

}

public void attributesPriorityModified(AttributesPriorityEvent arg0) {

// TODO Auto-generated method stub

}

}

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi,

Can , we achieve the data level event generation and notification using SP05?

Thanks,

Priya.