/* notify */
private void deviceClientMonitorLoop() {
        do {
            try {
                // This synchronized block stops us from doing the select() if a new
                // Device is being added.
                // @see startMonitoringDevice()
                synchronized (mDevices) {
                }
                int count = mSelector.select();
                if (mQuit) {
                    return;
                }
                synchronized (mClientsToReopen) {
                    if (mClientsToReopen.size() > 0) {
                        Set<Client> clients = mClientsToReopen.keySet();
                        MonitorThread monitorThread = MonitorThread.getInstance();
                        for (Client client : clients) {
                            Device device = client.getDeviceImpl();
                            int pid = client.getClientData().getPid();
                            monitorThread.dropClient(client, false /* notify */);
                            // This is kinda bad, but if we don't wait a bit, the client
                            // will never answer the second handshake!
                            waitABit();
                            int port = mClientsToReopen.get(client);
                            if (port == IDebugPortProvider.NO_STATIC_PORT) {
                                port = getNextDebuggerPort();
                            }
                            Log.d("DeviceMonitor", "Reopening " + client);
                            openClient(device, pid, port, monitorThread);
                            device.update(Device.CHANGE_CLIENT_LIST);
                        }
                        mClientsToReopen.clear();
                    }
                }
                if (count == 0) {
                    continue;
                }
                Set<SelectionKey> keys = mSelector.selectedKeys();
                Iterator<SelectionKey> iter = keys.iterator();
                while (iter.hasNext()) {
                    SelectionKey key = iter.next();
                    iter.remove();
                    if (key.isValid() && key.isReadable()) {
                        Object attachment = key.attachment();
                        if (attachment instanceof Device) {
                            Device device = (Device)attachment;
                            SocketChannel socket = device.getClientMonitoringSocket();
                            if (socket != null) {
                                try {
                                    int length = readLength(socket, mLengthBuffer2);
                                    processIncomingJdwpData(device, socket, length);
                                } catch (IOException ioe) {
                                    Log.d("DeviceMonitor",
                                            "Error reading jdwp list: " + ioe.getMessage());
                                    socket.close();
                                    // restart the monitoring of that device
                                    synchronized (mDevices) {
                                        if (mDevices.contains(device)) {
                                            Log.d("DeviceMonitor",
                                                    "Restarting monitoring service for " + device);
                                            startMonitoringDevice(device);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            } catch (IOException e) {
                if (mQuit == false) {
                }
            }
        } while (mQuit == false);
    }
Device device = client.getDeviceImpl();
int pid = client.getClientData().getPid();
monitorThread.dropClient(client, false /* notify */);
// This is kinda bad, but if we don't wait a bit, the client
// will never answer the second handshake!
if (mQuit) {
return;
}
synchronized (mClientsToReopen) {
if (mClientsToReopen.size() > 0) {
Set<Client> clients = mClientsToReopen.keySet();
MonitorThread monitorThread = MonitorThread.getInstance();
for (Client client : clients) {
Device device = client.getDeviceImpl();
int pid = client.getClientData().getPid();
monitorThread.dropClient(client, false /* notify */);
// This is kinda bad, but if we don't wait a bit, the client
// will never answer the second handshake!
waitABit();
int port = mClientsToReopen.get(client);
if (port == IDebugPortProvider.NO_STATIC_PORT) {
port = getNextDebuggerPort();
}
Log.d("DeviceMonitor", "Reopening " + client);
openClient(device, pid, port, monitorThread);
device.update(Device.CHANGE_CLIENT_LIST);
private void deviceClientMonitorLoop() {
do {
try {
// This synchronized block stops us from doing the select() if a new
// Device is being added.
// @see startMonitoringDevice()
synchronized (mDevices) {
}
int count = mSelector.select();
if (mQuit) {
return;
}
synchronized (mClientsToReopen) {
if (mClientsToReopen.size() > 0) {
Set<Client> clients = mClientsToReopen.keySet();
MonitorThread monitorThread = MonitorThread.getInstance();
for (Client client : clients) {
Device device = client.getDeviceImpl();
int pid = client.getClientData().getPid();
monitorThread.dropClient(client, false /* notify */);
// This is kinda bad, but if we don't wait a bit, the client
// will never answer the second handshake!
waitABit();
int port = mClientsToReopen.get(client);
if (port == IDebugPortProvider.NO_STATIC_PORT) {
port = getNextDebuggerPort();
}
Log.d("DeviceMonitor", "Reopening " + client);
openClient(device, pid, port, monitorThread);
device.update(Device.CHANGE_CLIENT_LIST);
}
mClientsToReopen.clear();
}
}
if (count == 0) {
continue;
}
Set<SelectionKey> keys = mSelector.selectedKeys();
Iterator<SelectionKey> iter = keys.iterator();
while (iter.hasNext()) {