@@ -37,6 +37,7 @@ public class RelpHandler extends Handler {
3737 private RelpConnection relpConnection ;
3838 private RelpBatch batch ;
3939 private RelpConfig config ;
40+ boolean connected = false ;
4041
4142 // No arguments defaults to 'default' logger
4243 public RelpHandler () throws NumberFormatException , NoSuchFieldException , IOException , TimeoutException {
@@ -112,6 +113,12 @@ public synchronized void flush() {
112113 } catch (IllegalStateException | IOException | java .util .concurrent .TimeoutException e ) {
113114 System .out .println ("RelpLogger.flush.commit> exception:" );
114115 e .printStackTrace ();
116+ try {
117+ this .relpConnection .tearDown ();
118+ } catch (IOException ioException ) {
119+ ioException .printStackTrace ();
120+ }
121+ this .connected = false ;
115122 }
116123 // Check if everything has been sent, retry and reconnect if not.
117124 if (!this .batch .verifyTransactionAll ()) {
@@ -135,20 +142,23 @@ private void reconnect() throws IOException, TimeoutException {
135142 }
136143
137144 private void disconnect () throws IOException , TimeoutException {
145+ if (!this .connected ) {
146+ return ;
147+ }
138148 this .relpConnection .disconnect ();
139149 this .relpConnection .tearDown ();
150+ this .connected = false ;
140151 }
141152
142153 private void connect () {
143- boolean connected = false ;
144- while (!connected ) {
154+ while (!this .connected ) {
145155 try {
146- connected = relpConnection .connect (this .config .getAddress (), this .config .getPort ());
156+ this . connected = relpConnection .connect (this .config .getAddress (), this .config .getPort ());
147157 } catch (Exception e ) {
148158 System .out .println ("RelpHandler.connect> exception:" );
149159 e .printStackTrace ();
150160 }
151- if (!connected ) {
161+ if (!this . connected ) {
152162 try {
153163 Thread .sleep (this .config .getReconnectInterval ());
154164 } catch (InterruptedException e ) {
@@ -160,6 +170,9 @@ private void connect() {
160170
161171 @ Override
162172 public synchronized void close () {
173+ if (!this .connected ) {
174+ return ;
175+ }
163176 try {
164177 disconnect ();
165178 } catch (IOException | TimeoutException e ) {
0 commit comments