test_class.file: core/src/test/java/org/ulordj/core/TransactionBroadcastTest.java
test_class.identifier: TransactionBroadcastTest
test_class.superclass: extends TestWithPeerGroup
test_case.body: @Test
      public void rejectHandling() throws Exception {
          InboundMessageQueuer[] channels = { connectPeer(0), connectPeer(1), connectPeer(2), connectPeer(3), connectPeer(4) };
          Transaction tx = FakeTxBuilder.createFakeTx(UNITTEST);
          TransactionBroadcast broadcast = new TransactionBroadcast(peerGroup, tx);
          ListenableFuture<Transaction> future = broadcast.broadcast();
          // 0 and 3 are randomly selected to receive the broadcast.
          assertEquals(tx, outbound(channels[1]));
          assertEquals(tx, outbound(channels[2]));
          assertEquals(tx, outbound(channels[4]));
          RejectMessage reject = new RejectMessage(UNITTEST, RejectMessage.RejectCode.DUST, tx.getHash(), "tx", "dust");
          inbound(channels[1], reject);
          inbound(channels[4], reject);
          try {
              future.get();
              fail();
          } catch (ExecutionException e) {
              assertEquals(RejectedTransactionException.class, e.getCause().getClass());
          }
      }
test_case.class_method_signature: TransactionBroadcastTest.rejectHandling()
test_case.full_signature: @Test public void rejectHandling()
test_case.identifier: rejectHandling
test_case.invocations: connectPeer connectPeer connectPeer connectPeer connectPeer createFakeTx broadcast assertEquals outbound assertEquals outbound assertEquals outbound getHash inbound inbound get fail assertEquals getClass getCause
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void rejectHandling()
focal_class.declarator: log = LoggerFactory.getLogger(TransactionBroadcast.class)
focal_class.modifier: private static final
focal_class.original_string: private static final Logger log = LoggerFactory.getLogger(TransactionBroadcast.class);
focal_class.type: Logger
focal_class.var_name: log
focal_class.declarator: future = SettableFuture.create()
focal_class.modifier: private final
focal_class.original_string: private final SettableFuture<Transaction> future = SettableFuture.create();
focal_class.type: SettableFuture<Transaction>
focal_class.var_name: future
focal_class.declarator: peerGroup
focal_class.modifier: private final
focal_class.original_string: private final PeerGroup peerGroup;
focal_class.type: PeerGroup
focal_class.var_name: peerGroup
focal_class.declarator: tx
focal_class.modifier: private final
focal_class.original_string: private final Transaction tx;
focal_class.type: Transaction
focal_class.var_name: tx
focal_class.declarator: minConnections
focal_class.modifier: private
focal_class.original_string: private int minConnections;
focal_class.type: int
focal_class.var_name: minConnections
focal_class.declarator: numWaitingFor
focal_class.modifier: private
focal_class.original_string: private int numWaitingFor;
focal_class.type: int
focal_class.var_name: numWaitingFor
focal_class.declarator: random = new Random()
focal_class.modifier: @VisibleForTesting
      public static
focal_class.original_string: @VisibleForTesting
      public static Random random = new Random();
focal_class.type: Random
focal_class.var_name: random
focal_class.declarator: rejects = Collections.synchronizedMap(new HashMap<Peer, RejectMessage>())
focal_class.modifier: private
focal_class.original_string: private Map<Peer, RejectMessage> rejects = Collections.synchronizedMap(new HashMap<Peer, RejectMessage>());
focal_class.type: Map<Peer, RejectMessage>
focal_class.var_name: rejects
focal_class.declarator: rejectionListener = new PreMessageReceivedEventListener() {
          @Override
          public Message onPreMessageReceived(Peer peer, Message m) {
              if (m instanceof RejectMessage) {
                  RejectMessage rejectMessage = (RejectMessage)m;
                  if (tx.getHash().equals(rejectMessage.getRejectedObjectHash())) {
                      rejects.put(peer, rejectMessage);
                      int size = rejects.size();
                      long threshold = Math.round(numWaitingFor / 2.0);
                      if (size > threshold) {
                          log.warn("Threshold for considering broadcast rejected has been reached ({}/{})", size, threshold);
                          future.setException(new RejectedTransactionException(tx, rejectMessage));
                          peerGroup.removePreMessageReceivedEventListener(this);
                      }
                  }
              }
              return m;
          }
      }
focal_class.modifier: private
focal_class.original_string: private PreMessageReceivedEventListener rejectionListener = new PreMessageReceivedEventListener() {
          @Override
          public Message onPreMessageReceived(Peer peer, Message m) {
              if (m instanceof RejectMessage) {
                  RejectMessage rejectMessage = (RejectMessage)m;
                  if (tx.getHash().equals(rejectMessage.getRejectedObjectHash())) {
                      rejects.put(peer, rejectMessage);
                      int size = rejects.size();
                      long threshold = Math.round(numWaitingFor / 2.0);
                      if (size > threshold) {
                          log.warn("Threshold for considering broadcast rejected has been reached ({}/{})", size, threshold);
                          future.setException(new RejectedTransactionException(tx, rejectMessage));
                          peerGroup.removePreMessageReceivedEventListener(this);
                      }
                  }
              }
              return m;
          }
      };
focal_class.type: PreMessageReceivedEventListener
focal_class.var_name: rejectionListener
focal_class.declarator: numSeemPeers
focal_class.modifier: private
focal_class.original_string: private int numSeemPeers;
focal_class.type: int
focal_class.var_name: numSeemPeers
focal_class.declarator: mined
focal_class.modifier: private
focal_class.original_string: private boolean mined;
focal_class.type: boolean
focal_class.var_name: mined
focal_class.declarator: callback
focal_class.modifier: @Nullable private
focal_class.original_string: @Nullable private ProgressCallback callback;
focal_class.type: ProgressCallback
focal_class.var_name: callback
focal_class.declarator: progressCallbackExecutor
focal_class.modifier: @Nullable private
focal_class.original_string: @Nullable private Executor progressCallbackExecutor;
focal_class.type: Executor
focal_class.var_name: progressCallbackExecutor
focal_class.file: core/src/main/java/org/ulordj/core/TransactionBroadcast.java
focal_class.identifier: TransactionBroadcast
focal_class.class_method_signature: TransactionBroadcast.TransactionBroadcast(PeerGroup peerGroup, Transaction tx)
focal_class.full_signature:   TransactionBroadcast(PeerGroup peerGroup, Transaction tx)
focal_class.identifier: TransactionBroadcast
focal_class.parameters: (PeerGroup peerGroup, Transaction tx)
focal_class.signature:  TransactionBroadcast(PeerGroup peerGroup, Transaction tx)
focal_class.class_method_signature: TransactionBroadcast.TransactionBroadcast(Transaction tx)
focal_class.full_signature: private  TransactionBroadcast(Transaction tx)
focal_class.identifier: TransactionBroadcast
focal_class.modifiers: private
focal_class.parameters: (Transaction tx)
focal_class.signature:  TransactionBroadcast(Transaction tx)
focal_class.class_method_signature: TransactionBroadcast.createMockBroadcast(Transaction tx, final SettableFuture<Transaction> future)
focal_class.full_signature: @VisibleForTesting public static TransactionBroadcast createMockBroadcast(Transaction tx, final SettableFuture<Transaction> future)
focal_class.identifier: createMockBroadcast
focal_class.modifiers: @VisibleForTesting public static
focal_class.parameters: (Transaction tx, final SettableFuture<Transaction> future)
focal_class.return: TransactionBroadcast
focal_class.signature: TransactionBroadcast createMockBroadcast(Transaction tx, final SettableFuture<Transaction> future)
focal_class.class_method_signature: TransactionBroadcast.future()
focal_class.full_signature: public ListenableFuture<Transaction> future()
focal_class.identifier: future
focal_class.modifiers: public
focal_class.parameters: ()
focal_class.return: ListenableFuture<Transaction>
focal_class.signature: ListenableFuture<Transaction> future()
focal_class.class_method_signature: TransactionBroadcast.setMinConnections(int minConnections)
focal_class.full_signature: public void setMinConnections(int minConnections)
focal_class.identifier: setMinConnections
focal_class.modifiers: public
focal_class.parameters: (int minConnections)
focal_class.return: void
focal_class.signature: void setMinConnections(int minConnections)
focal_class.class_method_signature: TransactionBroadcast.broadcast()
focal_class.full_signature: public ListenableFuture<Transaction> broadcast()
focal_class.identifier: broadcast
focal_class.modifiers: public
focal_class.parameters: ()
focal_class.return: ListenableFuture<Transaction>
focal_class.signature: ListenableFuture<Transaction> broadcast()
focal_class.class_method_signature: TransactionBroadcast.invokeAndRecord(int numSeenPeers, boolean mined)
focal_class.full_signature: private void invokeAndRecord(int numSeenPeers, boolean mined)
focal_class.identifier: invokeAndRecord
focal_class.modifiers: private
focal_class.parameters: (int numSeenPeers, boolean mined)
focal_class.return: void
focal_class.signature: void invokeAndRecord(int numSeenPeers, boolean mined)
focal_class.class_method_signature: TransactionBroadcast.invokeProgressCallback(int numSeenPeers, boolean mined)
focal_class.full_signature: private void invokeProgressCallback(int numSeenPeers, boolean mined)
focal_class.identifier: invokeProgressCallback
focal_class.modifiers: private
focal_class.parameters: (int numSeenPeers, boolean mined)
focal_class.return: void
focal_class.signature: void invokeProgressCallback(int numSeenPeers, boolean mined)
focal_class.class_method_signature: TransactionBroadcast.setProgressCallback(ProgressCallback callback)
focal_class.full_signature: public void setProgressCallback(ProgressCallback callback)
focal_class.identifier: setProgressCallback
focal_class.modifiers: public
focal_class.parameters: (ProgressCallback callback)
focal_class.return: void
focal_class.signature: void setProgressCallback(ProgressCallback callback)
focal_class.class_method_signature: TransactionBroadcast.setProgressCallback(ProgressCallback callback, @Nullable Executor executor)
focal_class.full_signature: public void setProgressCallback(ProgressCallback callback, @Nullable Executor executor)
focal_class.identifier: setProgressCallback
focal_class.modifiers: public
focal_class.parameters: (ProgressCallback callback, @Nullable Executor executor)
focal_class.return: void
focal_class.signature: void setProgressCallback(ProgressCallback callback, @Nullable Executor executor)
focal_method.body: public ListenableFuture<Transaction> broadcast() {
          peerGroup.addPreMessageReceivedEventListener(Threading.SAME_THREAD, rejectionListener);
          log.info("Waiting for {} peers required for broadcast, we have {} ...", minConnections, peerGroup.getConnectedPeers().size());
          peerGroup.waitForPeers(minConnections).addListener(new EnoughAvailablePeers(), Threading.SAME_THREAD);
          return future;
      }
focal_method.class_method_signature: TransactionBroadcast.broadcast()
focal_method.full_signature: public ListenableFuture<Transaction> broadcast()
focal_method.identifier: broadcast
focal_method.invocations: addPreMessageReceivedEventListener info size getConnectedPeers addListener waitForPeers
focal_method.modifiers: public
focal_method.parameters: ()
focal_method.return: ListenableFuture<Transaction>
focal_method.signature: ListenableFuture<Transaction> broadcast()