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);
    }
private void deviceClientMonitorLoop() {
        do {
            try {
               
               
               
                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);
                           
                           
                            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();
                                   
                                    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);
    }
private void deviceclientmonitorloop() { do { try { 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); 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(); 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); }