本文整理匯總了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) { }
}
}