private void enqueue(ReplyContext context, String message, ErrorCode status, boolean isConditionNotMet, Trace trace) { try { String traceMessage = (trace != null && trace.getLevel() > 0) ? trace.toString() : ""; context.feedReplies.put(new OperationStatus(message, context.docId, status, isConditionNotMet, traceMessage)); } catch (InterruptedException e) { log.log(LogLevel.WARNING, "Interrupted while enqueueing result from putting document with id: " + context.docId); Thread.currentThread().interrupt(); } } }
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(); }
SendContext(RoutingNode recipient, long timeRemaining) { this.recipient = recipient; trace = new Trace(recipient.getTrace().getLevel()); timeout = timeRemaining * 0.001; } }
/** * Constructs a new instance of this class. This is the child node constructor, and is the constructor used when * building the routing tree. * * @param parent The parent routing node. * @param route The route to assign to this. */ private RoutingNode(RoutingNode parent, Route route) { mbus = parent.mbus; net = parent.net; resender = parent.resender; handler = null; msg = parent.msg; trace = new Trace(parent.trace.getLevel()); this.route = new Route(route); this.parent = parent; recipients.addAll(parent.recipients); }
@Override public void handleReply(Reply reply) { if (reply.getTrace().getLevel() > 0) { log.log(LogLevel.INFO, reply.getTrace().toString()); } Response response = toResponse(reply); if (handler != null) { handler.handleResponse(response); } else { queue.add(response); } } }
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(); }
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); }
/** * This is a convenience method to assign an {@link EmptyReply} containing a single error to this. This also fiddles * with the trace object so that the error gets written to it. * * @param err The error to set. * @see #setReply(Reply) */ public void setError(Error err) { Reply reply = new EmptyReply(); reply.getTrace().setLevel(trace.getLevel()); reply.addError(err); setReply(reply); }
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; }
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); } }
/** * 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); } }
/** * Removes and returns the reply of the current child. This is the correct way of reusing a reply of a child node, * the {@link #getReplyRef()} should be used when just inspecting a child reply. * * @return The reply. */ public Reply removeReply() { Reply ret = entry.getReply(); ret.getTrace().setLevel(entry.getTrace().getLevel()); ret.getTrace().swap(entry.getTrace()); entry.setReply(null); return ret; }
@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()); } });
} else if (trace.getLevel() > 0) { trace.getRoot().addChild(reply.getTrace().getRoot()); trace.getRoot().normalize();
if (trace.getLevel() > 0) { TraceNode tail = new TraceNode(); for (RoutingNode child : children) {
errorServices[i].length() > 0 ? errorServices[i] : serviceName)); if (trace.getLevel() > 0) { trace.getRoot().addChild(TraceNode.decode(replyTrace));
@Override public final void send(RoutingNode recipient, Version version, byte[] payload, long timeRemaining) { SendContext ctx = new SendContext(recipient, timeRemaining); RPCServiceAddress address = (RPCServiceAddress)recipient.getServiceAddress(); Message msg = recipient.getMessage(); Route route = new Route(recipient.getRoute()); Hop hop = route.removeHop(0); Request req = encodeRequest(version, route, address,msg, timeRemaining, payload, ctx.trace.getLevel()); if (ctx.trace.shouldTrace(TraceLevel.SEND_RECEIVE)) { ctx.trace.trace(TraceLevel.SEND_RECEIVE, "Sending message (version " + version + ") from " + clientIdent + " to '" + address.getServiceName() + "' with " + ctx.timeout + " seconds timeout."); } if (hop.getIgnoreResult()) { address.getTarget().getJRTTarget().invokeVoid(req); if (ctx.trace.shouldTrace(TraceLevel.SEND_RECEIVE)) { ctx.trace.trace(TraceLevel.SEND_RECEIVE, "Not waiting for a reply from '" + address.getServiceName() + "'."); } Reply reply = new EmptyReply(); reply.getTrace().swap(ctx.trace); net.getOwner().deliverReply(reply, recipient); } else { req.setContext(ctx); address.getTarget().getJRTTarget().invokeAsync(req, ctx.timeout, this); } req.discardParameters(); // allow garbage collection of request parameters }
(service != null && service.length() > 0) ? service : serviceName)); if (trace.getLevel() > 0) { trace.getRoot().addChild(TraceNode.decode(root.field(TRACE_F).asString()));
root.setString(PROTOCOL_F, reply.getProtocol().toString()); root.setData(BLOB_F, payload); if (reply.getTrace().getLevel() > 0) { root.setString(TRACE_F, reply.getTrace().getRoot().encode());