ASysCore: Init module
This commit is contained in:
37
core/pom.xml
37
core/pom.xml
@@ -1,14 +1,39 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
|
||||||
|
http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<name>Core</name>
|
||||||
|
|
||||||
|
<artifactId>core</artifactId>
|
||||||
|
<version>0.1-SNAPSHOT</version>
|
||||||
|
<packaging>bundle</packaging>
|
||||||
|
|
||||||
<parent>
|
<parent>
|
||||||
<artifactId>arcadexsystem</artifactId>
|
<artifactId>arcadexsystem</artifactId>
|
||||||
<groupId>eu.arcadex.system</groupId>
|
<groupId>eu.arcadex.system</groupId>
|
||||||
<version>${global.version}</version>
|
<version>${global.version}</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
|
|
||||||
<artifactId>core</artifactId>
|
<build>
|
||||||
<packaging>jar</packaging>
|
<finalName>${groupId}.${artifactId}-${version}</finalName>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.felix</groupId>
|
||||||
|
<artifactId>maven-bundle-plugin</artifactId>
|
||||||
|
<version>2.3.5</version>
|
||||||
|
<extensions>true</extensions>
|
||||||
|
<configuration>
|
||||||
|
<instructions>
|
||||||
|
<Bundle-Name>Arcadex System: ${name} ${version}</Bundle-Name>
|
||||||
|
<Bundle-SymbolicName>${groupId}.${artifactId}</Bundle-SymbolicName>
|
||||||
|
<Bundle-Activator>eu.arcadex.system.core.ASysCoreActivator</Bundle-Activator>
|
||||||
|
<Export-Package>eu.arcadex.system.core.api</Export-Package>
|
||||||
|
<Import-Package>*</Import-Package>
|
||||||
|
</instructions>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
</project>
|
</project>
|
||||||
93
core/src/main/java/eu/arcadex/system/core/ASysCore.java
Normal file
93
core/src/main/java/eu/arcadex/system/core/ASysCore.java
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
package eu.arcadex.system.core;
|
||||||
|
|
||||||
|
import eu.arcadex.system.core.api.ICore;
|
||||||
|
import org.osgi.framework.Bundle;
|
||||||
|
import org.osgi.framework.BundleContext;
|
||||||
|
import org.osgi.framework.BundleException;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author DmitriyMX <mail@dmitriymx.ru>
|
||||||
|
* 2016
|
||||||
|
*/
|
||||||
|
class ASysCore implements ICore {
|
||||||
|
private Logger logger = LoggerFactory.getLogger(ASysCore.class.getName());
|
||||||
|
private BundleContext bundleContext;
|
||||||
|
private List<Bundle> modules;
|
||||||
|
|
||||||
|
ASysCore(BundleContext bundleContext) {
|
||||||
|
this.bundleContext = bundleContext;
|
||||||
|
}
|
||||||
|
|
||||||
|
void init() {
|
||||||
|
// Загрузка библиотек
|
||||||
|
logger.trace("Load libraries");
|
||||||
|
startBundles(loadJars("lib"));
|
||||||
|
|
||||||
|
// Загрузка модулей
|
||||||
|
logger.trace("Load modules");
|
||||||
|
modules = loadJars("modules");
|
||||||
|
startBundles(modules);
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Bundle> loadJars(String directory) {
|
||||||
|
List<Bundle> bundlesList = new ArrayList<>();
|
||||||
|
|
||||||
|
File libsDir = new File(directory);
|
||||||
|
String[] jarsList = libsDir.list();
|
||||||
|
for (String jar : jarsList) {
|
||||||
|
if (!jar.endsWith(".jar")) continue;
|
||||||
|
try {
|
||||||
|
logger.trace("Load jar \"{}/{}\"", directory, jar);
|
||||||
|
Bundle bundle = bundleContext.installBundle(String.format("file:%s/%s", directory, jar));
|
||||||
|
bundlesList.add(bundle);
|
||||||
|
} catch (BundleException e) {
|
||||||
|
logger.error(String.format("Error load jar \"%s/%s\"", directory, jar), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return bundlesList;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void startBundles(List<Bundle> bundleList) {
|
||||||
|
for (Bundle bundle : bundleList) {
|
||||||
|
try {
|
||||||
|
logger.trace("Start module \"{}\"", bundle.getSymbolicName());
|
||||||
|
bundle.start();
|
||||||
|
} catch (BundleException e) {
|
||||||
|
logger.error(String.format("Error start bundle \"%s\"", bundle.getSymbolicName()), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void stopBundles(List<Bundle> bundleList) {
|
||||||
|
for (Bundle bundle : bundleList) {
|
||||||
|
try {
|
||||||
|
bundle.stop();
|
||||||
|
} catch (BundleException e) {
|
||||||
|
logger.error(String.format("Error stop bundle \"%s\"", bundle.getSymbolicName()), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void reloadMoludes() {
|
||||||
|
logger.trace("Reload modules - start");
|
||||||
|
|
||||||
|
// Остановка модулей
|
||||||
|
stopBundles(modules);
|
||||||
|
|
||||||
|
// Загрузка модулей по-новой
|
||||||
|
modules = loadJars("modules");
|
||||||
|
|
||||||
|
// Запуск модулей
|
||||||
|
startBundles(modules);
|
||||||
|
|
||||||
|
logger.trace("Reload modules - end");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package eu.arcadex.system.core;
|
||||||
|
|
||||||
|
import eu.arcadex.system.core.api.ICore;
|
||||||
|
import org.osgi.framework.BundleActivator;
|
||||||
|
import org.osgi.framework.BundleContext;
|
||||||
|
import org.osgi.framework.ServiceRegistration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author DmitriyMX <mail@dmitriymx.ru>
|
||||||
|
* 2016
|
||||||
|
*/
|
||||||
|
public class ASysCoreActivator implements BundleActivator {
|
||||||
|
private ServiceRegistration<?> service;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void start(BundleContext bundleContext) throws Exception {
|
||||||
|
ASysCore core = new ASysCore(bundleContext);
|
||||||
|
|
||||||
|
// Регистрация сервиса доступа к Ядру
|
||||||
|
service = bundleContext.registerService(ICore.class.getName(), core, null);
|
||||||
|
|
||||||
|
// Инициализация Ядра
|
||||||
|
core.init();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void stop(BundleContext bundleContext) throws Exception {
|
||||||
|
service.unregister();
|
||||||
|
}
|
||||||
|
}
|
||||||
9
core/src/main/java/eu/arcadex/system/core/api/ICore.java
Normal file
9
core/src/main/java/eu/arcadex/system/core/api/ICore.java
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
package eu.arcadex.system.core.api;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author DmitriyMX <mail@dmitriymx.ru>
|
||||||
|
* 2016
|
||||||
|
*/
|
||||||
|
public interface ICore {
|
||||||
|
void reloadMoludes();
|
||||||
|
}
|
||||||
46
pom.xml
46
pom.xml
@@ -3,9 +3,11 @@
|
|||||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<name>Arcadex System</name>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<global.version>0.1</global.version>
|
<global.version>0.1</global.version>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<groupId>eu.arcadex.system</groupId>
|
<groupId>eu.arcadex.system</groupId>
|
||||||
@@ -43,47 +45,19 @@
|
|||||||
<target>1.8</target>
|
<target>1.8</target>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-shade-plugin</artifactId>
|
|
||||||
<version>2.1</version>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<phase>package</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>shade</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
<configuration>
|
|
||||||
<filters>
|
|
||||||
<filter>
|
|
||||||
<artifact>*:*</artifact>
|
|
||||||
<excludes>
|
|
||||||
<exclude>**/*.java</exclude>
|
|
||||||
<exclude>**/*.SF</exclude>
|
|
||||||
<exclude>**/*.DSA</exclude>
|
|
||||||
</excludes>
|
|
||||||
</filter>
|
|
||||||
</filters>
|
|
||||||
<transformers>
|
|
||||||
<!-- ToDo: Change main class -->
|
|
||||||
<transformer
|
|
||||||
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
|
||||||
<mainClass>eu.arcadex.system.ArcadexSystemImpl</mainClass>
|
|
||||||
</transformer>
|
|
||||||
</transformers>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.projectlombok</groupId>
|
<groupId>org.slf4j</groupId>
|
||||||
<artifactId>lombok</artifactId>
|
<artifactId>slf4j-api</artifactId>
|
||||||
<version>1.16.2</version>
|
<version>1.7.20</version>
|
||||||
<scope>provided</scope>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.osgi</groupId>
|
||||||
|
<artifactId>org.osgi.core</artifactId>
|
||||||
|
<version>6.0.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
Reference in New Issue
Block a user