com.alachisoft.ncache.licensing.LicenseLogger Maven / Gradle / Ivy
Show all versions of nc-activate Show documentation
package com.alachisoft.ncache.licensing;
/**
* ***********************************************************************
* Author: Hasan Khan Date created: 06-05-2008
*
* Modified By: Last modified by: Date modified: /************************************************************************
*/
//C# TO JAVA CONVERTER TODO TASK: There is no preprocessor in Java:
//#if NCPEX
//#else
//#endif
public class LicenseLogger {
private java.util.ArrayList licenses;
private boolean autoSave;
private ILicenseSink sink;
private Object syncRoot = new Object();
private boolean enabled;
public LicenseLogger() {
// licenses = new java.util.ArrayList();
// autoSave = false;
// sink = new FileLicenseSink(Path.Combine(GetLogDirPath(), "licenseLog.dat"));
// syncRoot = new Object();
}
private String GetLogDirPath() {
// String logDir = ServicePropValues.LOGS_FOLDER;
// String installDir = AppUtil.getInstallDir();
// return installDir + "/" + logDir;
return "";
}
public final boolean getAutoSave() {
return autoSave;
}
public final void setAutoSave(boolean value) {
autoSave = value;
}
public final boolean getEnabled() {
return enabled;
}
public final void setEnabled(boolean value) {
enabled = value;
}
public final void Load() {
synchronized (syncRoot) {
// licenses = sink.Load();
}
}
public final void Save() {
synchronized (syncRoot) {
try {
sink.Dump(licenses);
} catch (java.lang.Exception e) {
}
}
}
private int Find(LicenseInfo item) {
boolean found = false;
int i;
for (i = 0; i < licenses.size(); i++) {
if (licenses.get(i).equals(item)) {
found = true;
break;
}
}
return found ? i : -1;
}
public final void Add(LicenseInfo item) {
if (!getEnabled()) {
return;
}
synchronized (syncRoot) {
int i = Find(item);
if (i >= 0) {
boolean changed = licenses.get(i).Update(item);
if (changed && getAutoSave()) {
sink.Dump(licenses);
}
} else {
licenses.add(item);
if (getAutoSave()) {
sink.Dump(licenses);
}
}
}
}
public final boolean Contains(LicenseInfo item) {
synchronized (syncRoot) {
return licenses.contains(item);
}
}
public final LicenseInfo[] getLicenses() {
synchronized (syncRoot) {
LicenseInfo[] array = new LicenseInfo[licenses.size()];
// licenses.CopyTo(array, 0);
return array;
}
}
public final int getCount() {
synchronized (syncRoot) {
return licenses.size();
}
}
}