-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #230 from shiyindaxiaojie/feature
update
- Loading branch information
Showing
7 changed files
with
250 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 0 additions & 3 deletions
3
...ponents/eden-spring-boot-starters/eden-curator-spring-boot-starter/src/main/java/.gitkeep
This file was deleted.
Oops, something went wrong.
150 changes: 150 additions & 0 deletions
150
...c/main/java/org/ylzl/eden/curator/spring/boot/autoconfigure/CuratorAutoConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
89 changes: 89 additions & 0 deletions
89
...g-boot-starter/src/main/java/org/ylzl/eden/curator/spring/boot/env/CuratorProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
3 changes: 0 additions & 3 deletions
3
...ts/eden-spring-boot-starters/eden-curator-spring-boot-starter/src/main/resources/.gitkeep
This file was deleted.
Oops, something went wrong.
3 changes: 3 additions & 0 deletions
3
...ot-starters/eden-curator-spring-boot-starter/src/main/resources/META-INF/spring.factories
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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)"; | ||
|
||
|
@@ -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; | ||
|
@@ -78,8 +78,4 @@ public Object plugin(Object target) { | |
} | ||
return target; | ||
} | ||
|
||
public void setSlownessThreshold(Duration slownessThreshold) { | ||
this.slownessThreshold = slownessThreshold; | ||
} | ||
} |