Top Description Inners Fields Constructors Methods
com.mysql.cj.protocol.x

public Class SyncMessageReader

extends Object
implements MessageReader<XMessageHeader, XMessage>
Class Inheritance
All Implemented Interfaces
com.mysql.cj.protocol.MessageReader
Imports
java.io.IOException, java.util.ArrayList, .LinkedList, .List, .Optional, java.util.concurrent.BlockingQueue, .LinkedBlockingQueue, .TimeUnit, java.util.concurrent.locks.Lock, .ReentrantLock, com.google.protobuf.InvalidProtocolBufferException, .Message, .Parser, com.mysql.cj.exceptions.CJCommunicationsException, .MysqlErrorNumbers, .WrongArgumentException, com.mysql.cj.protocol.FullReadInputStream, .MessageListener, .MessageReader, .Protocol.ProtocolEventHandler, .Protocol.ProtocolEventListener.EventType, com.mysql.cj.protocol.x.Notice.XWarning, com.mysql.cj.x.protobuf.Mysqlx.Error, .Mysqlx.ServerMessages, .MysqlxNotice.Frame

Synchronous-only implementation of MessageReader. This implementation wraps a java.io.InputStream.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class

Field Summary

Modifier and TypeField and Description
pack-priv Thread
pack-priv final Lock
dispatchingThreadLock

Lock to protect the pending message.

pack-priv LinkedList<XMessageHeader>
private FullReadInputStream
inputStream

Stream as a source of messages.

pack-priv BlockingQueue<MessageListener<XMessage>>
messageListenerQueue

Queue of MessageListeners waiting to process messages.

pack-priv LinkedList<Message>
private Protocol.ProtocolEventHandler
pack-priv final Lock
syncOperationLock

Lock to protect async reads from sync ones.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public int
public void
pushMessageListener(final MessageListener<XMessage> listener)

Overrides default com.mysql.cj.protocol.MessageReader.pushMessageListener.

Queue a MessageListener to receive messages delivered asynchronously.

public XMessageHeader
readHeader()

Implements com.mysql.cj.protocol.MessageReader.readHeader.

Read the next message header from server, possibly blocking indefinitely until the message is received.

private XMessageHeader
public XMessage
readMessage(Optional<XMessage>
Message object to reuse. May be ignored by implementation.
reuse
,
XMessageHeader
MessageHeader instance
hdr
)

Implements com.mysql.cj.protocol.MessageReader.readMessage.

Read message from server into to the given Message instance or into the new one if not present.

public XMessage
readMessage(Optional<XMessage>
Message object to reuse. May be ignored by implementation.
reuse
,
int
Expected type of message.
expectedType
)

Overrides default com.mysql.cj.protocol.MessageReader.readMessage.

Implements com.mysql.cj.protocol.MessageReader.readMessage.

Read message from server into to the given Message instance or into the new one if not present.

private <T extends Message> T
readMessageLocal(Class<T> messageClass, boolean fromQueue)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

dispatchingThreadback to summary
pack-priv Thread dispatchingThread
dispatchingThreadLockback to summary
pack-priv final Lock dispatchingThreadLock

Lock to protect the pending message.

headersQueueback to summary
pack-priv LinkedList<XMessageHeader> headersQueue
inputStreamback to summary
private FullReadInputStream inputStream

Stream as a source of messages.

messageListenerQueueback to summary
pack-priv BlockingQueue<MessageListener<XMessage>> messageListenerQueue

Queue of MessageListeners waiting to process messages.

messagesQueueback to summary
pack-priv LinkedList<Message> messagesQueue
protocolEventHandlerback to summary
private Protocol.ProtocolEventHandler protocolEventHandler
syncOperationLockback to summary
pack-priv final Lock syncOperationLock

Lock to protect async reads from sync ones.

Constructor Detail

SyncMessageReaderback to summary
public SyncMessageReader(FullReadInputStream inputStream, Protocol.ProtocolEventHandler protocolEventHandler)

Method Detail

getNextNonNoticeMessageTypeback to summary
public int getNextNonNoticeMessageType() throws IOException
pushMessageListenerback to summary
public void pushMessageListener(final MessageListener<XMessage> listener)

Overrides default com.mysql.cj.protocol.MessageReader.pushMessageListener.

Doc from com.mysql.cj.protocol.MessageReader.pushMessageListener.

Queue a MessageListener to receive messages delivered asynchronously.

Parameters
listener:MessageListener<XMessage>

MessageListener

Annotations
@Override
readHeaderback to summary
public XMessageHeader readHeader() throws IOException

Implements com.mysql.cj.protocol.MessageReader.readHeader.

Doc from com.mysql.cj.protocol.MessageReader.readHeader.

Read the next message header from server, possibly blocking indefinitely until the message is received.

Returns:XMessageHeader

MessageHeader of the next message

Annotations
@Override
Exceptions
IOException:
if an error occurs
readHeaderLocalback to summary
private XMessageHeader readHeaderLocal() throws IOException
readMessageback to summary
public XMessage readMessage(Optional<XMessage> reuse, XMessageHeader hdr) throws IOException

Implements com.mysql.cj.protocol.MessageReader.readMessage.

Doc from com.mysql.cj.protocol.MessageReader.readMessage.

Read message from server into to the given Message instance or into the new one if not present. For asynchronous channel it synchronously reads the next message in the stream, blocking until the message is read fully. Could throw CJCommunicationsException wrapping an IOException during read or parse

Parameters
reuse:Optional<XMessage>

Message object to reuse. May be ignored by implementation.

hdr:XMessageHeader

MessageHeader instance

Returns:XMessage

Message instance

Annotations
@Override
Exceptions
IOException:
if an error occurs
readMessageback to summary
public XMessage readMessage(Optional<XMessage> reuse, int expectedType) throws IOException

Overrides default com.mysql.cj.protocol.MessageReader.readMessage.

Implements com.mysql.cj.protocol.MessageReader.readMessage.

Doc from com.mysql.cj.protocol.MessageReader.readMessage.

Read message from server into to the given Message instance or into the new one if not present. For asynchronous channel it synchronously reads the next message in the stream, blocking until the message is read fully. Could throw WrongArgumentException if the expected message type is not the next message (exception will be thrown in *caller* context).

Parameters
reuse:Optional<XMessage>

Message object to reuse. May be ignored by implementation.

expectedType:int

Expected type of message.

Returns:XMessage

Message instance

Annotations
@Override
Exceptions
IOException:
if an error occurs
readMessageLocalback to summary
private <T extends Message> T readMessageLocal(Class<T> messageClass, boolean fromQueue)
Annotations
@SuppressWarnings:unchecked
com.mysql.cj.protocol.x back to summary

private Class SyncMessageReader.ListenersDispatcher

extends Object
implements Runnable
Class Inheritance
  • java.lang.Object
  • com.mysql.cj.protocol.x.SyncMessageReader.ListenersDispatcher
All Implemented Interfaces
java.lang.Runnable

Field Summary

Modifier and TypeField and Description
private static final long
POLL_TIMEOUT

The timeout value for queue.poll(timeout, unit) defining the time after which we close and unregister the dispatching thread.

pack-priv boolean

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
run()

Implements java.lang.Runnable.run.

Runs this operation.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

POLL_TIMEOUTback to summary
private static final long POLL_TIMEOUT

The timeout value for queue.poll(timeout, unit) defining the time after which we close and unregister the dispatching thread. On the other hand, a bigger timeout value allows us to keep dispatcher thread running while multiple concurrent asynchronous read operations are pending, thus avoiding the delays for new dispatching threads creation.

startedback to summary
pack-priv boolean started

Constructor Detail

ListenersDispatcherback to summary
public ListenersDispatcher()

Method Detail

runback to summary
public void run()

Implements java.lang.Runnable.run.

Doc from java.lang.Runnable.run.

Runs this operation.

Annotations
@Override