void setOwner(final BareJid owner) { this.owner = owner; Async.go(new Runnable() { @Override public void run() { for (ThingStateChangeListener thingStateChangeListener : listeners) { thingStateChangeListener.owned(owner); } } }); }
/** * Creates a new thread with the given Runnable, marks it daemon, starts it and returns the started thread. * * @param runnable * @return the started thread. */ public static Thread go(Runnable runnable) { Thread thread = daemonThreadFrom(runnable); thread.start(); return thread; }
@Override public void processStanza(final Stanza packet) { Async.go(new Runnable() { @Override public void run() { try { getOmemoService().onOmemoMessageStanzaReceived(packet, new LoggedInOmemoManager(OmemoManager.this)); } catch (SmackException.NotLoggedInException e) { LOGGER.warning("Received OMEMO stanza while being offline: " + e); } } }); } };
/** * Creates a new thread with the given Runnable, marks it daemon, sets the name, starts it and returns the started * thread. * * @param runnable * @param threadName the thread name. * @return the started thread. */ public static Thread go(Runnable runnable, String threadName) { Thread thread = daemonThreadFrom(runnable); thread.setName(threadName); thread.start(); return thread; }
@Override public void onCarbonCopyReceived(final CarbonExtension.Direction direction, final Message carbonCopy, final Message wrappingMessage) { Async.go(new Runnable() { @Override public void run() { if (omemoMessageStanzaFilter.accept(carbonCopy)) { try { getOmemoService().onOmemoCarbonCopyReceived(direction, carbonCopy, wrappingMessage, new LoggedInOmemoManager(OmemoManager.this)); } catch (SmackException.NotLoggedInException e) { LOGGER.warning("Received OMEMO carbon copy while being offline: " + e); } } } }); } };
/** * Creates a new thread with the given Runnable, marks it daemon, starts it and returns the started thread. * * @param runnable * @return the started thread. */ public static Thread go(Runnable runnable) { Thread thread = daemonThreadFrom(runnable); thread.start(); return thread; }
/** * Initialize the manager without blocking. Once the manager is successfully initialized, the finishedCallback will * be notified. It will also get notified, if an error occurs. * * @param finishedCallback callback that gets called once the manager is initialized. */ public void initializeAsync(final InitializationFinishedCallback finishedCallback) { Async.go(new Runnable() { @Override public void run() { try { initialize(); finishedCallback.initializationFinished(OmemoManager.this); } catch (Exception e) { finishedCallback.initializationFailed(e); } } }); }
/** * Creates a new thread with the given Runnable, marks it daemon, sets the name, starts it and returns the started * thread. * * @param runnable * @param threadName the thread name. * @return the started thread. */ public static Thread go(Runnable runnable, String threadName) { Thread thread = daemonThreadFrom(runnable); thread.setName(threadName); thread.start(); return thread; }
@Override public void newIncomingMessage(final EntityBareJid from, final Message message, Chat chat) { Async.go(new Runnable() { @Override public void run() {
/** * 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 Reader (" + getConnectionCounter() + ")"); }
/** * 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() + ')'); }
if (mucs.isEmpty()) return; Async.go(new Runnable() { @Override public void run() {
@Override public void eventReceived(final EntityBareJid from, final EventElement event, final Message message) { if (PEP_NODE_PUBLIC_KEYS.equals(event.getEvent().getNode())) { final BareJid contact = from.asBareJid(); LOGGER.log(Level.INFO, "Received OpenPGP metadata update from " + contact); Async.go(new Runnable() { @Override public void run() { ItemsExtension items = (ItemsExtension) event.getExtensions().get(0); PayloadItem<?> payload = (PayloadItem) items.getItems().get(0); PublicKeysListElement listElement = (PublicKeysListElement) payload.getPayload(); processPublicKeysListElement(from, listElement); } }, "ProcessOXMetadata"); } } };
Async.go(new Runnable() { @Override public void run() {
/** * 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 Writer (" + getConnectionCounter() + ")"); }
@Test(expected = TestException.class) public void exceptionTestResultSyncPoint() throws Exception { final CyclicBarrier barrier = new CyclicBarrier(2); final ResultSyncPoint<String, TestException> rsp = new ResultSyncPoint<>(); Async.go(new Async.ThrowingRunnable() { @Override public void runOrThrow() throws InterruptedException, BrokenBarrierException { barrier.await(); rsp.signal(new TestException()); } }); barrier.await(); rsp.waitForResult(60 * 1000); }
@Test public void testResultSyncPoint() throws Exception { final String result = "Hip Hip Hurrary!!111!"; final CyclicBarrier barrier = new CyclicBarrier(2); final ResultSyncPoint<String, Exception> rsp = new ResultSyncPoint<>(); Async.go(new Async.ThrowingRunnable() { @Override public void runOrThrow() throws InterruptedException, BrokenBarrierException { barrier.await(); rsp.signal(result); } }); barrier.await(); String receivedResult = rsp.waitForResult(60 * 1000); assertEquals(result, receivedResult); }
" Received: " + Arrays.toString(receivedDeviceList.copyDeviceIds().toArray()) + " Published: " + Arrays.toString(newDeviceList.copyDeviceIds().toArray())); Async.go(new Runnable() { @Override public void run() {
void setOwner(final BareJid owner) { this.owner = owner; Async.go(new Runnable() { @Override public void run() { for (ThingStateChangeListener thingStateChangeListener : listeners) { thingStateChangeListener.owned(owner); } } }); }
/** * 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() + ')'); }