optimized startup sequence

This commit is contained in:
2018-11-15 10:54:34 +01:00
parent 6f5baaaa69
commit 389e3a6a73
8 changed files with 195 additions and 128 deletions

View File

@ -17,6 +17,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<timestamp>${maven.build.timestamp}</timestamp>
<applicationUuid>143a2bd3-7e0b-4162-a76e-3031331c7dfe</applicationUuid>
<maven.compiler.source>10</maven.compiler.source>
<maven.compiler.target>10</maven.compiler.target>

View File

@ -1,59 +0,0 @@
package de.muehlencord.shared.account.web;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import javax.annotation.PostConstruct;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Named;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
* @author joern.muehlencord
*/
@Named(value = "applicationController")
@ApplicationScoped
public class ApplicationController {
private final static Logger LOGGER = LoggerFactory.getLogger(ApplicationController.class.getName());
private String version;
private String buildDate;
@PostConstruct
public void init() {
InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream("buildInfo.properties");
if (in == null) {
return;
}
Properties props = new Properties();
try {
props.load(in);
version = props.getProperty("build.version");
buildDate = props.getProperty("build.timestamp");
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("buildInfo.properties read successfully");
}
} catch (IOException ex) {
LOGGER.error("Cannot find buildInfo.properties. ", ex);
version = "??";
buildDate = "??";
}
}
/* *** getter / setter *** */
public String getVersion() {
return version;
}
public String getBuildDate() {
return buildDate;
}
}

View File

@ -1,67 +0,0 @@
/*
* Copyright 2018 Joern Muehlencord <joern at muehlencord.de>.
*
* 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 de.muehlencord.shared.account.web;
import de.muehlencord.shared.account.business.application.boundary.ApplicationService;
import de.muehlencord.shared.account.business.application.entity.ApplicationEntity;
import java.util.UUID;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.Produces;
import javax.inject.Named;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
* @author Joern Muehlencord <joern at muehlencord.de>
*/
@Named("applicationProdiucer")
@ApplicationScoped
public class ApplicationProducer {
private static final Logger LOGGER = LoggerFactory.getLogger(ApplicationProducer.class);
@EJB
ApplicationService applicationService;
private ApplicationEntity application = null;
@PostConstruct
public void init() {
String id = "143a2bd3-7e0b-4162-a76e-3031331c7dfe"; // TODO load from properties file
this.application = applicationService.findById(UUID.fromString(id));
if (application == null) {
LOGGER.error("Could not find application with id ");
} else {
LOGGER.info("Found application {} for id{}", application.getApplicationName(), id);
}
}
/**
* needs to return link to "Account UI" and not to current selected
* application TODO: ensure only Account UI can call functions where
* appliction can be handed in all other applications need to call the
* function which use the injected application
*/
@Produces
public ApplicationEntity getApplication() {
return application;
}
}

View File

@ -0,0 +1,71 @@
/*
* Copyright 2018 Joern Muehlencord <joern at muehlencord.de>.
*
* 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 de.muehlencord.shared.account.web.business.application.boundary;
import de.muehlencord.shared.account.business.application.entity.ApplicationEntity;
import de.muehlencord.shared.account.business.config.boundary.ConfigService;
import de.muehlencord.shared.account.business.config.entity.ConfigException;
import javax.annotation.PreDestroy;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.context.Initialized;
import javax.enterprise.event.Observes;
import javax.inject.Inject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
* @author Joern Muehlencord <joern at muehlencord.de>
*/
@ApplicationScoped
public class StartupBean {
private static final Logger LOGGER = LoggerFactory.getLogger(StartupBean.class);
@Inject
ConfigService configService;
@Inject
ApplicationEntity application;
public void init(@Observes @Initialized(ApplicationScoped.class) Object init) {
try {
LOGGER.info("Starting application {}", application.getApplicationName());
String instanceName = configService.getConfigValue("base.instance", "Development System", true);
LOGGER.info("instanceName={}", instanceName);
// ensure maxFailedLogins is available
configService.getConfigValue("account.maxFailedLogins", "5", true);
LOGGER.info("Application startup complete");
} catch (ConfigException ex) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(ex.toString(), ex);
} else {
LOGGER.error(ex.toString());
}
}
}
@PreDestroy
public void shutdown() {
LOGGER.info("Shutting down application {}", application.getApplicationName());
LOGGER.info("Application shutdown complete");
}
}

View File

@ -0,0 +1,116 @@
/*
* Copyright 2018 Joern Muehlencord <joern at muehlencord.de>.
*
* 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 de.muehlencord.shared.account.web.business.application.control;
import de.muehlencord.shared.account.business.application.boundary.ApplicationService;
import de.muehlencord.shared.account.business.application.entity.ApplicationEntity;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import java.util.UUID;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.Produces;
import javax.inject.Named;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
* @author Joern Muehlencord <joern at muehlencord.de>
*/
@Named("applicationController")
@ApplicationScoped
public class ApplicationController {
private static final Logger LOGGER = LoggerFactory.getLogger(ApplicationController.class);
@EJB
ApplicationService applicationService;
private String version;
private String buildDate;
private UUID uuid;
private ApplicationEntity application = null;
@PostConstruct
public void readBuildInfoProperties() {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Trying to read buildInfo.properties");
}
InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream("buildInfo.properties");
if (in == null) {
return;
}
Properties props = new Properties();
try {
props.load(in);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("properties read from buildInfo.properties");
}
version = props.getProperty("build.version");
buildDate = props.getProperty("build.timestamp");
uuid = UUID.fromString(props.getProperty("application.uuid"));
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("buildInfo.properties parsed successfully");
}
} catch (IOException ex) {
LOGGER.error("Cannot find buildInfo.properties. ", ex);
version = "??";
buildDate = "??";
uuid = null;
LOGGER.error("Application id not readable, application will not be able to run");
}
if (uuid != null) {
this.application = applicationService.findById(uuid);
if (application == null) {
LOGGER.error("Could not find application with id ");
} else {
LOGGER.info("Found application {} with id {}", application.getApplicationName(), uuid.toString());
}
}
}
/**
* needs to return link to "Account UI" and not to current selected
* application TODO: ensure only Account UI can call functions where
* appliction can be handed in - all other applications need to call the
* function which use the injected application
*/
@Produces
public ApplicationEntity getApplication() {
return application;
}
public String getVersion() {
return version;
}
public String getBuildDate() {
return buildDate;
}
public UUID getApplicationId() {
return uuid;
}
}

View File

@ -1,2 +1,3 @@
build.version=${project.version}
build.timestamp=${timestamp}
build.timestamp=${timestamp}
application.uuid=${applicationUuid}