Java源码示例:com.hazelcast.core.IdGenerator
示例1
@Override
public String service() {
IdGenerator idgen = ClusterDataFactory.INSTANCE.createIdGenerator("CLIENT_ID_GENERATOR");
String clientId = null;
while (clientId == null) {
clientId = String.format("laniClientId%011d", idgen.newId());
if (Session.NEXUS.get(clientId) != null) {
clientId = null;
}
}
return String.format("{\"id\":\"%s\"}", clientId);
}
示例2
public IdGenerator createIdGenerator(String name) {
switch (Settings.INSTANCE.clusteringMode()) {
case HAZELCAST:
return Hazelcast.INSTANCE.getIdGenerator(name);
case IGNITE:
case SINGLE:
return new SingleIdGenerator(name);
default:
return null;
}
}
示例3
public static void main(String[] args) {
HazelcastInstance hazelcastInstance = Hazelcast.newHazelcastInstance();
Map<Long, String> map = hazelcastInstance.getMap("data");
IdGenerator idGenerator = hazelcastInstance.getIdGenerator("newid");
for (int i = 0; i < 10; i++) {
map.put(idGenerator.newId(), "message" + 1);
}
}
示例4
@Override
public IdGenerator getIdGenerator(String s) {
return null;
}
示例5
protected IdGenerator getIdGenerator(String name) {
return substance.getIdGenerator(name);
}