Skip to content

Commit

Permalink
Adding realtime notification code
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashi1993 committed Dec 4, 2024
1 parent 86e2eaa commit c2997c3
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public class HTTPClientUtils {
* @return Closeable https client
* @throws FinancialServicesException FinancialServicesException exception
*/
@Generated(message = "Ignoring because ServerConfiguration cannot be mocked")
@Generated(message = "Ignoring since method contains no logics")
public static CloseableHttpClient getHttpsClient() throws FinancialServicesException {

SSLConnectionSocketFactory sslsf = createSSLConnectionSocketFactory();
Expand Down Expand Up @@ -94,7 +94,7 @@ public static CloseableHttpClient getHttpsClient() throws FinancialServicesExcep
* @return Closeable https client
* @throws FinancialServicesException FinancialServicesException exception
*/
@Generated(message = "Ignoring because ServerConfiguration cannot be mocked")
@Generated(message = "Ignoring since method contains no logics")
public static CloseableHttpClient getHttpsClient(int maxTotal, int maxPerRoute) throws FinancialServicesException {

SSLConnectionSocketFactory sslsf = createSSLConnectionSocketFactory();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ public String publishEventNotification(NotificationCreationDTO notificationCreat
eventResponse = eventCreationDAO.persistEventNotification(connection, notification, eventsList);
DatabaseUtils.commitTransaction(connection);

//TODO:
if (FinancialServicesConfigParser.getInstance().isRealtimeEventNotificationEnabled()) {
new Thread(new EventNotificationProducerService(notification, eventsList)).start();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public List<Notification> getNotificationsByStatus(String status)
DatabaseUtils.rollbackTransaction(connection);
throw new FSEventNotificationException(EventNotificationConstants.ERROR_STORING_EVENT_SUBSCRIPTION, e);
} finally {
log.debug(EventNotificationConstants.DATABASE_CONNECTION_CLOSE_LOG_MSG);
DatabaseUtils.closeConnection(connection);
}
}
Expand Down Expand Up @@ -100,6 +101,7 @@ public List<NotificationEvent> getEventsByNotificationID(String notificationId)
DatabaseUtils.rollbackTransaction(connection);
throw new FSEventNotificationException(EventNotificationConstants.ERROR_STORING_EVENT_SUBSCRIPTION, e);
} finally {
log.debug(EventNotificationConstants.DATABASE_CONNECTION_CLOSE_LOG_MSG);
DatabaseUtils.closeConnection(connection);
}
}
Expand Down Expand Up @@ -133,6 +135,7 @@ public void updateNotificationStatusById(String notificationId, String notificat
DatabaseUtils.rollbackTransaction(connection);
throw new FSEventNotificationException(e.getMessage(), e);
} finally {
log.debug(EventNotificationConstants.DATABASE_CONNECTION_CLOSE_LOG_MSG);
DatabaseUtils.closeConnection(connection);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,21 @@
name = "org.wso2.financial.services.accelerator.event.notifications.service.internal.EventNotificationComponent",
immediate = true)
public class EventNotificationComponent {

private static final Log log = LogFactory.getLog(EventNotificationComponent.class);

@Activate
protected void activate(ComponentContext context) throws Exception {
log.info("Event Notification Service Component Activated");
log.debug("Event Notification Service Component Activated");

// Check if realtime event notification enabled
if (FinancialServicesConfigParser.getInstance().isRealtimeEventNotificationEnabled()) {
log.info("Realtime Event Notification Service Activated");
/*
* Initialize the blocking queue for storing the realtime event notifications
* Initialize the quartz job for consuming the realtime event notifications
* Initialize the thread for producing the open state realtime event notifications
*/
log.debug("Realtime Event Notification Service Activated");
new Thread(new RealtimeEventNotificationLoaderService()).start();
new PeriodicalEventNotificationConsumerJobActivator().activate();
}
Expand All @@ -56,6 +62,7 @@ protected void activate(ComponentContext context) throws Exception {
/**
* Setters for the descendent OSGI services of the EventNotificationComponent.
* This is added to run the EventNotification OSGI component after the Common module
* @param configurationService FinancialServicesConfigurationService
*/
@Reference(
service = FinancialServicesConfigurationService.class,
Expand All @@ -81,7 +88,6 @@ public void unsetConfigService(FinancialServicesConfigurationService configurati
policy = ReferencePolicy.DYNAMIC,
unbind = "unsetOAuth2Service"
)

public void setOAuth2Service(OAuth2Service oAuth2Service) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public class EventNotificationProducerService implements Runnable {

public EventNotificationProducerService(
Notification notification, List<NotificationEvent> notificationEvents) {

this.notification = notification;
this.notificationEvents = notificationEvents;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,6 @@ private void postWithRetry() throws FSEventNotificationException {
log.error("Real-time event notification with notificationId: " +
notificationId.replaceAll("[\r\n]", "") + " sent failed", e);
}

}

}
}

0 comments on commit c2997c3

Please sign in to comment.