Skip to content

[0.4] Metrics #39

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

Open
wants to merge 2 commits into
base: refactor/0.4-old
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
/*
* Anvil - AnvilPowered
* Copyright (C) 2020-2021
*
* This program 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.
*
* This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
*/

package org.anvilpowered.anvil.api.misc

import com.google.common.reflect.TypeToken
import com.google.inject.Key
import com.google.inject.Provider
import com.google.inject.TypeLiteral
import org.anvilpowered.anvil.api.Anvil
import org.anvilpowered.anvil.api.datastore.DBComponent

@Suppress("unchecked", "UnstableApiUsage")
interface BindingExtensions {

/**
* Full binding method for a component
*
* A typical example of usage of this method:
*
* be.bind(
*
* &nbsp;&nbsp;new TypeToken<FooRepository<?, ?, ?>>(getClass()) {
* },
*
* &nbsp;&nbsp;new TypeToken<FooRepository<?, Foo<?, ?>>(getClass()) {
* },
*
* &nbsp;&nbsp;new TypeToken<FooRepository<ObjectId, Foo<ObjectId>, Datastore>>(getClass()) {
* },
*
* &nbsp;&nbsp;new TypeToken<CommonMongoFooRepository<TMongoFoo>>(getClass()) { // final implementation
* },
*
* &nbsp;&nbsp;Names.named("mongodb")
*
* );
*/
fun <From1 : DBComponent<*, *>, From2 : DBComponent<*, *>, From3 : From1, Target : From1> bind(
from1: TypeToken<From1>,
from2: TypeToken<From2>,
from3: TypeToken<From3>,
target: TypeToken<Target>,
componentAnnotation: Annotation,
)

/**
* Binding method for a component
*
*
* A typical example of usage of this method:
*
* be.bind(
*
* &nbsp;&nbsp;new TypeToken<FooRepository<?, ?>>(getClass()) {
* },
*
* &nbsp;&nbsp;new TypeToken<FooRepository<ObjectId, Datastore>>(getClass()) {
* },
*
* &nbsp;&nbsp;new TypeToken<CommonMongoFooRepository>(getClass()) { // final implementation
* },
* &nbsp;&nbsp;Names.named("mongodb")
*
* );
*/
fun <From1 : DBComponent<*, *>, From2 : From1, Target : From1> bind(
from1: TypeToken<From1>,
from2: TypeToken<From2>,
target: TypeToken<Target>,
componentAnnotation: Annotation,
)

fun <From, Target : From> bind(
from: TypeToken<From>,
target: TypeToken<Target>,
annotation: Annotation,
)

fun <From, Target : From> bind(
from: TypeToken<From>,
target: TypeToken<Target>,
annotation: Class<out Annotation>,
)

fun <From, Target : From> bind(
from: TypeToken<From>,
target: TypeToken<Target>,
)

/**
* Binds the mongodb [DataStoreContext]
*
* Using this method is the same as invoking:
*
* bind(new TypeLiteral<DataStoreContext<ObjectId, Datastore>>() {
* }).to(MongoContext.class);
*/
fun withMongoDB()

/**
* Binds the xodus [DataStoreContext]
*
* Using this method is the same as invoking:
*
* binder.bind(new TypeLiteral<DataStoreContext<EntityId, PersistentEntityStore>>() {
* }).to(XodusContext.class);
*
*/
fun withXodus()

companion object {
fun <T> getTypeLiteral(typeToken: TypeToken<T>): TypeLiteral<T> {
return TypeLiteral.get(typeToken.type) as TypeLiteral<T>
}

fun <T> getKey(typeToken: TypeToken<T>): Key<T>? {
return Key.get(getTypeLiteral(typeToken))
}

fun <T> asInternalProvider(clazz: Class<T>): Provider<T> {
return Provider { Anvil.getEnvironment().injector.getInstance(clazz) }
}

fun <T> asInternalProvider(typeLiteral: TypeLiteral<T>): Provider<T> {
return Anvil.getEnvironment().injector.getProvider(Key.get(typeLiteral))
}

fun <T> asInternalProvider(typeToken: TypeToken<T>): Provider<T> {
return Anvil.getEnvironment().injector.getProvider(getKey(typeToken))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,6 @@ interface PluginInfo : Named {
val organizationName: String

val buildDate: String

val metricIds: Map<String, Int>
}
2 changes: 2 additions & 0 deletions anvil-bungee/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ dependencies {
}

implementation bungee
implementation bstats
implementation configurate_hocon
implementation javasisst
implementation(kotlin_reflect + ":" + kotlin_version)
Expand Down Expand Up @@ -50,6 +51,7 @@ shadowJar {
include dependency(apache_commons)
include dependency(aopalliance)
include dependency(bson)
include dependency(bstats)
include dependency(configurate_core)
include dependency(configurate_hocon)
include dependency(guice)
Expand Down
Loading