本文整理匯總了Java中org.onosproject.store.primitives.resources.impl.AtomixLeaderElector類的典型用法代碼示例。如果您正苦於以下問題:Java AtomixLeaderElector類的具體用法?Java AtomixLeaderElector怎麽用?Java AtomixLeaderElector使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
AtomixLeaderElector類屬於org.onosproject.store.primitives.resources.impl包,在下文中一共展示了AtomixLeaderElector類的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: newAsyncLeaderElector
import org.onosproject.store.primitives.resources.impl.AtomixLeaderElector; //導入依賴的package包/類
@Override
public AsyncLeaderElector newAsyncLeaderElector(String name, long leaderTimeout, TimeUnit timeUnit) {
AtomixLeaderElector leaderElector = new AtomixLeaderElector(client.newProxyBuilder()
.withName(name)
.withServiceType(DistributedPrimitive.Type.LEADER_ELECTOR.name())
.withReadConsistency(ReadConsistency.LINEARIZABLE)
.withCommunicationStrategy(CommunicationStrategy.LEADER)
.withMinTimeout(Duration.ofMillis(timeUnit.toMillis(leaderTimeout)))
.withMaxTimeout(Duration.ofSeconds(5))
.withMaxRetries(MAX_RETRIES)
.build()
.open()
.join());
leaderElector.setupCache().join();
return leaderElector;
}
示例2: newAsyncLeaderElector
import org.onosproject.store.primitives.resources.impl.AtomixLeaderElector; //導入依賴的package包/類
@Override
public AsyncLeaderElector newAsyncLeaderElector(String name) {
AtomixLeaderElector leaderElector = client.getResource(name, AtomixLeaderElector.class)
.thenCompose(AtomixLeaderElector::setupCache)
.join();
Consumer<State> statusListener = state -> {
leaderElector.statusChangeListeners()
.forEach(listener -> listener.accept(mapper.apply(state)));
};
resourceClient.client().onStateChange(statusListener);
return leaderElector;
}