@@ -60,7 +60,11 @@ public interface EventHandler {
6060 private ByteBuffer mapFileHandle = null ;
6161 private ByteBuffer gameTableFileHandle = null ;
6262
63- Client () {}
63+ private boolean debugConnection = false ;
64+
65+ Client (boolean debugConnection ) {
66+ this .debugConnection = debugConnection ;
67+ }
6468
6569 /**
6670 * For test purposes only
@@ -89,6 +93,10 @@ void reconnect(){
8993 }
9094
9195 void disconnect () {
96+ if (debugConnection ) {
97+ System .err .print ("Disconnect called by: " );
98+ System .err .println (Thread .currentThread ().getStackTrace ()[2 ].getMethodName ());
99+ }
92100 if (!connected ) {
93101 return ;
94102 }
@@ -126,6 +134,9 @@ boolean connect() {
126134 }
127135 catch (Exception e ) {
128136 System .err .println ("Game table mapping not found." );
137+ if (debugConnection ) {
138+ e .printStackTrace ();
139+ }
129140 return false ;
130141 }
131142
@@ -135,6 +146,9 @@ boolean connect() {
135146 }
136147 catch (Exception e ) {
137148 System .err .println ("Unable to map Game table." );
149+ if (debugConnection ) {
150+ e .printStackTrace ();
151+ }
138152 return false ;
139153 }
140154
@@ -166,6 +180,9 @@ boolean connect() {
166180 }
167181 catch (Exception e ) {
168182 System .err .println ("Unable to open communications pipe: " + communicationPipe );
183+ if (debugConnection ) {
184+ e .printStackTrace ();
185+ }
169186 gameTableFileHandle = null ;
170187 return false ;
171188 }
@@ -178,6 +195,9 @@ boolean connect() {
178195 }
179196 catch (Exception e ) {
180197 System .err .println ("Unable to open shared memory mapping: " + sharedMemoryName );
198+ if (debugConnection ) {
199+ e .printStackTrace ();
200+ }
181201 pipeObjectHandle = null ;
182202 gameTableFileHandle = null ;
183203 return false ;
@@ -188,6 +208,9 @@ boolean connect() {
188208 }
189209 catch (Exception e ) {
190210 System .err .println ("Unable to map game data." );
211+ if (debugConnection ) {
212+ e .printStackTrace ();
213+ }
191214 return false ;
192215 }
193216
@@ -205,8 +228,11 @@ boolean connect() {
205228 code = pipeObjectHandle .readByte ();
206229 }
207230 catch (Exception e ) {
208- disconnect ();
209231 System .err .println ("Unable to read pipe object." );
232+ if (debugConnection ) {
233+ e .printStackTrace ();
234+ }
235+ disconnect ();
210236 return false ;
211237 }
212238 }
@@ -223,6 +249,9 @@ void update(final EventHandler handler) {
223249 }
224250 catch (Exception e ) {
225251 System .err .println ("failed, disconnecting" );
252+ if (debugConnection ) {
253+ e .printStackTrace ();
254+ }
226255 disconnect ();
227256 return ;
228257 }
@@ -232,6 +261,9 @@ void update(final EventHandler handler) {
232261 }
233262 catch (Exception e ) {
234263 System .err .println ("failed, disconnecting" );
264+ if (debugConnection ) {
265+ e .printStackTrace ();
266+ }
235267 disconnect ();
236268 return ;
237269 }
0 commit comments