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