org.bson.RawBsonDocument Java Examples
The following examples show how to use
org.bson.RawBsonDocument.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MongoJobRepository.java From edison-microservice with Apache License 2.0 | 6 votes |
@Override public void keepJobMessagesWithinMaximumSize(String jobId) { final Optional<JobInfo> jobInfoOptional = this.findOne(jobId); if (jobInfoOptional.isPresent()) { JobInfo jobInfo = jobInfoOptional.get(); RawBsonDocument rawBsonDocument = RawBsonDocument.parse(encode(jobInfo).toJson()); int bsonSize = rawBsonDocument.getByteBuffer().remaining(); int averageMessageSize = bsonSize / jobInfo.getMessages().size(); LOG.debug("Bson size of running job with jobId {} is {} bytes. Average message size is {} bytes. Total messages: {}", jobId, bsonSize, averageMessageSize, jobInfo.getMessages().size()); //Is document taking more than 3/4 of the allowed space? if (bsonSize > (MAX_DOCUMENT_SIZE - (MAX_DOCUMENT_SIZE / 4))) { LOG.info("Bson size of running job with jobId {} is {} bytes. The size of this job's document is growing towards MongoDBs limit for single documents, so I'll drop all messages but the last 1000.", jobId, bsonSize); JobMessage jobMessage = JobMessage.jobMessage(Level.INFO, "The messages array for this job is growing towards MongoDBs limit for single documents, so I'll drop all messages but the last 1000.", OffsetDateTime.now()); collectionWithWriteTimeout(mongoProperties.getDefaultWriteTimeout(), TimeUnit.MILLISECONDS).updateOne(eq(ID, jobId), combine(pushEach(JobStructure.MESSAGES.key(), Collections.singletonList(encodeJobMessage(jobMessage)), new PushOptions().slice(-1000)), set(JobStructure.LAST_UPDATED.key(), Date.from(jobMessage.getTimestamp().toInstant())))); } } }
Example #2
Source File: JacksonCodec.java From clouditor with Apache License 2.0 | 5 votes |
@Override public T decode(BsonReader reader, DecoderContext decoderContext) { RawBsonDocument doc = codec.decode(reader, decoderContext); try { return mapper .readerWithView(DatabaseOnly.class) .forType(this.clazz) .readValue(doc.getByteBuffer().array()); } catch (IOException e) { throw new MongoException(e.getMessage()); } }
Example #3
Source File: JacksonCodec.java From clouditor with Apache License 2.0 | 5 votes |
@Override public void encode(BsonWriter writer, T value, EncoderContext encoderContext) { try { byte[] data = mapper.writerWithView(DatabaseOnly.class).writeValueAsBytes(value); codec.encode(writer, new RawBsonDocument(data), encoderContext); } catch (JsonProcessingException e) { throw new MongoException(e.getMessage()); } }
Example #4
Source File: JacksonCodec.java From EDDI with Apache License 2.0 | 5 votes |
public JacksonCodec(ObjectMapper bsonObjectMapper, CodecRegistry codecRegistry, Class<T> type) { this.bsonObjectMapper = bsonObjectMapper; this.rawBsonDocumentCodec = codecRegistry.get(RawBsonDocument.class); this.type = type; }
Example #5
Source File: JacksonCodec.java From EDDI with Apache License 2.0 | 5 votes |
@Override public T decode(BsonReader reader, DecoderContext decoderContext) { try { RawBsonDocument document = rawBsonDocumentCodec.decode(reader, decoderContext); return bsonObjectMapper.readValue(document.getByteBuffer().array(), type); } catch (IOException e) { throw new UncheckedIOException(e); } }
Example #6
Source File: JacksonCodec.java From EDDI with Apache License 2.0 | 5 votes |
@Override public void encode(BsonWriter writer, Object value, EncoderContext encoderContext) { try { byte[] data = bsonObjectMapper.writeValueAsBytes(value); rawBsonDocumentCodec.encode(writer, new RawBsonDocument(data, 0, data.length), encoderContext); } catch (IOException e) { throw new UncheckedIOException(e); } }
Example #7
Source File: JacksonCodec.java From mongo-jackson-codec with Apache License 2.0 | 5 votes |
public JacksonCodec(ObjectMapper bsonObjectMapper, CodecRegistry codecRegistry, Class<T> type) { this.bsonObjectMapper = bsonObjectMapper; this.rawBsonDocumentCodec = codecRegistry.get(RawBsonDocument.class); this.type = type; }
Example #8
Source File: JacksonCodec.java From mongo-jackson-codec with Apache License 2.0 | 5 votes |
@Override public T decode(BsonReader reader, DecoderContext decoderContext) { try { RawBsonDocument document = rawBsonDocumentCodec.decode(reader, decoderContext); return bsonObjectMapper.readValue(document.getByteBuffer().array(), type); } catch (IOException e) { throw new UncheckedIOException(e); } }
Example #9
Source File: JacksonCodec.java From mongo-jackson-codec with Apache License 2.0 | 5 votes |
@Override public void encode(BsonWriter writer, Object value, EncoderContext encoderContext) { try { byte[] data = bsonObjectMapper.writeValueAsBytes(value); rawBsonDocumentCodec.encode(writer, new RawBsonDocument(data), encoderContext); } catch (IOException e) { throw new UncheckedIOException(e); } }
Example #10
Source File: JacksonCodec.java From clouditor with Apache License 2.0 | 4 votes |
JacksonCodec(ObjectMapper mapper, Class<T> clazz, CodecRegistry registry) { this.mapper = mapper; this.clazz = clazz; this.codec = registry.get(RawBsonDocument.class); }