/** * Every time a message gets broadcasted, make sure we update the cluster. * * @param o the message to broadcast. * @return The same message. */ @Override public BroadcastAction filter(String broadcasterId, Object originalMessage, Object o) { if (o instanceof String) { String message = (String) o; // Avoid re-broadcasting if (!receivedMessages.remove(message)) { try { String id = bc.getID(); if (id.startsWith("/*")) { id = "atmosphere"; } TextMessage textMessage = session.createTextMessage(message.toString()); textMessage.setStringProperty("BroadcasterId", id); publisher.send(textMessage); } catch (JMSException ex) { logger.warn("failed to publish message", ex); } } return new BroadcastAction(message); } else { return new BroadcastAction(o); } }
@Override public BroadcastAction filter(String broadcasterId, AtmosphereResource r, Object originalMessage, Object message) { ensureInitialized(); try { if (message == null || r.isCancelled()) { return new BroadcastAction(BroadcastAction.ACTION.ABORT, null); } JSONObject json = new JSONObject(message.toString()); if (this.throttleMillis > 0 && !"batch".equals(json.optString("type"))) { String uuid = r.uuid(); synchronized (getMutex(uuid)) { boolean queueFuture = !broadcastScheduledForUuid.containsKey(uuid); Long timeSinceLastRequest = getTimeSinceLastRequest(uuid); if (timeSinceLastRequest < this.throttleMillis) { addMessageToBatch(json, uuid); if (queueFuture) { delayBatchBroadcast(r, this.throttleMillis - timeSinceLastRequest); } return new BroadcastAction(BroadcastAction.ACTION.ABORT, message); } } } return new BroadcastAction(message); } catch (JSONException e) { LOGGER.error("Failed to filter message:\n" + originalMessage, e); return new BroadcastAction(BroadcastAction.ACTION.ABORT, message); } }
/** * Wrap message inside our {@link RPCEvent} * * @param originalMessage the String message * @param message the String message * @return an RPCEvent instance. */ @Override public BroadcastAction filter(String broadcasterId, Object originalMessage, Object message) { if (!AtmosphereMessage.class.isAssignableFrom(message.getClass())) { try { AtmosphereMessage<Object> m = (AtmosphereMessage<Object>) messageClazz.newInstance(); m.setMessage(message); return new BroadcastAction(BroadcastAction.ACTION.CONTINUE, m); } catch (Exception e) { logger.warn("Oups. Make sure your RPCEvent implements AtmosphereMessage<Your Class>. Or remove the AtmosphereMessageInterceptor {}", e); return new BroadcastAction(BroadcastAction.ACTION.CONTINUE, message); } } else { return new BroadcastAction(BroadcastAction.ACTION.CONTINUE, message); } }
@Override public BroadcastAction filter(String broadcasterId, AtmosphereResource r, Object originalMessage, Object message) { ensureInitialized(); try { if (message == null || r.isCancelled()) { return new BroadcastAction(BroadcastAction.ACTION.ABORT, null); } JSONObject json = new JSONObject(message.toString()); if (shouldSendMessage(json, r.getRequest().getSession())) { return new BroadcastAction(message); } else { return new BroadcastAction(BroadcastAction.ACTION.ABORT, message); } } catch (JSONException e) { LOGGER.error("Failed to filter message:\n" + originalMessage, e); return new BroadcastAction(BroadcastAction.ACTION.ABORT, message); } }
/** * {@inheritDoc} */ @Override public BroadcastFilter.BroadcastAction filter(String broadcasterId, Object originalMessage, Object o) { String contents = originalMessage.toString(); if (!localMessages.remove(contents)) { redisUtil.outgoingBroadcast(originalMessage.toString()); return new BroadcastFilter.BroadcastAction(BroadcastAction.ACTION.CONTINUE, o); } else { return new BroadcastFilter.BroadcastAction(BroadcastAction.ACTION.ABORT, o); } }
/** * Every time a message gets broadcasted, make sure we update the cluster. * * @param message the message to broadcast. * @return The same message. */ @Override public BroadcastAction filter(String broadcasterId, Object originalMessage, Object message) { if (bc != null) { this.jchannel.send(this.bc.getID(), message); } return new BroadcastAction(message); }
/** * {@inheritDoc} */ @Override public BroadcastFilter.BroadcastAction filter(String broadcasterId, Object originalMessage, Object o) { String contents = originalMessage.toString(); if (!localMessages.remove(contents)) { redisUtil.outgoingBroadcast(originalMessage.toString()); return new BroadcastFilter.BroadcastAction(BroadcastAction.ACTION.CONTINUE, o); } else { return new BroadcastFilter.BroadcastAction(BroadcastAction.ACTION.ABORT, o); } }
@Override public BroadcastAction filter(AtmosphereResource r, Object message, Object originalMessage) { AtmosphereRequest request = r.getRequest(); if ("true".equalsIgnoreCase(request.getHeader(X_ATMOSPHERE_TRACKMESSAGESIZE)) && message != null && String.class.isAssignableFrom(message.getClass())) { String msg = message.toString(); msg = msg.length() + "<|msg|>" + msg; return new BroadcastAction(BroadcastAction.ACTION.CONTINUE, msg); } return new BroadcastAction(BroadcastAction.ACTION.CONTINUE, message); }
public BroadcastAction filter(Object o) { if (o instanceof String) { String m = (String) o; String name = m; String message = ""; if (m.indexOf("__") > 0) { name = m.substring(0, m.indexOf("__")); message = m.substring(m.indexOf("__") + 2); } return new BroadcastAction(BEGIN_SCRIPT_TAG + "window.parent.app.update({ name: \"" + name + "\", message: \"" + message + "\" });\n" + END_SCRIPT_TAG); } else { return new BroadcastAction(o); } } }
/** * Every time a message gets broadcasted, make sure we update the cluster. * * @param message the message to broadcast. * @return The same message. */ @Override public BroadcastAction filter(String broadcasterId, Object originalMessage, Object message) { if (bc != null) { this.jchannel.send(this.bc.getID(), message); } return new BroadcastAction(message); }
@Override public BroadcastAction filter(String broadcasterId, Object originalMessage, Object message) { return new BroadcastAction(message); }
/** * {@inheritDoc} */ @Override public BroadcastAction filter(String broadcasterId, final Object originalMessage, final Object message) { logger.info("Filtering message '{}' with {}", new Object[] { message, getClass().getName() }); RMIPeerManager.getInstance().sendAll(bc.getID(), message); return new BroadcastAction(message); }
@Override public BroadcastAction filter(String broadcasterId, Object originalMessage, Object message) { return new BroadcastAction(message); }
/** * {@inheritDoc} */ @Override public BroadcastFilter.BroadcastAction filter(String broadcasterId, Object originalMessage, Object o) { String contents = originalMessage.toString(); if (!localMessages.remove(contents)) { redisUtil.outgoingBroadcast(originalMessage.toString()); return new BroadcastFilter.BroadcastAction(BroadcastAction.ACTION.CONTINUE, o); } else { return new BroadcastFilter.BroadcastAction(BroadcastAction.ACTION.ABORT, o); } }
@Override public BroadcastAction filter(Object originalMessage, Object message) { return new BroadcastAction(BroadcastAction.ACTION.CONTINUE, message); } }
@Override public BroadcastAction filter(AtmosphereResource r, Object originalMessage, Object message) { String m = message.toString(); if (r.transport().equals(AtmosphereResource.TRANSPORT.LONG_POLLING)) { m += END_MESSAGE; } return new BroadcastAction(BroadcastAction.ACTION.CONTINUE, m); }
@Override public BroadcastAction filter(Object originalMessage, Object message) { return new BroadcastAction(message); } }
private BroadcastFilter.BroadcastAction invoke(RemoteEndpoint r, Object originalMessage, Object message) { Object o; o = message(r, message); if (o != null) { return new BroadcastFilter.BroadcastAction(BroadcastFilter.BroadcastAction.ACTION.CONTINUE, o); } return new BroadcastFilter.BroadcastAction(BroadcastFilter.BroadcastAction.ACTION.CONTINUE, message); }