Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 27 additions & 10 deletions src/org/lockss/app/LockssDaemon.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ of this software and associated documentation files (the "Software"), to deal
import org.lockss.crawler.*;
import org.lockss.remote.*;
import org.lockss.clockss.*;
import org.lockss.safenet.*;
import org.lockss.entitlement.*;
import org.apache.commons.collections.map.LinkedMap;

/**
Expand Down Expand Up @@ -103,6 +103,9 @@ public class LockssDaemon extends LockssApp {
static final long DEFAULT_DAEMON_DEADLINE_REASONABLE_FUTURE =
20 * Constants.WEEK;

public static final String PARAM_KEEPSAFE_ENABLED = Configuration.PREFIX + "entitlement.keepsafe.enabled";
static final boolean DEFAULT_KEEPSAFE_ENABLED = false;

/** List of local IP addresses to which to bind listen sockets for
* servers (admin ui, content, proxy). If not set, servers listen on all
* interfaces. Does not affect the port on which various servers listen.
Expand Down Expand Up @@ -147,7 +150,8 @@ public class LockssDaemon extends LockssApp {
public static final String ICP_MANAGER = "IcpManager";
public static final String CRON = "Cron";
public static final String CLOCKSS_PARAMS = "ClockssParams";
public static final String SAFENET_MANAGER = "SafenetManager";
public static final String ENTITLEMENT_REGISTRY_CLIENT = "EntitlementRegistryClient";
public static final String CACHED_ENTITLEMENT_REGISTRY_CLIENT = "CachedEntitlementRegistryClient";
public static final String TRUEZIP_MANAGER = "TrueZipManager";
public static final String DB_MANAGER = "DbManager";
public static final String COUNTER_REPORTS_MANAGER = "CounterReportsManager";
Expand Down Expand Up @@ -237,9 +241,13 @@ public class LockssDaemon extends LockssApp {
public boolean shouldStart() {
return isClockss();
}},
new ManagerDesc(SAFENET_MANAGER, "org.lockss.safenet.CachingEntitlementRegistryClient") {
new ManagerDesc(ENTITLEMENT_REGISTRY_CLIENT, "org.lockss.entitlement.KeepsafeEntitlementRegistryClient") {
public boolean shouldStart() {
return isKeepsafe();
}},
new ManagerDesc(CACHED_ENTITLEMENT_REGISTRY_CLIENT, "org.lockss.entitlement.CachingEntitlementRegistryClient") {
public boolean shouldStart() {
return isSafenet();
return isKeepsafe();
}},
// watchdog last
new ManagerDesc(WATCHDOG_SERVICE, DEFAULT_WATCHDOG_SERVICE)
Expand Down Expand Up @@ -271,7 +279,7 @@ public boolean shouldStart() {

private static LockssDaemon theDaemon;
private boolean isClockss;
private boolean isSafenet;
private boolean isKeepsafe;
protected String testingMode;

protected LockssDaemon(List<String> propUrls) {
Expand Down Expand Up @@ -338,10 +346,10 @@ public boolean isDetectClockssSubscription() {
}

/**
* True if running as a Safenet daemon
* True if running as a Keepsafe daemon
*/
public boolean isSafenet() {
return isSafenet;
public boolean isKeepsafe() {
return isKeepsafe;
}

/** Stop the daemon. Currently only used in testing. */
Expand Down Expand Up @@ -630,7 +638,16 @@ public ClockssParams getClockssParams() {
* @throws IllegalArgumentException if the manager is not available.
*/
public EntitlementRegistryClient getEntitlementRegistryClient() {
return (EntitlementRegistryClient) getManager(SAFENET_MANAGER);
return (EntitlementRegistryClient) getManager(ENTITLEMENT_REGISTRY_CLIENT);
}

/**
* return the EntitlementRegistryClient instance.
* @return EntitlementRegistryClient instance.
* @throws IllegalArgumentException if the manager is not available.
*/
public EntitlementRegistryClient getCachedEntitlementRegistryClient() {
return (EntitlementRegistryClient) getManager(CACHED_ENTITLEMENT_REGISTRY_CLIENT);
}

// LockssAuManager accessors
Expand Down Expand Up @@ -977,7 +994,7 @@ protected void setConfig(Configuration config, Configuration prevConfig,
testingMode = config.get(PARAM_TESTING_MODE);
String proj = ConfigManager.getPlatformProject();
isClockss = "clockss".equalsIgnoreCase(proj);
isSafenet = "safenet".equalsIgnoreCase(proj);
isKeepsafe = config.getBoolean(PARAM_KEEPSAFE_ENABLED, DEFAULT_KEEPSAFE_ENABLED);

super.setConfig(config, prevConfig, changedKeys);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.lockss.safenet;
package org.lockss.entitlement;

import java.io.IOException;
import java.util.Collections;
Expand All @@ -7,32 +7,35 @@
import org.apache.commons.collections.map.LRUMap;
import org.apache.commons.collections.map.MultiKeyMap;

import org.lockss.app.BaseLockssManager;
import org.lockss.app.BaseLockssDaemonManager;
import org.lockss.app.ConfigurableManager;
import org.lockss.config.Configuration;

/*
* A very basic cache which just stores the results of the last 100 calls to the Entitlement Registry.
* There's a strong chance this will need to become something more complicated down the line.
* There's a strong chance this will need to become something more complicated down the line if performance isn't acceptable.
* In this case though, it would probably be best to replace it with something like Guava's caching, rather than building something custom.
*/
public class CachingEntitlementRegistryClient extends BaseLockssManager implements EntitlementRegistryClient, ConfigurableManager {
private BaseEntitlementRegistryClient client;
public class CachingEntitlementRegistryClient extends BaseLockssDaemonManager implements EntitlementRegistryClient, ConfigurableManager {
public static final String PREFIX = Configuration.PREFIX + "entitlement.cache.";
public static final String PARAM_CACHE_SIZE = PREFIX + "size";
static final int DEFAULT_CACHE_SIZE = 100;
private EntitlementRegistryClient client;
private MultiKeyMap cache;

public CachingEntitlementRegistryClient() {
this(new BaseEntitlementRegistryClient(), 100);
}

protected CachingEntitlementRegistryClient(BaseEntitlementRegistryClient client, int size) {
this.client = client;
this.cache = MultiKeyMap.decorate(new LRUMap(size));
public void startService() {
super.startService();
this.client = getDaemon().getEntitlementRegistryClient();
}

public void setConfig(Configuration config, Configuration oldConfig, Configuration.Differences diffs) {
client.setConfig(config, oldConfig, diffs);
if (diffs.contains(PREFIX)) {
int size = config.getInt(PARAM_CACHE_SIZE, DEFAULT_CACHE_SIZE);
this.cache = MultiKeyMap.decorate(new LRUMap(size));
}
}

public boolean isUserEntitled(String issn, String institution, String start, String end) throws IOException {
public synchronized boolean isUserEntitled(String issn, String institution, String start, String end) throws IOException {
Object result = this.cache.get("isUserEntitled", issn, institution, start, end);
if(result == null) {
result = this.client.isUserEntitled(issn, institution, start, end);
Expand All @@ -41,16 +44,16 @@ public boolean isUserEntitled(String issn, String institution, String start, Str
return (Boolean) result;
}

public String getPublisher(String issn, String start, String end) throws IOException {
Object result = this.cache.get("getPublisher", issn, start, end);
public synchronized String getPublisher(String issn, String institution, String start, String end) throws IOException {
Object result = this.cache.get("getPublisher", issn, institution, start, end);
if(result == null) {
result = this.client.getPublisher(issn, start, end);
this.cache.put("getPublisher", issn, start, end, result);
result = this.client.getPublisher(issn, institution, start, end);
this.cache.put("getPublisher", issn, institution, start, end, result);
}
return (String) result;
}

public PublisherWorkflow getPublisherWorkflow(String publisherName) throws IOException {
public synchronized PublisherWorkflow getPublisherWorkflow(String publisherName) throws IOException {
Object result = this.cache.get("getPublisherWorkflow", publisherName);
if(result == null) {
result = this.client.getPublisherWorkflow(publisherName);
Expand All @@ -59,14 +62,13 @@ public PublisherWorkflow getPublisherWorkflow(String publisherName) throws IOExc
return (PublisherWorkflow) result;
}

public String getInstitution(String scope) throws IOException {
public synchronized String getInstitution(String scope) throws IOException {
Object result = this.cache.get("getInstitution", scope);
if(result == null) {
result = this.client.getInstitution(scope);
this.cache.put("getInstitution", scope, result);
}
return (String) result;
}

}

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.lockss.safenet;
package org.lockss.entitlement;

import java.io.IOException;

Expand All @@ -7,6 +7,6 @@
public interface EntitlementRegistryClient extends LockssManager {
boolean isUserEntitled(String issn, String institution, String start, String end) throws IOException;
String getInstitution(String scope) throws IOException;
String getPublisher(String issn, String start, String end) throws IOException;
String getPublisher(String issn, String institution, String start, String end) throws IOException;
PublisherWorkflow getPublisherWorkflow(String publisherGuid) throws IOException;
}
Loading