mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2024-12-27 09:58:45 +01:00
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:
parent
7c8622392d
commit
0bbf7272aa
1 changed files with 43 additions and 39 deletions
|
@ -67,58 +67,62 @@ 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
|
||||
}
|
||||
|
||||
try {
|
||||
DataOutputStream outStream =
|
||||
new DataOutputStream( m_socket.getOutputStream() );
|
||||
outStream.writeShort( 2 + 2 + (2*obits.length) + strLens );
|
||||
outStream.writeByte( NetUtils.PROTOCOL_VERSION );
|
||||
outStream.writeByte( NetUtils.PRX_DEVICE_GONE );
|
||||
outStream.writeShort( obits.length );
|
||||
|
||||
for ( int ii = 0; ii < obits.length; ++ii ) {
|
||||
outStream.writeShort( obits[ii].m_seed );
|
||||
outStream.writeBytes( obits[ii].m_relayID );
|
||||
outStream.write( '\n' );
|
||||
}
|
||||
|
||||
outStream.flush();
|
||||
|
||||
DataInputStream dis =
|
||||
new DataInputStream( m_socket.getInputStream() );
|
||||
short resLen = dis.readShort();
|
||||
m_socket.close();
|
||||
|
||||
if ( resLen == 0 ) {
|
||||
DBUtils.clearObits( m_context, obits );
|
||||
}
|
||||
} catch ( java.io.IOException ioe ) {
|
||||
Utils.logf( ioe.toString() );
|
||||
}
|
||||
int strLens = 0;
|
||||
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*m_obits.length) + strLens );
|
||||
outStream.writeByte( NetUtils.PROTOCOL_VERSION );
|
||||
outStream.writeByte( NetUtils.PRX_DEVICE_GONE );
|
||||
outStream.writeShort( m_obits.length );
|
||||
|
||||
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' );
|
||||
}
|
||||
|
||||
outStream.flush();
|
||||
|
||||
DataInputStream dis =
|
||||
new DataInputStream( m_socket.getInputStream() );
|
||||
short resLen = dis.readShort();
|
||||
m_socket.close();
|
||||
|
||||
if ( resLen == 0 ) {
|
||||
DBUtils.clearObits( m_context, m_obits );
|
||||
}
|
||||
} catch ( java.io.IOException ioe ) {
|
||||
Utils.logf( ioe.toString() );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static void informOfDeaths( Context context )
|
||||
{
|
||||
Socket socket = MakeProxySocket( context, 10000 );
|
||||
if ( null != socket ) {
|
||||
InformThread thread = new InformThread( context, socket );
|
||||
thread.start();
|
||||
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, obits, socket );
|
||||
thread.start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue