本文整理汇总了Java中org.cometd.bayeux.server.ServerMessage类的典型用法代码示例。如果您正苦于以下问题:Java ServerMessage类的具体用法?Java ServerMessage怎么用?Java ServerMessage使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ServerMessage类属于org.cometd.bayeux.server包,在下文中一共展示了ServerMessage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sub
import org.cometd.bayeux.server.ServerMessage; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public synchronized void sub(ServerMessage.Mutable message) {
Map<String, ?> map = (Map<String, ?>)message.getData();
if (closed) {
log.warn("sub[session=" + remote.getId() + "] ignored closed session: " + map);
return;
}
if (log.debugEnabled())
log.debug("sub[session=" + remote.getId() + "]: " + map);
Boolean reset = (Boolean)map.get("reset");
if (reset != null && reset)
resetSub();
processSub(false, false, (Map<String, List<?>>)map.get("remove"));
processSub(true, false, (Map<String, List<?>>)map.get("add"));
processSub(false, true, (Map<String, List<?>>)map.get("removeTimeSeries"));
processSub(true, true, (Map<String, List<?>>)map.get("addTimeSeries"));
stats.regSubscription(
regularSubscriptionsMap.values().stream().mapToInt(sub -> sub.getSymbols().size()).sum(), false);
stats.regSubscription(
timeSeriesSubscriptionsMap.values().stream().mapToInt(sub -> sub.getSymbols().size()).sum(), true);
}
示例2: push
import org.cometd.bayeux.server.ServerMessage; //导入依赖的package包/类
public void push(ServerSession remote, ServerMessage cometdMessage) throws Exception {
Object data = null;
Message message = binding.createCamelMessage(remote, cometdMessage, data);
Exchange exchange = endpoint.createExchange();
exchange.setIn(message);
consumer.getProcessor().process(exchange);
if (ExchangeHelper.isOutCapable(exchange)) {
ServerChannel channel = getBayeux().getChannel(channelName);
ServerSession serverSession = getServerSession();
ServerMessage.Mutable outMessage = binding.createCometdMessage(channel, serverSession, exchange.getOut());
remote.deliver(serverSession, outMessage);
}
}
示例3: createCamelMessage
import org.cometd.bayeux.server.ServerMessage; //导入依赖的package包/类
public Message createCamelMessage(ServerSession remote, ServerMessage cometdMessage, Object data) {
if (cometdMessage != null) {
data = cometdMessage.getData();
}
Message message = new DefaultMessage();
message.setBody(data);
Map headers = getHeadersFromMessage(cometdMessage);
if (headers != null) {
message.setHeaders(headers);
}
message.setHeader(COMETD_CLIENT_ID_HEADER_NAME, remote.getId());
if (cometdMessage != null && cometdMessage.get(COMETD_SUBSCRIPTION_HEADER_NAME) != null) {
message.setHeader(COMETD_SUBSCRIPTION_HEADER_NAME, cometdMessage.get(COMETD_SUBSCRIPTION_HEADER_NAME));
}
if (enableSessionHeader) {
addSessionAttributesToMessageHeaders(remote, message);
}
return message;
}
示例4: process
import org.cometd.bayeux.server.ServerMessage; //导入依赖的package包/类
public void process(final Exchange exchange) {
String channelName = producer.getEndpoint().getPath();
BayeuxServerImpl bayeux = producer.getBayeux();
ServerChannel channel = bayeux.getChannel(channelName);
ServerSession serverSession = getServerSession();
try {
if (channel != null) {
logDelivery(exchange, channel);
ServerMessage.Mutable mutable = binding.createCometdMessage(channel, serverSession,
exchange.getIn());
channel.publish(serverSession, mutable);
}
} finally {
if (disconnectLocalSession && serverSession.isLocalSession()) {
LOG.trace("Disconnection local session {}", serverSession);
serverSession.disconnect();
}
}
}
示例5: testSessionHeadersAdded
import org.cometd.bayeux.server.ServerMessage; //导入依赖的package包/类
@Test
public void testSessionHeadersAdded() throws Exception {
// setup
when(endpoint.isSessionHeadersEnabled()).thenReturn(true);
testObj.start();
ServerMessage cometdMessage = mock(ServerMessage.class);
Exchange exchange = mock(Exchange.class);
when(endpoint.createExchange()).thenReturn(exchange);
ArgumentCaptor<Message> transferredMessage = ArgumentCaptor.forClass(Message.class);
// act
testObj.getConsumerService().push(remote, cometdMessage);
// verify
verify(exchange).setIn(transferredMessage.capture());
Message message = transferredMessage.getValue();
assertEquals(MEMEBER_USER_NAME, message.getHeader(USER_NAME));
}
示例6: canHandshake
import org.cometd.bayeux.server.ServerMessage; //导入依赖的package包/类
@Override
public boolean canHandshake(BayeuxServer server, ServerSession session, ServerMessage message) {
if (session.isLocalSession()) {
return true;
}
Map<String, Object> ext = message.getExt();
if (ext == null) {
return false;
}
@SuppressWarnings("unchecked")
Map<String, Object> authentication = (Map<String, Object>) ext.get("authentication");
if (authentication == null) {
return false;
}
Object authenticationData = verify(authentication);
if (authenticationData == null) {
return false;
}
session.addListener(this);
return true;
}
示例7: parse
import org.cometd.bayeux.server.ServerMessage; //导入依赖的package包/类
@Override
public ServerMessage.Mutable[] parse(InputStream stream) throws ParseException {
try {
return DXFeedJson.MAPPER.readValue(stream, VALUE_TYPE);
} catch (IOException e) {
throw (ParseException)new ParseException("", -1).initCause(e);
}
}
示例8: onDemand
import org.cometd.bayeux.server.ServerMessage; //导入依赖的package包/类
@Listener("/service/onDemand")
public void onDemand(ServerSession remote, ServerMessage.Mutable message) {
Map<String, Object> map = message.getDataAsMap();
String op = (String)map.get("op");
List<?> rawArgs = (List<?>)map.get("args");
Method method = ONDEMAND_OPS.get(op);
if (method == null)
throw new IllegalArgumentException("Unsupported ondemand operation: " + op);
try {
invokeMethod(remote, method, rawArgs);
} catch (Exception e) {
throw new RuntimeException("Failed to invoke onDemand." + op + " with " + rawArgs, e);
}
}
示例9: rcv
import org.cometd.bayeux.server.ServerMessage; //导入依赖的package包/类
@Override
public boolean rcv(ServerSession session, ServerMessage.Mutable message) {
if (message instanceof DataMessage) {
stats.readEvents += ((DataMessage)message).getEvents().size();
}
stats.lastActiveTime = System.currentTimeMillis();
stats.read++;
return true;
}
示例10: send
import org.cometd.bayeux.server.ServerMessage; //导入依赖的package包/类
@Override
public ServerMessage send(ServerSession session, ServerMessage message) {
if (message.getData() instanceof DataMessage) {
stats.writeEvents += ((DataMessage)message.getData()).getEvents().size();
}
if (sessionImpl != null) {
stats.regQueueSize(((ServerSessionImpl)remote).getQueue().size());
}
stats.lastActiveTime = System.currentTimeMillis();
stats.write++;
return message;
}
示例11: createCometdMessage
import org.cometd.bayeux.server.ServerMessage; //导入依赖的package包/类
public ServerMessage.Mutable createCometdMessage(ServerChannel channel, ServerSession serverSession, Message camelMessage) {
ServerMessage.Mutable mutable = bayeux.newMessage();
mutable.setChannel(channel.getId());
if (serverSession != null) {
mutable.setClientId(serverSession.getId());
}
addHeadersToMessage(mutable, camelMessage);
mutable.setData(camelMessage.getBody());
return mutable;
}
示例12: getHeadersFromMessage
import org.cometd.bayeux.server.ServerMessage; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private Map<String, Object> getHeadersFromMessage(ServerMessage message) {
Map<String, Object> ext = message.getExt();
if (ext != null && ext.containsKey(HEADERS_FIELD)) {
return (Map<String, Object>) ext.get(HEADERS_FIELD);
} else {
return null;
}
}
示例13: sendMeta
import org.cometd.bayeux.server.ServerMessage; //导入依赖的package包/类
public boolean sendMeta(ServerSession to, ServerMessage.Mutable message) {
if (Channel.META_HANDSHAKE.equals(message.getChannel())) {
if (!message.isSuccessful()) {
Map<String, Object> advice = message.getAdvice(true);
advice.put(Message.RECONNECT_FIELD, Message.RECONNECT_HANDSHAKE_VALUE);
Map<String, Object> ext = message.getExt(true);
Map<String, Object> authentication = new HashMap<String, Object>();
ext.put("authentication", authentication);
authentication.put("failed", true);
authentication.put("failureReason", "invalid_credentials");
}
}
return true;
}
示例14: send
import org.cometd.bayeux.server.ServerMessage; //导入依赖的package包/类
public boolean send(ServerSession from, ServerSession to, ServerMessage.Mutable message) {
Object data = message.getData();
if (forbidden.contains(data)) {
message.put("data", "***");
}
return true;
}
示例15: join
import org.cometd.bayeux.server.ServerMessage; //导入依赖的package包/类
@Listener("/service/join/*")
public void join(ServerSession remote, ServerMessage.Mutable message) {
JoinRequest joinRequest = new JoinRequest(remote, message);
LOGGER.info(String.format("Client %s on behalf of %s is requesting to join %s.",joinRequest.getRequesterId(), getCurrentParticipant(), joinRequest.getCollaborationId()));
try {
server.joinClient(joinRequest.getRequesterId(), getCurrentParticipant(), joinRequest.getCollaborationId());
remote.addListener(this);
} catch (ServerException e) {
LOGGER.error(String.format("Joining collaboration has failed: %s",e.getMessage()));
}
}