Java 类org.jivesoftware.smack.util.Async 实例源码

项目:android-xmpp-iot-demo    文件:ClaimThingActivity.java   
@Override
public void onCreate(Bundle savedInstance) {
    super.onCreate(savedInstance);

    setContentView(R.layout.activity_claim_thing);

    mRegistryTextView = (TextView) findViewById(R.id.registry_text_view);
    mSnTextView = (TextView) findViewById(R.id.sn_text_view);
    mManTextView = (TextView) findViewById(R.id.man_text_view);
    mModelTextView = (TextView) findViewById(R.id.model_text_view);
    mVTextView = (TextView) findViewById(R.id.v_text_view);
    mKeyTextView = (TextView) findViewById(R.id.key_text_view);

    mClaimButton = (Button) findViewById(R.id.claim_button);

    mXmppManger = XmppManager.getInstance(this);

    Async.go(() -> findRegistry());
}
项目:android-xmpp-iot-demo    文件:XiotBluetoothLeManager.java   
void startBleDeviceDiscovery() {

        if (mBluetoothAdapter == null || !mBluetoothAdapter.isEnabled()) return;

        if (mBluetoothLeScanOngoing) return;

        Async.go(() -> {
            try {
                Thread.sleep(SCAN_PERIOD);
            } catch (InterruptedException e) {
                throw new AssertionError(e);
            }

            stopBleDeviceDiscovery();
        });

        LOGGER.info("Starting Bluetooth LE scan on " + mBluetoothAdapter);
        MainActivity.withMainActivity((ma) -> {
            Toast.makeText(ma, "Starting Bluetooth LE scan", Toast.LENGTH_SHORT).show();
        });
        mBluetoothLeScanOngoing = true;
        mBluetoothAdapter.startLeScan(mLeScanCallback);
    }
项目:Smack    文件:XMPPTCPConnection.java   
/** 
* Initializes the writer in order to be used. It is called at the first connection and also 
* is invoked if the connection is disconnected by an error.
*/ 
void init() {
    shutdownDone.init();
    shutdownTimestamp = null;

    if (unacknowledgedStanzas != null) {
        // It's possible that there are new stanzas in the writer queue that
        // came in while we were disconnected but resumable, drain those into
        // the unacknowledged queue so that they get resent now
        drainWriterQueueToUnacknowledgedStanzas();
    }

    queue.start();
    Async.go(new Runnable() {
        @Override
        public void run() {
            writePackets();
        }
    }, "Smack Packet Writer (" + getConnectionCounter() + ")");
}
项目:Smack    文件:ReconnectionManager.java   
/**
 * Starts a reconnection mechanism if it was configured to do that.
 * The algorithm is been executed when the first connection error is detected.
 */
private synchronized void reconnect() {
    XMPPConnection connection = this.weakRefConnection.get();
    if (connection == null) {
        LOGGER.fine("Connection is null, will not reconnect");
        return;
    }
    // Since there is no thread running, creates a new one to attempt
    // the reconnection.
    // avoid to run duplicated reconnectionThread -- fd: 16/09/2010
    if (reconnectionThread != null && reconnectionThread.isAlive())
        return;

    reconnectionThread = Async.go(reconnectionRunnable,
                    "Smack Reconnection Manager (" + connection.getConnectionCounter() + ')');
}
项目:androidclient    文件:XMPPTCPConnection.java   
/**
* Initializes the writer in order to be used. It is called at the first connection and also
* is invoked if the connection is disconnected by an error.
*/
void init() {
    shutdownDone.init();
    shutdownTimestamp = null;

    if (unacknowledgedStanzas != null) {
        // It's possible that there are new stanzas in the writer queue that
        // came in while we were disconnected but resumable, drain those into
        // the unacknowledged queue so that they get resent now
        drainWriterQueueToUnacknowledgedStanzas();
    }

    queue.start();
    Async.go(new Runnable() {
        @Override
        public void run() {
            writePackets();
        }
    }, "Smack Packet Writer (" + getConnectionCounter() + ")");
}
项目:maxs    文件:SendStanzaDatabaseHandler.java   
@Override
public void connected(final XMPPConnection connection) {
    final List<Stanza> toResend = mSendUnackedStanzasTable.getAllAndDelete();
    if (toResend.isEmpty()) {
        return;
    }
    Async.go(new Runnable() {
        @Override
        public void run() {
            for (Stanza stanza : toResend) {
                try {
                    connection.sendStanza(stanza);
                } catch (NotConnectedException | InterruptedException e) {
                    // Simply abort if sending the stanzas throws an exception. We could
                    // consider re-adding the stanzas that weren't send to the database, but
                    // right now, just abort.
                    LOG.w("resend unacked stanzas got exception, aborting", e);
                    break;
                }
            }
        }
    }, "Re-send unacked stanzas");
}
项目:maxs    文件:XMPPService.java   
public void notifyAboutNewMasterAddress(final EntityBareJid newMasterAddress) {
    final XMPPConnection connection = getConnection();
    if (connection == null || !connection.isAuthenticated()) {
        return;
    }

    final Roster roster = Roster.getInstanceFor(connection);

    Async.go(new ThrowingRunnable() {
        @Override
        public void runOrThrow() throws NotLoggedInException, NotConnectedException,
                FeatureNotSupportedException, InterruptedException {
            if (roster.isSubscriptionPreApprovalSupported()) {
                roster.preApprove(newMasterAddress);
            }
            RosterUtil.askForSubscriptionIfRequired(roster, newMasterAddress);
        }
    });
}
项目:android-xmpp-iot-demo    文件:XmppIotDataControl.java   
private void performContiniousReadOut() {
    Async.go(() -> {
        if (!mContinousReadOut) return;
        try {
            Thread.sleep(500);
        } catch (InterruptedException e) {
            LOGGER.log(Level.INFO, "Interrupted", e);
        }
        if (mContinousReadOut) {
            performReadOut();
            performContiniousReadOut();
        }
    });
}
项目:Smack    文件:XMPPTCPConnection.java   
/**
 * Initializes the reader in order to be used. The reader is initialized during the
 * first connection and when reconnecting due to an abruptly disconnection.
 */
void init() {
    done = false;

    Async.go(new Runnable() {
        public void run() {
            parsePackets();
        }
    }, "Smack Packet Reader (" + getConnectionCounter() + ")");
 }
项目:Smack    文件:ServerPingWithAlarmManager.java   
@Override
public void onReceive(Context context, Intent intent) {
    LOGGER.fine("Ping Alarm broadcast received");
    Set<Entry<XMPPConnection, ServerPingWithAlarmManager>> managers;
    synchronized (ServerPingWithAlarmManager.class) {
        // Make a copy to avoid ConcurrentModificationException when
        // iterating directly over INSTANCES and the Set is modified
        // concurrently by creating a new ServerPingWithAlarmManager.
        managers = new HashSet<>(INSTANCES.entrySet());
    }
    for (Entry<XMPPConnection, ServerPingWithAlarmManager> entry : managers) {
        XMPPConnection connection = entry.getKey();
        if (entry.getValue().isEnabled()) {
            LOGGER.fine("Calling pingServerIfNecessary for connection "
                    + connection.getConnectionCounter());
            final PingManager pingManager = PingManager.getInstanceFor(connection);
            // Android BroadcastReceivers have a timeout of 60 seconds.
            // The connections reply timeout may be higher, which causes
            // timeouts of the broadcast receiver and a subsequent ANR
            // of the App of the broadcast receiver. We therefore need
            // to call pingServerIfNecessary() in a new thread to avoid
            // this. It could happen that the device gets back to sleep
            // until the Thread runs, but that's a risk we are willing
            // to take into account as it's unlikely.
            Async.go(new Runnable() {
                @Override
                public void run() {
                    pingManager.pingServerIfNecessary();
                }
            }, "PingServerIfNecessary (" + connection.getConnectionCounter() + ')');
        } else {
            LOGGER.fine("NOT calling pingServerIfNecessary (disabled) on connection "
                    + connection.getConnectionCounter());
        }
    }
}
项目:androidclient    文件:XMPPTCPConnection.java   
/**
 * Initializes the reader in order to be used. The reader is initialized during the
 * first connection and when reconnecting due to an abruptly disconnection.
 */
void init() {
    done = false;

    Async.go(new Runnable() {
        @Override
        public void run() {
            parsePackets();
        }
    }, "Smack Packet Reader (" + getConnectionCounter() + ")");
 }
项目:maxs    文件:TransportService.java   
@Override
public void onDestroy() {
    super.onDestroy();
    LOG.d("onDestroy");

    // We already unregister the receiver in onHandleIntent(), but in order to avoid leaking the
    // receiver, we make sure it's really unregistered by calling unregister() here, in
    // onDestroy(), again.
    NetworkConnectivityReceiver.unregister(this);

    final XMPPService xmppService = mXMPPService;
    if (xmppService != null) {
        // Ensure that all receivers are unregistered by calling XMPPService.disconnect(). We
        // need to perform that action async, since onDestory() is called from the main thread,
        // disconnect() is possible causing network IO and we want to avoid a
        // NetworkOnMainThreadException. Note that we can not use the Service's Looper, since it
        // will be already exited, because we already called super.onDestory().
        Async.go(new Runnable() {
            @Override
            public void run() {
                xmppService.disconnect();
            }
        });
    }

    XMPPEntityCapsCache.onDestroy(this);
    ServerPingWithAlarmManager.onDestroy();
}
项目:android-xmpp-iot-demo    文件:ClaimThingActivity.java   
public void claimButtonClicked(View view) {
    final String sn = mSnTextView.getText().toString();
    if (StringUtils.isNullOrEmpty(sn)) {
        showInGui("SN not set");
        return;
    }

    final String man = mManTextView.getText().toString();
    if (StringUtils.isNullOrEmpty(man)) {
        showInGui("MAN not set");
        return;
    }

    final String model = mModelTextView.getText().toString();
    if (StringUtils.isNullOrEmpty(model)) {
        showInGui("MODEL not set");
        return;
    }

    final String v = mVTextView.getText().toString();
    if (StringUtils.isNullOrEmpty(v)) {
        showInGui("V not set");
        return;
    }

    final String key = mKeyTextView.getText().toString();
    if (StringUtils.isNullOrEmpty(key)) {
        showInGui("KEY not set");
        return;
    }

    final Thing thing = Thing.builder()
            .setSerialNumber(sn)
            .setManufacturer(man)
            .setModel(model)
            .setVersion(v)
            .setKey(key)
            .build();

    Async.go(() -> claimButtonClicked(thing));
}
项目:android-xmpp-iot-demo    文件:XmppIotDataControl.java   
private void performReadOutAsync() {
    Async.go(() -> performReadOut());
}
项目:android-xmpp-iot-demo    文件:XmppIotDataControl.java   
private void controlNotificationAlarmAsync(boolean torchMode) {
    Async.go(() -> controlNotificationAlarm(torchMode));
}
项目:android-xmpp-iot-demo    文件:Feedback.java   
static void shareFeedbackAsync(Context context) {
    Async.go(() -> shareFeedback(context));
}
项目:androidclient    文件:MessageCenterService.java   
@Override
public void authenticated(XMPPConnection connection, boolean resumed) {
    Log.v(TAG, "authenticated!");

    // add message ack listener
    if (mConnection.isSmEnabled()) {
        mConnection.removeAllStanzaIdAcknowledgedListeners();
    }
    else {
        Log.w(TAG, "stream management not available - disabling delivery receipts");
    }

    // send presence
    sendPresence(mIdleHandler.isHeld() ? Presence.Mode.available : Presence.Mode.away);
    // clear upload service
    if (mUploadServices != null)
        mUploadServices.clear();
    // discovery
    discovery();

    // helper is not needed any more
    mHelper = null;

    broadcast(ACTION_CONNECTED);

    // we can now release any pending push notification
    Preferences.setLastPushNotification(-1);

    // force inactive state if needed
    mIdleHandler.forceInactiveIfNeeded();

    // update alarm manager
    AndroidAdaptiveServerPingManager
        .getInstanceFor(connection, this)
        .onConnectionCompleted();

    // request server key if needed
    Async.go(new Runnable() {
        @Override
        public void run() {
            final XMPPConnection conn = mConnection;
            if (conn != null && conn.isConnected()) {
                Jid jid = conn.getServiceName();
                if (Keyring.getPublicKey(MessageCenterService.this, jid.toString(), MyUsers.Keys.TRUST_UNKNOWN) == null) {
                    PublicKeyPublish pub = new PublicKeyPublish();
                    pub.setTo(jid);
                    sendPacket(pub, false);
                }
            }
        }
    });

    // release the wakelock
    mWakeLock.release();
}