/** * Returns the task session. */ public ServerSession session() { return commit.session(); }
/** * Returns the message session. */ public ServerSession session() { return commit.session(); }
@Override public ServerSession session() { return parent.session(); }
/** * Handles a listen commit. */ public void listen(Commit<AtomicValueCommands.Listen> commit) { listeners.put(commit.session(), commit); commit.session().onClose(s -> { Commit<AtomicValueCommands.Listen> listener = listeners.remove(commit.session()); if (listener != null) { listener.clean(); } }); }
/** * Handles a listen commit. */ public Set<String> listen(Commit<GroupCommands.Listen> commit) { try { sessions.add(commit.session()); return new HashSet<>(members.keySet()); } finally { commit.close(); } }
/** * Handles an unsubscribe commit. */ public void unsubscribe(Commit<TaskQueueCommands.Unsubscribe> commit) { close(commit.session()); }
/** * Handles a listen commit. */ public Set<String> listen(Commit<GroupCommands.Listen> commit) { try { sessions.add(commit.session()); return new HashSet<>(members.keySet()); } finally { commit.close(); } }
/** * Handles a subscribe commit. */ public void subscribe(Commit<TaskQueueCommands.Subscribe> commit) { workers.put(commit.session().id(), commit); Commit<TaskQueueCommands.Submit> task = taskQueue.poll(); if (task != null) { processing.put(commit.session().id(), task); commit.session().publish("process", task.operation().task()); } else { workerQueue.add(commit.session()); } }
/** * Registers an event listener. */ private void register(Commit<ResourceCommand.Register> commit) { Set<ServerSession> sessions = eventListeners.computeIfAbsent(commit.command().event(), k -> new HashSet<>()); sessions.add(commit.session()); }
/** * Unregisters an event listener. */ private void unregister(Commit<ResourceCommand.Unregister> commit) { Set<ServerSession> sessions = eventListeners.computeIfAbsent(commit.command().event(), k -> new HashSet<>()); sessions.remove(commit.session()); if (sessions.isEmpty()) { eventListeners.remove(commit.command().event()); } }
/** * Registers a key change listener. */ public void listen(Commit<MapCommands.KeyListen> commit) { Map<Integer, Map<Long, Commit<MapCommands.KeyListen>>> listeners = this.listeners.computeIfAbsent(commit.command().key(), k -> new HashMap<>()); Map<Long, Commit<MapCommands.KeyListen>> sessions = listeners.computeIfAbsent(commit.command().event(), e -> new HashMap<>()); if (!sessions.containsKey(commit.session().id())) { sessions.put(commit.session().id(), commit); } else { commit.release(); } }
@Override public void expire(ServerSession session) { if (expire != null) expire.session().publish("expired"); }
private void eventCommand(Commit<EventCommand> commit) { commit.session().publish("hello", "world!"); }
MemberState(Commit<GroupCommands.Join> commit) { this.commit = commit; this.index = commit.index(); this.memberId = commit.operation().member(); this.persistent = commit.operation().persist(); this.session = commit.session(); this.metadata = commit.operation().metadata(); }
private Member(Commit<GroupCommands.Join> commit) { this.commit = commit; this.index = commit.index(); this.memberId = commit.operation().member(); this.address = commit.operation().address(); this.persistent = commit.operation().persist(); this.session = commit.session(); }
/** * Handles a send commit. */ public void send(Commit<GroupCommands.Send> commit) { try { Commit<GroupCommands.Join> join = members.get(commit.operation().member()); if (join == null) { throw new IllegalArgumentException("unknown member: " + commit.operation().member()); } join.session().publish("message", new GroupCommands.Message(commit.operation().member(), commit.operation().topic(), commit.operation().message())); } finally { commit.close(); } }
public long event(Commit<TestEvent> commit) { try { if (commit.operation().own()) { commit.session().publish("test", commit.index()); } else { for (ServerSession session : sessions) { session.publish("test", commit.index()); } } return commit.index(); } finally { commit.close(); } }