Skip to content

Commit 4b7a225

Browse files
author
Stanley Shyiko
committed
#274 follow up
1 parent 2e93865 commit 4b7a225

File tree

2 files changed

+25
-20
lines changed

2 files changed

+25
-20
lines changed

src/main/java/com/github/shyiko/mysql/binlog/BinaryLogClient.java

+10-10
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,7 @@ private GreetingPacket receiveGreeting() throws IOException {
646646
}
647647

648648
private void enableHeartbeat() throws IOException {
649-
channel.writeBuffered(new QueryCommand("set @master_heartbeat_period=" + heartbeatInterval * 1000000));
649+
channel.write(new QueryCommand("set @master_heartbeat_period=" + heartbeatInterval * 1000000));
650650
byte[] statementResult = channel.read();
651651
if (statementResult[0] == (byte) 0xFF /* error */) {
652652
byte[] bytes = Arrays.copyOfRange(statementResult, 1, statementResult.length);
@@ -669,7 +669,7 @@ private void requestBinaryLogStream() throws IOException {
669669
dumpBinaryLogCommand = new DumpBinaryLogCommand(serverId, binlogFilename, binlogPosition);
670670
}
671671
}
672-
channel.writeBuffered(dumpBinaryLogCommand);
672+
channel.write(dumpBinaryLogCommand);
673673
}
674674

675675
private void ensureEventDataDeserializer(EventType eventType,
@@ -703,7 +703,7 @@ private void authenticate(GreetingPacket greetingPacket) throws IOException {
703703
if (serverSupportsSSL) {
704704
SSLRequestCommand sslRequestCommand = new SSLRequestCommand();
705705
sslRequestCommand.setCollation(collation);
706-
channel.writeBuffered(sslRequestCommand, packetNumber++);
706+
channel.write(sslRequestCommand, packetNumber++);
707707
SSLSocketFactory sslSocketFactory =
708708
this.sslSocketFactory != null ?
709709
this.sslSocketFactory :
@@ -718,7 +718,7 @@ private void authenticate(GreetingPacket greetingPacket) throws IOException {
718718
AuthenticateCommand authenticateCommand = new AuthenticateCommand(schema, username, password,
719719
greetingPacket.getScramble());
720720
authenticateCommand.setCollation(collation);
721-
channel.writeBuffered(authenticateCommand, packetNumber);
721+
channel.write(authenticateCommand, packetNumber);
722722
byte[] authenticationResult = channel.read();
723723
if (authenticationResult[0] != (byte) 0x00 /* ok */) {
724724
if (authenticationResult[0] == (byte) 0xFF /* error */) {
@@ -748,7 +748,7 @@ private void switchAuthentication(byte[] authenticationResult, boolean usingSSLS
748748
String scramble = buffer.readZeroTerminatedString();
749749

750750
Command switchCommand = new AuthenticateNativePasswordCommand(scramble, password);
751-
channel.writeBuffered(switchCommand, (usingSSLSocket ? 4 : 3));
751+
channel.write(switchCommand, (usingSSLSocket ? 4 : 3));
752752
byte[] authResult = channel.read();
753753

754754
if (authResult[0] != (byte) 0x00) {
@@ -790,7 +790,7 @@ public void run() {
790790
connectionLost = System.currentTimeMillis() - eventLastSeen > keepAliveInterval;
791791
} else {
792792
try {
793-
channel.writeBuffered(new PingCommand());
793+
channel.write(new PingCommand());
794794
} catch (IOException e) {
795795
connectionLost = true;
796796
}
@@ -894,7 +894,7 @@ public boolean isConnected() {
894894
}
895895

896896
private String fetchGtidPurged() throws IOException {
897-
channel.writeBuffered(new QueryCommand("show global variables like 'gtid_purged'"));
897+
channel.write(new QueryCommand("show global variables like 'gtid_purged'"));
898898
ResultSetRowPacket[] resultSet = readResultSet();
899899
if (resultSet.length != 0) {
900900
return resultSet[0].getValue(1).toUpperCase();
@@ -904,7 +904,7 @@ private String fetchGtidPurged() throws IOException {
904904

905905
private void fetchBinlogFilenameAndPosition() throws IOException {
906906
ResultSetRowPacket[] resultSet;
907-
channel.writeBuffered(new QueryCommand("show master status"));
907+
channel.write(new QueryCommand("show master status"));
908908
resultSet = readResultSet();
909909
if (resultSet.length == 0) {
910910
throw new IOException("Failed to determine binlog filename/position");
@@ -915,7 +915,7 @@ private void fetchBinlogFilenameAndPosition() throws IOException {
915915
}
916916

917917
private ChecksumType fetchBinlogChecksum() throws IOException {
918-
channel.writeBuffered(new QueryCommand("show global variables like 'binlog_checksum'"));
918+
channel.write(new QueryCommand("show global variables like 'binlog_checksum'"));
919919
ResultSetRowPacket[] resultSet = readResultSet();
920920
if (resultSet.length == 0) {
921921
return ChecksumType.NONE;
@@ -924,7 +924,7 @@ private ChecksumType fetchBinlogChecksum() throws IOException {
924924
}
925925

926926
private void confirmSupportOfChecksum(ChecksumType checksumType) throws IOException {
927-
channel.writeBuffered(new QueryCommand("set @master_binlog_checksum= @@global.binlog_checksum"));
927+
channel.write(new QueryCommand("set @master_binlog_checksum= @@global.binlog_checksum"));
928928
byte[] statementResult = channel.read();
929929
if (statementResult[0] == (byte) 0xFF /* error */) {
930930
byte[] bytes = Arrays.copyOfRange(statementResult, 1, statementResult.length);

src/main/java/com/github/shyiko/mysql/binlog/network/protocol/PacketChannel.java

+15-10
Original file line numberDiff line numberDiff line change
@@ -61,23 +61,28 @@ public byte[] read() throws IOException {
6161
return inputStream.read(length);
6262
}
6363

64-
/*
65-
Azure's MySQL has bizarre network properties that force us to write an
66-
auth-response challenge in one shot, lest their hair catch on fire and
67-
forcibly disconnect us.
68-
*/
69-
public void writeBuffered(Command command, int packetNumber) throws IOException {
64+
public void write(Command command, int packetNumber) throws IOException {
7065
byte[] body = command.toByteArray();
7166
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
7267
buffer.writeInteger(body.length, 3); // packet length
7368
buffer.writeInteger(packetNumber, 1);
7469
buffer.write(body, 0, body.length);
75-
buffer.flush();
76-
socket.getOutputStream().write(buffer.toByteArray());
70+
outputStream.write(buffer.toByteArray());
71+
// though it has no effect in case of default (underlying) output stream (SocketOutputStream),
72+
// it may be necessary in case of non-default one
73+
outputStream.flush();
74+
}
75+
76+
/**
77+
* @deprecated use {@link #write(Command, int)} instead
78+
*/
79+
@Deprecated
80+
public void writeBuffered(Command command, int packetNumber) throws IOException {
81+
write(command, packetNumber);
7782
}
7883

79-
public void writeBuffered(Command command) throws IOException {
80-
writeBuffered(command, 0);
84+
public void write(Command command) throws IOException {
85+
write(command, 0);
8186
}
8287

8388
public void upgradeToSSL(SSLSocketFactory sslSocketFactory, HostnameVerifier hostnameVerifier) throws IOException {

0 commit comments

Comments
 (0)