don't create thread if there are no obits in the db -- makes it

cheaper to call when there may be nothing to do.
This commit is contained in:
Andy2 2010-11-23 18:10:51 -08:00
parent 7c8622392d
commit 0bbf7272aa

View file

@ -67,32 +67,33 @@ public class NetUtils {
private static class InformThread extends Thread {
Context m_context;
private Socket m_socket;
public InformThread( Context context, Socket socket )
DBUtils.Obit[] m_obits;
public InformThread( Context context, DBUtils.Obit[] obits,
Socket socket )
{
m_context = context;
m_obits = obits;
m_socket = socket;
}
public void run() {
DBUtils.Obit[] obits = DBUtils.listObits( m_context );
if ( null != obits && 0 < obits.length ) {
int strLens = 0;
for ( int ii = 0; ii < obits.length; ++ii ) {
strLens += obits[ii].m_relayID.length() + 1; // 1 for /n
for ( int ii = 0; ii < m_obits.length; ++ii ) {
strLens += m_obits[ii].m_relayID.length() + 1; // 1 for /n
}
try {
DataOutputStream outStream =
new DataOutputStream( m_socket.getOutputStream() );
outStream.writeShort( 2 + 2 + (2*obits.length) + strLens );
outStream.writeShort( 2 + 2 + (2*m_obits.length) + strLens );
outStream.writeByte( NetUtils.PROTOCOL_VERSION );
outStream.writeByte( NetUtils.PRX_DEVICE_GONE );
outStream.writeShort( obits.length );
outStream.writeShort( m_obits.length );
for ( int ii = 0; ii < obits.length; ++ii ) {
outStream.writeShort( obits[ii].m_seed );
outStream.writeBytes( obits[ii].m_relayID );
for ( int ii = 0; ii < m_obits.length; ++ii ) {
outStream.writeShort( m_obits[ii].m_seed );
outStream.writeBytes( m_obits[ii].m_relayID );
outStream.write( '\n' );
}
@ -104,23 +105,26 @@ public class NetUtils {
m_socket.close();
if ( resLen == 0 ) {
DBUtils.clearObits( m_context, obits );
DBUtils.clearObits( m_context, m_obits );
}
} catch ( java.io.IOException ioe ) {
Utils.logf( ioe.toString() );
}
}
}
}
public static void informOfDeaths( Context context )
{
DBUtils.Obit[] obits = DBUtils.listObits( context );
if ( null != obits && 0 < obits.length ) {
Socket socket = MakeProxySocket( context, 10000 );
if ( null != socket ) {
InformThread thread = new InformThread( context, socket );
InformThread thread = new InformThread( context, obits, socket );
thread.start();
}
}
}
public static String[] QueryRelay( Context context )
{