Skip to content

Commit

Permalink
add static capabilites provider for creating and providing static cap…
Browse files Browse the repository at this point in the history
…abilities (generated by the service) instead of dynamic
  • Loading branch information
CarstenHollmann committed Sep 6, 2022
1 parent 193bc14 commit eaf6ef9
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@

import java.text.ParseException;
import java.util.Date;
import java.util.Optional;
import java.util.Timer;
import java.util.TimerTask;

import javax.inject.Inject;

import org.joda.time.DateTime;
import org.n52.faroe.ConfigurationError;
import org.n52.faroe.Validation;
Expand All @@ -44,9 +47,11 @@ public abstract class AbstractSchedulingContentCacheController implements Conten
private static final Logger LOGGER = LoggerFactory.getLogger(AbstractSchedulingContentCacheController.class);

private boolean initialized;
private long updateInterval;
private long updateInterval = 120;
private final Timer timer = new Timer("52n-iceland-capabilities-cache-controller", true);
private TimerTask current;
private Optional<StaticCapabilitiesProvider> staticCapabilitiesProvider;


/**
* Starts a new timer task
Expand Down Expand Up @@ -74,20 +79,20 @@ public void setCronExpression(String cronExpression) {
Validation.notNullOrEmpty("Cron expression for cache update", cronExpression);
try {
DateTime now = DateTime.now();
Date next = new CronExpression(cronExpression).getNextInvalidTimeAfter(DateTime.now().toDate());
setUpdateInterval(DateTimeHelper.getMinutesSince(now, new DateTime(next)));
CronExpression cronExp = new CronExpression(cronExpression);
Date first = cronExp.getNextValidTimeAfter(now.toDate());
Date next = cronExp.getNextValidTimeAfter(first);
setUpdateInterval(DateTimeHelper.getMinutesSince(new DateTime(first), new DateTime(next)));
} catch (ParseException e) {

throw new ConfigurationError(String.format("The defined cron expression '%s' is invalid!", cronExpression),
e);
}
// for later usage!
// if (this.cronExpression == null) {
// this.cronExpression = cronExpression;
// reschedule();
// } else if (!this.cronExpression.equalsIgnoreCase(cronExpression)) {
// this.cronExpression = cronExpression;
// reschedule();
// }
}

@Inject
public void setStaticCapabilitiesProvider(Optional<StaticCapabilitiesProvider> staticCapabilitiesProvider) {
this.staticCapabilitiesProvider = staticCapabilitiesProvider;
}

public void setUpdateInterval(int interval) throws ConfigurationError {
Expand Down Expand Up @@ -151,6 +156,9 @@ public void run() {
update();
LOGGER.info("Timertask: capabilities cache update successful!");
schedule();
if (staticCapabilitiesProvider.isPresent()) {
staticCapabilitiesProvider.get().create();
}
} catch (OwsExceptionReport e) {
LOGGER.error("Fatal error: Timertask couldn't update capabilities cache! " +
"Switch log level to DEBUG to get more details.");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (C) 2015-2022 52°North Spatial Information Research GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.n52.iceland.cache.ctrl;

import org.n52.shetland.ogc.ows.service.GetCapabilitiesResponse;

public interface StaticCapabilitiesProvider {

String PROVIDE_STATIC_CAPABILITIES = "service.capabilities.provide.static";

default boolean isProvideStaticCapabilities() {
return false;
}

void create();

String get(GetCapabilitiesResponse response);

String get(String identifier);

}

0 comments on commit eaf6ef9

Please sign in to comment.