Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Folia 1.21.4 support #124

Open
wants to merge 15 commits into
base: feat/folia
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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: 2 additions & 2 deletions .github/workflows/preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- name: Configure GPG Key
run: echo "${{secrets.SIGNING_KEY}}" | base64 --decode > /tmp/keyring.gpg
- name: Set up JDK 17
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
java-version: 17
distribution: zulu
Expand Down Expand Up @@ -39,7 +39,7 @@ jobs:
- name: Configure GPG Key
run: echo "${{secrets.SIGNING_KEY}}" | base64 --decode > /tmp/keyring.gpg
- name: Set up JDK 17
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
java-version: 17
distribution: zulu
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- name: Configure GPG Key
run: echo "${{secrets.SIGNING_KEY}}" | base64 --decode > /tmp/keyring.gpg
- name: Set up JDK 17
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
java-version: 17
distribution: zulu
Expand All @@ -38,7 +38,7 @@ jobs:
- name: Configure GPG Key
run: echo "${{secrets.SIGNING_KEY}}" | base64 --decode > /tmp/keyring.gpg
- name: Set up JDK 17
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
java-version: 17
distribution: zulu
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@

.gradle
build
**/run*/
**/run*/
.kotlin
.vscode/
58 changes: 58 additions & 0 deletions api/bin/main/dev/cubxity/plugins/metrics/api/UnifiedMetrics.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* This file is part of UnifiedMetrics.
*
* UnifiedMetrics is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* UnifiedMetrics is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with UnifiedMetrics. If not, see <https://www.gnu.org/licenses/>.
*/

package dev.cubxity.plugins.metrics.api

import dev.cubxity.plugins.metrics.api.logging.Logger
import dev.cubxity.plugins.metrics.api.metric.MetricsManager
import dev.cubxity.plugins.metrics.api.platform.Platform
import kotlinx.coroutines.CoroutineDispatcher

/**
* The UnifiedMetrics API
*/
interface UnifiedMetrics {
/**
* The platform UnifiedMetrics is running on.
*/
val platform: Platform

/**
* The name of this server.
*
* This is defined in the UnifiedMetrics configuration file, and is used for
* grouping server data.
*
* The default server name is "global"
*/
val serverName: String

/**
* The platform's logger.
*/
val logger: Logger

/**
* The platform's dispatcher.
*/
val dispatcher: CoroutineDispatcher

/**
* The metrics api.
*/
val metricsManager: MetricsManager
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* This file is part of UnifiedMetrics.
*
* UnifiedMetrics is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* UnifiedMetrics is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with UnifiedMetrics. If not, see <https://www.gnu.org/licenses/>.
*/

package dev.cubxity.plugins.metrics.api

/**
* Provides static access to the [UnifiedMetrics] service.
*/
object UnifiedMetricsProvider {
@JvmStatic
private var instance: UnifiedMetrics? = null

@JvmStatic
fun get(): UnifiedMetrics =
instance ?: error("The UnifiedMetrics API is not loaded.")

@JvmStatic
fun register(instance: UnifiedMetrics) {
UnifiedMetricsProvider.instance = instance
}

@JvmStatic
fun unregister() {
instance = null
}
}
30 changes: 30 additions & 0 deletions api/bin/main/dev/cubxity/plugins/metrics/api/logging/Logger.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* This file is part of UnifiedMetrics.
*
* UnifiedMetrics is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* UnifiedMetrics is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with UnifiedMetrics. If not, see <https://www.gnu.org/licenses/>.
*/

package dev.cubxity.plugins.metrics.api.logging

interface Logger {
fun info(message: String)

fun warn(message: String)

fun warn(message: String, error: Throwable)

fun severe(message: String)

fun severe(message: String, error: Throwable)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* This file is part of UnifiedMetrics.
*
* UnifiedMetrics is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* UnifiedMetrics is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with UnifiedMetrics. If not, see <https://www.gnu.org/licenses/>.
*/

package dev.cubxity.plugins.metrics.api.metric

import java.io.Closeable

interface MetricsDriver : Closeable {
fun initialize()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* This file is part of UnifiedMetrics.
*
* UnifiedMetrics is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* UnifiedMetrics is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with UnifiedMetrics. If not, see <https://www.gnu.org/licenses/>.
*/

package dev.cubxity.plugins.metrics.api.metric

import dev.cubxity.plugins.metrics.api.UnifiedMetrics
import kotlinx.serialization.KSerializer

interface MetricsDriverFactory<T : Any> {
val configSerializer: KSerializer<T>

val defaultConfig: T

fun createDriver(api: UnifiedMetrics, config: T): MetricsDriver
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* This file is part of UnifiedMetrics.
*
* UnifiedMetrics is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* UnifiedMetrics is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with UnifiedMetrics. If not, see <https://www.gnu.org/licenses/>.
*/

package dev.cubxity.plugins.metrics.api.metric

import dev.cubxity.plugins.metrics.api.metric.collector.CollectorCollection
import dev.cubxity.plugins.metrics.api.metric.data.Metric

interface MetricsManager {
val collections: List<CollectorCollection>

fun initialize()

fun registerCollection(collection: CollectorCollection)

fun unregisterCollection(collection: CollectorCollection)

fun registerDriver(name: String, factory: MetricsDriverFactory<out Any>)

/**
* This should be called asynchronously
*/
suspend fun collect(): List<Metric>

fun dispose()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* This file is part of UnifiedMetrics.
*
* UnifiedMetrics is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* UnifiedMetrics is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with UnifiedMetrics. If not, see <https://www.gnu.org/licenses/>.
*/

package dev.cubxity.plugins.metrics.api.metric.collector

import dev.cubxity.plugins.metrics.api.metric.data.Metric

const val NANOSECONDS_PER_MILLISECOND: Double = 1E6
const val NANOSECONDS_PER_SECOND: Double = 1E9
const val MILLISECONDS_PER_SECOND: Double = 1E3

interface Collector {
/**
* Collects the metric and returns a list of samples.
*
* @return [List] of [Metric]
*/
fun collect(): List<Metric>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* This file is part of UnifiedMetrics.
*
* UnifiedMetrics is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* UnifiedMetrics is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with UnifiedMetrics. If not, see <https://www.gnu.org/licenses/>.
*/

package dev.cubxity.plugins.metrics.api.metric.collector

import dev.cubxity.plugins.metrics.api.metric.data.Metric
import dev.cubxity.plugins.metrics.api.util.fastFlatMap

interface CollectorCollection {
/**
* List of collectors associated with this metric.
*/
val collectors: List<Collector>

/**
* Whether the collection should be collected asynchronously.
*/
val isAsync: Boolean get() = false

fun initialize() {
// Do nothing
}

fun dispose() {
// Do nothing
}
}

fun CollectorCollection.collect(): List<Metric> =
collectors.fastFlatMap { it.collect() }
Loading