/** {@inheritDoc} */ @Override public byte[] encode(ClientListenerResponse msg) { assert msg != null; assert msg instanceof JdbcResponse; JdbcResponse res = (JdbcResponse)msg; BinaryWriterExImpl writer = createWriter(INIT_CAP); res.writeBinary(writer, ver); return writer.array(); }
/** * @param obj Object to marshal. * @param failIfUnregistered Throw exception if class isn't registered. * @return Byte array. * @throws org.apache.ignite.binary.BinaryObjectException In case of error. */ public byte[] marshal(@Nullable Object obj, boolean failIfUnregistered) throws BinaryObjectException { if (obj == null) return new byte[] { NULL }; try (BinaryWriterExImpl writer = new BinaryWriterExImpl(ctx)) { writer.failIfUnregistered(failIfUnregistered); writer.marshal(obj); return writer.array(); } }
/** {@inheritDoc} */ @Override public BinaryObject build() { try (BinaryWriterExImpl writer = new BinaryWriterExImpl(ctx)) { Thread curThread = Thread.currentThread(); if (curThread instanceof IgniteThread) writer.failIfUnregistered(((IgniteThread)curThread).isForbiddenToRequestBinaryMetadata()); writer.typeId(typeId); BinaryBuilderSerializer serializationCtx = new BinaryBuilderSerializer(); serializationCtx.registerObjectWriting(this, 0); serializeTo(writer, serializationCtx); byte[] arr = writer.array(); return new BinaryObjectImpl(ctx, arr, 0); } }
/** * @param req Request. * @throws IOException In case of IO error. */ private void sendRequestRaw(JdbcRequest req) throws IOException { int cap = guessCapacity(req); BinaryWriterExImpl writer = new BinaryWriterExImpl(null, new BinaryHeapOutputStream(cap), null, null); req.writeBinary(writer, srvProtocolVer); synchronized (connMux) { send(writer.array()); } }
writer.writeBoolean(connProps.isAutoCloseServerCursor()); send(writer.array());
send(writer.array());
/** * @throws IgniteCheckedException If failed. */ @Test public void testThreadLocalArrayReleased() throws Exception { // Checking the writer directly. assertEquals(false, INSTANCE.isAcquired()); BinaryMarshaller marsh = binaryMarshaller(); try (BinaryWriterExImpl writer = new BinaryWriterExImpl(binaryContext(marsh))) { assertEquals(true, INSTANCE.isAcquired()); writer.writeString("Thread local test"); writer.array(); assertEquals(true, INSTANCE.isAcquired()); } // Checking the binary marshaller. assertEquals(false, INSTANCE.isAcquired()); marsh = binaryMarshaller(); marsh.marshal(new SimpleObject()); assertEquals(false, INSTANCE.isAcquired()); marsh = binaryMarshaller(); // Checking the builder. BinaryObjectBuilder builder = new BinaryObjectBuilderImpl(binaryContext(marsh), "org.gridgain.foo.bar.TestClass"); builder.setField("a", "1"); BinaryObject binaryObj = builder.build(); assertEquals(false, INSTANCE.isAcquired()); }
ses.send(writer.array());
/** {@inheritDoc} */ @Override public byte[] encode(ClientListenerResponse msg) { assert msg != null; assert msg instanceof JdbcResponse; JdbcResponse res = (JdbcResponse)msg; BinaryWriterExImpl writer = createWriter(INIT_CAP); res.writeBinary(writer, ver); return writer.array(); }}
/** * @param obj Object to marshal. * @param failIfUnregistered Throw exception if class isn't registered. * @return Byte array. * @throws org.apache.ignite.binary.BinaryObjectException In case of error. */ public byte[] marshal(@Nullable Object obj, boolean failIfUnregistered) throws BinaryObjectException { if (obj == null) return new byte[] { NULL }; try (BinaryWriterExImpl writer = new BinaryWriterExImpl(ctx)) { writer.failIfUnregistered(failIfUnregistered); writer.marshal(obj); return writer.array(); } }
send(writer.array());
/** * @param req Request. * @return Server response. * @throws IOException In case of IO error. * @throws SQLException On concurrent access to JDBC connection. */ @SuppressWarnings("unchecked") JdbcResponse sendRequest(JdbcRequest req) throws SQLException, IOException { synchronized (mux) { if (ownThread != null) { throw new SQLException("Concurrent access to JDBC connection is not allowed" + " [ownThread=" + ownThread.getName() + ", curThread=" + Thread.currentThread().getName(), SqlStateCode.CONNECTION_FAILURE); } ownThread = Thread.currentThread(); } try { int cap = guessCapacity(req); BinaryWriterExImpl writer = new BinaryWriterExImpl(null, new BinaryHeapOutputStream(cap), null, null); req.writeBinary(writer, srvProtocolVer); send(writer.array()); return readResponse(); } finally { synchronized (mux) { ownThread = null; } } }
/** {@inheritDoc} */ @Override public BinaryObject build() { try (BinaryWriterExImpl writer = new BinaryWriterExImpl(ctx)) { Thread curThread = Thread.currentThread(); if (curThread instanceof IgniteThread) writer.failIfUnregistered(((IgniteThread)curThread).executingEntryProcessor() && ((IgniteThread)curThread).holdsTopLock()); writer.typeId(typeId); BinaryBuilderSerializer serializationCtx = new BinaryBuilderSerializer(); serializationCtx.registerObjectWriting(this, 0); serializeTo(writer, serializationCtx); byte[] arr = writer.array(); return new BinaryObjectImpl(ctx, arr, 0); } }
writer.writeBoolean(connProps.isAutoCloseServerCursor()); send(writer.array());
send(writer.array());
ses.send(writer.array());