@Override public boolean isConnected() { return mConnection != null && super.isConnected(); }
@Override public boolean isConnected() { boolean connected = false; // If we can't get the lock in 100ms, must be blocked waiting for a // connection so we consider it disconnected. try { if(mConnectionLock.readLock().tryLock(100, TimeUnit.MILLISECONDS)) { connected = mSocket != null && mSocket.isConnected() && super.isConnected(); mConnectionLock.readLock().unlock(); } } catch(InterruptedException e) {} return connected; }
@Override public void run() { if(!mSource.isRunning() || mSource.isConnected()) { return; } try { mSource.connect(); } catch(DataSourceException e) { Log.d(mSource.toString(), "Unable to connect because of exception", e); } } }
connected = super.isConnected(); if (!connectingToBLE) { if (mSocket == null) {
if(!isConnected() && mConnectionCheckTask == null) { setFastPolling(true); while(isRunning() && !isConnected()) { ++mReconnectionAttempts; mConnectionLock.writeLock().lock();
public void receive(VehicleMessage command) throws DataSinkException { if(isConnected()) { VehicleMessageStreamer streamer; synchronized(this) { streamer = mStreamHandler; if(streamer == null) { // See https://github.com/openxc/openxc-android/issues/181 streamer = new JsonStreamer(); Log.i(getTag(), "Payload format unknown, guessing JSON"); } } try { if(!write(streamer.serializeForStream(command))) { throw new DataSinkException("Unable to send command"); } } catch(SerializationException e) { throw new DataSinkException( "Unable to serialize command for sending", e); } } else { throw new DataSinkException("Not connected"); } }