Skip to content

Commit

Permalink
Merge pull request #15 from sgandon/sgandon/fix_touch_timeout
Browse files Browse the repository at this point in the history
fix(dshm): touch method fixed, no more timeout
  • Loading branch information
grrolland authored Dec 17, 2021
2 parents 8e605e9 + 4ab95f9 commit 94031b9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
1 change: 0 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
<properties>
<vertx.version>4.1.5</vertx.version>
<hazelcast.version>5.0</hazelcast.version>
<hazelcast-kubernetes-version>2.2.3</hazelcast-kubernetes-version>
<slf4j.version>1.7.32</slf4j.version>
<logback.version>1.2.6</logback.version>
<junit.version>4.13.2</junit.version>
Expand Down
11 changes: 10 additions & 1 deletion src/main/java/io/github/grrolland/hcshm/ShmProtocolHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
*/
package io.github.grrolland.hcshm;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import io.github.grrolland.hcshm.commands.Command;
import io.github.grrolland.hcshm.commands.CommandFactory;
import io.vertx.core.Handler;
Expand All @@ -30,6 +33,7 @@
* @author grrolland
*/
public class ShmProtocolHandler implements Handler<Buffer> {
Logger logger = LoggerFactory.getLogger(ShmProtocolHandler.class);
/**
* Protocol Encoding
*/
Expand Down Expand Up @@ -93,7 +97,9 @@ 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) {

final String[] commandTokens = buffer.toString(PROTOCOL_ENCODING).split(COMMAND_LINE_DELIMITER);
Expand Down Expand Up @@ -123,6 +129,9 @@ else if (currentCommand.needsDataPart())
expectedMode = FrameMode.COMMAND;
parser.delimitedMode(PROTOCOL_DELIMITER);
}
if (buffer != null && logger.isDebugEnabled()) {
logger.debug("Done handling buffer [{}]", buffer.toString(PROTOCOL_ENCODING));
}

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,23 @@
*/
package io.github.grrolland.hcshm.processor;

import io.github.grrolland.hcshm.HazelcastInstanceHandler;
import io.github.grrolland.hcshm.ShmRegionLocator;
import io.github.grrolland.hcshm.ShmValue;
import com.hazelcast.map.EntryProcessor;

import java.io.Serializable;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import com.hazelcast.map.EntryProcessor;
import com.hazelcast.map.ExtendedMapEntry;

import io.github.grrolland.hcshm.ShmValue;

/**
* Entry processor for the touch command
*/
public class TouchProcessor implements EntryProcessor<String, ShmValue, Object>, Serializable {
public class TouchProcessor implements EntryProcessor<String, ShmValue, Object> {
/**
* Touch expiration
*/
private int expire = 0;
/**
* Region Locator
*/
private ShmRegionLocator regionLocator = new ShmRegionLocator();


/**
* constructor
* @param expire touch expiration
Expand All @@ -54,12 +49,11 @@ 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);
regionLocator.getMap(HazelcastInstanceHandler.getInstance(), key).set(key, r, expire, TimeUnit.SECONDS);
((ExtendedMapEntry<String, ShmValue>) entry).setValue(r, expire, TimeUnit.SECONDS);
}
return null;
}
Expand Down

0 comments on commit 94031b9

Please sign in to comment.