tweaks to logging and imports; should have no effect

This commit is contained in:
Eric House 2019-03-20 07:23:34 -07:00
parent 52891e8391
commit 4354cbdc4f
2 changed files with 31 additions and 26 deletions

View file

@ -46,12 +46,14 @@ import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.net.DatagramPacket; import java.net.DatagramPacket;
import java.net.DatagramSocket; import java.net.DatagramSocket;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.Socket; import java.net.Socket;
import java.net.SocketException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
@ -534,7 +536,7 @@ public class RelayService extends XWJIService
s_UDPSocket.connect( addr, port ); // remember this address s_UDPSocket.connect( addr, port ); // remember this address
Log.d( TAG, "connectSocket(%s:%d): s_UDPSocket now %H", Log.d( TAG, "connectSocket(%s:%d): s_UDPSocket now %H",
host, port, s_UDPSocket ); host, port, s_UDPSocket );
} catch( java.net.SocketException se ) { } catch( SocketException se ) {
Log.ex( TAG, se ); Log.ex( TAG, se );
Assert.fail(); Assert.fail();
} catch( java.net.UnknownHostException uhe ) { } catch( java.net.UnknownHostException uhe ) {
@ -951,7 +953,7 @@ public class RelayService extends XWJIService
break; break;
} }
} }
} catch ( java.io.IOException ioe ) { } catch ( IOException ioe ) {
Log.ex( TAG, ioe ); Log.ex( TAG, ioe );
} }
@ -1038,7 +1040,7 @@ public class RelayService extends XWJIService
postPacket( bas, XWRelayReg.XWPDEV_REG, timestamp ); postPacket( bas, XWRelayReg.XWPDEV_REG, timestamp );
s_regStartTime = now; s_regStartTime = now;
} catch ( java.io.IOException ioe ) { } catch ( IOException ioe ) {
Log.ex( TAG, ioe ); Log.ex( TAG, ioe );
} }
} }
@ -1065,7 +1067,7 @@ public class RelayService extends XWJIService
} else { } else {
Log.d(TAG, "requestMessages(): devid is null" ); Log.d(TAG, "requestMessages(): devid is null" );
} }
} catch ( java.io.IOException ioe ) { } catch ( IOException ioe ) {
Log.ex( TAG, ioe ); Log.ex( TAG, ioe );
} }
} }
@ -1079,7 +1081,7 @@ public class RelayService extends XWJIService
out.writeInt( (int)rowid ); out.writeInt( (int)rowid );
out.write( msg, 0, msg.length ); out.write( msg, 0, msg.length );
postPacket( bas, XWRelayReg.XWPDEV_MSG, timestamp ); postPacket( bas, XWRelayReg.XWPDEV_MSG, timestamp );
} catch ( java.io.IOException ioe ) { } catch ( IOException ioe ) {
Log.ex( TAG, ioe ); Log.ex( TAG, ioe );
} }
} }
@ -1099,7 +1101,7 @@ public class RelayService extends XWJIService
out.write( '\n' ); out.write( '\n' );
out.write( msg, 0, msg.length ); out.write( msg, 0, msg.length );
postPacket( bas, XWRelayReg.XWPDEV_MSGNOCONN, timestamp ); postPacket( bas, XWRelayReg.XWPDEV_MSGNOCONN, timestamp );
} catch ( java.io.IOException ioe ) { } catch ( IOException ioe ) {
Log.ex( TAG, ioe ); Log.ex( TAG, ioe );
} }
} }
@ -1133,7 +1135,7 @@ public class RelayService extends XWJIService
out.writeShort( nliData.length ); out.writeShort( nliData.length );
out.write( nliData, 0, nliData.length ); out.write( nliData, 0, nliData.length );
postPacket( bas, XWRelayReg.XWPDEV_INVITE, timestamp ); postPacket( bas, XWRelayReg.XWPDEV_INVITE, timestamp );
} catch ( java.io.IOException ioe ) { } catch ( IOException ioe ) {
Log.ex( TAG, ioe ); Log.ex( TAG, ioe );
} }
} }
@ -1146,14 +1148,14 @@ public class RelayService extends XWJIService
DataOutputStream out = new DataOutputStream( bas ); DataOutputStream out = new DataOutputStream( bas );
un2vli( header.m_packetID, out ); un2vli( header.m_packetID, out );
postPacket( bas, XWRelayReg.XWPDEV_ACK, -1 ); postPacket( bas, XWRelayReg.XWPDEV_ACK, -1 );
} catch ( java.io.IOException ioe ) { } catch ( IOException ioe ) {
Log.ex( TAG, ioe ); Log.ex( TAG, ioe );
} }
} }
} }
private PacketHeader readHeader( DataInputStream dis ) private PacketHeader readHeader( DataInputStream dis )
throws java.io.IOException throws IOException
{ {
PacketHeader result = null; PacketHeader result = null;
byte proto = dis.readByte(); byte proto = dis.readByte();
@ -1171,8 +1173,7 @@ public class RelayService extends XWJIService
return result; return result;
} }
private String getVLIString( DataInputStream dis ) private String getVLIString( DataInputStream dis ) throws IOException
throws java.io.IOException
{ {
byte[] tmp = new byte[vli2un( dis )]; byte[] tmp = new byte[vli2un( dis )];
dis.readFully( tmp ); dis.readFully( tmp );
@ -1185,8 +1186,8 @@ public class RelayService extends XWJIService
{ {
PacketData packet = new PacketData( bas, cmd, timestamp ); PacketData packet = new PacketData( bas, cmd, timestamp );
s_queue.add( packet ); s_queue.add( packet );
Log.d( TAG, "postPacket(%s); (now %d in queue)", packet, // Log.d( TAG, "postPacket(%s); (now %d in queue)", packet,
s_queue.size() ); // s_queue.size() );
} }
private String getDevID( DevIDType[] typp ) private String getDevID( DevIDType[] typp )
@ -1311,8 +1312,9 @@ public class RelayService extends XWJIService
// service.resetExitTimer(); // service.resetExitTimer();
// service.gotPacket( packet ); // service.gotPacket( packet );
} catch ( java.io.InterruptedIOException iioe ) { } catch ( java.io.InterruptedIOException iioe ) {
// poll timing out, typically
// Log.d( TAG, "iioe from receive(): %s", iioe.getMessage() ); // Log.d( TAG, "iioe from receive(): %s", iioe.getMessage() );
} catch( java.io.IOException ioe ) { } catch( IOException ioe ) {
Log.d( TAG, "ioe from receive(): %s/%s", ioe.getMessage() ); Log.d( TAG, "ioe from receive(): %s/%s", ioe.getMessage() );
Assert.assertFalse( BuildConfig.DEBUG ); Assert.assertFalse( BuildConfig.DEBUG );
break; break;
@ -1411,7 +1413,7 @@ public class RelayService extends XWJIService
outStream.flush(); outStream.flush();
socket.close(); socket.close();
} }
} catch ( java.io.IOException ioe ) { } catch ( IOException ioe ) {
Log.ex( TAG, ioe ); Log.ex( TAG, ioe );
} }
} // run } // run
@ -1562,7 +1564,7 @@ public class RelayService extends XWJIService
} }
private static void un2vli( int nn, OutputStream os ) private static void un2vli( int nn, OutputStream os )
throws java.io.IOException throws IOException
{ {
int indx = 0; int indx = 0;
boolean done = false; boolean done = false;
@ -1577,7 +1579,7 @@ public class RelayService extends XWJIService
} while ( !done ); } while ( !done );
} }
private static int vli2un( InputStream is ) throws java.io.IOException private static int vli2un( InputStream is ) throws IOException
{ {
int result = 0; int result = 0;
byte[] buf = new byte[1]; byte[] buf = new byte[1];
@ -1602,7 +1604,7 @@ public class RelayService extends XWJIService
} }
private static void writeVLIString( DataOutputStream os, String str ) private static void writeVLIString( DataOutputStream os, String str )
throws java.io.IOException throws IOException
{ {
if ( null == str ) { if ( null == str ) {
str = ""; str = "";
@ -1804,7 +1806,7 @@ public class RelayService extends XWJIService
un2vli( m_packetID, out ); un2vli( m_packetID, out );
out.writeByte( m_cmd.ordinal() ); out.writeByte( m_cmd.ordinal() );
m_header = bas.toByteArray(); m_header = bas.toByteArray();
} catch ( java.io.IOException ioe ) { } catch ( IOException ioe ) {
Log.ex( TAG, ioe ); Log.ex( TAG, ioe );
} }
} }

View file

@ -36,7 +36,8 @@ import java.util.Map;
abstract class XWJIService extends JobIntentService { abstract class XWJIService extends JobIntentService {
private static final String TAG = XWJIService.class.getSimpleName(); private static final String TAG = XWJIService.class.getSimpleName();
private static final boolean LOG_COUNTS = false; private static final boolean LOG_INTENT_COUNTS = false;
private static final boolean LOG_PACKETS = false;
static final String CMD_KEY = "CMD"; static final String CMD_KEY = "CMD";
private static final String TIMESTAMP = "TIMESTAMP"; private static final String TIMESTAMP = "TIMESTAMP";
@ -60,10 +61,12 @@ abstract class XWJIService extends JobIntentService {
long timestamp = getTimestamp(intent); long timestamp = getTimestamp(intent);
XWJICmds cmd = cmdFrom( intent ); XWJICmds cmd = cmdFrom( intent );
Log.d( getClass().getSimpleName(), if ( LOG_PACKETS ) {
"onHandleWork(): cmd=%s; age=%dms; threadCount: %d)", Log.d( getClass().getSimpleName(),
cmd, System.currentTimeMillis() - timestamp, "onHandleWork(): cmd=%s; age=%dms; threadCount: %d)",
Thread.activeCount() ); cmd, System.currentTimeMillis() - timestamp,
Thread.activeCount() );
}
onHandleWorkImpl( intent, cmd, timestamp ); onHandleWorkImpl( intent, cmd, timestamp );
} }
@ -110,7 +113,7 @@ abstract class XWJIService extends JobIntentService {
sPendingIntents.put( name, new ArrayList<Intent>() ); sPendingIntents.put( name, new ArrayList<Intent>() );
} }
sPendingIntents.get(name).add( intent ); sPendingIntents.get(name).add( intent );
if ( LOG_COUNTS ) { if ( LOG_INTENT_COUNTS ) {
Log.d( TAG, "remember(): now have %d intents for class %s", Log.d( TAG, "remember(): now have %d intents for class %s",
sPendingIntents.get(name).size(), name ); sPendingIntents.get(name).size(), name );
} }
@ -162,7 +165,7 @@ abstract class XWJIService extends JobIntentService {
} }
if ( found != null ) { if ( found != null ) {
if ( LOG_COUNTS ) { if ( LOG_INTENT_COUNTS ) {
Log.d( TAG, "forget(): now have %d intents for class %s", Log.d( TAG, "forget(): now have %d intents for class %s",
sPendingIntents.get(found).size(), found ); sPendingIntents.get(found).size(), found );
} }