<commit_before>package ch.elexis.core.data.service.internal;

import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
import java.util.UUID;

import org.eclipse.core.runtime.IProgressMonitor;
import org.osgi.service.component.annotations.Component;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.eclipsesource.jaxrs.consumer.ConsumerFactory;

import ch.elexis.core.common.InstanceStatus;
import ch.elexis.core.common.InstanceStatus.STATE;
import ch.elexis.core.constants.ElexisSystemPropertyConstants;
import ch.elexis.core.constants.Preferences;
import ch.elexis.core.data.activator.CoreHub;
import ch.elexis.core.data.events.ElexisEvent;
import ch.elexis.core.data.events.ElexisEventDispatcher;
import ch.elexis.core.data.server.ElexisServerInstanceService;
import ch.elexis.core.data.server.ElexisServerLockService;
import ch.elexis.core.data.service.ContextServiceHolder;
import ch.elexis.core.data.service.StoreToStringServiceHolder;
import ch.elexis.core.data.status.ElexisStatus;
import ch.elexis.core.lock.types.LockInfo;
import ch.elexis.core.lock.types.LockRequest;
import ch.elexis.core.lock.types.LockRequest.Type;
import ch.elexis.core.lock.types.LockResponse;
import ch.elexis.core.model.IUser;
import ch.elexis.core.model.Identifiable;
import ch.elexis.core.server.IInstanceService;
import ch.elexis.core.server.ILockService;
import ch.elexis.core.services.ILocalLockService;
import ch.elexis.data.PersistentObject;

/**
 * ILocalLockService implementation. Managing locks of PersistentObjects, or Identifiable.</br>
 * If the environment variable <b>ELEXIS_SERVER_REST_INTERFACE_URL</b> is set a connection to a
 * remote LockService will used internal.
 * 
 * @author marco
 * 
 */
@Component
public class LocalLockService implements ILocalLockService {
	
	private ILockService ils;
	private IInstanceService iis;
	private InstanceStatus inst;
	
	private final HashMap<String, Integer> lockCount = new HashMap<String, Integer>();
	private final HashMap<String, LockInfo> locks = new HashMap<String, LockInfo>();
	private boolean standalone = false;
	private Logger logger = LoggerFactory.getLogger(LocalLockService.class);
	
	/**
	 * A unique id for this instance of Elexis. Changes on every restart
	 */
	private static final UUID systemUuid = UUID.randomUUID();
	
	private Timer timer;
	
	/**
	 * Construct a new LocalLockService. Application code should access via
	 * {@link CoreHub#getLocalLockService()} and <b>NOT</b> create its own instance.
	 * 
	 */
	public LocalLockService(){
		ils = new DenyAllLockService();
		timer = new Timer();
		timer.schedule(new LockRefreshTask(), 10000, 10000);
		
		inst = new InstanceStatus();
		inst.setState(InstanceStatus.STATE.ACTIVE);
		inst.setUuid(getSystemUuid());
		inst.setVersion(CoreHub.readElexisBuildVersion());
		inst.setOperatingSystem(
			System.getProperty("os.name") + "/" + System.getProperty("os.version") + "/"
				+ System.getProperty("os.arch") + "/J" + System.getProperty("java.version"));
	}<commit_msg>[20235] CoreHub.readElexisBuildVersion -> Elexis.VERSION<commit_after>package ch.elexis.core.data.service.internal;

import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
import java.util.UUID;

import org.eclipse.core.runtime.IProgressMonitor;
import org.osgi.service.component.annotations.Component;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.eclipsesource.jaxrs.consumer.ConsumerFactory;

import ch.elexis.core.common.InstanceStatus;
import ch.elexis.core.common.InstanceStatus.STATE;
import ch.elexis.core.constants.ElexisSystemPropertyConstants;
import ch.elexis.core.constants.Preferences;
import ch.elexis.core.constants.Elexis;
import ch.elexis.core.data.activator.CoreHub;
import ch.elexis.core.data.events.ElexisEvent;
import ch.elexis.core.data.events.ElexisEventDispatcher;
import ch.elexis.core.data.server.ElexisServerInstanceService;
import ch.elexis.core.data.server.ElexisServerLockService;
import ch.elexis.core.data.service.ContextServiceHolder;
import ch.elexis.core.data.service.StoreToStringServiceHolder;
import ch.elexis.core.data.status.ElexisStatus;
import ch.elexis.core.lock.types.LockInfo;
import ch.elexis.core.lock.types.LockRequest;
import ch.elexis.core.lock.types.LockRequest.Type;
import ch.elexis.core.lock.types.LockResponse;
import ch.elexis.core.model.IUser;
import ch.elexis.core.model.Identifiable;
import ch.elexis.core.server.IInstanceService;
import ch.elexis.core.server.ILockService;
import ch.elexis.core.services.ILocalLockService;
import ch.elexis.data.PersistentObject;

/**
 * ILocalLockService implementation. Managing locks of PersistentObjects, or Identifiable.</br>
 * If the environment variable <b>ELEXIS_SERVER_REST_INTERFACE_URL</b> is set a connection to a
 * remote LockService will used internal.
 * 
 * @author marco
 * 
 */
@Component
public class LocalLockService implements ILocalLockService {
	
	private ILockService ils;
	private IInstanceService iis;
	private InstanceStatus inst;
	
	private final HashMap<String, Integer> lockCount = new HashMap<String, Integer>();
	private final HashMap<String, LockInfo> locks = new HashMap<String, LockInfo>();
	private boolean standalone = false;
	private Logger logger = LoggerFactory.getLogger(LocalLockService.class);
	
	/**
	 * A unique id for this instance of Elexis. Changes on every restart
	 */
	private static final UUID systemUuid = UUID.randomUUID();
	
	private Timer timer;
	
	/**
	 * Construct a new LocalLockService. Application code should access via
	 * {@link CoreHub#getLocalLockService()} and <b>NOT</b> create its own instance.
	 * 
	 */
	public LocalLockService(){
		ils = new DenyAllLockService();
		timer = new Timer();
		timer.schedule(new LockRefreshTask(), 10000, 10000);
		
		inst = new InstanceStatus();
		inst.setState(InstanceStatus.STATE.ACTIVE);
		inst.setUuid(getSystemUuid());
		inst.setVersion(Elexis.VERSION);
		inst.setOperatingSystem(
			System.getProperty("os.name") + "/" + System.getProperty("os.version") + "/"
				+ System.getProperty("os.arch") + "/J" + System.getProperty("java.version"));
	}
{'fraction_non_alphanumeric': 0.1131582987870413, 'fraction_numerical': 0.004452633195148165, 'mean_word_length': 5.481592039800995, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '538508', 'n_tokens_mistral': 2083, 'n_tokens_neox': 2045, 'n_words': 414}