Skip to content

Commit

Permalink
APPNG-2479
Browse files Browse the repository at this point in the history
  • Loading branch information
madness-inc committed May 4, 2023
1 parent 0b50eb7 commit f0e090f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
public class ReloadSiteEvent extends SiteEvent {

private static final long serialVersionUID = 8053808333634879840L;
private static final int DEFAULT_MAX_RELOAD_DELAY = (int) TimeUnit.SECONDS.toMillis(5);
private static final int DEFAULT_MAX_RELOAD_DELAY = (int) TimeUnit.SECONDS.toMillis(6);

public ReloadSiteEvent(String siteName) {
super(siteName, true);
Expand All @@ -63,9 +63,9 @@ public void perform(Environment env, Site site) throws InvalidConfigurationExcep

public void waitForClusterState(Environment env, Site site, Logger logger) {
Properties cfg = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG);
Integer siteReloadMaxDelay = cfg.getInteger(Platform.Property.SITE_RELOAD_MAX_RANDOM_DELAY,
Integer maxReloadDelay = cfg.getInteger(Platform.Property.SITE_RELOAD_MAX_RANDOM_DELAY,
DEFAULT_MAX_RELOAD_DELAY);
long delayMillis = (long) (Math.random() * siteReloadMaxDelay);
long delayMillis = maxReloadDelay + (long) (Math.random() * maxReloadDelay);
try {
logger.info("Waiting {}ms before reloading site {} on node {}", delayMillis, site.getName(),
Messaging.getNodeId());
Expand Down
19 changes: 15 additions & 4 deletions appng-core/src/main/java/org/appng/core/domain/SiteImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@
*/
package org.appng.core.domain;

import javax.persistence.CollectionTable;
import javax.persistence.ElementCollection;
import javax.persistence.ForeignKey;
import javax.persistence.JoinColumn;
import static org.appng.api.Scope.REQUEST;

import java.io.File;
Expand All @@ -29,16 +25,21 @@
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;

import javax.persistence.CollectionTable;
import javax.persistence.Column;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.FetchType;
import javax.persistence.ForeignKey;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;
Expand All @@ -50,6 +51,7 @@

import org.appng.api.Environment;
import org.appng.api.Path;
import org.appng.api.Platform;
import org.appng.api.Scope;
import org.appng.api.SiteProperties;
import org.appng.api.ValidationMessages;
Expand Down Expand Up @@ -425,6 +427,15 @@ public void setState(SiteState state, Environment env) {
SiteStateEvent event = new SiteStateEvent(getName(), state, Messaging.getNodeId());
if (null != env) {
event.handleSiteState(env);
if (SiteState.STARTED.equals(this.state.get())) {
Properties cfg = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG);
Integer setSiteStartedDelay = cfg.getInteger("setSiteStateStartedDelay", 10);
try {
Thread.sleep(TimeUnit.SECONDS.toMillis(setSiteStartedDelay));
} catch (InterruptedException e) {
// ignore
}
}
}
sendEvent(event);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -931,7 +931,7 @@ public Runnable getSiteLoader(SiteImpl siteToLoad, Environment env, boolean send
}
} catch (Throwable t) {
((DefaultEnvironment) env).clearSiteScope(site);
site.setState(SiteState.INACTIVE);
site.setState(SiteState.INACTIVE, env);
throw new SiteLoadingException("Error while loading site " + siteToLoad.getName(), t);
} finally {
if (sw.isRunning()) {
Expand Down

0 comments on commit f0e090f

Please sign in to comment.