use of org.mule.runtime.api.streaming.bytes.CursorStream in project mule by mulesoft.
the class CustomJavaSerializationProtocol method doSerialize.
/**
* {@inheritDoc}
*/
@Override
protected byte[] doSerialize(Object object) throws Exception {
// TODO: MULE-11939
if (object instanceof CursorStreamProvider) {
try (CursorStream cursor = ((CursorStreamProvider) object).openCursor()) {
object = toByteArray(cursor);
}
}
validateForSerialization(object);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(512);
try (ObjectOutputStream out = new ArtifactClassLoaderObjectOutputStream(classLoaderRepository, outputStream)) {
out.writeObject(object);
} catch (IOException ex) {
throw new SerializationException("Cannot serialize object", ex);
}
return outputStream.toByteArray();
}
use of org.mule.runtime.api.streaming.bytes.CursorStream in project mule by mulesoft.
the class ReconnectionWithStreamingTestCase method standaloneCursorIsResetOnReconnection.
@Test
public void standaloneCursorIsResetOnReconnection() throws Exception {
CursorStream cursorStream = createMockCursor();
assertReconnection(cursorStream, cursorStream);
}
use of org.mule.runtime.api.streaming.bytes.CursorStream in project mule by mulesoft.
the class CursorStreamProviderTestCase method ioExceptionIfClosed.
@Test(expected = IOException.class)
public void ioExceptionIfClosed() throws Exception {
CursorStream cursor = streamProvider.openCursor();
cursor.close();
cursor.read();
}
use of org.mule.runtime.api.streaming.bytes.CursorStream in project mule by mulesoft.
the class StreamingUtils method updateTypedValueWithCursorProvider.
/**
* Updates the {@link Cursor} value a given {@link TypedValue} instance by replacing it with a {@link CursorProvider}.
*
* @param value the typed value to update
* @param event the current event
* @param streamingManager the streaming manager
* @return updated {@link TypedValue instance}
*/
public static TypedValue updateTypedValueWithCursorProvider(final TypedValue value, final CoreEvent event, final StreamingManager streamingManager) {
if (event == null) {
return value;
} else {
Object payload = value.getValue();
if (payload instanceof CursorStream) {
CursorProvider provider = ((CursorStream) value.getValue()).getProvider();
DataType dataType = DataType.builder(value.getDataType()).type(provider.getClass()).build();
return new TypedValue(provider, dataType, value.getByteLength());
} else {
return value;
}
}
}
use of org.mule.runtime.api.streaming.bytes.CursorStream in project mule by mulesoft.
the class ReconnectionWithStreamingTestCase method cursorComingFromProviderIsResetOnReconnection.
@Test
public void cursorComingFromProviderIsResetOnReconnection() throws Exception {
CursorStream cursorStream = createMockCursor();
CursorStreamProvider provider = mock(CursorStreamProvider.class);
when(provider.openCursor()).thenReturn(cursorStream);
assertReconnection(cursorStream, provider);
}
Aggregations