@Override public boolean canSubscribe(BayeuxServer server, ServerSession session, ServerChannel channel, ServerMessage message) { return session != null && session.isLocalSession() || !channel.isMeta(); } }
@Service public class GetPlayer { @Session private LocalSession sender; @Listener("/service/player/get") public void perform(ServerSession session, ServerMessage message) { Map<String, Object> player = retrievePlayerInfo(message.get("playerId")); session.deliver(sender, message.getChannel(), player); } }
@Override public boolean canPublish(BayeuxServer server, ServerSession session, ServerChannel channel, ServerMessage message) { return session != null && session.isHandshook() && !channel.isMeta(); }
protected void error(ServerMessage.Mutable reply, String error) { if (reply != null) { reply.put(Message.ERROR_FIELD, error); reply.setSuccessful(false); } }
private LocalSession findOrCreateLocalSession(Object bean, String name) { LocalSession session = sessions.get(bean); if (session == null) { session = bayeuxServer.newLocalSession(name); LocalSession existing = sessions.putIfAbsent(bean, session); if (existing != null) { session = existing; } else { session.handshake(); } } return session; }
public void sendNotification(Notification notification, int id) { ServerSession remoteClient = retrieveSessionFromId(id); remoteClient.deliver(serverSession, "/person/notification", notification); }
/** * <p>Callback method invoked every time a message is incoming.</p> * * @param session the session that sent the message * @param message the incoming message * @param promise the promise to notify whether message processing should continue */ default void incoming(ServerSession session, ServerMessage.Mutable message, Promise<Boolean> promise) { promise.succeed(message.isMeta() ? rcvMeta(session, message) : rcv(session, message)); }
/** * <p>Callback method invoked every time a message is incoming.</p> * * @param from the session that sent the message * @param message the incoming message * @param promise the promise to notify whether message processing should continue */ default void incoming(ServerSession from, ServerMessage.Mutable message, Promise<Boolean> promise) { promise.succeed(message.isMeta() ? rcvMeta(from, message) : rcv(from, message)); }
/** * <p>Callback method invoked every time a message is outgoing.</p> * * @param from the session that sent the message or null * @param to the session the message is sent to, or null for a publish. * @param message the outgoing message * @param promise the promise to notify whether message processing should continue */ default void outgoing(ServerSession from, ServerSession to, ServerMessage.Mutable message, Promise<Boolean> promise) { promise.succeed(message.isMeta() ? sendMeta(to, message) : send(from, to, message)); }
@Override public void configureChannel(ConfigurableServerChannel channel) { channel.setPersistent(true); } });
public static void createChannel(BayeuxServer bayeux, String channelName){ bayeux.createChannelIfAbsent(channelName, new ServerChannel.Initializer() { public void configureChannel(ConfigurableServerChannel channel) { channel.setPersistent(true); System.out.println(channel.getChannelId()); } }); } }
/** * <p>Callback invoked to notify that the queue of messages and the message replies are * about to be sent to the remote client.</p> * <p>This is the last chance to process the queue, to remove duplicates or merge messages, * and to process the replies.</p> * * @param session the session whose messages are being sent * @param queue the queue of messages to send * @param replies the message replies to send */ public default void deQueue(ServerSession session, Queue<ServerMessage> queue, List<ServerMessage.Mutable> replies) { deQueue(session, queue); }
/** * @return The {@link ServerSession} of the {@link LocalSession} associated * with this CometD service */ public ServerSession getServerSession() { return _session.getServerSession(); }
/** * @param reason the reason for which the authorization is denied * @return a result that denies the authorization */ public static Result deny(String reason) { return new Denied(reason); }
@Override public String toString() { return super.toString() + " (reason='" + reason + "')"; } }
public void notifyResumed(ServerMessage message, boolean timeout) { for (ServerSessionListener listener : _listeners) { if (listener instanceof ServerSession.HeartBeatListener) { ((HeartBeatListener)listener).onResumed(this, message, timeout); } } }
protected void disconnect(ServerSession session) { if (session != null) { session.disconnect(); } } }
public void notifySuspended(ServerMessage message, long timeout) { for (ServerSessionListener listener : _listeners) { if (listener instanceof ServerSession.HeartBeatListener) { ((HeartBeatListener)listener).onSuspended(this, message, timeout); } } }
private void configureRoom(String roomName) { final String channelName = "/" + roomName + "/members"; ServerChannel channel = bayeuxServer.createChannelIfAbsent(channelName).getReference(); channel.addListener(new SubscriptionListener() { @Override public void subscribed(ServerSession session, ServerChannel channel, ServerMessage message) { // Send back the whole list to the subscriber. session.deliver(sender, channelName, memberList); } });
@Override public void configureChannel(ConfigurableServerChannel channel) { channel.setPersistent(true); } }