optimized startup sequence
This commit is contained in:
@ -17,6 +17,7 @@
|
|||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<timestamp>${maven.build.timestamp}</timestamp>
|
<timestamp>${maven.build.timestamp}</timestamp>
|
||||||
|
<applicationUuid>143a2bd3-7e0b-4162-a76e-3031331c7dfe</applicationUuid>
|
||||||
<maven.compiler.source>10</maven.compiler.source>
|
<maven.compiler.source>10</maven.compiler.source>
|
||||||
<maven.compiler.target>10</maven.compiler.target>
|
<maven.compiler.target>10</maven.compiler.target>
|
||||||
|
|
||||||
|
|||||||
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -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;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -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");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,2 +1,3 @@
|
|||||||
build.version=${project.version}
|
build.version=${project.version}
|
||||||
build.timestamp=${timestamp}
|
build.timestamp=${timestamp}
|
||||||
|
application.uuid=${applicationUuid}
|
||||||
@ -38,6 +38,7 @@ import org.hibernate.annotations.Type;
|
|||||||
@XmlRootElement
|
@XmlRootElement
|
||||||
@NamedQueries({
|
@NamedQueries({
|
||||||
@NamedQuery(name = "AccountEntity.findAll", query = "SELECT a FROM AccountEntity a ORDER by a.lastname, a.firstname"),
|
@NamedQuery(name = "AccountEntity.findAll", query = "SELECT a FROM AccountEntity a ORDER by a.lastname, a.firstname"),
|
||||||
|
@NamedQuery(name = "AccountEntity.findByUsername", query = "SELECT a FROM AccountEntity a WHERE a.username = :username"),
|
||||||
@NamedQuery(name = "AccountEntity.findByStatus", query = "SELECT a FROM AccountEntity a WHERE a.status = :status"),
|
@NamedQuery(name = "AccountEntity.findByStatus", query = "SELECT a FROM AccountEntity a WHERE a.status = :status"),
|
||||||
@NamedQuery(name = "AccountEntity.findByCreatedOn", query = "SELECT a FROM AccountEntity a WHERE a.createdOn = :createdOn"),
|
@NamedQuery(name = "AccountEntity.findByCreatedOn", query = "SELECT a FROM AccountEntity a WHERE a.createdOn = :createdOn"),
|
||||||
@NamedQuery(name = "AccountEntity.findByCreatedBy", query = "SELECT a FROM AccountEntity a WHERE a.createdBy = :createdBy"),
|
@NamedQuery(name = "AccountEntity.findByCreatedBy", query = "SELECT a FROM AccountEntity a WHERE a.createdBy = :createdBy"),
|
||||||
|
|||||||
@ -9,7 +9,6 @@ import de.muehlencord.shared.account.business.config.entity.ConfigException;
|
|||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import javax.annotation.PostConstruct;
|
|
||||||
import javax.ejb.Lock;
|
import javax.ejb.Lock;
|
||||||
import javax.ejb.LockType;
|
import javax.ejb.LockType;
|
||||||
import javax.ejb.Singleton;
|
import javax.ejb.Singleton;
|
||||||
@ -81,6 +80,8 @@ public class ConfigService implements Serializable {
|
|||||||
return getConfigValue(configKey, defaultValue, false);
|
return getConfigValue(configKey, defaultValue, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
@Lock(LockType.WRITE)
|
||||||
public String getConfigValue(String configKey, String defaultValue, boolean storeDefaultValue) throws ConfigException {
|
public String getConfigValue(String configKey, String defaultValue, boolean storeDefaultValue) throws ConfigException {
|
||||||
// get configValue as usual
|
// get configValue as usual
|
||||||
String configValue = getConfigValue(configKey);
|
String configValue = getConfigValue(configKey);
|
||||||
@ -121,6 +122,8 @@ public class ConfigService implements Serializable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
@Lock(LockType.WRITE)
|
||||||
public String getConfigValue(String configKey, String defaultValue, boolean storeDefaultValue, Account account, boolean fallbackToSystem) throws ConfigException {
|
public String getConfigValue(String configKey, String defaultValue, boolean storeDefaultValue, Account account, boolean fallbackToSystem) throws ConfigException {
|
||||||
String configValue = getConfigValue(configKey, account, fallbackToSystem);
|
String configValue = getConfigValue(configKey, account, fallbackToSystem);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user