Search in sources :

Example 16 with SimpleBooleanProperty

use of javafx.beans.property.SimpleBooleanProperty in project bitsquare by bitsquare.

the class StressTestMailboxMessage method test_direct.

// # DIRECT SENDING AND RECEIVING
/**
     * Test each peer sending a direct message to another random peer.
     */
@Test
public void test_direct() throws InterruptedException {
    final int nPeers = peerNodes.size();
    BooleanProperty sentDirectFailed = new SimpleBooleanProperty(false);
    final List<Long> sentDelays = new Vector<>(nPeers * directCount);
    final CountDownLatch sentDirectLatch = new CountDownLatch(directCount * nPeers);
    final CountDownLatch receivedDirectLatch = new CountDownLatch(directCount * nPeers);
    final long sendStartMillis = System.currentTimeMillis();
    for (final P2PService srcPeer : peerNodes) {
        final NodeAddress srcPeerAddress = srcPeer.getAddress();
        // Make the peer ready for receiving direct messages.
        srcPeer.addDecryptedDirectMessageListener((decryptedMsgWithPubKey, peerNodeAddress) -> {
            if (!(decryptedMsgWithPubKey.message instanceof StressTestDirectMessage))
                return;
            StressTestDirectMessage directMessage = (StressTestDirectMessage) (decryptedMsgWithPubKey.message);
            if ((directMessage.getData().equals("test/" + srcPeerAddress)))
                receivedDirectLatch.countDown();
        });
        long nextSendMillis = System.currentTimeMillis();
        for (int i = 0; i < directCount; i++) {
            // Select a random peer (different than source one) and send a direct message to it...
            int peerIdx;
            NodeAddress peerAddr;
            do {
                peerIdx = (int) (Math.random() * nPeers);
                peerAddr = peerNodes.get(peerIdx).getAddress();
            } while (srcPeerAddress.equals(peerAddr));
            final int dstPeerIdx = peerIdx;
            final NodeAddress dstPeerAddress = peerAddr;
            // ...after a random delay not shorter than throttle limits.
            nextSendMillis += Math.round(Math.random() * (MAX_DIRECT_DELAY_MILLIS - MIN_DIRECT_DELAY_MILLIS));
            final long sendAfterMillis = nextSendMillis - System.currentTimeMillis();
            /*print("sending direct message from peer %s to %s in %sms",
                        srcPeer.getAddress(), dstPeer.getAddress(), sendAfterMillis);*/
            UserThread.runAfter(() -> {
                final long sendMillis = System.currentTimeMillis();
                srcPeer.sendEncryptedDirectMessage(dstPeerAddress, peerPKRings.get(dstPeerIdx), new StressTestDirectMessage("test/" + dstPeerAddress), new SendDirectMessageListener() {

                    @Override
                    public void onArrived() {
                        sentDelays.add(System.currentTimeMillis() - sendMillis);
                        countDownAndPrint(sentDirectLatch, 'd');
                    }

                    @Override
                    public void onFault() {
                        sentDirectFailed.set(true);
                        countDownAndPrint(sentDirectLatch, 'd');
                    }
                });
            }, sendAfterMillis, TimeUnit.MILLISECONDS);
        }
    }
    print("%d direct messages scheduled to be sent by each of %d peers", directCount, nPeers);
    // Since receiving is completed before sending is reported to be complete,
    // all receiving checks should end before all sending checks to avoid deadlocking.
    /** Time to transmit all messages in the worst random case, and with no computation delays. */
    final long idealMaxDirectDelay = MAX_DIRECT_DELAY_MILLIS * directCount;
    // Wait for peers to complete receiving.  We are generous here.
    assertLatch("timed out while receiving direct messages", receivedDirectLatch, 25 * idealMaxDirectDelay, TimeUnit.MILLISECONDS);
    final long recvMillis = System.currentTimeMillis() - sendStartMillis;
    print("receiving %d direct messages per peer took %ss (%.2f x ideal max)", directCount, recvMillis / 1000.0, recvMillis / (float) idealMaxDirectDelay);
    // Wait for peers to complete sending.
    // This should be nearly instantaneous after waiting for reception is completed.
    assertLatch("timed out while sending direct messages", sentDirectLatch, idealMaxDirectDelay / 10, TimeUnit.MILLISECONDS);
    Tuple3<Long, Long, Long> mma = minMaxAvg(sentDelays);
    print("sending %d direct messages per peer took %ss (min/max/avg %s/%s/%s ms)", directCount, (System.currentTimeMillis() - sendStartMillis) / 1000.0, mma.first, mma.second, mma.third);
    org.junit.Assert.assertFalse("some peer(s) failed to send a direct message", sentDirectFailed.get());
}
Also used : SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) BooleanProperty(javafx.beans.property.BooleanProperty) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 17 with SimpleBooleanProperty

use of javafx.beans.property.SimpleBooleanProperty in project Gargoyle by callakrsos.

the class ButtonTableColumn method initialize.

private void initialize(String buttonText, Function<Integer, Boolean> changeFunc) {
    this.changeFunc = changeFunc == null ? (i -> true) : changeFunc;
    this.setStyle(" -fx-alignment: CENTER;");
    ButtonCellFactory value = new ButtonCellFactory(buttonText, this);
    this.setCellFactory(value);
    this.setCellValueFactory(p -> new SimpleBooleanProperty(p.getValue() != null));
}
Also used : SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty)

Example 18 with SimpleBooleanProperty

use of javafx.beans.property.SimpleBooleanProperty in project VocabHunter by VocabHunter.

the class WordStateHandler method initialise.

public void initialise(final Button buttonUnseen, final Button buttonKnown, final Button buttonUnknown, final SessionModel sessionModel, final ObjectBinding<WordState> wordStateProperty, final Runnable nextWordSelector) {
    this.sessionModel = sessionModel;
    this.nextWordSelector = nextWordSelector;
    SimpleBooleanProperty editableProperty = sessionModel.editableProperty();
    BooleanBinding resettableProperty = editableProperty.and(notEqual(WordState.UNSEEN, wordStateProperty));
    buttonUnseen.visibleProperty().bind(resettableProperty);
    buttonKnown.visibleProperty().bind(editableProperty);
    buttonUnknown.visibleProperty().bind(editableProperty);
    buttonUnseen.setOnAction(e -> processResponse(WordState.UNSEEN, false));
    buttonKnown.setOnAction(e -> processResponse(WordState.KNOWN, true));
    buttonUnknown.setOnAction(e -> processResponse(WordState.UNKNOWN, true));
}
Also used : SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) BooleanBinding(javafx.beans.binding.BooleanBinding)

Example 19 with SimpleBooleanProperty

use of javafx.beans.property.SimpleBooleanProperty in project PretendYoureXyzzyReborn by devgianlu.

the class CheckboxCardSetCell method updateItem.

@Override
public void updateItem(CCompactCardSet item, boolean empty) {
    if (!empty) {
        setSelectedStateCallback(param -> {
            SimpleBooleanProperty property = new SimpleBooleanProperty(newOptions.cardSetIds.contains(item.id));
            property.addListener((observable, oldValue, newValue) -> {
                if (newValue) {
                    if (!newOptions.cardSetIds.contains(item.id))
                        newOptions.cardSetIds.add(item.id);
                } else {
                    newOptions.cardSetIds.remove((Integer) item.id);
                }
            });
            return property;
        });
    }
    super.updateItem(item, empty);
    if (!empty)
        setText(item.name);
    Node node = getGraphic();
    if (node != null)
        node.setDisable(!amHost);
}
Also used : SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) Node(javafx.scene.Node)

Aggregations

SimpleBooleanProperty (javafx.beans.property.SimpleBooleanProperty)19 BooleanProperty (javafx.beans.property.BooleanProperty)8 FXML (javafx.fxml.FXML)4 CountDownLatch (java.util.concurrent.CountDownLatch)3 ObservableValue (javafx.beans.value.ObservableValue)3 ActionEvent (javafx.event.ActionEvent)3 IManager (EmployeeContracts.IManager)2 ConnectionFailure (EmployeeDefs.AEmployeeException.ConnectionFailure)2 EmployeeNotConnected (EmployeeDefs.AEmployeeException.EmployeeNotConnected)2 InvalidParameter (EmployeeDefs.AEmployeeException.InvalidParameter)2 Manager (EmployeeImplementations.Manager)2 CriticalError (SMExceptions.CommonExceptions.CriticalError)2 InjectionFactory (UtilsImplementations.InjectionFactory)2 StackTraceUtil (UtilsImplementations.StackTraceUtil)2 JFXButton (com.jfoenix.controls.JFXButton)2 JFXListView (com.jfoenix.controls.JFXListView)2 JFXTextField (com.jfoenix.controls.JFXTextField)2 URL (java.net.URL)2 HashSet (java.util.HashSet)2 ResourceBundle (java.util.ResourceBundle)2