Skip to content

Commit

Permalink
Merge pull request #230 from shiyindaxiaojie/feature
Browse files Browse the repository at this point in the history
update
  • Loading branch information
shiyindaxiaojie authored Feb 13, 2025
2 parents 1e88e93 + f6cb66d commit 9037391
Show file tree
Hide file tree
Showing 7 changed files with 250 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-zookeeper-core</artifactId>
</dependency>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-framework</artifactId>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
/*
* Copyright 2012-2019 the original author or authors.
*
* 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
*
* https://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 org.ylzl.eden.curator.spring.boot.autoconfigure;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.zookeeper.ZookeeperProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Role;
import org.ylzl.eden.curator.spring.boot.env.CuratorProperties;
import org.ylzl.eden.spring.boot.bootstrap.constant.Conditions;

/**
* Curator 自动装配
*
* @author <a href="mailto:[email protected]">gyl</a>
* @since 2.4.13
*/
@ConditionalOnProperty(
prefix = ZookeeperProperties.PREFIX,
name = Conditions.ENABLED,
havingValue = Conditions.TRUE
)
@ConditionalOnClass(CuratorFramework.class)
@EnableConfigurationProperties(CuratorProperties.class)
@RequiredArgsConstructor
@Slf4j
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
@Configuration(proxyBeanMethods = false)
public class CuratorAutoConfiguration {

public static final String AUTOWIRED_CURATOR_FRAMEWORK = "Autowired CuratorFramework";

private final CuratorProperties curatorProperties;

private final ZookeeperProperties zookeeperProperties;

@Bean
public CuratorFramework curatorFramework() {
log.debug(AUTOWIRED_CURATOR_FRAMEWORK);
CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder();

builder.connectString(zookeeperProperties.getConnectString());

if (curatorProperties.getSessionTimeoutMs() > 0) {
builder.sessionTimeoutMs(curatorProperties.getSessionTimeoutMs());
} else if (!zookeeperProperties.getSessionTimeout().isZero()) {
builder.sessionTimeoutMs((int) zookeeperProperties.getSessionTimeout().toMillis());
}

if (curatorProperties.getConnectionTimeoutMs() > 0) {
builder.connectionTimeoutMs(curatorProperties.getConnectionTimeoutMs());
} else if (!zookeeperProperties.getConnectionTimeout().isZero()) {
builder.sessionTimeoutMs((int) zookeeperProperties.getConnectionTimeout().toMillis());
}

if (curatorProperties.getEnsembleProvider() != null) {
builder.ensembleProvider(curatorProperties.getEnsembleProvider());
}

if (curatorProperties.getDefaultData() != null) {
builder.defaultData(curatorProperties.getDefaultData());
}

if (curatorProperties.getNamespace() != null) {
builder.namespace(curatorProperties.getNamespace());
}

if (curatorProperties.getMaxCloseWaitMs() > 0) {
builder.maxCloseWaitMs(curatorProperties.getMaxCloseWaitMs());
}

if (curatorProperties.getRetryPolicy() != null) {
builder.retryPolicy(curatorProperties.getRetryPolicy());
}

if (curatorProperties.getThreadFactory() != null) {
builder.threadFactory(curatorProperties.getThreadFactory());
}

if (curatorProperties.getCompressionProvider() != null) {
builder.compressionProvider(curatorProperties.getCompressionProvider());
}

if (curatorProperties.getZookeeperFactory() != null) {
builder.zookeeperFactory(curatorProperties.getZookeeperFactory());
}

if (curatorProperties.getAclProvider() != null) {
builder.aclProvider(curatorProperties.getAclProvider());
}

builder.canBeReadOnly(curatorProperties.isCanBeReadOnly());

if (!builder.useContainerParentsIfAvailable()) {
builder.dontUseContainerParents();
}

if (curatorProperties.getConnectionStateErrorPolicy() != null) {
builder.connectionStateErrorPolicy(curatorProperties.getConnectionStateErrorPolicy());
}

builder.zk34CompatibilityMode(curatorProperties.isZk34CompatibilityMode());

if (curatorProperties.getWaitForShutdownTimeoutMs() > 0) {
builder.waitForShutdownTimeoutMs(curatorProperties.getWaitForShutdownTimeoutMs());
}

if (curatorProperties.getConnectionHandlingPolicy() != null) {
builder.connectionHandlingPolicy(curatorProperties.getConnectionHandlingPolicy());
}

if (curatorProperties.getSchemaSet() != null) {
builder.schemaSet(curatorProperties.getSchemaSet());
}

if (curatorProperties.getRunSafeService() != null) {
builder.runSafeService(curatorProperties.getRunSafeService());
}

if (curatorProperties.getConnectionStateListenerManagerFactory() != null) {
builder.connectionStateListenerManagerFactory(curatorProperties.getConnectionStateListenerManagerFactory());
}

CuratorFramework curatorFramework = builder.build();
curatorFramework.start();
return curatorFramework;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* Copyright 2012-2019 the original author or authors.
*
* 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
*
* https://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 org.ylzl.eden.curator.spring.boot.env;

import lombok.Data;
import org.apache.curator.RetryPolicy;
import org.apache.curator.connection.ConnectionHandlingPolicy;
import org.apache.curator.ensemble.EnsembleProvider;
import org.apache.curator.framework.AuthInfo;
import org.apache.curator.framework.api.ACLProvider;
import org.apache.curator.framework.api.CompressionProvider;
import org.apache.curator.framework.schema.SchemaSet;
import org.apache.curator.framework.state.ConnectionStateErrorPolicy;
import org.apache.curator.framework.state.ConnectionStateListenerManagerFactory;
import org.apache.curator.utils.ZookeeperFactory;
import org.springframework.boot.context.properties.ConfigurationProperties;

import java.util.List;
import java.util.concurrent.Executor;
import java.util.concurrent.ThreadFactory;

/**
* Curator 配置
*
* @author <a href="mailto:[email protected]">gyl</a>
* @since 2.4.13
*/
@Data
@ConfigurationProperties(prefix = CuratorProperties.PREFIX)
public class CuratorProperties {

public static final String PREFIX = "spring.cloud.zookeeper.curator";

private EnsembleProvider ensembleProvider;

private int sessionTimeoutMs;

private int connectionTimeoutMs;

private int maxCloseWaitMs;

private RetryPolicy retryPolicy;

private ThreadFactory threadFactory;

private String namespace;

private List<AuthInfo> authInfos;

private byte[] defaultData;

private CompressionProvider compressionProvider;

private ZookeeperFactory zookeeperFactory;

private ACLProvider aclProvider;

private boolean canBeReadOnly;

private boolean useContainerParentsIfAvailable;

private ConnectionStateErrorPolicy connectionStateErrorPolicy;

private ConnectionHandlingPolicy connectionHandlingPolicy;

private SchemaSet schemaSet;

private boolean zk34CompatibilityMode;

private int waitForShutdownTimeoutMs;

private Executor runSafeService;

private ConnectionStateListenerManagerFactory connectionStateListenerManagerFactory;
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Auto Configure
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
org.ylzl.eden.curator.spring.boot.autoconfigure.CuratorAutoConfiguration
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.ylzl.eden.spring.data.mybatis.plugin;

import com.baomidou.mybatisplus.core.toolkit.SystemClock;
import lombok.Setter;
import org.apache.ibatis.cache.CacheKey;
import org.apache.ibatis.executor.Executor;
import org.apache.ibatis.mapping.BoundSql;
Expand All @@ -36,16 +37,15 @@
* @author <a href="mailto:[email protected]">gyl</a>
* @since 2.4.13
*/
@Setter
@Intercepts({
@Signature(method = "query", type = Executor.class, args = {MappedStatement.class, Object.class, RowBounds.class, ResultHandler.class}),
@Signature(method = "query", type = Executor.class, args = {MappedStatement.class, Object.class, RowBounds.class, ResultHandler.class, CacheKey.class, BoundSql.class}),
@Signature(method = "update", type = Executor.class, args = {MappedStatement.class, Object.class})
})
public class MybatisSqlLogInterceptor implements Interceptor {

private static final String MYBATIS_SQL_LOG = "MybatisSqlLog";

private static final Logger log = LoggerFactory.getLogger(MYBATIS_SQL_LOG);
private static final Logger log = LoggerFactory.getLogger("MybatisSqlLog");

private static final String INFO_SQL = "{} execute sql: {} ({} ms)";

Expand All @@ -65,7 +65,7 @@ public Object intercept(Invocation invocation) throws Throwable {
long duration = SystemClock.now() - start;
if (Duration.ofMillis(duration).compareTo(slownessThreshold) < 0) {
log.info(INFO_SQL, mapperId, originalSql, duration);
} else {
} else if (log.isWarnEnabled()) {
log.warn(WARN_SQL, mapperId, slownessThreshold.toMillis(), originalSql, duration);
}
return result;
Expand All @@ -78,8 +78,4 @@ public Object plugin(Object target) {
}
return target;
}

public void setSlownessThreshold(Duration slownessThreshold) {
this.slownessThreshold = slownessThreshold;
}
}

0 comments on commit 9037391

Please sign in to comment.