Merge pull request #71 from onixbyte/feature/remove-simple-serial

refactor: remove `simple-serial`
This commit is contained in:
Jam'o Siu
2025-06-17 10:34:49 +08:00
committed by GitHub
7 changed files with 0 additions and 281 deletions
-1
View File
@@ -28,5 +28,4 @@ include(
"simple-jwt-facade",
"simple-jwt-authzero",
"simple-jwt-spring-boot-starter",
"simple-serial-spring-boot-starter"
)
@@ -1,14 +0,0 @@
# Simple Serial
> Thanks to [@siujamo](https://github.com/siujamo)'s donation.
Simple Serial reuses the configuration of Redis connections to provide am easy-to-use serial
service.
## Configuration
Simple Serial reused the redis configuration of Spring Boot to provide redis support for the
service.
Besides, **Simple Serial** provides a configuration property `onixbyte.serial.start-serial` to
specify the start value of a serial, and default to `0`.
@@ -1,57 +0,0 @@
/*
* Copyright (C) 2024-2025 OnixByte.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.onixbyte.serial;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializer;
/**
* Redis Configuration provides redis templates for operations to serial.
*
* @author siujamo
*/
@AutoConfiguration
public class RedisConfig {
/**
* Redis auto configuration.
*/
public RedisConfig() {
}
/**
* RedisTemplate for serial service.
*
* @param redisConnectionFactory redis connection factory
* @return a configured redis template for serial service
*/
@Bean
public RedisTemplate<String, Long> serialRedisTemplate(RedisConnectionFactory redisConnectionFactory) {
var redisTemplate = new RedisTemplate<String, Long>();
redisTemplate.setConnectionFactory(redisConnectionFactory);
redisTemplate.setKeySerializer(RedisSerializer.string());
redisTemplate.setValueSerializer(new Jackson2JsonRedisSerializer<>(Long.class));
redisTemplate.afterPropertiesSet();
return redisTemplate;
}
}
@@ -1,99 +0,0 @@
/*
* Copyright (C) 2024-2025 OnixByte.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.onixbyte.serial;
import com.onixbyte.serial.properties.SerialProperties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import java.util.Optional;
/**
* {@code SerialService} provides simple serial operations.
*
* @author siujamo
*/
@Service
@EnableConfigurationProperties(SerialProperties.class)
public class SerialService {
private static final Logger log = LoggerFactory.getLogger(SerialService.class);
private final String appName;
private final RedisTemplate<String, Long> serialRedisTemplate;
private final SerialProperties serialProperties;
/**
* Default constructor.
*
* @param appName the name of this application
* @param serialRedisTemplate serial redis template
* @param serialProperties serial properties
*/
public SerialService(@Value("${spring.application.name}") String appName,
RedisTemplate<String, Long> serialRedisTemplate,
SerialProperties serialProperties) {
this.appName = appName;
this.serialRedisTemplate = serialRedisTemplate;
this.serialProperties = serialProperties;
}
/**
* Build a serial key.
*
* @param tag tag of the serial
* @return key of a serial
*/
public String buildKey(String tag) {
return appName + ":serial:" + tag;
}
/**
* Get the next available serial for specific tag.
*
* @param tag tag of the serial
* @return next available serial
*/
public Long nextSerial(String tag) {
var key = buildKey(tag);
var next = Optional.ofNullable(serialRedisTemplate.opsForValue().get(key))
.orElse(serialProperties.getStartSerial());
serialRedisTemplate.opsForValue().set(key, next + 1);
return next;
}
/**
* Reset all serial values.
*/
public void reset() {
var keys = serialRedisTemplate.keys(buildKey("*"));
var startSerial = serialProperties.getStartSerial();
if (!keys.isEmpty()) {
for (var key : keys) {
serialRedisTemplate.opsForValue().set(key, startSerial);
log.debug("Serial {} has been reset to {}", key, startSerial);
}
}
}
}
@@ -1,59 +0,0 @@
/*
* Copyright (C) 2024-2025 OnixByte.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.onixbyte.serial.properties;
import org.springframework.boot.context.properties.ConfigurationProperties;
/**
* SerialProperties can modify the start value of a serial.
*
* @author siujamo
*/
@ConfigurationProperties(prefix = "onixbyte.serial")
public class SerialProperties {
/**
* The start of the serial, default to 0.
*/
private Long startSerial = 0L;
/**
* Get the start of the serial.
*
* @return start of the serial
*/
public Long getStartSerial() {
return startSerial;
}
/**
* Set the start of the serial.
*
* @param startSerial start of the serial
*/
public void setStartSerial(Long startSerial) {
this.startSerial = startSerial;
}
/**
* Default constructor.
*/
public SerialProperties() {
}
}
@@ -1,19 +0,0 @@
#
# Copyright (C) 2024-2025 OnixByte.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#
# See the License for the specific language governing permissions and
# limitations under the License.
#
com.onixbyte.serial.RedisConfig
com.onixbyte.serial.SerialService
@@ -1,32 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (C) 2024-2025 OnixByte.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<configuration>
<property name="COLOURFUL_OUTPUT" value="%black(%date{'dd MMM, yyyy HH:mm:ss', Asia/Hong_Kong, en-UK}) %highlight(%-5level) %black(---) %black([%10.10t]) %cyan(%-20.20logger{20}) %black(:) %msg%n"/>
<property name="STANDARD_OUTPUT" value="%date{'dd MMM, yyyy HH:mm:ss', Asia/Hong_Kong, en-UK} %-5level %black(---) [%10.10t] %-20.20logger{20} : %msg%n"/>
<statusListener class="ch.qos.logback.core.status.NopStatusListener" />
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>${COLOURFUL_OUTPUT}</pattern>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="STDOUT"/>
</root>
</configuration>