[Minor] fixed logger in ClientSocketEndpoint

This commit is contained in:
Robert von Burg 2018-02-28 17:52:49 +01:00
parent 1830d9fe86
commit 5ecfb9d722
1 changed files with 43 additions and 37 deletions

View File

@ -24,6 +24,7 @@ import java.net.UnknownHostException;
import java.text.MessageFormat;
import java.util.Map;
import li.strolch.utils.helper.ExceptionHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -99,10 +100,8 @@ public class ClientSocketEndpoint implements CommunicationEndpoint {
* @return true if {@link Socket} is connected and ready for transmission, false otherwise
*/
protected boolean checkConnection() {
return !this.closed
&& this.connected
&& (this.socket != null && !this.socket.isClosed() && this.socket.isBound()
&& this.socket.isConnected() && !this.socket.isInputShutdown() && !this.socket
return !this.closed && this.connected && (this.socket != null && !this.socket.isClosed() && this.socket
.isBound() && this.socket.isConnected() && !this.socket.isInputShutdown() && !this.socket
.isOutputShutdown());
}
@ -175,8 +174,9 @@ public class ClientSocketEndpoint implements CommunicationEndpoint {
// configure the socket
if (logger.isDebugEnabled()) {
String msg = "BufferSize (send/read): {0} / {1} SoLinger: {2} TcpNoDelay: {3}"; //$NON-NLS-1$
logger.info(MessageFormat.format(msg, this.socket.getSendBufferSize(),
this.socket.getReceiveBufferSize(), this.socket.getSoLinger(), this.socket.getTcpNoDelay()));
logger.info(MessageFormat
.format(msg, this.socket.getSendBufferSize(), this.socket.getReceiveBufferSize(),
this.socket.getSoLinger(), this.socket.getTcpNoDelay()));
}
//outputSocket.setSendBufferSize(1);
//outputSocket.setSoLinger(true, 0);
@ -213,9 +213,8 @@ public class ClientSocketEndpoint implements CommunicationEndpoint {
this.connection.notifyStateChange(ConnectionState.DISCONNECTED, null);
} catch (Exception e) {
String msg = "Error while connecting to {0}:{1}: {2}"; //$NON-NLS-1$
logger.error(
MessageFormat.format(msg, this.remoteInputAddressS, Integer.toString(this.remoteInputPort)),
e.getMessage());
logger.error(MessageFormat.format(msg, this.remoteInputAddressS, Integer.toString(this.remoteInputPort),
ExceptionHelper.formatExceptionMessage(e)));
this.connection.notifyStateChange(ConnectionState.BROKEN, e.getLocalizedMessage());
}
}
@ -234,7 +233,8 @@ public class ClientSocketEndpoint implements CommunicationEndpoint {
try {
this.outputStream.close();
} catch (IOException e) {
logger.error(MessageFormat.format("Error closing OutputStream: {0}", e.getLocalizedMessage())); //$NON-NLS-1$
logger.error(
MessageFormat.format("Error closing OutputStream: {0}", e.getLocalizedMessage())); //$NON-NLS-1$
} finally {
this.outputStream = null;
}
@ -244,7 +244,8 @@ public class ClientSocketEndpoint implements CommunicationEndpoint {
try {
this.inputStream.close();
} catch (IOException e) {
logger.error(MessageFormat.format("Error closing InputStream: {0}", e.getLocalizedMessage())); //$NON-NLS-1$
logger.error(
MessageFormat.format("Error closing InputStream: {0}", e.getLocalizedMessage())); //$NON-NLS-1$
} finally {
this.inputStream = null;
}
@ -254,7 +255,8 @@ public class ClientSocketEndpoint implements CommunicationEndpoint {
try {
this.socket.close();
} catch (IOException e) {
logger.error(MessageFormat.format("Error closing OutputSocket: {0}", e.getLocalizedMessage())); //$NON-NLS-1$
logger.error(
MessageFormat.format("Error closing OutputSocket: {0}", e.getLocalizedMessage())); //$NON-NLS-1$
} finally {
this.socket = null;
}
@ -361,8 +363,9 @@ public class ClientSocketEndpoint implements CommunicationEndpoint {
try {
this.retry = Long.parseLong(retryS);
} catch (NumberFormatException e) {
throw ConnectionMessages.throwInvalidParameter(ClientSocketEndpoint.class,
SocketEndpointConstants.PARAMETER_RETRY, retryS);
throw ConnectionMessages
.throwInvalidParameter(ClientSocketEndpoint.class, SocketEndpointConstants.PARAMETER_RETRY,
retryS);
}
}
@ -371,8 +374,8 @@ public class ClientSocketEndpoint implements CommunicationEndpoint {
if (StringHelper.isNotEmpty(connectOnStartS)) {
this.connectOnStart = StringHelper.parseBoolean(connectOnStartS);
} else {
ConnectionMessages.warnUnsetParameter(ClientSocketEndpoint.class,
SocketEndpointConstants.PARAMETER_CONNECT_ON_START,
ConnectionMessages
.warnUnsetParameter(ClientSocketEndpoint.class, SocketEndpointConstants.PARAMETER_CONNECT_ON_START,
String.valueOf(SocketEndpointConstants.CONNECT_ON_START));
this.connectOnStart = SocketEndpointConstants.CONNECT_ON_START;
}
@ -382,8 +385,8 @@ public class ClientSocketEndpoint implements CommunicationEndpoint {
if (StringHelper.isNotEmpty(closeAfterSendS)) {
this.closeAfterSend = StringHelper.parseBoolean(closeAfterSendS);
} else {
ConnectionMessages.warnUnsetParameter(ClientSocketEndpoint.class,
SocketEndpointConstants.PARAMETER_CLOSE_AFTER_SEND,
ConnectionMessages
.warnUnsetParameter(ClientSocketEndpoint.class, SocketEndpointConstants.PARAMETER_CLOSE_AFTER_SEND,
String.valueOf(SocketEndpointConstants.CLOSE_AFTER_SEND));
this.closeAfterSend = SocketEndpointConstants.CLOSE_AFTER_SEND;
}
@ -391,8 +394,9 @@ public class ClientSocketEndpoint implements CommunicationEndpoint {
// configure if timeout on connection should be activated
String useTimeoutS = parameters.get(SocketEndpointConstants.PARAMETER_USE_TIMEOUT);
if (useTimeoutS == null || useTimeoutS.length() == 0) {
ConnectionMessages.warnUnsetParameter(ClientSocketEndpoint.class,
SocketEndpointConstants.PARAMETER_USE_TIMEOUT, String.valueOf(SocketEndpointConstants.USE_TIMEOUT));
ConnectionMessages
.warnUnsetParameter(ClientSocketEndpoint.class, SocketEndpointConstants.PARAMETER_USE_TIMEOUT,
String.valueOf(SocketEndpointConstants.USE_TIMEOUT));
this.useTimeout = SocketEndpointConstants.USE_TIMEOUT;
} else {
this.useTimeout = Boolean.parseBoolean(useTimeoutS);
@ -402,8 +406,9 @@ public class ClientSocketEndpoint implements CommunicationEndpoint {
// configure timeout on connection
String timeoutS = parameters.get(SocketEndpointConstants.PARAMETER_TIMEOUT);
if (timeoutS == null || timeoutS.length() == 0) {
ConnectionMessages.warnUnsetParameter(ClientSocketEndpoint.class,
SocketEndpointConstants.PARAMETER_TIMEOUT, String.valueOf(SocketEndpointConstants.TIMEOUT));
ConnectionMessages
.warnUnsetParameter(ClientSocketEndpoint.class, SocketEndpointConstants.PARAMETER_TIMEOUT,
String.valueOf(SocketEndpointConstants.TIMEOUT));
this.timeout = SocketEndpointConstants.TIMEOUT;
} else {
try {
@ -418,8 +423,8 @@ public class ClientSocketEndpoint implements CommunicationEndpoint {
// configure if the connection should be cleared on connect
String clearOnConnectS = parameters.get(SocketEndpointConstants.PARAMETER_CLEAR_ON_CONNECT);
if (clearOnConnectS == null || clearOnConnectS.length() == 0) {
ConnectionMessages.warnUnsetParameter(ClientSocketEndpoint.class,
SocketEndpointConstants.PARAMETER_CLEAR_ON_CONNECT,
ConnectionMessages
.warnUnsetParameter(ClientSocketEndpoint.class, SocketEndpointConstants.PARAMETER_CLEAR_ON_CONNECT,
String.valueOf(SocketEndpointConstants.CLEAR_ON_CONNECT));
this.clearOnConnect = SocketEndpointConstants.CLEAR_ON_CONNECT;
} else {
@ -465,7 +470,8 @@ public class ClientSocketEndpoint implements CommunicationEndpoint {
@Override
public void start() {
if (!this.closed) {
logger.warn(MessageFormat.format("CommunicationConnection {0} already started.", this.connection.getId())); //$NON-NLS-1$
logger.warn(MessageFormat
.format("CommunicationConnection {0} already started.", this.connection.getId())); //$NON-NLS-1$
} else {
// logger.info(MessageFormat.format("Enabling connection {0}...", this.connection.getId())); //$NON-NLS-1$
this.closed = false;