本文整理汇总了Java中io.atomix.copycat.client.ServerSelectionStrategies类的典型用法代码示例。如果您正苦于以下问题:Java ServerSelectionStrategies类的具体用法?Java ServerSelectionStrategies怎么用?Java ServerSelectionStrategies使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ServerSelectionStrategies类属于io.atomix.copycat.client包,在下文中一共展示了ServerSelectionStrategies类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: newResourceClient
import io.atomix.copycat.client.ServerSelectionStrategies; //导入依赖的package包/类
private ResourceClient newResourceClient(Transport transport,
io.atomix.catalyst.serializer.Serializer serializer,
Collection<ResourceType> resourceTypes) {
ResourceRegistry registry = new ResourceRegistry();
resourceTypes.forEach(registry::register);
CopycatClient copycatClient = CopycatClient.builder()
.withServerSelectionStrategy(ServerSelectionStrategies.ANY)
.withConnectionStrategy(ConnectionStrategies.FIBONACCI_BACKOFF)
.withRecoveryStrategy(RecoveryStrategies.RECOVER)
.withTransport(transport)
.withSerializer(serializer)
.build();
copycatClient.serializer().resolve(new ResourceManagerTypeResolver());
for (ResourceType type : registry.types()) {
try {
type.factory()
.newInstance()
.createSerializableTypeResolver()
.resolve(copycatClient.serializer().registry());
} catch (InstantiationException | IllegalAccessException e) {
throw new ResourceManagerException(e);
}
}
return new ResourceClient(new OnosCopycatClient(copycatClient, 5, 100));
}
示例2: testIterate
import io.atomix.copycat.client.ServerSelectionStrategies; //导入依赖的package包/类
/**
* Tests iterating an address selector.
*/
public void testIterate() throws Throwable {
Collection<Address> servers = Arrays.asList(
new Address("localhost", 5000),
new Address("localhost", 5001),
new Address("localhost", 5002)
);
AddressSelector selector = new AddressSelector(ServerSelectionStrategies.ANY);
selector.reset(null, servers);
assertNull(selector.leader());
assertEquals(selector.servers(), servers);
assertEquals(selector.state(), AddressSelector.State.RESET);
assertTrue(selector.hasNext());
assertNotNull(selector.next());
assertEquals(selector.state(), AddressSelector.State.ITERATE);
assertTrue(selector.hasNext());
assertNotNull(selector.next());
assertTrue(selector.hasNext());
assertNotNull(selector.next());
assertFalse(selector.hasNext());
assertEquals(selector.state(), AddressSelector.State.COMPLETE);
}
示例3: testReset
import io.atomix.copycat.client.ServerSelectionStrategies; //导入依赖的package包/类
/**
* Tests resetting an address selector.
*/
public void testReset() throws Throwable {
Collection<Address> servers = Arrays.asList(
new Address("localhost", 5000),
new Address("localhost", 5001),
new Address("localhost", 5002)
);
AddressSelector selector = new AddressSelector(ServerSelectionStrategies.ANY);
selector.reset(null, servers);
selector.next();
selector.next();
selector.next();
assertFalse(selector.hasNext());
selector.reset();
assertTrue(selector.hasNext());
assertEquals(selector.state(), AddressSelector.State.RESET);
selector.next();
assertEquals(selector.state(), AddressSelector.State.ITERATE);
}
示例4: testUpdate
import io.atomix.copycat.client.ServerSelectionStrategies; //导入依赖的package包/类
/**
* Tests updating the members in a selector.
*/
public void testUpdate() throws Throwable {
Collection<Address> servers = Arrays.asList(
new Address("localhost", 5000),
new Address("localhost", 5001),
new Address("localhost", 5002)
);
AddressSelector selector = new AddressSelector(ServerSelectionStrategies.ANY);
selector.reset(null, servers);
assertNull(selector.leader());
assertEquals(selector.servers(), servers);
selector.next();
assertEquals(selector.state(), AddressSelector.State.ITERATE);
selector.reset(new Address("localhost", 5000), servers);
assertEquals(selector.leader(), new Address("localhost", 5000));
assertEquals(selector.servers(), servers);
assertEquals(selector.state(), AddressSelector.State.RESET);
}
示例5: main
import io.atomix.copycat.client.ServerSelectionStrategies; //导入依赖的package包/类
/**
* Starts the client.
*/
public static void main(String[] args) throws Exception {
if (args.length < 1)
throw new IllegalArgumentException("must supply a set of host:port tuples");
// Build a list of all member addresses to which to connect.
List<Address> members = new ArrayList<>();
for (String arg : args) {
String[] parts = arg.split(":");
members.add(new Address(parts[0], Integer.valueOf(parts[1])));
}
CopycatClient client = CopycatClient.builder()
.withTransport(new NettyTransport())
.withConnectionStrategy(ConnectionStrategies.FIBONACCI_BACKOFF)
.withRecoveryStrategy(RecoveryStrategies.RECOVER)
.withServerSelectionStrategy(ServerSelectionStrategies.LEADER)
.withSessionTimeout(Duration.ofSeconds(15))
.build();
client.serializer().register(SetCommand.class, 1);
client.serializer().register(GetQuery.class, 2);
client.serializer().register(DeleteCommand.class, 3);
client.connect(members).join();
recursiveSet(client);
while (client.state() != CopycatClient.State.CLOSED) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
break;
}
}
}