@Override public void insert(InsertMessage insertMessage, MessageReplier messageReplier) { C connection = getConnection(messageReplier); try { Request req = new Request( insertMessage.getDatabase(), new ExternalClientInfo(insertMessage.getClientAddress(), insertMessage.getRequestId()), false, null //Set the requested timeout ); safeRequestProcessor.insert(connection, req, insertMessage); } catch (MongoException ex) { errorHandler.handleMongodbException(connection, messageReplier.getRequestId(), false, ex); } }
@Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("InsertMessage{") .append(super.toString()) .append(", database='") .append(database) .append("' , collection='") .append(collection) .append('\''); if (getDataContext().isValid()) { //TODO: This must be changed to preserve privacy on logs int docsLimit = 10; sb.append(", documents (limited to ").append(docsLimit).append(")=") .append( Iterables.toString( documents.getIterable(AllocationType.HEAP).limit(docsLimit) )); } else { sb.append(", documents=<not available>"); } return sb.append('}').toString(); } }
@Override @SuppressFBWarnings(value = {"RV_RETURN_VALUE_IGNORED_NO_SIDE_EFFECT"}, justification = "Findbugs thinks ByteBuf#readerIndex(...) has no" + "side effect") public InsertMessage decode(ByteBuf buffer, RequestBaseMessage requestBaseMessage) throws InvalidNamespaceException, InvalidBsonException { try { MyBsonContext context = new MyBsonContext(buffer); int flags = buffer.readInt(); String fullCollectionName = stringReader.readCString(buffer, true); ByteBuf docBuf = buffer.slice(buffer.readerIndex(), buffer.readableBytes()); docBuf.retain(); buffer.readerIndex(buffer.writerIndex()); ByteBufIterableDocumentProvider documents = new ByteBufIterableDocumentProvider(docBuf, docReader); //TODO: improve the way database and cache are pooled return new InsertMessage( requestBaseMessage, context, getDatabase(fullCollectionName).intern(), getCollection(fullCollectionName).intern(), EnumInt32FlagsUtil.isActive(Flag.CONTINUE_ON_ERROR, flags), documents ); } catch (NettyBsonReaderException ex) { throw new InvalidBsonException(ex); } }