本文整理汇总了Java中java.net.SocketAddress.equals方法的典型用法代码示例。如果您正苦于以下问题:Java SocketAddress.equals方法的具体用法?Java SocketAddress.equals怎么用?Java SocketAddress.equals使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.net.SocketAddress
的用法示例。
在下文中一共展示了SocketAddress.equals方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: closeConnectionAsync
import java.net.SocketAddress; //导入方法依赖的package包/类
@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;
}
示例2: closeConnectionAsync
import java.net.SocketAddress; //导入方法依赖的package包/类
@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;
}
示例3: run
import java.net.SocketAddress; //导入方法依赖的package包/类
@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) { }
}
}