Corrected bug in connection retry.

This commit is contained in:
didfet
2015-03-23 17:06:30 +01:00
parent bb15f83732
commit cb36f31dbd
4 changed files with 31 additions and 0 deletions

View File

@@ -100,10 +100,20 @@ public class Forwarder {
private static void connectToServer() { private static void connectToServer() {
int randomServerIndex = 0; int randomServerIndex = 0;
List<String> serverList = configManager.getConfig().getNetwork().getServers(); 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) { while(adapter == null) {
try { try {
randomServerIndex = random.nextInt(serverList.size()); randomServerIndex = random.nextInt(serverList.size());
String[] serverAndPort = serverList.get(randomServerIndex).split(":"); 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])); adapter = new LumberjackClient(configManager.getConfig().getNetwork().getSslCA(),serverAndPort[0],Integer.parseInt(serverAndPort[1]));
reader.setAdapter(adapter); reader.setAdapter(adapter);
} catch(Exception ex) { } catch(Exception ex) {

View File

@@ -24,4 +24,6 @@ import java.util.List;
public interface ProtocolAdapter { public interface ProtocolAdapter {
public int sendEvents(List<Event> eventList) throws AdapterException; public int sendEvents(List<Event> eventList) throws AdapterException;
public void close() throws AdapterException; public void close() throws AdapterException;
public String getServer();
public int getPort();
} }

View File

@@ -204,4 +204,13 @@ public class LumberjackClient implements ProtocolAdapter {
} }
logger.info("Connection to " + server + ":" + port + " closed"); logger.info("Connection to " + server + ":" + port + " closed");
} }
public String getServer() {
return server;
}
public int getPort() {
return port;
}
} }

View File

@@ -38,4 +38,14 @@ public class MockProtocolAdapter implements ProtocolAdapter {
// not implemented // not implemented
} }
public String getServer() {
// TODO Auto-generated method stub
return "";
}
public int getPort() {
// TODO Auto-generated method stub
return 0;
}
} }