use of com.ctrip.framework.dal.cluster.client.base.HostSpec in project dal by ctripcorp.
the class CompositeStrategyTransformerTest method visit.
@Test
public void visit() {
CompositeRoundRobinStrategy localizedAccessStrategy = (CompositeRoundRobinStrategy) strategyContext.accept(strategyTransformer);
Assert.assertTrue(!localizedAccessStrategy.isEmpty());
HostSpec hostSpec1 = localizedAccessStrategy.pickNode(dalHints);
// pick from local
Assert.assertEquals(getRequestZone(), hostSpec1.zone());
HostSpec hostSpec2 = localizedAccessStrategy.pickNode(dalHints);
// pick from local
Assert.assertEquals(getRequestZone(), hostSpec2.zone());
HostSpec hostSpec_1 = new HostSpec(SHAOY_IP1, SHAOY_PORT1, SHAOY, true);
HostSpec hostSpec_2 = new HostSpec(SHAOY_IP2, SHAOY_PORT2, SHAOY, true);
boolean same = (hostSpec1.equals(hostSpec_1) && hostSpec2.equals(hostSpec_2)) || (hostSpec1.equals(hostSpec_2) && hostSpec2.equals(hostSpec_1));
Assert.assertTrue(same);
localizedAccessStrategy.dispose();
}
use of com.ctrip.framework.dal.cluster.client.base.HostSpec in project dal by ctripcorp.
the class ReadCurrentZoneSlavesOnlyStrategy method init.
@Override
public void init(Set<HostSpec> hostSpecs, CaseInsensitiveProperties strategyProperties) {
super.init(hostSpecs, strategyProperties);
for (HostSpec hostSpec : hostSpecs) {
if (!zoneToHost.containsKey(hostSpec.getTrimLowerCaseZone())) {
List<HostSpec> hosts = new ArrayList<>();
hosts.add(hostSpec);
zoneToHost.put(hostSpec.getTrimLowerCaseZone(), hosts);
} else {
zoneToHost.get(hostSpec.getTrimLowerCaseZone()).add(hostSpec);
}
}
if (StringUtils.isTrimmedEmpty(currentZone))
throw new DalMetadataException(ZONE_MSG_LOST);
}
use of com.ctrip.framework.dal.cluster.client.base.HostSpec in project dal by ctripcorp.
the class ReadMasterZoneSlavesFirstStrategy method pickRead.
@Override
public HostSpec pickRead(DalHints dalHints) throws HostNotExpectedException {
HostSpec hostSpec = hintsRoute(dalHints);
if (hostSpec != null)
return hostSpec;
hostSpec = pickMasterZoneSlave();
return hostSpec == null ? pickSlaveFirst() : hostSpec;
}
use of com.ctrip.framework.dal.cluster.client.base.HostSpec in project dal by ctripcorp.
the class ReadSlavesFirstStrategy method init.
@Override
public void init(Set<HostSpec> hostSpecs, CaseInsensitiveProperties strategyProperties) {
this.hostSpecs = hostSpecs;
this.strategyProperties = strategyProperties;
List<HostSpec> masters = new ArrayList<>();
List<HostSpec> slaves = new ArrayList<>();
for (HostSpec hostSpec : hostSpecs) {
if (hostSpec.isMaster())
masters.add(hostSpec);
else
slaves.add(hostSpec);
}
hostMap.putIfAbsent(masterRole, masters);
hostMap.putIfAbsent(slaveRole, slaves);
}
use of com.ctrip.framework.dal.cluster.client.base.HostSpec in project dal by ctripcorp.
the class OBStrategy method pickNode.
@Override
public HostSpec pickNode(DalHints hints) throws HostNotExpectedException {
HostSpec hostSpec = delegate.pickNode(hints);
LOGGER.logEvent(CAT_LOG_TYPE, CURRENT_HOST + hostSpec.toString(), cluster);
return hostSpec;
}
Aggregations