本文整理匯總了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));
}