Skip to content

Commit

Permalink
change the API to make it harder to screw up
Browse files Browse the repository at this point in the history
thx @teosarca for feedback
refactor trx event listeners metasfresh/metasfresh#3222
  • Loading branch information
metas-ts committed Dec 18, 2017
1 parent f77a15f commit 324bdcf
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 21 deletions.
13 changes: 5 additions & 8 deletions src/main/java/de/metas/ui/web/address/AddressRepository.java
Expand Up @@ -151,10 +151,8 @@ public void processAddressDocumentChanges(final int addressDocIdInt, final List<
addressDoc.processValueChanges(events, REASON_ProcessAddressDocumentChanges);

Services.get(ITrxManager.class)
.getCurrentTrxListenerManagerOrAutoCommit().newEventListener()
.timing(TrxEventTiming.AFTER_COMMIT)
.handlingMethod(trx -> putAddressDocument(addressDoc))
.register();
.getCurrentTrxListenerManagerOrAutoCommit().newEventListener(TrxEventTiming.AFTER_COMMIT)
.registerHandlingMethod(trx -> putAddressDocument(addressDoc));

}

Expand All @@ -166,10 +164,9 @@ public LookupValue complete(final int addressDocIdInt)
final I_C_Location locationRecord = createC_Location(addressDoc);

Services.get(ITrxManager.class)
.getCurrentTrxListenerManagerOrAutoCommit().newEventListener()
.timing(TrxEventTiming.AFTER_COMMIT)
.handlingMethod(trx -> removeAddressDocumentById(addressDocId))
.register();
.getCurrentTrxListenerManagerOrAutoCommit()
.newEventListener(TrxEventTiming.AFTER_COMMIT)
.registerHandlingMethod(trx -> removeAddressDocumentById(addressDocId));

final String locationStr = Services.get(ILocationBL.class).mkAddress(locationRecord);
return IntegerLookupValue.of(locationRecord.getC_Location_ID(), locationStr);
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/de/metas/ui/web/pattribute/ASIRepository.java
Expand Up @@ -229,10 +229,9 @@ public <R> R forASIDocumentWritable(final DocumentId asiDocId, final IDocumentCh
final R result = processor.apply(asiDoc);

Services.get(ITrxManager.class)
.getCurrentTrxListenerManagerOrAutoCommit().newEventListener()
.timing(TrxEventTiming.AFTER_COMMIT)
.handlingMethod(trx -> commit(asiDoc))
.register();
.getCurrentTrxListenerManagerOrAutoCommit()
.newEventListener(TrxEventTiming.AFTER_COMMIT)
.registerHandlingMethod(trx -> commit(asiDoc));

return result;
}
Expand Down
Expand Up @@ -74,9 +74,8 @@ public static final ViewChangesCollector getCurrentOrNull()
.getProperty(TRXPROPERTY_Name, trx -> {
final ViewChangesCollector collector = new ViewChangesCollector();
trx.getTrxListenerManager()
.newEventListener().timing(TrxEventTiming.AFTER_COMMIT)
.handlingMethod(innerTrx -> collector.close())
.register();
.newEventListener(TrxEventTiming.AFTER_COMMIT)
.registerHandlingMethod(innerTrx -> collector.close());
return collector;
});
}
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/de/metas/ui/web/websocket/WebsocketSender.java
Expand Up @@ -116,9 +116,8 @@ private WebsocketEventsQueue createAndBindTrxQueue(@NonNull final ITrx trx)

// Bind
trx.getTrxListenerManager()
.newEventListener().timing(TrxEventTiming.AFTER_COMMIT)
.handlingMethod(innerTrx -> queue.sendEventsAndClear())
.register();
.newEventListener(TrxEventTiming.AFTER_COMMIT)
.registerHandlingMethod(innerTrx -> queue.sendEventsAndClear());

return queue;
}
Expand Down
Expand Up @@ -104,9 +104,8 @@ private static JSONDocumentChangedWebSocketEventCollector createCollectorAndBind
final JSONDocumentChangedWebSocketEventCollector collector = JSONDocumentChangedWebSocketEventCollector.newInstance();

trx.getTrxListenerManager()
.newEventListener().timing(TrxEventTiming.AFTER_COMMIT)
.handlingMethod(transaction -> sendAllAndClear(collector, websocketSender))
.register();
.newEventListener(TrxEventTiming.AFTER_COMMIT)
.registerHandlingMethod(transaction -> sendAllAndClear(collector, websocketSender));

return collector;
}
Expand Down

0 comments on commit 324bdcf

Please sign in to comment.