Skip to content

Commit

Permalink
Introduce ChargePointActionStatusUpdateDao API with AsyncJdbcChargePo…
Browse files Browse the repository at this point in the history
…intActionStatusDao to offload OCPP status updates to dedicated processor thread and not burden OCPP processing with associated DB transaction.
  • Loading branch information
msqr committed May 15, 2024
1 parent c648dd1 commit 357e7f5
Show file tree
Hide file tree
Showing 17 changed files with 1,301 additions and 97 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@

package net.solarnetwork.central.ocpp.config;

import javax.sql.DataSource;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcOperations;
Expand All @@ -36,6 +38,7 @@
import net.solarnetwork.central.ocpp.dao.ChargePointSettingsDao;
import net.solarnetwork.central.ocpp.dao.ChargePointStatusDao;
import net.solarnetwork.central.ocpp.dao.UserSettingsDao;
import net.solarnetwork.central.ocpp.dao.jdbc.AsyncJdbcChargePointActionStatusDao;
import net.solarnetwork.central.ocpp.dao.jdbc.JdbcChargePointActionStatusDao;
import net.solarnetwork.central.ocpp.dao.jdbc.JdbcChargePointStatusDao;
import net.solarnetwork.central.ocpp.dao.mybatis.MyBatisCentralAuthorizationDao;
Expand All @@ -61,6 +64,9 @@ public class OcppDaoConfig {
@Autowired
private JdbcOperations jdbcOperations;

@Autowired
private DataSource dataSource;

@Bean
public CentralAuthorizationDao ocppCentralAuthorizationDao() {
MyBatisCentralAuthorizationDao dao = new MyBatisCentralAuthorizationDao();
Expand Down Expand Up @@ -120,4 +126,10 @@ public ChargePointActionStatusDao ocppChargePointActionStatusDao() {
return new JdbcChargePointActionStatusDao(jdbcOperations);
}

@ConfigurationProperties(prefix = "app.ocpp.async-action-status-updater")
@Bean(initMethod = "serviceDidStartup", destroyMethod = "serviceDidShutdown")
public AsyncJdbcChargePointActionStatusDao ocppChargePointActionStatusUpdateDao() {
return new AsyncJdbcChargePointActionStatusDao(dataSource);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
package net.solarnetwork.central.ocpp.dao;

import java.io.IOException;
import java.time.Instant;
import java.util.List;
import net.solarnetwork.central.ocpp.domain.ChargePointActionStatus;
import net.solarnetwork.central.ocpp.domain.ChargePointActionStatusKey;
Expand All @@ -35,69 +34,11 @@
* DAO API for {@link ChargePointActionStatus} entities.
*
* @author matt
* @version 1.1
* @version 2.0
*/
public interface ChargePointActionStatusDao extends
FilterableDao<ChargePointActionStatus, ChargePointActionStatusKey, ChargePointActionStatusFilter> {

/**
* Update the timestamp for a specific charge point action.
*
* <p>
* This method will create a new entity if one does not already exist.
* </p>
*
* @param userId
* the user ID
* @param chargePointIdentifier
* the charge point identifier
* @param connectorId
* the connector ID the message is related to, or {@literal null} or
* {@literal 0} for charger-wide actions
* @param action
* the action name
* @param messageId
* the message ID
* @param date
* the date
* @throws IllegalArgumentException
* if any argument other than {@code connectorId} is {@literal null}
*/
default void updateActionTimestamp(Long userId, String chargePointIdentifier, Integer connectorId,
String action, String messageId, Instant date) {
updateActionTimestamp(userId, chargePointIdentifier, 0, connectorId, action, messageId, date);
}

/**
* Update the timestamp for a specific charge point action.
*
* <p>
* This method will create a new entity if one does not already exist.
* </p>
*
* @param userId
* the user ID
* @param chargePointIdentifier
* the charge point identifier
* @param evseId
* the EVSE ID the message is related to, or {@literal null} for
* charger-wide actions
* @param connectorId
* the connector ID the message is related to, or {@literal null} or
* {@literal 0} for EVSE-wide actions
* @param action
* the action name
* @param messageId
* the message ID
* @param date
* the date
* @throws IllegalArgumentException
* if any argument other than {@code connectorId} is {@literal null}
* @since 1.1
*/
void updateActionTimestamp(Long userId, String chargePointIdentifier, Integer evseId,
Integer connectorId, String action, String messageId, Instant date);

/**
* API for querying for a stream of {@link ChargePointActionStatus}.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/* ==================================================================
* ChargePointActionStatusUpdateDao.java - 15/05/2024 7:28:37 am
*
* Copyright 2024 SolarNetwork.net Dev Team
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
* 02111-1307 USA
* ==================================================================
*/

package net.solarnetwork.central.ocpp.dao;

import java.time.Instant;
import net.solarnetwork.central.ocpp.domain.ChargePointActionStatus;

/**
* DAO API for updating {@link ChargePointActionStatus} entities.
*
* @author matt
* @version 1.0
*/
public interface ChargePointActionStatusUpdateDao {

/**
* Update the timestamp for a specific charge point action.
*
* <p>
* This method will create a new entity if one does not already exist.
* </p>
*
* @param userId
* the user ID
* @param chargePointIdentifier
* the charge point identifier
* @param connectorId
* the connector ID the message is related to, or {@literal null} or
* {@literal 0} for charger-wide actions
* @param action
* the action name
* @param messageId
* the message ID
* @param date
* the date
* @throws IllegalArgumentException
* if any argument other than {@code connectorId} is {@literal null}
*/
default void updateActionTimestamp(Long userId, String chargePointIdentifier, Integer connectorId,
String action, String messageId, Instant date) {
updateActionTimestamp(userId, chargePointIdentifier, 0, connectorId, action, messageId, date);
}

/**
* Update the timestamp for a specific charge point action.
*
* <p>
* This method will create a new entity if one does not already exist.
* </p>
*
* @param userId
* the user ID
* @param chargePointIdentifier
* the charge point identifier
* @param evseId
* the EVSE ID the message is related to, or {@literal null} for
* charger-wide actions
* @param connectorId
* the connector ID the message is related to, or {@literal null} or
* {@literal 0} for EVSE-wide actions
* @param action
* the action name
* @param messageId
* the message ID
* @param date
* the date
* @throws IllegalArgumentException
* if any argument other than {@code connectorId} is {@literal null}
*/
void updateActionTimestamp(Long userId, String chargePointIdentifier, Integer evseId,
Integer connectorId, String action, String messageId, Instant date);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/* ==================================================================
* AsyncJdbcChargePointActionStatusCount.java - 11/06/2018 7:43:25 PM
*
* Copyright 2018 SolarNetwork.net Dev Team
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
* 02111-1307 USA
* ==================================================================
*/

package net.solarnetwork.central.ocpp.dao.jdbc;

import net.solarnetwork.util.StatCounter.Stat;

/**
* Statistics for asynchronous JDBC charge point action status processing.
*
* @author matt
* @version 1.0
*/
public enum AsyncJdbcChargePointActionStatusCount implements Stat {

ResultsAdded(0, "results added"),

WriterThreadsStarted(1, "write threads started"),

WriterThreadsEnded(2, "write threads ended"),

ConnectionsCreated(3, "JDBC connections created"),

UpdatesExecuted(4, "SQL updates executed"),

UpdatesFailed(5, "SQL updates failed"),

;

private final int index;
private final String description;

private AsyncJdbcChargePointActionStatusCount(int index, String description) {
this.index = index;
this.description = description;
}

@Override
public int getIndex() {
return index;
}

@Override
public String getDescription() {
return description;
}

}
Loading

0 comments on commit 357e7f5

Please sign in to comment.