Skip to content
This repository was archived by the owner on Dec 8, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# feather-core [![License](https://img.shields.io/github/license/feather-core/feather-core.svg)](/LICENSE) [![Build status](https://img.shields.io/travis/feather-core/feather-core.svg)](https://travis-ci.org/feather-core/feather-core/)
[![Build Status](https://img.shields.io/badge/dynamic/json.svg?color=blueviolet&label=DubTrack&prefix=playing%20&query=data.currentSong.name&url=https%3A%2F%2Fapi.dubtrack.fm%2Froom%2Ffeather-core)](https://www.dubtrack.fm/join/feather-core)

Modularized minecraft server for advanced usage
44 changes: 44 additions & 0 deletions module-api/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?><!--
~ Copyright 2019 Feather Core
~
~ 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.
-->

<project 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">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>feather-core</artifactId>
<groupId>org.feathercore</groupId>
<version>1.0.0-SNAPSHOT</version>
</parent>

<artifactId>feathercore-module-api</artifactId>

<dependencies>
<dependency>
<groupId>${project.parent.groupId}</groupId>
<artifactId>feathercore-shared</artifactId>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>

<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright 2019 Feather Core
*
* 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 ru.feathercore.moduleapi;

import lombok.*;
import lombok.experimental.FieldDefaults;
import org.jetbrains.annotations.NotNull;

import java.util.Collection;
import java.util.Collections;

/**
* An abstract implementation of {@link ModuleLoader<M>} sufficient for all its requires operations.
*
* @param <M> super-type of all modules managed
*/
@ToString
@EqualsAndHashCode
@FieldDefaults(level = AccessLevel.PROTECTED, makeFinal = true)
public class AbstractModuleLoader<M extends Module> implements ModuleLoader<M> {

@NonNull Collection<? extends M> modules, modulesView;

public AbstractModuleLoader(@NonNull final Collection<? extends M> modules) {
this.modules = modules;
modulesView = Collections.unmodifiableCollection(modules);
}

@Override
public Collection<? extends M> getModules() {
return modulesView;
}

@Override
public <T extends M, C> T loadModule(@NonNull final ModuleInitializer<T, C> initializer, final C configuration) {
val module = initializer.loadModule(configuration);
onModuleLoad(module);

return module;
}

/**
* Callback used by {@link #loadModule(ModuleInitializer, Object)} to notify that the module has been loaded.
*
* @param module module which has just been loaded
*/
protected void onModuleLoad(@NotNull final M module) {}
}
23 changes: 23 additions & 0 deletions module-api/src/main/java/ru/feathercore/moduleapi/Module.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright 2019 Feather Core
*
* 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 ru.feathercore.moduleapi;

/**
* Base for any feather-core Module API's module
*/
public interface Module {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright 2019 Feather Core
*
* 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 ru.feathercore.moduleapi;

import lombok.NoArgsConstructor;

/**
* An exception thrown due to something being wrong with the configuration required by the module.
*/
@NoArgsConstructor
public class ModuleConfigurationException extends RuntimeException {

public ModuleConfigurationException(final String message) {
super(message);
}

public ModuleConfigurationException(final String message, final Throwable cause) {
super(message, cause);
}

public ModuleConfigurationException(final Throwable cause) {
super(cause);
}

public ModuleConfigurationException(final String message, final Throwable cause, final boolean enableSuppression,
final boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright 2019 Feather Core
*
* 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 ru.feathercore.moduleapi;

import lombok.NoArgsConstructor;

/**
* An exception thrown on module initialization.
*/
@NoArgsConstructor
public class ModuleInitializationException extends RuntimeException {

public ModuleInitializationException(final String message) {
super(message);
}

public ModuleInitializationException(final String message, final Throwable cause) {
super(message, cause);
}

public ModuleInitializationException(final Throwable cause) {
super(cause);
}

public ModuleInitializationException(final String message, final Throwable cause, final boolean enableSuppression,
final boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright 2019 Feather Core
*
* 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 ru.feathercore.moduleapi;

import org.feathercore.shared.object.ValueContainer;
import org.jetbrains.annotations.NotNull;

/**
* Initializer of a module which is normally used by {@link ModuleLoader} to load a specific module.
*
* @param <M> type of a module initialized
* @param <C> module configuration (use {@link Void} when none)
*/
@FunctionalInterface
public interface ModuleInitializer<M extends Module, C> {

/**
* Loads the associated module.
*
* @param configuration configuration of a module
* @return initialized module
* @throws ModuleConfigurationException if the configuration was proven to be inappropriate
* @throws ModuleInitializationException if a module could not be initialized
*
* @apiNote if a {@link ModuleConfigurationException} happens at the very module initialization
* then it is expected to be wrapped using {@link ModuleInitializationException}
*/
M loadModule(C configuration) throws ModuleConfigurationException, ModuleInitializationException;

/**
* Gets the default configuration for the module.
*
* @return value container of the default configuration if it exists
* or an empty one of this module initializer <b>requires</b> a configuration for which a default one does not exist
*
* @apiNote if type of {@link C} is {@link Void} then {@link ValueContainer#ofNull()} should be returned
*/
@NotNull default ValueContainer<C> getDefaultConfiguration() {
return ValueContainer.ofNull();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright 2019 Feather Core
*
* 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 ru.feathercore.moduleapi;

import lombok.NonNull;

import java.util.Collection;

/**
* Loader of {@link Module modules} which uses {@link ModuleInitializer initializers} for this purpose.
*
* @param <M> super-type of all modules managed
*/
public interface ModuleLoader<M extends Module> {

/**
* Loads a module provided by the specified initializer using the given configuration.
*
* @param initializer initializer to use for module's initialization
* @param configuration configuration required by the module
* (might be {@link null} depending on the initializer implementation)
* @param <T> exact type of a module loaded
* @param <C> configuration type of a module ({@link Void} if none is expected)
* @return initialized module
*/
<T extends M, C> T loadModule(@NonNull ModuleInitializer<T, C> initializer, C configuration);

/**
* Loads a module provided by the specified initializer using its default configuration.
*
* @param initializer initializer to use for module's initialization
* @param <T> exact type of a module loaded
* @param <C> configuration type of a module ({@link Void} if none is expected)
* @return initialized module
* @throws ModuleConfigurationException if this initializer doesn't allow default configuration
*/
default <T extends M, C> T loadModule(@NonNull ModuleInitializer<T, C> initializer) {
return loadModule(initializer, initializer.getDefaultConfiguration().orElseThrow(
() -> new ModuleConfigurationException(initializer + " does not allow usage of default configuration")
));
}

/**
* Gets all modules loaded by this module loader.
*
* @return all loaded modules
*
* @apiNote modifications to returned collection should not have side-effect on this module loader
*/
Collection<? extends M> getModules();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright 2019 Feather Core
*
* 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.
*/

/**
* Root package of feather-core's Module API providing its basic objects.
*/
package ru.feathercore.moduleapi;
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
<module>shared</module>
<module>runtime</module>
<module>eventbus</module>
<module>module-api</module>
<module>protocol</module>
</modules>

Expand Down Expand Up @@ -96,6 +97,11 @@
<artifactId>feathercore-eventbus</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>feathercore-module-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>feathercore-protocol</artifactId>
Expand Down
Loading