Skip to content

Commit

Permalink
Fix sonar issues
Browse files Browse the repository at this point in the history
  • Loading branch information
admin committed Nov 20, 2023
1 parent 33d9aaf commit dc19fce
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 34 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[![Build](https://github.com/grrolland/ngx-distributed-shm/actions/workflows/build.yml/badge.svg?branch=master)](https://github.com/grrolland/ngx-distributed-shm/actions/workflows/build.yml)
[![Quality Gate](https://sonarcloud.io/api/project_badges/measure?project=io.github.grrolland%3Angx-distributed-shm&metric=alert_status)](https://sonarcloud.io/dashboard/index/io.github.grrolland:ngx-distributed-shm)
[![Technical debt ratio](https://sonarcloud.io/api/project_badges/measure?project=io.github.grrolland%3Angx-distributed-shm&metric=sqale_index)](https://sonarcloud.io/dashboard/index/io.github.grrolland:ngx-distributed-shm)
[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=io.github.grrolland%3Angx-distributed-shm&metric=coverage)](https://sonarcloud.io/dashboard/index/io.github.grrolland:ngx-distributed-shm)
[![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=grrolland_ngx-distributed-shm&metric=reliability_rating)](https://sonarcloud.io/summary/new_code?id=grrolland_ngx-distributed-shm)
[![Bugs](https://sonarcloud.io/api/project_badges/measure?project=grrolland_ngx-distributed-shm&metric=bugs)](https://sonarcloud.io/summary/new_code?id=grrolland_ngx-distributed-shm)
[![Vulnerabilities](https://sonarcloud.io/api/project_badges/measure?project=grrolland_ngx-distributed-shm&metric=vulnerabilities)](https://sonarcloud.io/summary/new_code?id=grrolland_ngx-distributed-shm)
[![Release](https://img.shields.io/github/release/grrolland/ngx-distributed-shm)](https://github.com/grrolland/ngx-distributed-shm/tags/)

# ngx-distributed-shm
Expand Down
54 changes: 25 additions & 29 deletions src/main/java/io/github/grrolland/hcshm/ShmProtocolHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,42 +97,38 @@ public ShmProtocolHandler(NetSocket socket, ShmService service) {
*/
@Override
public void handle(Buffer buffer) {
if (buffer != null && logger.isDebugEnabled()) {
logger.debug("handling buffer [{}]", buffer.toString(PROTOCOL_ENCODING));
}
if (expectedMode == FrameMode.COMMAND) {
if (null != buffer) {
if (logger.isDebugEnabled()) {
logger.debug("handling buffer [{}]", buffer.toString(PROTOCOL_ENCODING));
}
if (expectedMode == FrameMode.COMMAND) {

final String[] commandTokens = buffer.toString(PROTOCOL_ENCODING).split(COMMAND_LINE_DELIMITER);
currentCommand = commandFactory.get(commandTokens);
final String result = currentCommand.execute(commandTokens);
final String[] commandTokens = buffer.toString(PROTOCOL_ENCODING).split(COMMAND_LINE_DELIMITER);
currentCommand = commandFactory.get(commandTokens);
final String result = currentCommand.execute(commandTokens);

socket.write(result, PROTOCOL_ENCODING);
socket.write(result, PROTOCOL_ENCODING);

if (currentCommand.isTerminationCommand()) {
socket.close();
}
else if (currentCommand.needsDataPart())
{
expectedMode = FrameMode.DATA;
parser.fixedSizeMode(currentCommand.getDataPartSize());
}
else
{
if (currentCommand.isTerminationCommand()) {
socket.close();
} else if (currentCommand.needsDataPart()) {
expectedMode = FrameMode.DATA;
parser.fixedSizeMode(currentCommand.getDataPartSize());
} else {
expectedMode = FrameMode.COMMAND;
parser.delimitedMode(PROTOCOL_DELIMITER);
}

} else {
final String result = currentCommand.executeDataPart(buffer.toString(PROTOCOL_ENCODING));
socket.write(result, PROTOCOL_ENCODING);
expectedMode = FrameMode.COMMAND;
parser.delimitedMode(PROTOCOL_DELIMITER);
}

}
else {
final String result = currentCommand.executeDataPart(buffer.toString(PROTOCOL_ENCODING));
socket.write(result, PROTOCOL_ENCODING);
expectedMode = FrameMode.COMMAND;
parser.delimitedMode(PROTOCOL_DELIMITER);
if (logger.isDebugEnabled()) {
logger.debug("Done handling buffer [{}]", buffer.toString(PROTOCOL_ENCODING));
}
}
if (buffer != null && logger.isDebugEnabled()) {
logger.debug("Done handling buffer [{}]", buffer.toString(PROTOCOL_ENCODING));
}

}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/github/grrolland/hcshm/ShmTcpServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public ShmTcpServer() {
* @throws Exception unable to start the server
*/
@Override
public void start() throws Exception {
public void start() {
NetServerOptions options = new NetServerOptions().setPort(Configuration.getPort()).setHost(Configuration.getBindAddress());
NetServer server = vertx.createNetServer(options);
server.connectHandler(sock -> ShmProtocolHandler.create(sock, service));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ public TouchProcessor(int expire) {
@Override
public Object process(Map.Entry<String, ShmValue> entry) {
final ShmValue r = entry.getValue();
final String key = entry.getKey();
if (null != r) {
r.expire(expire);
((ExtendedMapEntry<String, ShmValue>) entry).setValue(r, expire, TimeUnit.SECONDS);
Expand Down

0 comments on commit dc19fce

Please sign in to comment.