Skip to content

Commit

Permalink
0001306: Add setting in web.xml to allow the engines to be stored sta…
Browse files Browse the repository at this point in the history
…tically so multiple wars in an ear can reference the same engine
  • Loading branch information
chenson42 committed Jul 2, 2013
1 parent 25e3333 commit 4c9d182
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 41 deletions.
Expand Up @@ -33,8 +33,12 @@ public class WebConstants {

public static final String INIT_PARAM_AUTO_START = "autoStart";

public static final String INIT_PARAM_AUTO_CREATE = "autoCreate";

public static final String INIT_PARAM_MULTI_SERVER_MODE = "multiServerMode";

public static final String INIT_PARAM_STATIC_ENGINES_MODE = "staticEnginesMode";

public static final String INIT_PARAM_DEPLOYMENT_TYPE = "deploymentType";

public static final String INIT_SINGLE_SERVER_PROPERTIES_FILE = "singleServerPropertiesFile";
Expand Down
Expand Up @@ -29,14 +29,24 @@ public class SymmetricContextListener implements ServletContextListener {
public void contextInitialized(ServletContextEvent sce) {
SymmetricEngineHolder engineHolder = new SymmetricEngineHolder();
ServletContext ctx = sce.getServletContext();

String autoStart = ctx.getInitParameter(WebConstants.INIT_PARAM_AUTO_START);
engineHolder.setAutoStart(autoStart == null ? true : autoStart.equalsIgnoreCase("true"));

String autoCreate = ctx.getInitParameter(WebConstants.INIT_PARAM_AUTO_CREATE);
engineHolder.setAutoCreate(autoCreate == null ? true : autoCreate.equalsIgnoreCase("true"));

String multiServerMode = ctx.getInitParameter(WebConstants.INIT_PARAM_MULTI_SERVER_MODE);
engineHolder.setMultiServerMode(multiServerMode != null
&& multiServerMode.equalsIgnoreCase("true"));

engineHolder.setSingleServerPropertiesFile(ctx
.getInitParameter(WebConstants.INIT_SINGLE_SERVER_PROPERTIES_FILE));

String staticEnginesMode = ctx.getInitParameter(WebConstants.INIT_PARAM_STATIC_ENGINES_MODE);
engineHolder.setStaticEnginesMode(staticEnginesMode != null
&& staticEnginesMode.equalsIgnoreCase("true"));

engineHolder.setDeploymentType(ctx.getInitParameter(WebConstants.INIT_PARAM_DEPLOYMENT_TYPE));
ctx.setAttribute(WebConstants.ATTR_ENGINE_HOLDER, engineHolder);
engineHolder.start();
Expand Down
Expand Up @@ -57,14 +57,22 @@
public class SymmetricEngineHolder {

final Logger log = LoggerFactory.getLogger(getClass());

private static Map<String, ServerSymmetricEngine> staticEngines = new HashMap<String, ServerSymmetricEngine>();

private static Set<EngineStarter> staticEnginesStarting = new HashSet<SymmetricEngineHolder.EngineStarter>();

private Map<String, ServerSymmetricEngine> engines = new HashMap<String, ServerSymmetricEngine>();

private Set<EngineStarter> enginesStarting = new HashSet<SymmetricEngineHolder.EngineStarter>();

private boolean staticEnginesMode = false;

private boolean multiServerMode = false;

private boolean autoStart = true;

private boolean autoCreate = true;

private String singleServerPropertiesFile;

Expand All @@ -89,6 +97,22 @@ public void setMultiServerMode(boolean multiServerMode) {
public boolean isMultiServerMode() {
return multiServerMode;
}

public void setAutoCreate(boolean autoCreate) {
this.autoCreate = autoCreate;
}

public boolean isAutoCreate() {
return autoCreate;
}

public void setStaticEnginesMode(boolean staticEnginesMode) {
this.staticEnginesMode = staticEnginesMode;
}

public boolean isStaticEnginesMode() {
return staticEnginesMode;
}

public void setSingleServerPropertiesFile(String singleServerPropertiesFile) {
this.singleServerPropertiesFile = singleServerPropertiesFile;
Expand Down Expand Up @@ -123,46 +147,58 @@ public synchronized void stop() {
}

public void start() {
if (isMultiServerMode()) {
File enginesDir = new File(AbstractCommandLauncher.getEnginesDir());
File[] files = null;

if (enginesDir != null) {
files = enginesDir.listFiles();
}

if (files == null) {
String firstAttempt = enginesDir.getAbsolutePath();
enginesDir = new File(".");
log.warn(
"Unable to retrieve engine properties files from {}. Trying current working directory {}",
firstAttempt, enginesDir.getAbsolutePath());

if (enginesDir != null) {
files = enginesDir.listFiles();
}
}

if (files != null) {
for (int i = 0; i < files.length; i++) {
engineCount++;
File file = files[i];
if (file.getName().endsWith(".properties")) {
enginesStarting.add(new EngineStarter(file.getAbsolutePath()));
}
}
} else {
log.error("Unable to retrieve engine properties files from default location or from current working directory. No engines to start.");
}

} else {
engineCount++;
enginesStarting.add(new EngineStarter(singleServerPropertiesFile));
}

for (EngineStarter starter : enginesStarting) {
starter.start();
}
if (staticEnginesMode) {
log.info("In static engine mode");
engines = staticEngines;
enginesStarting = staticEnginesStarting;
}

if (autoCreate) {
if (isMultiServerMode()) {
File enginesDir = new File(
AbstractCommandLauncher.getEnginesDir());
File[] files = null;

if (enginesDir != null) {
files = enginesDir.listFiles();
}

if (files == null) {
String firstAttempt = enginesDir.getAbsolutePath();
enginesDir = new File(".");
log.warn(
"Unable to retrieve engine properties files from {}. Trying current working directory {}",
firstAttempt, enginesDir.getAbsolutePath());

if (enginesDir != null) {
files = enginesDir.listFiles();
}
}

if (files != null) {
for (int i = 0; i < files.length; i++) {
engineCount++;
File file = files[i];
if (file.getName().endsWith(".properties")) {
enginesStarting.add(new EngineStarter(file
.getAbsolutePath()));
}
}
} else {
log.error("Unable to retrieve engine properties files from default location or from current working directory. No engines to start.");
}

} else {
engineCount++;
enginesStarting.add(new EngineStarter(
singleServerPropertiesFile));
}

for (EngineStarter starter : enginesStarting) {
starter.start();
}

}

}

Expand Down Expand Up @@ -386,7 +422,7 @@ public EngineStarter(String propertiesFile) {

@Override
public void run() {
ISymmetricEngine engine = create(propertiesFile);
ISymmetricEngine engine = create(propertiesFile);
if (engine != null && autoStart) {
engine.start();
}
Expand Down

0 comments on commit 4c9d182

Please sign in to comment.