Skip to content

Commit

Permalink
Merge pull request #2495 from SCADA-LTS/fix/#2487_Fixed_problem_an_HT…
Browse files Browse the repository at this point in the history
…TP_request_processing_performance

#2487 Fixed problem an HTTP request processing performance
  • Loading branch information
Limraj authored Mar 28, 2023
2 parents 126c348 + e695b1c commit 5cbf497
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 51 deletions.
3 changes: 3 additions & 0 deletions WebContent/WEB-INF/web.xml
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,9 @@
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>com.serotonin.mango.MangoContextListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.security.web.session.HttpSessionEventPublisher</listener-class>
</listener>
Expand Down
4 changes: 4 additions & 0 deletions src/com/serotonin/mango/MangoContextListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ public void contextInitialized(ServletContextEvent evt) {
}

public void contextDestroyed(ServletContextEvent evt) {
if(Common.ctx == null) {
log.warn("Scada-LTS context terminated");
return;
}
log.info("Scada-LTS context terminating");

if (Common.ctx.getEventManager() != null) {
Expand Down
2 changes: 1 addition & 1 deletion src/com/serotonin/mango/db/BasePooledAccess.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public void terminate()
log.info("Stopping database");
try
{
if(dataSourceFound)
if(dataSourceFound && (dataSource instanceof BasicDataSource))
((BasicDataSource) dataSource).close();
}
catch(SQLException e)
Expand Down
34 changes: 20 additions & 14 deletions src/com/serotonin/mango/rt/EventManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,6 @@ public class EventManager implements ILifecycle, ScadaWebSockets<String> {
private long lastAlarmTimestamp = 0;
private int highestActiveAlarmLevel = 0;
private static final String WS_MESSAGE = "Event Raised";

private UserEventServiceWebSocket userEventServiceWebsocket;
private EventsServiceWebSocket eventsServiceWebSocket;
private IHighestAlarmLevelService highestAlarmLevelService;

//
Expand Down Expand Up @@ -318,8 +315,6 @@ private LocalizableMessage getAlarmLevelChangeMessage(String key,
public void initialize() {
eventService = new EventService();
userService = new UserService();
userEventServiceWebsocket = ApplicationBeans.getUserEventServiceWebsocketBean();
eventsServiceWebSocket = ApplicationBeans.getEventsServiceWebSocketBean();
highestAlarmLevelService = ApplicationBeans.getHighestAlarmLevelServiceBean();

// Get all active events from the database.
Expand Down Expand Up @@ -457,7 +452,9 @@ public void notifyAlarmTimestampChange(long alarmTimestamp) {
}

public void resetHighestAlarmLevels() {
highestAlarmLevelService.doResetAlarmLevels(userEventServiceWebsocket::sendAlarmLevel);
ApplicationBeans.Lazy.getUserEventServiceWebsocketBean().ifPresent(websocket -> {
highestAlarmLevelService.doResetAlarmLevels(websocket::sendAlarmLevel);
});
notifyEventReset();
}

Expand All @@ -475,14 +472,17 @@ public void notifyEventRaise(int eventId, int userId) {

public void notifyEventRaise(EventInstance evt, User user) {
if(evt.getAlarmLevel() > AlarmLevels.NONE) {
highestAlarmLevelService.doUpdateAlarmLevel(user, evt, userEventServiceWebsocket::sendAlarmLevel);
notifyEventUpdate(user, WsEventMessage.create(evt));
ApplicationBeans.Lazy.getUserEventServiceWebsocketBean().ifPresent(userEventService -> {
highestAlarmLevelService.doUpdateAlarmLevel(user, evt, userEventService::sendAlarmLevel);
});
}
}

public void notifyEventAck(EventInstance evt, User user) {
if(evt.getAlarmLevel() > AlarmLevels.NONE) {
highestAlarmLevelService.doRemoveAlarmLevel(user, evt, userEventServiceWebsocket::sendAlarmLevel);
ApplicationBeans.Lazy.getUserEventServiceWebsocketBean().ifPresent(userEventService -> {
highestAlarmLevelService.doRemoveAlarmLevel(user, evt, userEventService::sendAlarmLevel);
});
notifyEventUpdate(user, WsEventMessage.delete(evt));
}
}
Expand All @@ -503,7 +503,9 @@ public void notifyEventAck(int eventId) {

public void notifyEventToggle(EventInstance evt, User user) {
if(evt.getAlarmLevel() > AlarmLevels.NONE) {
highestAlarmLevelService.doRemoveAlarmLevel(user, evt, userEventServiceWebsocket::sendAlarmLevel);
ApplicationBeans.Lazy.getUserEventServiceWebsocketBean().ifPresent(userEventService -> {
highestAlarmLevelService.doRemoveAlarmLevel(user, evt, userEventService::sendAlarmLevel);
});
notifyEventUpdate(user, WsEventMessage.update(evt));
}
}
Expand All @@ -524,16 +526,20 @@ public void notifyEventToggle(int eventId, int userId) {
}

public void notifyEventUpdate(User user, WsEventMessage message) {
userEventServiceWebsocket.sendEventUpdate(user, message);
ApplicationBeans.Lazy.getUserEventServiceWebsocketBean().ifPresent(websocket -> {
websocket.sendEventUpdate(user, message);
});
}

public void notifyEventReset() {
for(User user: userService.getActiveUsers())
userEventServiceWebsocket.sendEventUpdate(user, WsEventMessage.reset());
ApplicationBeans.Lazy.getUserEventServiceWebsocketBean().ifPresent(websocket -> {
for(User user: userService.getActiveUsers())
websocket.sendEventUpdate(user, WsEventMessage.reset());
});
}

@Override
public void notifyWebSocketSubscribers(String message) {
eventsServiceWebSocket.notifyEventsSubscribers(message);
ApplicationBeans.Lazy.getEventsServiceWebSocketBean().ifPresent(ws -> ws.notifyEventsSubscribers(message));
}
}
10 changes: 4 additions & 6 deletions src/com/serotonin/mango/rt/dataImage/DataPointRT.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,30 +77,26 @@ public class DataPointRT implements IDataPoint, ILifecycle, TimeoutClient, Scada
* determining whether to log numeric values.
*/
private double toleranceOrigin;
private final DataPointServiceWebSocket dataPointServiceWebSocket;
private final PointValueService pointValueService;

public DataPointRT(DataPointVO vo, PointLocatorRT pointLocator) {
this.vo = vo;
this.pointLocator = pointLocator;
valueCache = new PointValueCache(vo.getId(), vo.getDefaultCacheSize());
dataPointServiceWebSocket = ApplicationBeans.getDataPointServiceWebSocketBean();
pointValueService = new PointValueService();
}
public DataPointRT(DataPointVO vo, PointLocatorRT pointLocator,int cacheSize,int maxSize) {
this.vo = vo;
this.pointLocator = pointLocator;
valueCache = new PointValueCache(cacheSize);
valueCache.setMaxSize(maxSize);
dataPointServiceWebSocket = ApplicationBeans.getDataPointServiceWebSocketBean();
pointValueService = new PointValueService();
}

public DataPointRT(DataPointVO vo) {
this.vo = vo;
this.pointLocator = null;
valueCache = new PointValueCache();
dataPointServiceWebSocket = ApplicationBeans.getDataPointServiceWebSocketBean();
pointValueService = new PointValueService();
}
public PointValueCache getPointValueCache(){
Expand Down Expand Up @@ -494,11 +490,13 @@ protected void fireEvents(PointValueTime oldValue, PointValueTime newValue,

@Override
public void notifyWebSocketSubscribers(MangoValue message) {
dataPointServiceWebSocket.notifyValueSubscribers(message, this.vo.getId());
ApplicationBeans.Lazy.getDataPointServiceWebSocketBean()
.ifPresent(ws -> ws.notifyValueSubscribers(message, this.vo.getId()));
}

public void notifyWebSocketStateSubscribers(boolean enabled) {
dataPointServiceWebSocket.notifyStateSubscribers(enabled, this.vo.getId());
ApplicationBeans.Lazy.getDataPointServiceWebSocketBean()
.ifPresent(ws -> ws.notifyStateSubscribers(enabled, this.vo.getId()));
}

static class EventNotifyWorkItem extends AbstractBeforeAfterWorkItem {
Expand Down
3 changes: 1 addition & 2 deletions src/org/scada_lts/web/beans/ApplicationBeans.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ public static EventsServiceWebSocket getEventsServiceWebSocketBean() {
return getBeanFromContext("eventsServiceWebSocket", EventsServiceWebSocket.class);
}

@Deprecated
public static class Lazy {

private Lazy() {}
Expand All @@ -174,7 +173,7 @@ private static <T> Optional<T> getBeanFromContext(String beanName, Class<T> claz
try {
return Optional.ofNullable(get(beanName, clazz));
} catch (NoSuchBeanDefinitionException ex) {
LOG.error(ex);
LOG.warn(ex);
return Optional.empty();
} catch (Exception ex) {
LOG.error(ex.getMessage(), ex);
Expand Down
4 changes: 2 additions & 2 deletions src/org/scada_lts/web/beans/ScadaContextClosedEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public ScadaContextClosedEvent(MangoContextListener mangoContextListener) {
}

@Override
public void onApplicationEvent(ContextClosedEvent contextRefreshedEvent) {
WebApplicationContext webApplicationContext = (WebApplicationContext)contextRefreshedEvent.getSource();
public void onApplicationEvent(ContextClosedEvent contextClosedEvent) {
WebApplicationContext webApplicationContext = (WebApplicationContext)contextClosedEvent.getSource();
ServletContextEvent servletContextEvent = new ServletContextEvent(webApplicationContext.getServletContext());
mangoContextListener.contextDestroyed(servletContextEvent);
}
Expand Down
26 changes: 0 additions & 26 deletions src/org/scada_lts/web/beans/ScadaContextRefreshedEvent.java

This file was deleted.

0 comments on commit 5cbf497

Please sign in to comment.