private OperationStatus createOperationStatus(String id, String message, ErrorCode code, boolean isConditionNotMet, Message msg) { String traceMessage = msg != null && msg.getTrace() != null && msg.getTrace().getLevel() > 0 ? msg.getTrace().toString() : ""; return new OperationStatus(message, id, code, isConditionNotMet, traceMessage); }
SendContext(RPCNetwork net, Message msg, List<RoutingNode> recipients) { this.net = net; this.msg = msg; this.traceLevel = this.msg.getTrace().getLevel(); this.recipients.addAll(recipients); this.pending = this.recipients.size(); this.version = this.net.getVersion(); }
public Message awaitMessage() { Message msg = null; try { msg = server.awaitMessage(60, TimeUnit.SECONDS); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } if (msg != null) { msg.getTrace().trace(0, "Message received by RemoteServer."); } return msg; }
/** * Filter a message against the current sequencing state. If this method returns true, the message has been cleared * for sending and its sequencing information has been added to the state. If this method returns false, it has been * queued for later sending due to sequencing restrictions. This method also sets the sequence id as message * context. * * @param msg The message to filter. * @return True if the message was consumed. */ private boolean filter(Message msg) { long seqId = msg.getSequenceId(); msg.setContext(seqId); synchronized (this) { if (seqMap.containsKey(seqId)) { Queue<Message> queue = seqMap.get(seqId); if (queue == null) { queue = new LinkedList<Message>(); seqMap.put(seqId, queue); } if (msg.getTrace().shouldTrace(TraceLevel.COMPONENT)) { msg.getTrace().trace(TraceLevel.COMPONENT, "Sequencer queued message with sequence id '" + seqId + "'."); } queue.add(msg); return false; } seqMap.put(seqId, null); } return true; }
/** * Internal method for forwarding a sequenced message to the underlying sender. * * @param msg The message to forward. */ private void sequencedSend(Message msg) { if (msg.getTrace().shouldTrace(TraceLevel.COMPONENT)) { msg.getTrace().trace(TraceLevel.COMPONENT, "Sequencer sending message with sequence id '" + msg.getContext() + "'."); } msg.pushHandler(this); sender.handleMessage(msg); }
public Request newClientRequest(Message msg) { msg.setRoute(Route.parse(server.connectionSpec())); if (msg.getTrace().getLevel() == 0) { msg.getTrace().setLevel(9); } final Request parent = newServerRequest(); try (final ResourceReference ref = References.fromResource(parent)) { return new MbusRequest(parent, URI.create("mbus://remotehost/"), msg); } }
public void handleMessage(Message msg) { Trace trace = msg.getTrace(); if (trace.getLevel() == 0) { if (log.isLoggable(LogLevel.SPAM)) { trace.setLevel(9); logTrace = true; } else if (log.isLoggable(LogLevel.DEBUG)) { trace.setLevel(6); logTrace = true; } } this.msg = msg; RoutingNode root = new RoutingNode(mbus, net, resender, this, msg); root.send(); }
/** * A convenience method for assigning the internal trace level and route string to a message before sending it * through the internal mbus session object. * * @param msg the message to send. * @return the document api result object. */ public Result send(Message msg) { try { long reqId = requestId.incrementAndGet(); msg.setContext(reqId); msg.getTrace().setLevel(traceLevel); String toRoute = (msg.getType() == DocumentProtocol.MESSAGE_GETDOCUMENT ? routeForGet : route); if (toRoute != null) { return toResult(reqId, session.send(msg, toRoute, true)); } else { return toResult(reqId, session.send(msg)); } } catch (Exception e) { return new Result(Result.ResultType.FATAL_ERROR, new Error(e.getMessage(), e)); } }
@Override public void handleMessage(Message msg) { if (!running.get()) { dispatchErrorReply(msg, ErrorCode.SESSION_BUSY, "Session temporarily closed."); return; } if (msg.getTrace().shouldTrace(6)) { msg.getTrace().trace(6, "Message received by MbusServer."); } Request request = null; ContentChannel content = null; try { request = new MbusRequest(container, uri, msg); content = request.connect(new ServerResponseHandler(msg)); } catch (RuntimeException e) { dispatchErrorReply(msg, ErrorCode.APP_FATAL_ERROR, e.toString()); } finally { if (request != null) { request.release(); } } if (content != null) { content.close(IgnoredCompletionHandler.INSTANCE); } }
public boolean sendMessage(Message msg) { msg.setRoute(Route.parse(server.connectionSpec())); msg.getTrace().setLevel(9); return client.sendMessage(msg).isAccepted(); }
@Override public ContentChannel handleRequest(final Request request, final ResponseHandler handler) { if (!(request instanceof MbusRequest)) { throw new RequestDeniedException(request); } final Message msg = ((MbusRequest)request).getMessage(); msg.getTrace().trace(6, "Request received by MbusClient."); msg.pushHandler(null); // save user context final Long timeout = request.timeRemaining(TimeUnit.MILLISECONDS); if (timeout != null) { msg.setTimeReceivedNow(); msg.setTimeRemaining(Math.max(1, timeout)); // negative or zero timeout has semantics } msg.setContext(handler); msg.pushHandler(this); queue.add((MbusRequest)request); return null; }
/** * Constructs a new instance of this class. This is the root node constructor, and will be used by the different * sessions for sending messages. Note that the {@link #discard()} functionality of this class is implemented so * that it passes a null reply to the handler to notify the discard. * * @param mbus The message bus on which we are running. * @param net The network layer we are to transmit through. * @param resender The resender to schedule with. * @param handler The handler to receive the final reply. * @param msg The message being sent. */ public RoutingNode(MessageBus mbus, Network net, Resender resender, ReplyHandler handler, Message msg) { this.mbus = mbus; this.net = net; this.resender = resender; this.handler = handler; this.msg = msg; this.trace = new Trace(msg.getTrace().getLevel()); this.route = msg.getRoute(); this.parent = null; if (route != null) { routeMetrics = mbus.getMetrics().getRouteMetrics(route); } }
private Result sendInternal(Message message) { synchronized (lock) { if (closed) { return new Result(ErrorCode.SEND_QUEUE_CLOSED, "Source session is closed."); } if (throttlePolicy != null && ! throttlePolicy.canSend(message, pendingCount)) { return new Result(ErrorCode.SEND_QUEUE_FULL, "Too much pending data (" + pendingCount + " messages)."); } message.pushHandler(replyHandler); if (throttlePolicy != null) { throttlePolicy.processMessage(message); } ++pendingCount; } if (message.getTrace().shouldTrace(TraceLevel.COMPONENT)) { message.getTrace().trace(TraceLevel.COMPONENT, "Source session accepted a " + message.getApproxSize() + " byte message. " + pendingCount + " message(s) now pending."); } message.pushHandler(this); sequencer.handleMessage(message); return Result.ACCEPTED; }
private void setMessageParameters(DocumentOperationMessageV3 msg, FeederSettings settings) { msg.getMessage().setContext(new ReplyContext(msg.getOperationId(), feedReplies, DocumentOperationType.fromMessage(msg.getMessage()))); if (settings.traceLevel != null) { msg.getMessage().getTrace().setLevel(settings.traceLevel); } if (settings.priority != null) { try { DocumentProtocol.Priority priority = DocumentProtocol.Priority.valueOf(settings.priority); if (msg.getMessage() instanceof DocumentMessage) { ((DocumentMessage) msg.getMessage()).setPriority(priority); } } catch (IllegalArgumentException i) { log.severe(i.getMessage()); } } }
public DocumentMessage fromDocumentOperation(Processing processing, DocumentOperation documentOperation) { DocumentMessage msg = newMessage(documentOperation); msg.setLoadType(loadType); msg.setPriority(priority); msg.setRoute(requestMsg.getRoute()); msg.setTimeReceivedNow(); msg.setTimeRemaining(requestMsg.getTimeRemainingNow()); msg.getTrace().setLevel(requestMsg.getTrace().getLevel()); if (log.isLoggable(LogLevel.DEBUG)) { log.log(LogLevel.DEBUG, "Created '" + msg.getClass().getName() + "', route = '" + msg.getRoute() + "', priority = '" + msg.getPriority().name() + "', load type = '" + msg.getLoadType() + "', trace level = '" + msg.getTrace().getLevel() + "', time remaining = '" + msg.getTimeRemaining() + "'."); } return msg; }
@Override public ContentChannel handleResponse(Response response) { synchronized (this) { if (response instanceof MbusResponse) { Reply reply = ((MbusResponse)response).getReply(); requestTrace.addChild(reply.getTrace().getRoot()); replies.add(reply); } if (--numPending != 0) { return null; } } requestMsg.getTrace().getRoot().addChild(requestTrace); Reply reply = DocumentProtocol.merge(replies); Response mbusResponse = new MbusResponse(StatusCodes.fromMbusReply(reply), reply); ResponseDispatch.newInstance(mbusResponse).dispatch(responseHandler); return null; }
@Override public void run() { Message msg = decode(envelope.msg.getProtocol(), payload, Message.class); msg.getTrace().setLevel(envelope.msg.getTrace().getLevel()); msg.setRoute(envelope.msg.getRoute()).getRoute().removeHop(0); msg.setRetryEnabled(envelope.msg.getRetryEnabled()); msg.setRetry(envelope.msg.getRetry()); msg.setTimeRemaining(envelope.msg.getTimeRemainingNow()); msg.pushHandler(new ReplyHandler() { @Override public void handleReply(Reply reply) { new ReplyEnvelope(LocalNetwork.this, envelope, reply).send(); } }); owner.deliverMessage(msg, LocalServiceAddress.class.cast(envelope.recipient.getServiceAddress()) .getSessionName()); } });
msg.setTimeReceivedNow(); msg.setTimeRemaining(p.timeRemaining); msg.getTrace().setLevel(p.traceLevel); if (msg.getTrace().shouldTrace(TraceLevel.SEND_RECEIVE)) { msg.getTrace().trace(TraceLevel.SEND_RECEIVE, "Message (type " + msg.getType() + ") received at " + serverIdent + " for session '" + p.session + "'.");
msg.discard(); } else { Trace trace = msg.getTrace(); if (logTrace) { if (reply.hasErrors()) {