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(); }
/** * Sets the reply of this routing node. This method also updates the internal state of this node; it is tagged for * resending if the reply has only transient errors, and the reply's {@link Trace} is copied. This method <u>does * not</u> call the parent node's {@link #notifyMerge()}. * * @param reply The reply to set. */ public void setReply(Reply reply) { if (reply != null) { shouldRetry = resender != null && resender.shouldRetry(reply); trace.getRoot().addChild(reply.getTrace().getRoot()); reply.getTrace().clear(); } this.reply = reply; }
/** * This method invokes the {@link #resolve(int)} method of all the child nodes of this. If any of these exceed the * depth limit, this method returns false. * * @param childDepth The depth of the children. * @return False if depth limit was exceeded. */ private boolean resolveChildren(int childDepth) { int numActiveChildren = 0; boolean ret = true; for (RoutingNode child : children) { if (child.trace.shouldTrace(TraceLevel.SPLIT_MERGE)) { child.trace.trace(TraceLevel.SPLIT_MERGE, "Resolving '" + child.route + "'."); } child.isActive = (child.reply == null); if (child.isActive) { ++numActiveChildren; if (!child.resolve(childDepth)) { ret = false; break; } } else { if (child.trace.shouldTrace(TraceLevel.SPLIT_MERGE)) { child.trace.trace(TraceLevel.SPLIT_MERGE, "Already completed."); } } } pending.set(numActiveChildren); return ret; }
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(); } } }
if (trace.getLevel() > 0) { TraceNode tail = new TraceNode(); for (RoutingNode child : children) { TraceNode root = child.trace.getRoot(); tail.addChild(root); root.clear(); trace.getRoot().addChild(tail); if (trace.shouldTrace(TraceLevel.SPLIT_MERGE)) { trace.trace(TraceLevel.SPLIT_MERGE, "Routing policy '" + dir.getName() + "' merging replies.");
/** * 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 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 }
/** * 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)); } }
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 + "'.");
/** * Add the given note to the trace information if tracing is enabled for the given level. * * @param level The trace level of the note. * @param note The note to add. * @return True if the note was added to the trace information, false otherwise. */ public boolean trace(int level, String note) { return trace(level, note, true); }
reply = createReply(req.returnValues(), serviceName, ctx.trace); if (ctx.trace.shouldTrace(TraceLevel.SEND_RECEIVE)) { ctx.trace.trace(TraceLevel.SEND_RECEIVE, "Reply (type " + reply.getType() + ") received at " + clientIdent + "."); reply.getTrace().swap(ctx.trace); if (error != null) { reply.addError(error);
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(); }
@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; }
/** * Indicates if tracing is enabled at this level. * @param level the level * @return true if tracing is enabled at this level */ public boolean shouldTrace(int level) { return node.getTrace().shouldTrace(level); }
@Override public void doSearch() throws InterruptedException, ParseException, TimeoutException { VisitorSession session = visitorSessionFactory.createVisitorSession(params); try { if ( !session.waitUntilDone(query.getTimeout())) { log.log(LogLevel.DEBUG, "Visitor returned from waitUntilDone without being completed for " + query + " with selection " + params.getDocumentSelection()); session.abort(); throw new TimeoutException("Query timed out in " + VdsStreamingSearcher.class.getName()); } } finally { session.destroy(); log.log(LogLevel.DEBUG, () -> session.getTrace().toString()); } query.trace(session.getTrace().toString(), false, 9); if (params.getControlHandler().getResult().code == VisitorControlHandler.CompletionCode.SUCCESS) { if (log.isLoggable(LogLevel.DEBUG)) { log.log(LogLevel.DEBUG, "VdsVisitor completed successfully for " + query + " with selection " + params.getDocumentSelection()); } } else { throw new IllegalArgumentException("Query failed: " // TODO: Is it necessary to use a runtime exception? + params.getControlHandler().getResult().code + ": " + params.getControlHandler().getResult().message); } }
public MessageBusVisitorSession(VisitorParameters visitorParameters, AsyncTaskExecutor taskExecutor, SenderFactory senderFactory, ReceiverFactory receiverFactory, RoutingTable routingTable, Clock clock) throws ParseException { this.params = visitorParameters; // TODO(vekterli): make copy? legacy impl does not copy initializeRoute(routingTable); this.sender = senderFactory.createSender(createReplyHandler(), this.params); this.receiver = receiverFactory.createReceiver(createMessageHandler(), sessionName); this.taskExecutor = taskExecutor; this.progress = createVisitingProgress(params); this.statistics = new VisitorStatistics(); this.state = new StateDescription(State.NOT_STARTED); this.clock = clock; initializeHandlers(); trace = new Trace(visitorParameters.getTraceLevel()); dataDestination = (params.getLocalDataHandler() == null ? params.getRemoteDataHandler() : receiver.getConnectionSpec()); validateSessionParameters(); // If we're already done, no need to do anything at all! if (progress.getIterator().isDone()) { markSessionCompleted(); } }