Skip to content

Commit

Permalink
Configuration parameter for default notification TTL
Browse files Browse the repository at this point in the history
  • Loading branch information
Pyshankov committed Sep 19, 2016
1 parent 3416a4a commit b37c8a2
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
Expand Up @@ -34,6 +34,7 @@
import java.util.List; import java.util.List;
import java.util.TimeZone; import java.util.TimeZone;


import javax.annotation.Resource;
import org.apache.avro.generic.GenericRecord; import org.apache.avro.generic.GenericRecord;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.kaaproject.kaa.common.avro.GenericAvroConverter; import org.kaaproject.kaa.common.avro.GenericAvroConverter;
Expand Down Expand Up @@ -71,6 +72,10 @@ public class NotificationServiceImpl implements NotificationService {


@Value("#{sql_dao[dao_max_wait_time]}") @Value("#{sql_dao[dao_max_wait_time]}")
private int waitSeconds; private int waitSeconds;

@Autowired(required = false)
private int ttl = 7 * 24 * 3600;

@Autowired @Autowired
private TopicDao<Topic> topicDao; private TopicDao<Topic> topicDao;
@Autowired @Autowired
Expand All @@ -80,9 +85,6 @@ public class NotificationServiceImpl implements NotificationService {
private NotificationDao<Notification> notificationDao; private NotificationDao<Notification> notificationDao;
private EndpointNotificationDao<EndpointNotification> unicastNotificationDao; private EndpointNotificationDao<EndpointNotification> unicastNotificationDao;


@Value("#{properties[default_ttl]}")
private int TTL;

@Override @Override
public NotificationSchemaDto saveNotificationSchema(NotificationSchemaDto notificationSchemaDto) { public NotificationSchemaDto saveNotificationSchema(NotificationSchemaDto notificationSchemaDto) {
validateNotificationSchemaObject(notificationSchemaDto); validateNotificationSchemaObject(notificationSchemaDto);
Expand Down Expand Up @@ -141,7 +143,7 @@ public UpdateNotificationDto<NotificationDto> saveNotification(NotificationDto d


long currentTime = new GregorianCalendar(TimeZone.getTimeZone("UTC")).getTimeInMillis(); long currentTime = new GregorianCalendar(TimeZone.getTimeZone("UTC")).getTimeInMillis();
Date expiredAt = dto.getExpiredAt(); Date expiredAt = dto.getExpiredAt();
dto.setExpiredAt(expiredAt != null ? expiredAt : new Date(currentTime + TTL)); dto.setExpiredAt(expiredAt != null ? expiredAt : new Date(currentTime + ttl));
dto.setLastTimeModify(new Date(currentTime)); dto.setLastTimeModify(new Date(currentTime));
NotificationDto notificationDto = saveNotificationAndIncTopicSecNum(dto); NotificationDto notificationDto = saveNotificationAndIncTopicSecNum(dto);
if (notificationDto != null) { if (notificationDto != null) {
Expand Down Expand Up @@ -305,7 +307,7 @@ public UpdateNotificationDto<EndpointNotificationDto> saveUnicastNotification(En
} }
long currentTime = new GregorianCalendar(TimeZone.getTimeZone("UTC")).getTimeInMillis(); long currentTime = new GregorianCalendar(TimeZone.getTimeZone("UTC")).getTimeInMillis();
Date expiredAt = notificationDto.getExpiredAt(); Date expiredAt = notificationDto.getExpiredAt();
notificationDto.setExpiredAt(expiredAt != null ? expiredAt : new Date(currentTime + TTL)); notificationDto.setExpiredAt(expiredAt != null ? expiredAt : new Date(currentTime + ttl));
notificationDto.setLastTimeModify(new Date(currentTime)); notificationDto.setLastTimeModify(new Date(currentTime));


EndpointNotificationDto unicast = getDto(unicastNotificationDao.save(dto)); EndpointNotificationDto unicast = getDto(unicastNotificationDao.save(dto));
Expand Down
3 changes: 2 additions & 1 deletion server/common/dao/src/test/resources/dao_test.properties
Expand Up @@ -34,4 +34,5 @@ jdbc_port=9092
# Path to logs root directory # Path to logs root directory
logs_root_dir=logs_root logs_root_dir=logs_root


jdbc_url_db_name=h2 jdbc_url_db_name=h2

5 changes: 4 additions & 1 deletion server/node/src/main/resources/kaaNodeContext.xml
Expand Up @@ -44,6 +44,10 @@
<util:properties id="properties" <util:properties id="properties"
location="classpath:/kaa-node.properties" /> location="classpath:/kaa-node.properties" />


<bean id="ttl" class="java.lang.Integer">
<constructor-arg value="#{properties[default_ttl]}" />
</bean>

<!-- Node configuration from properties file --> <!-- Node configuration from properties file -->


<bean id="kaaNodeServerConfig" class="org.kaaproject.kaa.server.node.service.config.KaaNodeServerConfig"> <bean id="kaaNodeServerConfig" class="org.kaaproject.kaa.server.node.service.config.KaaNodeServerConfig">
Expand All @@ -59,7 +63,6 @@
<property name="zkSleepTime" value="#{properties[zk_sleep_time]}" /> <property name="zkSleepTime" value="#{properties[zk_sleep_time]}" />
<property name="zkIgnoreErrors" value="#{properties[zk_ignore_errors]}" /> <property name="zkIgnoreErrors" value="#{properties[zk_ignore_errors]}" />
</bean> </bean>

<!--Zookeeper client configuration--> <!--Zookeeper client configuration-->


<bean id="zkRetryPolicy" class="org.apache.curator.retry.RetryUntilElapsed"> <bean id="zkRetryPolicy" class="org.apache.curator.retry.RetryUntilElapsed">
Expand Down
1 change: 1 addition & 0 deletions server/node/src/test/resources/common-test-context.xml
Expand Up @@ -41,6 +41,7 @@
<util:properties id="properties" <util:properties id="properties"
location="classpath:/kaa-node-test.properties" /> location="classpath:/kaa-node-test.properties" />



<!-- Node configuration from properties file --> <!-- Node configuration from properties file -->


<bean id="kaaNodeServerConfig" class="org.kaaproject.kaa.server.node.service.config.KaaNodeServerConfig"> <bean id="kaaNodeServerConfig" class="org.kaaproject.kaa.server.node.service.config.KaaNodeServerConfig">
Expand Down

0 comments on commit b37c8a2

Please sign in to comment.