Start the ConnectedThread to begin managing a Bluetooth connection
@param socket  The BluetoothSocket on which the connection was made
@param device  The BluetoothDevice that has been connected
3018
public synchronized void connected(BluetoothSocket socket, BluetoothDevice
            device, final String socketType) {
        // Cancel the thread that completed the connection
        if (mConnectThread != null) {mConnectThread.cancel(); mConnectThread = null;}

        // Cancel any thread currently running a connection
        if (mConnectedThread != null) {mConnectedThread.cancel(); mConnectedThread = null;}

        // Cancel the accept thread because we only want to tryConnect to one device
        if (mSecureAcceptThread != null) {
            mSecureAcceptThread.cancel();
            mSecureAcceptThread = null;
        }

        // Start the thread to manage the connection and perform transmissions
        mConnectedThread = new ConnectedThread(socket, socketType);
        mConnectedThread.start();

        // Send the name of the connected device back to the UI Activity
        Message msg = mHandler.obtainMessage(MESSAGE_DEVICE_NAME);
        mHandler.sendMessage(msg);

        setState(BluetoothService.STATE_CONNECTED);
    }
330390
public void checkConnection() {
        long start = Time.currentTimeMillis();

        while (clientChannel == null) {

            tcpSocketConsumer.checkNotShutdown();

            if (start + timeoutMs > Time.currentTimeMillis())
                try {
                    condition.await(1, TimeUnit.MILLISECONDS);

                } catch (InterruptedException e) {
                    throw new IORuntimeException("Interrupted");
                }
            else
                throw new IORuntimeException("Not connected to " + socketAddressSupplier);
        }

        if (clientChannel == null)
            throw new IORuntimeException("Not connected to " + socketAddressSupplier);
    }
740102
private void startConnection()
  {
    while (doStart()) {
      boolean isValid = false;

      try {
        long now = currentTimeActual();

        updateIdleExpireTime(now);

        int id = _gId.incrementAndGet();
        
        updateThrottle();

        /*
        if (id == 200) {
          ThreadDump.create().dumpThreads();
        }
        else */ 
        /*
        if (id == 1000) {
          ThreadDump.create().dumpThreads();
        }
        */

        launchChildThread(id);
        
        isValid = true;
      } finally {
        if (! isValid) {
          onStartFail();
        }
      }
    }
  }
168674
protected void checkIfAlreadyConnected(DeviceProxy device, String attribute, String event_name, CallBack callback, int max_size, boolean stateless)
            throws DevFailed {
        if (device == null || (callback == null && max_size < 0)) {
            Except.throw_wrong_syntax_exception("API_InvalidArgs",
                    "Device or callback pointer NULL and  event queue not used !!",
                    "EventConsumer.subscribe_event()");
        }

        if (device == null || device.name() == null)
            Except.throw_event_system_failed("API_NotificationServiceFailed",
                    "Failed to connect to device",
                    "EventConsumer.subscribe_event()");
        else {
            //	Check if already connected (exists in map)
            String callback_key = device.name().toLowerCase() + "/" + attribute + "." + event_name;
            if (event_callback_map.containsKey(callback_key))
                Except.throw_event_system_failed("API_MethodArgument",
                        "Already connected to event " + callback_key,
                        "EventConsumer.subscribe_event()");

            //	Check if already trying to connects (exists in map)
            if (stateless && failed_event_callback_map.containsKey(callback_key))
                Except.throw_event_system_failed("API_MethodArgument",
                        "Already trying to connect to event " + callback_key,
                        "EventConsumer.subscribe_event()");
        }
    }
775104
private void startConnecting()
    {
        //  Open the connecting socket.
        try {
            boolean rc = open();

            //  Connect may succeed in synchronous manner.
            if (rc) {
                handle = ioObject.addFd(fd);
                connectEvent();
            }
            //  Connection establishment may be delayed. Poll for its completion.
            else {
                handle = ioObject.addFd(fd);
                ioObject.setPollConnect(handle);
                socket.eventConnectDelayed(addr.toString(), -1);
            }
        }
        catch (RuntimeException | IOException e) {
            //  Handle any other error condition by eventual reconnect.
            if (fd != null) {
                close();
            }
            addReconnectTimer();
        }
    }
1056757
@Override
    protected  void checkDeviceConnection(DeviceProxy device,
                        String attribute, DeviceData deviceData, String event_name) throws DevFailed {

        String deviceName = device.name();
        if (!device_channel_map.containsKey(deviceName)) {
            connect(device, attribute, event_name, deviceData);
            if (!device_channel_map.containsKey(deviceName)) {
                Except.throw_event_system_failed("API_NotificationServiceFailed",
                        "Failed to connect to event channel for device",
                        "EventConsumer.subscribe_event()");
            }
        }
    }
953769
public synchronized void start() {
    if (isStarted()) {
      throw new IllegalStateException("Failed to start Socket.IO server: server already started");
    }

    log.info("Socket.IO server starting");

    // Configure heartbeat scheduler
    timer = new HashedWheelTimer();
    timer.start();
    SocketIOHeartbeatScheduler.setHashedWheelTimer(timer);
    SocketIOHeartbeatScheduler.setHeartbeatInterval(configuration.getHeartbeatInterval());
    SocketIOHeartbeatScheduler.setHeartbeatTimeout(configuration.getHeartbeatTimeout());

    // Configure and bind server
    ServerBootstrapFactory bootstrapFactory = serverBootstrapFactory != null
        ? serverBootstrapFactory
        : new DefaultServerBootstrapFactory(configuration);
    bootstrap = bootstrapFactory.createServerBootstrap();
    bootstrap.childHandler(new SocketIOChannelInitializer(configuration, listener, pipelineModifier));
    bootstrap.bind(configuration.getPort()).syncUninterruptibly();

    state = State.STARTED;
    log.info("Socket.IO server started: {}", configuration);
  }
1065531
private void connectIfNotDone(ZMQ.Socket socket, ZMQutils.ControlStructure controlStructure){

        traceZmqSubscription(controlStructure.eventName, true);
        //  Check if not already connected or forced (re connection)
        if (controlStructure.forceReconnection || !alreadyConnected(controlStructure.endPoint)) {
            ApiUtil.printTrace("Set socket buffer for HWM to " + controlStructure.hwm);

            //  Check if it ia a reconnection -> disconnect before connection
            if (controlStructure.forceReconnection && alreadyConnected(controlStructure.endPoint)) {
                try {
                    //  needs an un subscribe before disconnection
                    //socket.unsubscribe(controlStructure.eventName.getBytes());
                    socket.disconnect(controlStructure.endPoint);
                }
                catch (org.zeromq.ZMQException e) {
                    System.err.println(e.getMessage());
                }
            }

            //  Do the connection
            //System.out.println("Connect on " + controlStructure.endPoint);
            //System.out.println("        for " + controlStructure.eventName);
            socket.setHWM(controlStructure.hwm);
            socket.connect(controlStructure.endPoint);
            if (!alreadyConnected(controlStructure.endPoint)) {
                EventList eventList = new EventList();
                eventList.add(controlStructure.eventName);
                connectedMap.put(controlStructure.endPoint, eventList);
            }
            else {
                //  Add to event list if not done
                EventList eventList = connectedMap.get(controlStructure.endPoint);
                String  s = eventList.getEvent(controlStructure.eventName);
                if (s==null)
                    eventList.add(controlStructure.eventName);
            }
        }
        else {
            //  Add to event list if not done
            EventList eventList = connectedMap.get(controlStructure.endPoint);
            String  s = eventList.getEvent(controlStructure.eventName);
            if (s==null)
                eventList.add(controlStructure.eventName);
            ApiUtil.printTrace(
                    ((controlStructure.commandCode==ZMQutils.ZMQ_CONNECT_EVENT)? "Event" : "Heartbeat") +
                    " already connected to " + controlStructure.endPoint);
        }
    }
930753
public synchronized void connect() {
        if (state != State.NONE) {
            eventHandler.onError(new WebSocketException("connect() already called"));
            close();
            return;
        }
        getIntializer().setName(getInnerThread(), THREAD_BASE_NAME + "Reader-" + clientId);
        state = State.CONNECTING;
        getInnerThread().start();
    }
575976
public void write(byte[] out) {
        // Create temporary object
        ConnectedThread r;
        // Synchronize a copy of the ConnectedThread
        synchronized (this) {
            if (mState != BluetoothState.STATE_CONNECTED) return;
            r = mConnectedThread;
        }
        // Perform the write unsynchronized
        r.write(out);
    }
104494
function isSocketConnected(socket) {
       return socket && (
            (socket.socket && socket.socket.connected) || socket.connected
        );
    }
78564
public synchronized void connected(ISOBUSSocket engSocket,
            ISOBUSSocket impSocket, ISOBUSSocket bufEngSocket,
            ISOBUSSocket bufImpSocket, ISOBlueDevice device) {
        // Cancel the thread that completed the connection
        if (mConnectThread != null) {
            mConnectThread.cancel();
            mConnectThread = null;
        }

        // Cancel any thread currently running a connection
        if (mEngConnectedThread != null) {
            mEngConnectedThread.cancel();
            mEngConnectedThread = null;
        }
        if (mImpConnectedThread != null) {
            mImpConnectedThread.cancel();
            mImpConnectedThread = null;
        }

        // Start the thread to manage the connection and perform transmissions
        mEngConnectedThread = new ConnectedThread(engSocket,
                ISOBlueDemo.MESSAGE_ARG1_NEW);
        mEngConnectedThread.start();
        mImpConnectedThread = new ConnectedThread(impSocket,
                ISOBlueDemo.MESSAGE_ARG1_NEW);
        mImpConnectedThread.start();
        if (mPast) {
            mBufEngConnectedThread = new ConnectedThread(bufEngSocket,
                    ISOBlueDemo.MESSAGE_ARG1_BUF);
            mBufEngConnectedThread.start();
            mBufImpConnectedThread = new ConnectedThread(bufImpSocket,
                    ISOBlueDemo.MESSAGE_ARG1_BUF);
            mBufImpConnectedThread.start();
        }

        // Send the name of the connected device back to the UI Activity
        Message msg = mHandler.obtainMessage(ISOBlueDemo.MESSAGE_DEVICE_NAME);
        Bundle bundle = new Bundle();
        bundle.putString(ISOBlueDemo.DEVICE_NAME, device.getDevice().getName());
        msg.setData(bundle);
        mHandler.sendMessage(msg);

        setState(STATE_CONNECTED);
    }
566367
public void connectSocket() {

        synchronized (lock) {
            if (isForegrounded) {
                if (socketConnection == null) {
                    SocketFactory factory = new SocketFactory(socketURI, new SocketEventDispatcher(listener, new Parser()).setLogger(log), log);
                    socketConnection = new SocketConnectionController(new Handler(Looper.getMainLooper()), dataMgr, factory, listener, new RetryStrategy(60, 60000), log);
                    socketConnection.setProxy(proxyURI);
                    socketConnection.connect();

                } else {
                    socketConnection.connect();
                }
                socketConnection.setManageReconnection(true);
            }
            lock.notifyAll();
        }
    }
560200
@Override
    public void attachThreadToDevice(long threadId, Integer deviceId) {
        val t = Thread.currentThread();
        String name = "N/A";
        if (t.getId() == threadId)
            name = t.getName();

        List<Integer> devices = new ArrayList<>(CudaEnvironment.getInstance().getConfiguration().getAvailableDevices());
        logger.trace("Manually mapping thread [{} - {}] to device [{}], out of [{}] devices...", threadId,
                name, deviceId, devices.size());
        affinityMap.put(threadId, deviceId);
    }
1339992
public void start(final int timeout, boolean daemon) throws IOException {
        this.myServerSocket = this.getServerSocketFactory().create();
        this.myServerSocket.setReuseAddress(true);

        ServerRunnable serverRunnable = createServerRunnable(timeout);
        this.myThread = new Thread(serverRunnable);
        this.myThread.setDaemon(daemon);
        this.myThread.setName("NanoHttpd Main Listener");
        this.myThread.start();
        while (!serverRunnable.hasBinded && serverRunnable.bindException == null) {
            try {
                Thread.sleep(10L);
            } catch (Throwable e) {
                // on android this may not be allowed, that's why we
                // catch throwable the wait should be very short because we are
                // just waiting for the bind of the socket
            }
        }
        if (serverRunnable.bindException != null) {
            throw serverRunnable.bindException;
        }
    }
1263722
@Override
    protected void onStart() {
        super.onStart();
        mApiClient = new GoogleApiClient.Builder(this)
                .addApi(Wearable.API)
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .build();

        mApiClient.connect();
    }
185720
public void onConnected() {
        ConnectionState event = null;
        synchronized (this) {
            if (this.state != ConnectionState.CONNECTING) {
                LOG.debug("Unable to set to connected, not in CONNECTING state: {}", this.state);
                return;
            }

            this.state = ConnectionState.CONNECTED;
            inputAvailable = false; // cannot read (yet)
            outputAvailable = true; // write allowed
            event = this.state;
        }
        notifyStateListeners(event);
    }