Skip to content

Commit 2cf872c

Browse files
committed
Fixed checkstyle violations
1 parent 535b651 commit 2cf872c

File tree

2 files changed

+23
-16
lines changed

2 files changed

+23
-16
lines changed

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

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ public void connect() throws IOException {
319319
if (connected) {
320320
throw new IllegalStateException("BinaryLogClient is already connected");
321321
}
322-
Long connectionId;
322+
GreetingPacket greetingPacket;
323323
try {
324324
try {
325325
Socket socket = socketFactory != null ? socketFactory.createSocket() : new Socket();
@@ -332,15 +332,7 @@ public void connect() throws IOException {
332332
throw new IOException("Failed to connect to MySQL on " + hostname + ":" + port +
333333
". Please make sure it's running.", e);
334334
}
335-
byte[] initialHandshakePacket = channel.read();
336-
if (initialHandshakePacket[0] == (byte) 0xFF /* error */) {
337-
byte[] bytes = Arrays.copyOfRange(initialHandshakePacket, 1, initialHandshakePacket.length);
338-
ErrorPacket errorPacket = new ErrorPacket(bytes);
339-
throw new ServerException(errorPacket.getErrorMessage(), errorPacket.getErrorCode(),
340-
errorPacket.getSqlState());
341-
}
342-
GreetingPacket greetingPacket = new GreetingPacket(initialHandshakePacket);
343-
connectionId = greetingPacket.getThreadId();
335+
greetingPacket = receiveGreeting();
344336
authenticate(greetingPacket.getScramble(), greetingPacket.getServerCollation());
345337
if (binlogFilename == null) {
346338
fetchBinlogFilenameAndPosition();
@@ -365,7 +357,7 @@ public void connect() throws IOException {
365357
connected = true;
366358
if (logger.isLoggable(Level.INFO)) {
367359
logger.info("Connected to " + hostname + ":" + port + " at " + binlogFilename + "/" + binlogPosition +
368-
" (sid:" + serverId + ", cid:" + connectionId + ")");
360+
" (sid:" + serverId + ", cid:" + greetingPacket.getThreadId() + ")");
369361
}
370362
synchronized (lifecycleListeners) {
371363
for (LifecycleListener lifecycleListener : lifecycleListeners) {
@@ -384,6 +376,17 @@ public void connect() throws IOException {
384376
listenForEventPackets();
385377
}
386378

379+
private GreetingPacket receiveGreeting() throws IOException {
380+
byte[] initialHandshakePacket = channel.read();
381+
if (initialHandshakePacket[0] == (byte) 0xFF /* error */) {
382+
byte[] bytes = Arrays.copyOfRange(initialHandshakePacket, 1, initialHandshakePacket.length);
383+
ErrorPacket errorPacket = new ErrorPacket(bytes);
384+
throw new ServerException(errorPacket.getErrorMessage(), errorPacket.getErrorCode(),
385+
errorPacket.getSqlState());
386+
}
387+
return new GreetingPacket(initialHandshakePacket);
388+
}
389+
387390
private void requestBinaryLogStream() throws IOException {
388391
Command dumpBinaryLogCommand;
389392
synchronized (gtidSetAccessLock) {

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,16 @@ public boolean isOpen() {
7575

7676
@Override
7777
public void close() throws IOException {
78-
try {
78+
try {
7979
socket.shutdownInput(); // for socketInputStream.setEOF(true)
80-
} catch (Exception ignore) {}
81-
try {
82-
socket.shutdownOutput();
83-
} catch (Exception ignore) {}
80+
} catch (Exception e) {
81+
// ignore
82+
}
83+
try {
84+
socket.shutdownOutput();
85+
} catch (Exception e) {
86+
// ignore
87+
}
8488
socket.close();
8589
}
8690
}

0 commit comments

Comments
 (0)