mirror of
https://github.com/Febbweiss/logstash-forwarder-java.git
synced 2026-03-04 22:25:39 +00:00
Corrected bug in connection retry.
This commit is contained in:
@@ -100,10 +100,20 @@ public class Forwarder {
|
||||
private static void connectToServer() {
|
||||
int randomServerIndex = 0;
|
||||
List<String> serverList = configManager.getConfig().getNetwork().getServers();
|
||||
if(adapter != null) {
|
||||
try {
|
||||
adapter.close();
|
||||
} catch(AdapterException e) {
|
||||
logger.error("Error while closing connection to " + adapter.getServer() + ":" + adapter.getPort());
|
||||
} finally {
|
||||
adapter = null;
|
||||
}
|
||||
}
|
||||
while(adapter == null) {
|
||||
try {
|
||||
randomServerIndex = random.nextInt(serverList.size());
|
||||
String[] serverAndPort = serverList.get(randomServerIndex).split(":");
|
||||
logger.info("Trying to connect to " + serverList.get(randomServerIndex));
|
||||
adapter = new LumberjackClient(configManager.getConfig().getNetwork().getSslCA(),serverAndPort[0],Integer.parseInt(serverAndPort[1]));
|
||||
reader.setAdapter(adapter);
|
||||
} catch(Exception ex) {
|
||||
|
||||
@@ -24,4 +24,6 @@ import java.util.List;
|
||||
public interface ProtocolAdapter {
|
||||
public int sendEvents(List<Event> eventList) throws AdapterException;
|
||||
public void close() throws AdapterException;
|
||||
public String getServer();
|
||||
public int getPort();
|
||||
}
|
||||
|
||||
@@ -204,4 +204,13 @@ public class LumberjackClient implements ProtocolAdapter {
|
||||
}
|
||||
logger.info("Connection to " + server + ":" + port + " closed");
|
||||
}
|
||||
|
||||
public String getServer() {
|
||||
return server;
|
||||
}
|
||||
|
||||
public int getPort() {
|
||||
return port;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -38,4 +38,14 @@ public class MockProtocolAdapter implements ProtocolAdapter {
|
||||
// not implemented
|
||||
}
|
||||
|
||||
public String getServer() {
|
||||
// TODO Auto-generated method stub
|
||||
return "";
|
||||
}
|
||||
|
||||
public int getPort() {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user