Skip to content

Instantly share code, notes, and snippets.

import java.util.NavigableMap;
import java.util.TreeMap;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Stream;
public class Fibonacci {
public static final Fibonacci BASE = new Fibonacci(0, 1);
@Override
public void savePaymentStatus(String paymentId, AcquiringResponse.PaymentStatus paymentStatus) {
pmcRedisTemplate.execute(new SessionCallback<Void>(){
@Override
public Void execute(RedisOperations operations) throws DataAccessException {
operations.watch(paymentId);
if (!findPaymentStatusByPaymentId(paymentId).isPresent()) {
operations.multi();
updatePaymentStatus(paymentId, paymentStatus.getValue());
operations.exec();
import org.apache.logging.log4j.core.pattern.LogEventPatternConverter;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@Plugin(name = "EraseSensitiveData", category = "Converter")
@ConverterKeys({ "msg" })
public class EraseSensitiveDataConverter extends LogEventPatternConverter {
private static final String NAME = "msg";
private static final String JSON_REPLACEMENT_REGEX_1 = "\"$1\":\"٩(◕‿◕。)۶\"";
import org.togglz.core.manager.EnumBasedFeatureProvider;
import org.togglz.core.spi.FeatureProvider;
@Configuration
public class ToggleConfiguration {
@Bean
public FeatureProvider featureProvider() {
return new EnumBasedFeatureProvider(FeatureEnum.class);
}
@RestController
public class PromotionController {
private final PromotionService promotionService;
@Autowired
public PromotionController(PromotionService promotionService){
this.promotionService = promotionService;
}
@Service
public class PromotionService {
@FeatureSwitch(value = FeatureEnum.PROMOTION_MANAGEMENT_FEATURE)
public void performPromotion() {
System.out.println("Perform Promotion.")
}
}
@Aspect
@Component
public class FeaturesAspect {
private static final Logger LOG = Logger.getLogger(FeaturesAspect.class);
@Around(value = "@within(featureSwitch) || @annotation(featureSwitch)")
public Object checkAspect(ProceedingJoinPoint joinPoint, FeatureSwitch featureSwitch) throws Throwable {
if (featureSwitch.value().isActive()) {
LOG.info("Feature " + featureSwitch.value().name() + " is Open");
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.METHOD, ElementType.TYPE })
public @interface FeatureSwitch {
FeatureEnum value();
}
import org.togglz.core.Feature;
public enum FeatureEnum implements Feature {
@Label("Promotion Management Feature")
@EnabledByDefault
@DefaultActivationStrategy(
id = SystemPropertyActivationStrategy.ID,
parameters = { @ActivationParameter(name = SystemPropertyActivationStrategy.PARAM_PROPERTY_NAME,
value = "promotion.feature"),
<!-- https://mvnrepository.com/artifact/org.togglz/togglz-core -->
<dependency>
<groupId>org.togglz</groupId>
<artifactId>togglz-core</artifactId>
<version>2.5.0.Final</version>
</dependency>