Java Code Examples for java.net.SocketAddress.equals()

The following are Jave code examples for showing how to use equals() of the java.net.SocketAddress class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: simulacron   File: BoundCluster.java   View Source Code Vote up 6 votes
@Override
public CompletionStage<ClusterConnectionReport> closeConnectionAsync(
    SocketAddress connection, CloseType type) {

  for (BoundNode node : this.getNodes()) {
    // identify the node that has the connection and close it with that node.
    for (SocketAddress address : node.getConnections().getConnections()) {
      if (connection.equals(address)) {
        return node.closeConnectionAsync(address, type)
            .thenApply(NodeConnectionReport::getRootReport);
      }
    }
  }

  CompletableFuture<ClusterConnectionReport> failedFuture = new CompletableFuture<>();
  failedFuture.completeExceptionally(new IllegalArgumentException("Not found"));
  return failedFuture;
}
 
Example 2
Project: simulacron   File: BoundDataCenter.java   View Source Code Vote up 6 votes
@Override
public CompletionStage<DataCenterConnectionReport> closeConnectionAsync(
    SocketAddress connection, CloseType type) {

  for (BoundNode node : this.getNodes()) {
    // identify the node that has the connection and close it with that node.
    for (SocketAddress address : node.getConnections().getConnections()) {
      if (connection.equals(address)) {
        return node.closeConnectionAsync(address, type)
            .thenApply(n -> n.getRootReport().getDataCenters().iterator().next());
      }
    }
  }

  CompletableFuture<DataCenterConnectionReport> failedFuture = new CompletableFuture<>();
  failedFuture.completeExceptionally(new IllegalArgumentException("Not found"));
  return failedFuture;
}
 
Example 3
Project: openjdk-jdk10   File: EmptyBuffer.java   View Source Code Vote up 5 votes
@Override
public void run() {
    try {
        ByteBuffer bb = ByteBuffer.allocateDirect(12);
        bb.clear();
        // Only one clear. The buffer will be full after
        // the first receive, but it should still block
        // and receive and discard the next two
        int numberReceived = 0;
        while (!Thread.interrupted()) {
            SocketAddress sa;
            try {
                sa = dc.receive(bb);
            } catch (ClosedByInterruptException cbie) {
                // Expected
                log.println("Took expected exit");
                // Verify that enough packets were received
                if (numberReceived != 3)
                    throw new RuntimeException("Failed: Too few datagrams");
                break;
            }
            if (sa != null) {
                log.println("Client: " + sa);
                // Check client address so as not to count stray packets
                if (sa.equals(clientAddress)) {
                    showBuffer("RECV", bb);
                    numberReceived++;
                }
                if (numberReceived > 3)
                    throw new RuntimeException("Failed: Too many datagrams");
                sa = null;
            }
        }
    } catch (Exception ex) {
        e = ex;
    } finally {
        try { dc.close(); } catch (IOException ignore) { }
    }
}