Skip to content

CSSTUDIO-3113 PVAClient: Accept TCP connections on a separate thread. #3338

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 24 additions & 21 deletions core/pva/src/main/java/org/epics/pva/client/PVAClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -250,32 +250,35 @@ void handleSearchResponse(final int channel_id, final InetSocketAddress server,
channel.setState(ClientChannelState.FOUND);
logger.log(Level.FINE, () -> "Reply for " + channel + " from " + (tls ? "TLS " : "TCP ") + server + " " + guid);

final ClientTCPHandler tcp = tcp_handlers.computeIfAbsent(server, addr ->
{
try
Thread thread = new Thread(() -> {
final ClientTCPHandler tcp = tcp_handlers.computeIfAbsent(server, addr ->
{
return new ClientTCPHandler(this, addr, guid, tls);
try
{
return new ClientTCPHandler(this, addr, guid, tls);
}
catch (Exception ex)
{
logger.log(Level.WARNING, "Cannot connect to TCP " + addr, ex);
}
return null;
});
// In case of connection errors, tcp will be null
if (tcp == null)
{ // Cannot connect to server on provided port? Likely a server or firewall problem.
// On the next search, that same server might reply and then we fail the same way on connect.
// Still, no way around re-registering the search so we succeed once the server is fixed.
search.register(channel, false /* not "now" but eventually */);
}
catch (Exception ex)
else
{
logger.log(Level.WARNING, "Cannot connect to TCP " + addr, ex);
if (tcp.updateGuid(guid))
logger.log(Level.FINE, "Search-only TCP handler received GUID, now " + tcp);

channel.registerWithServer(tcp);
}
return null;
});
// In case of connection errors, tcp will be null
if (tcp == null)
{ // Cannot connect to server on provided port? Likely a server or firewall problem.
// On the next search, that same server might reply and then we fail the same way on connect.
// Still, no way around re-registering the search so we succeed once the server is fixed.
search.register(channel, false /* not "now" but eventually */);
}
else
{
if (tcp.updateGuid(guid))
logger.log(Level.FINE, "Search-only TCP handler received GUID, now " + tcp);

channel.registerWithServer(tcp);
}
thread.start();
}

/** Called by {@link ClientTCPHandler} when connection is lost or closed because unused
Expand Down