@Override public void destroy() { session.destroy(); }
/** * <p>This is a convenience method to call {@link * #send(Message,String,boolean)} with a <code>false</code> value for the * 'parseIfNotFound' parameter.</p> * * @param msg The message to send. * @param routeName The route to assign to the message. * @return The immediate result of the attempt to send this message. */ public Result send(Message msg, String routeName) { return send(msg, routeName, false); }
@Override public int getPendingCount() { return sourceSession.getPendingCount(); }
@Override public boolean trySend() { if (destroyed.get()) return false; sendBlockedMessages(); expireStalledBlockedMessages(); return true; }
/** * <p>This is a blocking proxy to the {@link #send(Message)} method. This * method blocks until the message is accepted by the send queue. Note that * the message timeout does not activate by calling this method. This method * will also return if this session is closed or the calling thread is * interrupted.</p> * * @param msg The message to send. * @return The result of initiating send. * @throws InterruptedException Thrown if the calling thread is interrupted. */ public Result sendBlocking(Message msg) throws InterruptedException { Result res = send(msg); if (isSendQFull(res)) { BlockedMessage blockedMessage = new BlockedMessage(msg); synchronized (lock) { blockedQ.add(blockedMessage); } res = blockedMessage.waitComplete(); } return res; }
boolean sendOrExpire() { if ( ! notifyIfExpired() ) { Result res = sendInternal(msg); if ( ! isSendQFull(res) ) { notifyComplete(res); } else { return false; } } return true; }
/** * <p>Creates a source session on top of this message bus.</p> * * @param params The parameters to control the session. * @return The created session. */ public SourceSession createSourceSession(SourceSessionParams params) { if (destroyed.get()) { throw new IllegalStateException("Object is destroyed."); } return new SourceSession(this, params); }
@Override protected void destroy() { log.log(LogLevel.DEBUG, "Destroying shared source session."); session.close(); mbusReference.close(); }
boolean notifyIfExpired() { if (msg.isExpired()) { Error error = new Error(ErrorCode.TIMEOUT, "Timed out in sendQ"); notifyComplete(new Result(error)); replyHandler.handleReply(createSendTimedoutReply(msg, error)); return true; } return false; }
@Override public void handleReply(Reply reply) { if (destroyed.get()) { reply.discard(); return; } boolean done; synchronized (lock) { --pendingCount; if (throttlePolicy != null) { throttlePolicy.processReply(reply); } done = (closed && pendingCount == 0); sendBlockedMessages(); } if (reply.getTrace().shouldTrace(TraceLevel.COMPONENT)) { reply.getTrace().trace(TraceLevel.COMPONENT, "Source session received reply. " + pendingCount + " message(s) now pending."); } ReplyHandler handler = reply.popHandler(); handler.handleReply(reply); if (done) { this.done.countDown(); } }
public Result sendMessage(Message msg) { return session.send(msg); }
@Override public void destroy() { sourceSession.destroy(); } }
/** Returns the next message in the stream, or null if none */ protected DocumentOperationMessageV3 getNextMessage( String operationId, InputStream requestInputStream, FeederSettings settings) throws Exception { VespaXMLFeedReader.Operation operation = streamReaderV3.getNextOperation(requestInputStream, settings); // This is a bit hard to set up while testing, so we accept that things are not perfect. if (sourceSession.getResource().session() != null) { metric.set( MetricNames.PENDING, Double.valueOf(sourceSession.getResource().session().getPendingCount()), null); } DocumentOperationMessageV3 message = DocumentOperationMessageV3.create(operation, operationId, metric); if (message == null) { // typical end of feed return null; } metric.add(MetricNames.NUM_OPERATIONS, 1, null /*metricContext*/); log(LogLevel.DEBUG, "Successfully deserialized document id: ", message.getOperationId()); return message; }
@Override public Result send(Message msg) { return sourceSession.send(msg); }
/** * Reject all new messages and wait until no messages are pending. Before * returning, this method calls {@link #destroy()}. */ public void close() { synchronized (lock) { closed = true; } if (pendingCount == 0) { done.countDown(); } try { done.await(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } destroy(); }
@Override public Result sendMessage(Message msg) { return session.send(msg); }
public void close() { session.destroy(); mbus.destroy(); if (slobrok != null) { slobrok.stop(); } }
/** * <p>This is a convenience function to assign a given route to the given * message, and then pass it to the other {@link #send(Message)} method of * this session.</p> * * @param msg The message to send. * @param route The route to assign to the message. * @return The immediate result of the attempt to send this message. */ public Result send(Message msg, Route route) { return send(msg.setRoute(route)); }
/** * 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.setRoute(Route.parse(routeName)); return send(msg);