mirror of
https://github.com/dianping/camel.git
synced 2024-09-20 06:56:03 +08:00
init default strategy
This commit is contained in:
parent
1b0c54da92
commit
b0a412ddf5
|
@ -47,9 +47,9 @@ public class NginxLogDaoImpl extends AbstractMongoDao implements NginxLogDao {
|
|||
public void initCollection() {
|
||||
try {
|
||||
Index index = new Index().on("m_time", Direction.DESC);
|
||||
CollectionOptions options = new CollectionOptions(100 * 1024 * 1024 * 1024, 200 * 60 * 60 * 24 * 7, true);
|
||||
// CollectionOptions options = new CollectionOptions(100 * 1024 * 1024 * 1024, 200 * 60 * 60 * 24 * 7, true);
|
||||
|
||||
createIfNullCollection(SLB_NGINX_LOG_COLLECTION_NAME, options, index);
|
||||
createIfNullCollection(SLB_NGINX_LOG_COLLECTION_NAME, null, index);
|
||||
} catch (Exception ex) {
|
||||
logger.error("create colection failed: " + SLB_NGINX_LOG_COLLECTION_NAME, ex);
|
||||
}
|
||||
|
|
|
@ -42,9 +42,8 @@ public class RecordDaoImpl extends AbstractMongoDao implements RecordDao {
|
|||
public void initCollection() {
|
||||
try {
|
||||
Index index = new Index().on("date", Direction.DESC);
|
||||
CollectionOptions options = new CollectionOptions(1 * 1024 * 1024 * 1024, 100 * 365, true);
|
||||
|
||||
createIfNullCollection(SLB_RECORD_COLLECTION_NAME, options, index);
|
||||
createIfNullCollection(SLB_RECORD_COLLECTION_NAME, null, index);
|
||||
} catch (Exception ex) {
|
||||
logger.error("create colection failed: " + SLB_RECORD_COLLECTION_NAME, ex);
|
||||
}
|
||||
|
|
|
@ -15,11 +15,11 @@ import org.apache.commons.lang.StringUtils;
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Leo Liang
|
||||
*
|
||||
*/
|
||||
@Service
|
||||
public class StrategyServiceImpl extends ConcurrentControlServiceTemplate implements StrategyService {
|
||||
|
@ -35,9 +35,51 @@ public class StrategyServiceImpl extends ConcurrentControlServiceTemplate implem
|
|||
this.strategyDao = strategyDao;
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
private void initStrategy() throws BizException {
|
||||
List<Strategy> strategies = listStrategies();
|
||||
|
||||
if (strategies.size() == 0) {
|
||||
initDefaultStrategy();
|
||||
}
|
||||
}
|
||||
|
||||
private void initDefaultStrategy() throws BizException {
|
||||
Strategy ipHash = new Strategy();
|
||||
|
||||
ipHash.setName("ip-hash");
|
||||
ipHash.setType("ip-hash");
|
||||
ipHash.setDynamicAttribute("argumentType", "NON_ARGUMENT");
|
||||
|
||||
addStrategy("ip-hash", ipHash);
|
||||
|
||||
Strategy roundRobin = new Strategy();
|
||||
|
||||
roundRobin.setName("round-robinh");
|
||||
roundRobin.setType("round-robin");
|
||||
|
||||
addStrategy("round-robin", roundRobin);
|
||||
|
||||
Strategy consistentHashRid = new Strategy();
|
||||
|
||||
consistentHashRid.setName("consistent_hash_rid");
|
||||
consistentHashRid.setType("consistent_hash");
|
||||
consistentHashRid.setDynamicAttribute("target", "$arg_rid");
|
||||
|
||||
addStrategy("consistent_hash_rid", consistentHashRid);
|
||||
|
||||
Strategy consistentHashRequestId = new Strategy();
|
||||
|
||||
consistentHashRequestId.setName("consistent_hash_arg_requestId");
|
||||
consistentHashRequestId.setType("consistent_hash");
|
||||
consistentHashRequestId.setDynamicAttribute("target", "$arg_requestId");
|
||||
consistentHashRequestId.setDynamicAttribute("argumentType", "ONE_ARGUMENT");
|
||||
|
||||
addStrategy("consistent_hash_arg_requestId", consistentHashRequestId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param strategyDao
|
||||
* the strategyDao to set
|
||||
* @param strategyDao the strategyDao to set
|
||||
*/
|
||||
public void setStrategyDao(StrategyDao strategyDao) {
|
||||
this.strategyDao = strategyDao;
|
||||
|
|
Loading…
Reference in a new issue