Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,11 @@ public interface BinaryRawReaderEx extends BinaryRawReader {
* @throws org.apache.ignite.binary.BinaryObjectException In case of error.
*/
@Nullable public Object readObjectDetached() throws BinaryObjectException;

/**
* @param deserialize {@code True} if object should be deserialized during reading.
* @return Object.
* @throws org.apache.ignite.binary.BinaryObjectException In case of error.
*/
@Nullable public Object readObjectDetached(boolean deserialize) throws BinaryObjectException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -1333,7 +1333,12 @@ float readFloat(int fieldId) throws BinaryObjectException {

/** {@inheritDoc} */
@Nullable @Override public Object readObjectDetached() throws BinaryObjectException {
return BinaryUtils.unmarshal(in, ctx, ldr, this, true);
return readObjectDetached(false);
}

/** {@inheritDoc} */
@Nullable @Override public Object readObjectDetached(boolean deserialize) throws BinaryObjectException {
return BinaryUtils.unmarshal(in, ctx, ldr, this, true, deserialize);
}

/** {@inheritDoc} */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1853,6 +1853,15 @@ public static Object doReadOptimized(BinaryInputStream in, BinaryContext ctx, @N
*/
@Nullable public static Object unmarshal(BinaryInputStream in, BinaryContext ctx, ClassLoader ldr,
BinaryReaderHandlesHolder handles, boolean detach) throws BinaryObjectException {
return unmarshal(in, ctx, ldr, handles, detach, false);
}

/**
* @return Unmarshalled value.
* @throws BinaryObjectException In case of error.
*/
@Nullable public static Object unmarshal(BinaryInputStream in, BinaryContext ctx, ClassLoader ldr,
BinaryReaderHandlesHolder handles, boolean detach, boolean deserialize) throws BinaryObjectException {
int start = in.position();

byte flag = in.readByte();
Expand All @@ -1871,7 +1880,7 @@ public static Object doReadOptimized(BinaryInputStream in, BinaryContext ctx, @N

in.position(handlePos);

obj = unmarshal(in, ctx, ldr, handles, detach);
obj = unmarshal(in, ctx, ldr, handles, detach, deserialize);

in.position(retPos);
}
Expand Down Expand Up @@ -1992,13 +2001,13 @@ public static Object doReadOptimized(BinaryInputStream in, BinaryContext ctx, @N
return doReadTimeArray(in);

case GridBinaryMarshaller.OBJ_ARR:
return doReadObjectArray(in, ctx, ldr, handles, detach, false);
return doReadObjectArray(in, ctx, ldr, handles, detach, deserialize);

case GridBinaryMarshaller.COL:
return doReadCollection(in, ctx, ldr, handles, detach, false, null);
return doReadCollection(in, ctx, ldr, handles, detach, deserialize, null);

case GridBinaryMarshaller.MAP:
return doReadMap(in, ctx, ldr, handles, detach, false, null);
return doReadMap(in, ctx, ldr, handles, detach, deserialize, null);

case GridBinaryMarshaller.BINARY_OBJ:
return doReadBinaryObject(in, ctx, detach);
Expand Down Expand Up @@ -2190,7 +2199,7 @@ public static Collection<?> doReadCollection(BinaryInputStream in, BinaryContext
*/
private static Object deserializeOrUnmarshal(BinaryInputStream in, BinaryContext ctx, ClassLoader ldr,
BinaryReaderHandlesHolder handles, boolean detach, boolean deserialize) {
return deserialize ? doReadObject(in, ctx, ldr, handles) : unmarshal(in, ctx, ldr, handles, detach);
return deserialize ? doReadObject(in, ctx, ldr, handles) : unmarshal(in, ctx, ldr, handles, detach, deserialize);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,8 @@ private ServiceDescriptor findDescriptor(String name) {
assert arg != null;
assert arg instanceof ServiceProxyHolder;

ServiceProxyHolder svc = (ServiceProxyHolder)arg;

String mthdName = reader.readString();

Object[] args;
Expand All @@ -279,13 +281,13 @@ private ServiceDescriptor findDescriptor(String name) {
args = new Object[reader.readInt()];

for (int i = 0; i < args.length; i++)
args[i] = reader.readObjectDetached();
args[i] = reader.readObjectDetached(!srvKeepBinary && !svc.isPlatformService());
}
else
args = null;

try {
Object result = ((ServiceProxyHolder)arg).invoke(mthdName, srvKeepBinary, args);
Object result = svc.invoke(mthdName, srvKeepBinary, args);

PlatformUtils.writeInvocationResult(writer, result, null);
}
Expand Down Expand Up @@ -610,7 +612,7 @@ private ServiceProxyHolder(Object proxy, Class clazz, PlatformContext ctx) {
*/
public Object invoke(String mthdName, boolean srvKeepBinary, Object[] args)
throws IgniteCheckedException, NoSuchMethodException {
if (proxy instanceof PlatformService)
if (isPlatformService())
return ((PlatformService)proxy).invokeMethod(mthdName, srvKeepBinary, args);
else {
assert proxy instanceof GridServiceProxy;
Expand Down Expand Up @@ -715,6 +717,11 @@ private static boolean areMethodArgsCompatible(Class[] argTypes, Object[] args)
private static Class wrap(Class c) {
return c.isPrimitive() ? PRIMITIVES_TO_WRAPPERS.get(c) : c;
}

/** @return {@code True} if service is platform service. */
public boolean isPlatformService() {
return proxy instanceof PlatformService;
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -989,6 +989,9 @@ private static Collection<Object> unwrapKnownCollection(Collection<Object> col)
* @return Result.
*/
public static Object[] unwrapBinariesInArray(Object[] arr) {
if (arr.getClass().getComponentType() != Object.class)
return arr;

Object[] res = new Object[arr.length];

for (int i = 0; i < arr.length; i++)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
import org.apache.ignite.internal.managers.systemview.GridSystemViewManager;
import org.apache.ignite.internal.managers.systemview.JmxSystemViewExporterSpi;
import org.apache.ignite.internal.processors.cache.CacheObjectContext;
import org.apache.ignite.internal.processors.platform.utils.PlatformUtils;
import org.apache.ignite.internal.util.GridUnsafe;
import org.apache.ignite.internal.util.IgniteUtils;
import org.apache.ignite.internal.util.lang.GridMapEntry;
Expand Down Expand Up @@ -2969,7 +2970,7 @@ public void testReadDetachedMap() throws Exception {
assertTrue(map.containsKey(key));
assertEquals(val, map.get(key));
});
});
}, false);
}

/**
Expand All @@ -2989,27 +2990,59 @@ public void testReadDetachedCollection() throws Exception {

assertTrue(col.contains(val));
});
});
}, false);
}

/**
* @throws Exception If failed.
*/
/** @throws Exception If failed. */
@Test
public void testReadDetachedArray() throws Exception {
public void testReadDetachedTypedArray() throws Exception {
Value[] arr = IntStream.range(0, 1000).mapToObj(Value::new).toArray(Value[]::new);

testReadDetachObjectProperly(arr, obj -> {
Object[] desArr = (Object[])obj;
assertArrayEquals(arr, (Value[])obj);

assertEquals(arr.length, desArr.length);
Object[] args = new Object[] {obj};

for (int i = 0; i < arr.length; i++) {
BinaryObject val = (BinaryObject)desArr[i];
assertTrue(args[0] instanceof Value[]);

assertEquals(arr[i], new Value(val.field("val")));
}
});
args = PlatformUtils.unwrapBinariesInArray(args);

assertTrue(args[0] instanceof Value[]);
assertArrayEquals(arr, (Value[])args[0]);
}, true);
}

/** @throws Exception If failed. */
@Test
public void testReadArrayOfCollections() throws Exception {
Collection[] arr = new Collection[] { Arrays.asList(new Value(1), new Value(2), new Value(3)) };
testReadDetachObjectProperly(arr, obj -> {
assertArrayEquals(arr, (Collection[])obj);

Object[] args = new Object[] {obj};

assertTrue(args[0] instanceof Collection[]);

args = PlatformUtils.unwrapBinariesInArray(args);

assertTrue(args[0] instanceof Collection[]);
assertArrayEquals(arr, (Collection[])args[0]);
}, true);
}


/** @throws Exception If failed. */
@Test
public void testReadArrayOfBinaryCollections() throws Exception {
Collection[] arr = new Collection[] { new ArrayList<>(Arrays.asList(new Value(1), new Value(2), new Value(3))) };

testReadDetachObjectProperly(arr, obj -> {
Object[] args = PlatformUtils.unwrapBinariesInArray(new Object[] {obj});

Collection deserVals = (Collection)((Object[])args[0])[0];

assertEqualsCollections(arr[0], deserVals);
}, false);
}

/**
Expand All @@ -3019,7 +3052,7 @@ public void testReadDetachedArray() throws Exception {
* @param action Action to perform on object.
* @throws Exception If failed.
*/
private void testReadDetachObjectProperly(Object obj, IgniteThrowableConsumer<Object> action) throws Exception {
private void testReadDetachObjectProperly(Object obj, IgniteThrowableConsumer<Object> action, boolean deserialize) throws Exception {
BinaryMarshaller marsh = binaryMarshaller();

BinaryHeapOutputStream os = new BinaryHeapOutputStream(1024);
Expand All @@ -3032,7 +3065,7 @@ private void testReadDetachObjectProperly(Object obj, IgniteThrowableConsumer<Ob

BinaryReaderExImpl reader = marsh.binaryMarshaller().reader(is);

Object bObj = reader.readObjectDetached();
Object bObj = reader.readObjectDetached(deserialize);

Arrays.fill(os.array(), (byte)0);

Expand Down Expand Up @@ -5507,27 +5540,6 @@ private static class DecimalMarshalAware extends DecimalReflective implements Bi
}
}

/**
* Wrapper object.
*/
private static class Wrapper {

/** Value. */
private final Object value;

/** Constructor. */
public Wrapper(Object value) {
this.value = value;
}

/**
* @return Value.
*/
public Object getValue() {
return value;
}
}

/**
*/
private static class SingleHandleA {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,25 @@ public Address testAddress(Address addr) {
return addr;
}

/** */
public int testOverload(Integer count, Employee[] emps) {
assertNotNull(emps);
assertEquals((int)count, emps.length);

assertEquals("Sarah Connor", emps[0].getFio());
assertEquals(1, emps[0].getSalary());

assertEquals("John Connor", emps[1].getFio());
assertEquals(2, emps[1].getSalary());

return 42;
}

/** */
public int testOverload(int first, int second) {
return first + second;
}

/** */
public Employee[] testEmployees(Employee[] emps) {
if (emps == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,12 @@ public interface IJavaService
/** */
Address testAddress(Address addr);

/** */
int testOverload(int count, Employee[] emps);

/** */
int testOverload(int first, int second);

/** */
Employee[] testEmployees(Employee[] emps);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,18 @@ public Address testAddress(Address addr)
return _svc.testAddress(addr);
}

/** <inheritDoc /> */
public int testOverload(int count, Employee[] emps)
{
return _svc.testOverload(count, emps);
}

/** <inheritDoc /> */
public int testOverload(int first, int second)
{
return _svc.testOverload(first, second);
}

/** <inheritDoc /> */
public Employee[] testEmployees(Employee[] emps)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,19 @@ private void doTestService(IJavaService svc)
Assert.AreEqual("127000", addr.Zip);
Assert.AreEqual("Moscow Akademika Koroleva 12", addr.Addr);

Employee[] emps = new[]
{
new Employee {Fio = "Sarah Connor", Salary = 1},
new Employee {Fio = "John Connor", Salary = 2}
};

Assert.AreEqual(42, svc.testOverload(2, emps));
Assert.AreEqual(3, svc.testOverload(1, 2));
Assert.AreEqual(5, svc.testOverload(3, 2));

Assert.IsNull(svc.testEmployees(null));

Employee[] emps = svc.testEmployees(new[]
{
new Employee { Fio = "Sarah Connor", Salary = 1 },
new Employee { Fio = "John Connor", Salary = 2 }
});
emps = svc.testEmployees(emps);

Assert.NotNull(emps);
Assert.AreEqual(1, emps.Length);
Expand Down