// Path: myeslib-util/src/main/java/org/myeslib/util/TimeUnitHelper.java
// @AllArgsConstructor
// public class TimeUnitHelper {
// 
// 	private static final Pattern pattern = Pattern.compile("([0-9]+)(s|m|h)");
// 
// 	private final String duration;
// 
// 	public TimeUnit getDurationTime() {
// 		Matcher m = pattern.matcher(duration.trim());
// 		if (m.matches()){
// 			if ("s".equals(m.group(2))){
// 				return TimeUnit.SECONDS;
// 			} else if ("m".equals(m.group(2))){
// 				return TimeUnit.MINUTES;
// 			} if ("h".equals(m.group(2))){
// 				return TimeUnit.HOURS;	
// 			} else {
// 				throw new IllegalArgumentException(String.format("1 Bad format for interval [%s]", duration));
// 			}
// 		} else {
// 			throw new IllegalArgumentException(String.format("2 Bad format for interval [%s]", duration));
// 		}
// 	}
// 
// 	public Long getDurationAsNumber() {
// 		Matcher m = pattern.matcher(duration.trim());
// 		if (m.matches()){
// 			return new Long(m.group(1));
// 		} else {
// 			throw new IllegalArgumentException(String.format("3 Bad format for interval [%s]", duration));
// 		}
// 	}
// 	
// }


import java.util.concurrent.TimeUnit;
import lombok.extern.slf4j.Slf4j;
import org.myeslib.util.TimeUnitHelper;
import com.google.inject.Inject;
import com.google.inject.name.Named;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.core.IMap;
package org.myeslib.util.hazelcast;





@Slf4j
public class HzJobLocker {

	public static final String LOCK_FAILED_MSG = "Cannot lock. May be there is another job instance working concurrently";
	private static final String TARGET_MAP = "distributedLockMap";

	@Inject
	public HzJobLocker(HazelcastInstance instance, @Named("job.id") String jobId, @Named("job.lock.duration") String jobDuration) {
		this.instance = instance;
		this.jobId = jobId;
		this.jobDuration = jobDuration;
	}

	private final HazelcastInstance instance;
	private final String jobId;
	private final String jobDuration;
	
	public boolean lock() {
		boolean success ;
		try {
// Path: myeslib-util/src/main/java/org/myeslib/util/TimeUnitHelper.java
// @AllArgsConstructor
// public class TimeUnitHelper {
// 
// 	private static final Pattern pattern = Pattern.compile("([0-9]+)(s|m|h)");
// 
// 	private final String duration;
// 
// 	public TimeUnit getDurationTime() {
// 		Matcher m = pattern.matcher(duration.trim());
// 		if (m.matches()){
// 			if ("s".equals(m.group(2))){
// 				return TimeUnit.SECONDS;
// 			} else if ("m".equals(m.group(2))){
// 				return TimeUnit.MINUTES;
// 			} if ("h".equals(m.group(2))){
// 				return TimeUnit.HOURS;	
// 			} else {
// 				throw new IllegalArgumentException(String.format("1 Bad format for interval [%s]", duration));
// 			}
// 		} else {
// 			throw new IllegalArgumentException(String.format("2 Bad format for interval [%s]", duration));
// 		}
// 	}
// 
// 	public Long getDurationAsNumber() {
// 		Matcher m = pattern.matcher(duration.trim());
// 		if (m.matches()){
// 			return new Long(m.group(1));
// 		} else {
// 			throw new IllegalArgumentException(String.format("3 Bad format for interval [%s]", duration));
// 		}
// 	}
// 	
// }


// Path: myeslib-util/src/main/java/org/myeslib/util/hazelcast/HzJobLocker.java
import java.util.concurrent.TimeUnit;
import lombok.extern.slf4j.Slf4j;
import org.myeslib.util.TimeUnitHelper;
import com.google.inject.Inject;
import com.google.inject.name.Named;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.core.IMap;

package org.myeslib.util.hazelcast;





@Slf4j
public class HzJobLocker {

	public static final String LOCK_FAILED_MSG = "Cannot lock. May be there is another job instance working concurrently";
	private static final String TARGET_MAP = "distributedLockMap";

	@Inject
	public HzJobLocker(HazelcastInstance instance, @Named("job.id") String jobId, @Named("job.lock.duration") String jobDuration) {
		this.instance = instance;
		this.jobId = jobId;
		this.jobDuration = jobDuration;
	}

	private final HazelcastInstance instance;
	private final String jobId;
	private final String jobDuration;
	
	public boolean lock() {
		boolean success ;
		try {
			TimeUnitHelper helper = new TimeUnitHelper(jobDuration);