Skip to content

Commit 110886e

Browse files
authored
IGNITE-27177 Remove BinaryWriter#typeId setter (#12534)
1 parent 576ab46 commit 110886e

File tree

8 files changed

+44
-40
lines changed

8 files changed

+44
-40
lines changed

modules/binary/api/src/main/java/org/apache/ignite/internal/binary/BinaryClassDescriptor.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -608,8 +608,6 @@ void write(Object obj, BinaryWriterExImpl writer) throws BinaryObjectException {
608608
assert writer != null;
609609
assert mode != BinaryWriteMode.OPTIMIZED : "OptimizedMarshaller should not be used here: " + cls.getName();
610610

611-
writer.typeId(typeId);
612-
613611
switch (mode) {
614612
case P_BYTE:
615613
case BYTE:

modules/binary/api/src/main/java/org/apache/ignite/internal/binary/BinaryUtils.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2922,17 +2922,19 @@ static BinaryReaderEx reader(BinaryContext ctx,
29222922
/**
29232923
* @param ctx Context.
29242924
* @param failIfUnregistered Flag to fail while writing object of unregistered type.
2925+
* @param typeId Type id.
29252926
* @return Writer instance.
29262927
*/
2927-
public static BinaryWriterEx writer(BinaryContext ctx, boolean failIfUnregistered) {
2928+
public static BinaryWriterEx writer(BinaryContext ctx, boolean failIfUnregistered, int typeId) {
29282929
BinaryThreadLocalContext locCtx = BinaryThreadLocalContext.get();
29292930

29302931
return new BinaryWriterExImpl(
29312932
ctx,
29322933
BinaryStreams.outputStream((int)CommonUtils.KB, locCtx.chunk()),
29332934
locCtx.schemaHolder(),
29342935
null,
2935-
failIfUnregistered
2936+
failIfUnregistered,
2937+
typeId
29362938
);
29372939
}
29382940

@@ -2942,7 +2944,14 @@ public static BinaryWriterEx writer(BinaryContext ctx, boolean failIfUnregistere
29422944
* @return Writer instance.
29432945
*/
29442946
public static BinaryWriterEx writer(BinaryContext ctx, BinaryOutputStream out) {
2945-
return new BinaryWriterExImpl(ctx, out, BinaryThreadLocalContext.get().schemaHolder(), null, false);
2947+
return new BinaryWriterExImpl(
2948+
ctx,
2949+
out,
2950+
BinaryThreadLocalContext.get().schemaHolder(),
2951+
null,
2952+
false,
2953+
GridBinaryMarshaller.UNREGISTERED_TYPE_ID
2954+
);
29462955
}
29472956

29482957
/**
@@ -2951,7 +2960,7 @@ public static BinaryWriterEx writer(BinaryContext ctx, BinaryOutputStream out) {
29512960
* @return Writer instance.
29522961
*/
29532962
public static BinaryWriterEx writer(BinaryContext ctx, BinaryOutputStream out, BinaryWriterSchemaHolder schema) {
2954-
return new BinaryWriterExImpl(ctx, out, schema, null, false);
2963+
return new BinaryWriterExImpl(ctx, out, schema, null, false, GridBinaryMarshaller.UNREGISTERED_TYPE_ID);
29552964
}
29562965

29572966
/** @return Instance of caching handler. */

modules/binary/api/src/main/java/org/apache/ignite/internal/binary/BinaryWriterEx.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,6 @@ public interface BinaryWriterEx extends BinaryWriter, BinaryRawWriter, ObjectOut
7272
*/
7373
void marshal(Object obj) throws BinaryObjectException;
7474

75-
/**
76-
* @param typeId Type ID.
77-
*/
78-
public void typeId(int typeId);
79-
8075
/**
8176
* @return Array.
8277
*/

modules/binary/api/src/main/java/org/apache/ignite/internal/binary/BinaryWriterExImpl.java

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -90,19 +90,22 @@ class BinaryWriterExImpl implements BinaryWriterEx {
9090
* @param out Output stream.
9191
* @param handles Handles.
9292
* @param failIfUnregistered Flag to fail while writing object of unregistered type.
93+
* @param typeId Type id.
9394
*/
9495
public BinaryWriterExImpl(
9596
BinaryContext ctx,
9697
BinaryOutputStream out,
9798
BinaryWriterSchemaHolder schema,
9899
BinaryWriterHandles handles,
99-
boolean failIfUnregistered
100+
boolean failIfUnregistered,
101+
int typeId
100102
) {
101103
this.ctx = ctx;
102104
this.out = out;
103105
this.schema = schema;
104106
this.handles = handles;
105107
this.failIfUnregistered = failIfUnregistered;
108+
this.typeId = typeId;
106109

107110
start = out.position();
108111
}
@@ -112,11 +115,6 @@ public BinaryWriterExImpl(
112115
return failIfUnregistered;
113116
}
114117

115-
/** {@inheritDoc} */
116-
@Override public void typeId(int typeId) {
117-
this.typeId = typeId;
118-
}
119-
120118
/** {@inheritDoc} */
121119
@Override public void close() {
122120
out.close();
@@ -132,7 +130,7 @@ public BinaryWriterExImpl(
132130
* @param enableReplace Object replacing enabled flag.
133131
* @throws org.apache.ignite.binary.BinaryObjectException In case of error.
134132
*/
135-
void marshal(Object obj, boolean enableReplace) throws BinaryObjectException {
133+
private void marshal(Object obj, boolean enableReplace) throws BinaryObjectException {
136134
String newName = ctx.igniteInstanceName();
137135
String oldName = CommonUtils.setCurrentIgniteName(newName);
138136

@@ -204,6 +202,8 @@ private void marshal0(Object obj, boolean enableReplace) throws BinaryObjectExce
204202
return;
205203
}
206204

205+
this.typeId = desc.typeId();
206+
207207
desc.write(obj, this);
208208
}
209209

@@ -219,15 +219,6 @@ int position() {
219219
return out.position();
220220
}
221221

222-
/**
223-
* Sets new position.
224-
*
225-
* @param pos Position.
226-
*/
227-
void position(int pos) {
228-
out.position(pos);
229-
}
230-
231222
/** {@inheritDoc} */
232223
@Override public void preWrite(@Nullable String clsName) {
233224
out.position(out.position() + GridBinaryMarshaller.DFLT_HDR_LEN);
@@ -847,7 +838,14 @@ void writeBooleanField(@Nullable Boolean val) {
847838
if (obj == null)
848839
out.writeByte(GridBinaryMarshaller.NULL);
849840
else {
850-
BinaryWriterExImpl writer = new BinaryWriterExImpl(ctx, out, schema, handles(), failIfUnregistered);
841+
BinaryWriterExImpl writer = new BinaryWriterExImpl(
842+
ctx,
843+
out,
844+
schema,
845+
handles(),
846+
failIfUnregistered,
847+
GridBinaryMarshaller.UNREGISTERED_TYPE_ID
848+
);
851849

852850
writer.marshal(obj);
853851
}
@@ -858,7 +856,14 @@ void writeBooleanField(@Nullable Boolean val) {
858856
if (obj == null)
859857
out.writeByte(GridBinaryMarshaller.NULL);
860858
else {
861-
BinaryWriterExImpl writer = new BinaryWriterExImpl(ctx, out, schema, null, failIfUnregistered);
859+
BinaryWriterExImpl writer = new BinaryWriterExImpl(
860+
ctx,
861+
out,
862+
schema,
863+
null,
864+
failIfUnregistered,
865+
GridBinaryMarshaller.UNREGISTERED_TYPE_ID
866+
);
862867

863868
writer.marshal(obj);
864869
}
@@ -1537,11 +1542,7 @@ boolean tryWriteAsHandle(Object obj) {
15371542

15381543
/** {@inheritDoc} */
15391544
@Override public BinaryWriterEx newWriter(int typeId) {
1540-
BinaryWriterExImpl res = new BinaryWriterExImpl(ctx, out, schema, handles(), failIfUnregistered);
1541-
1542-
res.typeId(typeId);
1543-
1544-
return res;
1545+
return new BinaryWriterExImpl(ctx, out, schema, handles(), failIfUnregistered, typeId);
15451546
}
15461547

15471548
/** {@inheritDoc} */

modules/binary/api/src/main/java/org/apache/ignite/internal/binary/GridBinaryMarshaller.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ public byte[] marshal(@Nullable Object obj, boolean failIfUnregistered) throws B
250250
if (obj == null)
251251
return new byte[] { NULL };
252252

253-
try (BinaryWriterEx writer = BinaryUtils.writer(ctx, failIfUnregistered)) {
253+
try (BinaryWriterEx writer = BinaryUtils.writer(ctx, failIfUnregistered, UNREGISTERED_TYPE_ID)) {
254254
writer.marshal(obj);
255255

256256
return writer.array();

modules/binary/impl/src/main/java/org/apache/ignite/internal/binary/builder/BinaryObjectBuilderImpl.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,9 @@ public BinaryObjectBuilderImpl(BinaryObjectEx obj) {
176176

177177
try (BinaryWriterEx writer = BinaryUtils.writer(
178178
ctx,
179-
curThread instanceof IgniteThread && ((IgniteThread)curThread).isForbiddenToRequestBinaryMetadata())
179+
curThread instanceof IgniteThread && ((IgniteThread)curThread).isForbiddenToRequestBinaryMetadata(),
180+
typeId)
180181
) {
181-
writer.typeId(typeId);
182-
183182
BinaryBuilderSerializer serializationCtx = new BinaryBuilderSerializer();
184183

185184
serializationCtx.registerObjectWriting(this, 0);

modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryMarshallerSelfTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3019,7 +3019,7 @@ public void testThreadLocalArrayReleased() throws Exception {
30193019

30203020
BinaryMarshaller marsh = binaryMarshaller();
30213021

3022-
try (BinaryWriterEx writer = BinaryUtils.writer(binaryContext(marsh), false)) {
3022+
try (BinaryWriterEx writer = BinaryUtils.writer(binaryContext(marsh), false, GridBinaryMarshaller.UNREGISTERED_TYPE_ID)) {
30233023
assertEquals(true, BinaryStreamsTestUtils.threadLocalIsAcquired());
30243024

30253025
writer.writeString("Thread local test");

modules/core/src/test/java/org/apache/ignite/internal/binary/RawBinaryObjectExtractorTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
3939
import org.junit.Test;
4040

41+
import static org.apache.ignite.internal.binary.GridBinaryMarshaller.UNREGISTERED_TYPE_ID;
42+
4143
/** */
4244
public class RawBinaryObjectExtractorTest extends GridCommonAbstractTest {
4345
/** */
@@ -49,7 +51,7 @@ public void test() throws Exception {
4951

5052
byte[] serializedTestObjectsBytes;
5153

52-
try (BinaryWriterEx writer = BinaryUtils.writer(ctx, false)) {
54+
try (BinaryWriterEx writer = BinaryUtils.writer(ctx, false, UNREGISTERED_TYPE_ID)) {
5355
testObjects.forEach(writer::writeObject);
5456

5557
serializedTestObjectsBytes = writer.array();

0 commit comments

Comments
 (0)