本文整理汇总了Java中org.onosproject.event.Change类的典型用法代码示例。如果您正苦于以下问题:Java Change类的具体用法?Java Change怎么用?Java Change使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Change类属于org.onosproject.event包,在下文中一共展示了Change类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onSessionEnd
import org.onosproject.event.Change; //导入依赖的package包/类
private void onSessionEnd(ServerSession session) {
Commit<? extends AtomixLeaderElectorCommands.Listen> listener = listeners.remove(session.id());
if (listener != null) {
listener.close();
}
Set<String> topics = elections.keySet();
List<Change<Leadership>> changes = Lists.newArrayList();
topics.forEach(topic -> {
Leadership oldLeadership = leadership(topic);
elections.compute(topic, (k, v) -> v.cleanup(session, termCounter(topic)::incrementAndGet));
Leadership newLeadership = leadership(topic);
if (!Objects.equal(oldLeadership, newLeadership)) {
changes.add(new Change<>(oldLeadership, newLeadership));
}
});
notifyLeadershipChanges(changes);
}
示例2: addChangeListener
import org.onosproject.event.Change; //导入依赖的package包/类
@Override
public synchronized CompletableFuture<Void> addChangeListener(Consumer<Change<Leadership>> consumer) {
if (leadershipChangeListeners.isEmpty()) {
return client.submit(new Listen()).thenRun(() -> leadershipChangeListeners.add(consumer));
} else {
leadershipChangeListeners.add(consumer);
return CompletableFuture.completedFuture(null);
}
}
示例3: removeChangeListener
import org.onosproject.event.Change; //导入依赖的package包/类
@Override
public synchronized CompletableFuture<Void> removeChangeListener(Consumer<Change<Leadership>> consumer) {
if (leadershipChangeListeners.remove(consumer) && leadershipChangeListeners.isEmpty()) {
return client.submit(new Unlisten()).thenApply(v -> null);
}
return CompletableFuture.completedFuture(null);
}
示例4: notifyLeadershipChanges
import org.onosproject.event.Change; //导入依赖的package包/类
private void notifyLeadershipChanges(List<Change<Leadership>> changes) {
if (changes.isEmpty()) {
return;
}
listeners.values()
.forEach(listener -> listener.session()
.publish(AtomixLeaderElector.CHANGE_SUBJECT, changes));
}
示例5: accept
import org.onosproject.event.Change; //导入依赖的package包/类
@Override
public void accept(Change<Leadership> change) {
synchronized (this) {
if (pendingFuture != null) {
pendingFuture.complete(change);
pendingFuture = null;
} else {
eventQueue.add(change);
}
}
}
示例6: nextEvent
import org.onosproject.event.Change; //导入依赖的package包/类
public CompletableFuture<Change<Leadership>> nextEvent() {
synchronized (this) {
if (eventQueue.isEmpty()) {
if (pendingFuture == null) {
pendingFuture = new CompletableFuture<>();
}
return pendingFuture;
} else {
return CompletableFuture.completedFuture(eventQueue.poll());
}
}
}
示例7: addChangeListener
import org.onosproject.event.Change; //导入依赖的package包/类
@Override
public synchronized CompletableFuture<Void> addChangeListener(Consumer<Change<Leadership>> consumer) {
if (leadershipChangeListeners.isEmpty()) {
return proxy.invoke(ADD_LISTENER).thenRun(() -> leadershipChangeListeners.add(consumer));
} else {
leadershipChangeListeners.add(consumer);
return CompletableFuture.completedFuture(null);
}
}
示例8: removeChangeListener
import org.onosproject.event.Change; //导入依赖的package包/类
@Override
public synchronized CompletableFuture<Void> removeChangeListener(Consumer<Change<Leadership>> consumer) {
if (leadershipChangeListeners.remove(consumer) && leadershipChangeListeners.isEmpty()) {
return proxy.invoke(REMOVE_LISTENER).thenApply(v -> null);
}
return CompletableFuture.completedFuture(null);
}
示例9: onSessionEnd
import org.onosproject.event.Change; //导入依赖的package包/类
private void onSessionEnd(RaftSession session) {
listeners.remove(session.sessionId().id());
Set<String> topics = elections.keySet();
List<Change<Leadership>> changes = Lists.newArrayList();
topics.forEach(topic -> {
Leadership oldLeadership = leadership(topic);
elections.compute(topic, (k, v) -> v.cleanup(topic, session, termCounter(topic)::incrementAndGet));
Leadership newLeadership = leadership(topic);
if (!Objects.equal(oldLeadership, newLeadership)) {
changes.add(new Change<>(oldLeadership, newLeadership));
}
});
notifyLeadershipChanges(changes);
}
示例10: addChangeListener
import org.onosproject.event.Change; //导入依赖的package包/类
@Override
public void addChangeListener(Consumer<Change<Leadership>> consumer) {
complete(asyncElector.addChangeListener(consumer));
}
示例11: removeChangeListener
import org.onosproject.event.Change; //导入依赖的package包/类
@Override
public void removeChangeListener(Consumer<Change<Leadership>> consumer) {
complete(asyncElector.removeChangeListener(consumer));
}
示例12: handleEvent
import org.onosproject.event.Change; //导入依赖的package包/类
private void handleEvent(List<Change<Leadership>> changes) {
changes.forEach(change -> leadershipChangeListeners.forEach(l -> l.accept(change)));
}
示例13: notifyLeadershipChange
import org.onosproject.event.Change; //导入依赖的package包/类
private void notifyLeadershipChange(Leadership previousLeadership, Leadership newLeadership) {
notifyLeadershipChanges(Lists.newArrayList(new Change<>(previousLeadership, newLeadership)));
}
示例14: getSerializer
import org.onosproject.event.Change; //导入依赖的package包/类
public static Serializer getSerializer() {
Serializer serializer = new Serializer();
TypeSerializerFactory factory =
new DefaultCatalystTypeSerializerFactory(
org.onosproject.store.service.Serializer.using(Arrays.asList((KryoNamespaces.API)),
MapEntryUpdateResult.class,
MapEntryUpdateResult.Status.class,
Transaction.State.class,
PrepareResult.class,
CommitResult.class,
RollbackResult.class));
// ONOS classes
serializer.register(Change.class, factory);
serializer.register(Leader.class, factory);
serializer.register(Leadership.class, factory);
serializer.register(NodeId.class, factory);
serializer.register(Match.class, factory);
serializer.register(MapEntryUpdateResult.class, factory);
serializer.register(MapEntryUpdateResult.Status.class, factory);
serializer.register(Transaction.State.class, factory);
serializer.register(PrepareResult.class, factory);
serializer.register(CommitResult.class, factory);
serializer.register(RollbackResult.class, factory);
serializer.register(TransactionId.class, factory);
serializer.register(MapUpdate.class, factory);
serializer.register(MapUpdate.Type.class, factory);
serializer.register(MapTransaction.class, factory);
serializer.register(Versioned.class, factory);
serializer.register(MapEvent.class, factory);
serializer.register(Maps.immutableEntry("a", "b").getClass(), factory);
serializer.resolve(new LongCommands.TypeResolver());
serializer.resolve(new AtomixConsistentMapCommands.TypeResolver());
serializer.resolve(new AtomixLeaderElectorCommands.TypeResolver());
serializer.resolve(new ResourceManagerTypeResolver());
serializer.registerClassLoader(AtomixConsistentMapFactory.class)
.registerClassLoader(AtomixLeaderElectorFactory.class);
return serializer;
}
示例15: addChangeListener
import org.onosproject.event.Change; //导入依赖的package包/类
@Override
public CompletableFuture<Void> addChangeListener(Consumer<Change<Leadership>> listener) {
return CompletableFuture.allOf(getLeaderElectors().stream()
.map(map -> map.addChangeListener(listener))
.toArray(CompletableFuture[]::new));
}