Example usage for java.lang Object notifyAll

List of usage examples for java.lang Object notifyAll

Introduction

In this page you can find the example usage for java.lang Object notifyAll.

Prototype

@HotSpotIntrinsicCandidate
public final native void notifyAll();

Source Link

Document

Wakes up all threads that are waiting on this object's monitor.

Usage

From source file:RemoteDeviceDiscovery.java

public static void findDevices() throws IOException, InterruptedException {

    final Object inquiryCompletedEvent = new Object();

    devicesDiscovered.clear();/*from  w  ww  .  j av a2 s  .co m*/

    DiscoveryListener listener = new DiscoveryListener() {

        public void deviceDiscovered(RemoteDevice btDevice, DeviceClass cod) {
            if (debug)
                System.out.println("#" + "Device " + btDevice.getBluetoothAddress() + " found");
            devicesDiscovered.add(btDevice);
            try {
                if (debug)
                    System.out.println("#" + "     name " + btDevice.getFriendlyName(false));
            } catch (IOException cantGetDeviceName) {
            }
        }

        public void inquiryCompleted(int discType) {
            if (debug)
                System.out.println("#" + "Device Inquiry completed!");
            synchronized (inquiryCompletedEvent) {
                inquiryCompletedEvent.notifyAll();
            }
        }

        public void serviceSearchCompleted(int transID, int respCode) {
        }

        public void servicesDiscovered(int transID, ServiceRecord[] servRecord) {
            if (debug)
                System.out.println("#" + "servicesDiscovered");
        }
    };

    synchronized (inquiryCompletedEvent) {

        //ServiceRecord.

        LocalDevice ld = LocalDevice.getLocalDevice();
        //ld.getRecord()

        if (debug)
            System.out.println("#My Name is:" + ld.getFriendlyName());

        //           boolean started = LocalDevice.getLocalDevice().getDiscoveryAgent().startInquiry(DiscoveryAgent.LIAC, listener);
        //            if (started) {
        //               if (debug) System.out.println("wait for device inquiry to complete...");
        //                inquiryCompletedEvent.wait();
        //                if (debug) System.out.println(devicesDiscovered.size() +  " device(s) found");
        //            }

        boolean started = LocalDevice.getLocalDevice().getDiscoveryAgent().startInquiry(DiscoveryAgent.GIAC,
                listener);
        if (started) {
            if (debug)
                System.out.println("#" + "wait for device inquiry to complete...");
            inquiryCompletedEvent.wait();
            if (debug)
                System.out.println("#" + devicesDiscovered.size() + " device(s) found");
        }
    }

}

From source file:net.radai.confusion.core.inmem.InMemBinaryStoreTest.java

@Override
protected void writeUnderlying(BinaryStore store, byte[] value) throws Exception {
    InMemBinaryStore inMem = (InMemBinaryStore) store;
    ReflectionTestUtils.setField(inMem, "payload", value);
    final Object lock = ReflectionTestUtils.getField(inMem, "lock");
    //noinspection SynchronizationOnLocalVariableOrMethodParameter
    synchronized (lock) {
        lock.notifyAll();
    }//w w  w  . j a  v  a  2s  .  com
}

From source file:net.radai.confusion.core.inmem.InMemTextStoreTest.java

@Override
protected void writeUnderlying(TextStore store, String value) throws Exception {
    InMemTextStore inMem = (InMemTextStore) store;
    ReflectionTestUtils.setField(inMem, "payload", value);
    final Object lock = ReflectionTestUtils.getField(inMem, "lock");
    //noinspection SynchronizationOnLocalVariableOrMethodParameter
    synchronized (lock) {
        lock.notifyAll();
    }/*from  w w w  .  ja  va  2  s. com*/
}

From source file:com.zapp.library.merchant.test.TestUtils.java

/**
 * Change orientation of given activity and wait until the popup re-appears.
 *
 * @param activity The activity to rotate.
 * @param newOrientation The new orientation to change to.
 * @throws InterruptedException If thread synchronisation is interrupted.
 * @return The new activity after orientation change.
 *//*from  w w  w  .j a  v  a2s .com*/
@SuppressWarnings({ "SynchronizationOnLocalVariableOrMethodParameter", "UnconditionalWait", "WaitNotInLoop",
        "SameParameterValue" })
public static FragmentActivity changeOrientationWithPopup(@NonNull final FragmentActivity activity,
        final int newOrientation) throws InterruptedException {
    final Object monitor = new Object();
    final Wrapper<FragmentActivity> wrapper = new Wrapper<>(activity);

    activity.setRequestedOrientation(newOrientation);
    //wait until the popup re-appears
    Espresso.onView(ViewMatchers.withId(R.id.pbba_popup_container)).perform(ViewActions.click());

    activity.runOnUiThread(new Runnable() {
        @SuppressWarnings("NakedNotify")
        @Override
        public void run() {
            final Collection<Activity> activities = ActivityLifecycleMonitorRegistry.getInstance()
                    .getActivitiesInStage(Stage.RESUMED);
            final int numberOfActivities = activities.size();
            if (numberOfActivities != 1) {
                throw new IllegalStateException(
                        String.format(Locale.ENGLISH, "activities.size() = %d", numberOfActivities));
            }
            final TestActivity landscapeActivity = (TestActivity) activities.iterator().next();

            wrapper.setObject(landscapeActivity);

            synchronized (monitor) {
                //noinspection NakedNotify
                monitor.notifyAll();
            }
        }
    });

    synchronized (monitor) {
        //wait for popup callback re-connect on the UI thread.
        monitor.wait(WAIT_TIMEOUT_MS);
    }

    return wrapper.getObject();
}

From source file:org.rifidi.emulator.reader.command.controller.abstract_.AbstractOnCommandControllerPowerState.java

/**
 * Suspends the command controller, updating suspended/interruption
 * variables as necessary. <br>//from   w  ww  .  j av  a2  s.  c o  m
 * 
 * Note that this does NOT switch the power state, since there is no
 * concrete implementation known.
 * 
 * @see org.rifidi.emulator.common.PowerState#suspend(org.rifidi.emulator.common.PowerControllable)
 */
public void suspend(PowerControllable pcObject) {
    /* Cast to an AbstractCommandController */
    AbstractCommandController abstractController = (AbstractCommandController) pcObject;

    /* Synchronize on the passed processor's suspension lock */
    Object lock = abstractController.getSuspensionLock();
    synchronized (lock) {
        /* Clear suspension status */
        abstractController.setSuspended(true);

        /* Notify anything waiting */
        lock.notifyAll();

    }

}

From source file:org.rifidi.emulator.reader.command.controller.abstract_.AbstractOnCommandControllerPowerState.java

/**
 * Turns off the command controller, updating suspended/interruption
 * variables as necessary. <br>//from   ww  w.j  a  v a2  s  .c  o m
 * 
 * Note that this does NOT switch the power state, since there is no
 * concrete implementation known.
 * 
 * @see org.rifidi.emulator.common.PowerState#turnOff(org.rifidi.emulator.common.PowerControllable)
 */
@SuppressWarnings("unchecked")
public void turnOff(PowerControllable pcObject, Class callingClass) {

    /* Cast to an AbstractCommandController */
    AbstractCommandController abstractController = (AbstractCommandController) pcObject;

    /* Synchronize on the passed processor's suspension lock */
    Object lock = abstractController.getSuspensionLock();
    synchronized (lock) {
        /* Turn on interruption status */
        abstractController.setInterrupted(true);

        /* Notify anything waiting */
        lock.notifyAll();

    }

}

From source file:org.rifidi.emulator.reader.command.controller.abstract_.AbstractSuspendedCommandControllerPowerState.java

/**
 * Resumes the command controller, updating suspended/interruption variables
 * as necessary. <br>// w w  w. j  a  v a2s .  co  m
 * 
 * Note that this does NOT switch the power state, since there is no
 * concrete implementation known.
 * 
 * @see org.rifidi.emulator.common.PowerState#resume(org.rifidi.emulator.common.PowerControllable)
 */
public void resume(PowerControllable pcObject) {
    /* Cast to an AbstractCommandController */
    AbstractCommandController abstractController = (AbstractCommandController) pcObject;

    /* Synchronize on the passed processor's suspension lock */
    Object lock = abstractController.getSuspensionLock();
    synchronized (lock) {
        /* Clear suspension status */
        abstractController.setSuspended(false);

        /* Notify anything waiting */
        lock.notifyAll();

    }

}

From source file:org.rifidi.emulator.reader.command.controller.abstract_.AbstractSuspendedCommandControllerPowerState.java

/**
 * Turns off the command controller, updating suspended/interruption
 * variables as necessary. <br>//from www  . j  a  v a  2 s  .  c  om
 * 
 * Note that this does NOT switch the power state, since there is no
 * concrete implementation known.
 * 
 * @see org.rifidi.emulator.common.PowerState#turnOff(org.rifidi.emulator.common.PowerControllable)
 */
@SuppressWarnings("unchecked")
public void turnOff(PowerControllable pcObject, Class callingClass) {

    logger.debug("turned off by " + callingClass);

    /* Cast to an AbstractCommandController */
    AbstractCommandController abstractController = (AbstractCommandController) pcObject;

    /* Synchronize on the passed processor's suspension lock */
    Object lock = abstractController.getSuspensionLock();
    synchronized (lock) {
        /* Clear suspension status */
        abstractController.setSuspended(false);

        /* Turn on interruption status */
        abstractController.setInterrupted(true);

        /* Notify anything waiting */
        lock.notifyAll();

    }

}

From source file:org.logicblaze.lingo.cache.ClusteredCacheManager.java

protected void notifyOriginator(String originator) {
    Object lock = null;
    synchronized (locks) {
        lock = locks.get(originator);//from   w w  w. j a v a  2  s. c  o  m
    }
    if (lock != null) {
        if (log.isTraceEnabled()) {
            log.trace("Notifying orginator: " + originator + " with lock: " + lock);
        }
        synchronized (lock) {
            lock.notifyAll();
        }
        // now lets remove the lock in case
        // the other thread misses the notify
        synchronized (locks) {
            locks.remove(originator);
        }
    } else {
        if (log.isTraceEnabled()) {
            log.trace("Igoring notification from originator from another JVM: " + originator);
        }
    }
}

From source file:org.openengsb.connector.maven.internal.MavenServiceTest.java

private void makeNotifyAnswerForBuildSuccess(final Object syncFinish) {
    doAnswer(new Answer<Void>() {
        @Override//w w  w .  j a  va  2  s .  c o  m
        public Void answer(InvocationOnMock invocation) throws Throwable {
            synchronized (syncFinish) {
                syncFinish.notifyAll();
            }
            return null;
        }
    }).when(buildEvents).raiseEvent(any(BuildSuccessEvent.class));
}