@Override public void unsubscribed(final ServerSession session, final ServerChannel channel) { LOG.debug("Cometd channel unsubscribe. session={}, channel={}", session, channel); final List<CometdPushNode<?>> nodes = _nodesByCometdChannelId.remove(channel.getId()); if (nodes != null) for (final CometdPushNode<?> node : nodes) _onDisconnect(node); } });
/** * @param from the session from which the message originates * @param data the data of the message * @deprecated use {@link #publish(Session, Object, Promise)} instead */ @Deprecated default void publish(Session from, Object data) { publish(from, data, Promise.noop()); }
@Override public boolean onMessage(ServerSession from, ServerChannel channel, ServerMessage.Mutable message) { if (from == localSession.getServerSession() && !receiveOwnPublishes) { return true; } Map<String, String> matches = channelId.bind(channel.getChannelId()); if (!paramNames.isEmpty() && !matches.keySet().containsAll(paramNames)) { return true; } Object[] args = new Object[2 + paramNames.size()]; args[0] = from; args[1] = message; for (int i = 0; i < paramNames.size(); ++i) { args[2 + i] = matches.get(paramNames.get(i)); } return !Boolean.FALSE.equals(callPublic(target, method, args)); } }
@Override public void run() { for (SystemTopics topic : SystemTopics.values()) { String topicData; switch (topic) { case Time: topicData = logDateFormat.format(new Date()); break; default: topicData = "unknown topic: " + topic.toString(); } ServerMessage.Mutable message = bayeuxServer.newMessage(); message.setChannel(channels.get(topic.ordinal()).getId()); message.setData(topicData); channels.get(topic.ordinal()).publish(session, message); } } }
private void isPublishAuthorized(ServerChannel channel, ServerSession session, ServerMessage message, Promise<Authorizer.Result> promise) { if (_policy != null) { _policy.canPublish(this, session, channel, message, Promise.from(can -> { if (can == null || can) { isOperationAuthorized(Authorizer.Operation.PUBLISH, session, message, channel.getChannelId(), promise); } else { _logger.info("{} denied publish on channel {} by {}", session, channel.getId(), _policy); promise.succeed(Authorizer.Result.deny("denied_by_security_policy")); } }, promise::fail)); } else { isOperationAuthorized(Authorizer.Operation.PUBLISH, session, message, channel.getChannelId(), promise); } }
private boolean deprocessListener(Object bean) { boolean result = false; List<ListenerCallback> callbacks = listeners.remove(bean); if (callbacks != null) { for (ListenerCallback callback : callbacks) { ServerChannel channel = bayeuxServer.getChannel(callback.subscription); if (channel != null) { channel.removeListener(callback); result = true; } } } return result; }
channel.addListener(invoker); invokers.put(methodName, invoker);
@Override public boolean canSubscribe(BayeuxServer server, ServerSession session, ServerChannel channel, ServerMessage message) { return session != null && session.isLocalSession() || !channel.isMeta(); } }
private void flushLazy(ServerMessage message) { synchronized (getLock()) { ServerChannel channel = _bayeux.getChannel(message.getChannel()); long lazyTimeout = -1; if (channel != null) { lazyTimeout = channel.getLazyTimeout(); } if (lazyTimeout <= 0) { lazyTimeout = _maxLazy; } if (lazyTimeout <= 0) { flush(); } else { _lazyTask.schedule(lazyTimeout); } } }
private boolean deprocessRemoteCall(Object bean) { boolean result = false; List<RemoteCallCallback> callbacks = remoteCalls.remove(bean); if (callbacks != null) { for (RemoteCallCallback callback : callbacks) { ServerChannel channel = bayeuxServer.getChannel(callback.subscription); if (channel != null) { channel.removeListener(callback); result = true; } } } return result; }
initializedChannel.getReference().addListener(remoteCallCallback);
@Override public boolean canPublish(BayeuxServer server, ServerSession session, ServerChannel channel, ServerMessage message) { return session != null && session.isHandshook() && !channel.isMeta(); }
/** * @param from the session from which the message originates * @param message the message to publish * @deprecated use {@link #publish(Session, ServerMessage.Mutable, Promise)} instead */ @Deprecated default void publish(Session from, ServerMessage.Mutable message) { publish(from, message, Promise.noop()); }
@ManagedAttribute(value = "The channel names of this server", readonly = true) public Set<String> getChannels() { Set<String> channels = new TreeSet<>(); for (ServerChannel channel : bayeux.getChannels()) { channels.add(channel.getId()); } return channels; }
/** * <p>Unmaps the method with the given name that has been mapped to the given channel.</p> * * @param channelName The channel name * @param methodName The name of the method to unmap * @see #addService(String, String) * @see #removeService(String) */ protected void removeService(String channelName, String methodName) { ServerChannel channel = _bayeux.getChannel(channelName); if (channel != null) { Invoker invoker = invokers.remove(methodName); channel.removeListener(invoker); } }
private void isSubscribeAuthorized(ServerChannel channel, ServerSession session, ServerMessage message, Promise<Authorizer.Result> promise) { if (_policy != null) { _policy.canSubscribe(this, session, channel, message, Promise.from(can -> { if (can == null || can) { isOperationAuthorized(Authorizer.Operation.SUBSCRIBE, session, message, channel.getChannelId(), promise); } else { _logger.info("{} denied Subscribe@{} by {}", session, channel, _policy); promise.succeed(Authorizer.Result.deny("denied_by_security_policy")); } }, promise::fail)); } else { isOperationAuthorized(Authorizer.Operation.SUBSCRIBE, session, message, channel.getChannelId(), promise); } }
initializedChannel.getReference().addListener(listenerCallback);
/** * Directly sends JavaScript code to the node via a cometd channel without an additional Wicket * AJAX request roundtrip. */ public <EventType> void publishJavascript(final CometdPushNode<EventType> node, final String javascript) { final ServerChannel channel = _getBayeuxServerChannel(node); if (channel == null) LOG.warn("No cometd channel found for {}", node); else channel.publish(null, "javascript:" + javascript, node.getCometdChannelEventId()); }
/** * <p>Unmaps all the methods that have been mapped to the given channel.</p> * * @param channelName The channel name * @see #addService(String, String) * @see #removeService(String, String) */ protected void removeService(String channelName) { ServerChannel channel = _bayeux.getChannel(channelName); if (channel != null) { for (Invoker invoker : invokers.values()) { if (invoker.channelName.equals(channelName)) { channel.removeListener(invoker); } } } }
Map<String, String> matches = channelId.bind(channel.getChannelId()); if (!paramNames.isEmpty() && !matches.keySet().containsAll(paramNames)) { return true;