Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
freyacodes committed Jun 15, 2018
2 parents 8738c3c + f81b3f3 commit fbc2423
Show file tree
Hide file tree
Showing 18 changed files with 268 additions and 57 deletions.
3 changes: 2 additions & 1 deletion LavalinkClient/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
description = 'JDA based client for the Lavalink-Server'
version System.getenv('dev') == 'true' ? '-SNAPSHOT' : '2.0.1'
version System.getenv('dev') == 'true' ? '-SNAPSHOT' : '2.1'
ext {
moduleName = 'Lavalink-Client'
}
Expand Down Expand Up @@ -37,6 +37,7 @@ dependencies {
compile group: 'org.slf4j', name: 'slf4j-api', version: slf4jVersion
compile group: 'org.json', name: 'json', version: jsonOrgVersion
compile group: 'net.dv8tion', name: 'JDA', version: jdaVersion
compileOnly group: 'com.github.spotbugs', name: 'spotbugs-annotations', version: spotbugsAnnotationsVersion
compileOnly group: 'io.prometheus', name: 'simpleclient', version: prometheusVersion
testCompile group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: junitJupiterVersion
testCompile group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: junitJupiterVersion
Expand Down
20 changes: 10 additions & 10 deletions LavalinkClient/src/main/java/lavalink/client/io/Lavalink.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

package lavalink.client.io;

import edu.umd.cs.findbugs.annotations.NonNull;
import lavalink.client.LavalinkUtil;
import net.dv8tion.jda.core.JDA;
import net.dv8tion.jda.core.entities.Guild;
Expand All @@ -36,7 +37,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.annotation.Nonnull;
import java.net.URI;
import java.util.Collection;
import java.util.HashMap;
Expand Down Expand Up @@ -90,7 +90,7 @@ public boolean getAutoReconnect() {

private static final AtomicInteger nodeCounter = new AtomicInteger(0);

public void addNode(@Nonnull URI serverUri, @Nonnull String password) {
public void addNode(@NonNull URI serverUri, @NonNull String password) {
addNode("Lavalink_Node_#" + nodeCounter.getAndIncrement(), serverUri, password);
}

Expand All @@ -102,7 +102,7 @@ public void addNode(@Nonnull URI serverUri, @Nonnull String password) {
* @param password
* password of the node to be added
*/
public void addNode(@Nonnull String name, @Nonnull URI serverUri, @Nonnull String password) {
public void addNode(@NonNull String name, @NonNull URI serverUri, @NonNull String password) {
HashMap<String, String> headers = new HashMap<>();
headers.put("Authorization", password);
headers.put("Num-Shards", Integer.toString(numShards));
Expand All @@ -120,19 +120,19 @@ public void removeNode(int key) {
}

@SuppressWarnings("unused")
@Nonnull
@NonNull
public LavalinkLoadBalancer getLoadBalancer() {
return loadBalancer;
}

@SuppressWarnings("WeakerAccess")
@Nonnull
@NonNull
public Link getLink(String guildId) {
return links.computeIfAbsent(guildId, __ -> new Link(this, guildId));
}

@SuppressWarnings("WeakerAccess")
@Nonnull
@NonNull
public Link getLink(Guild guild) {
return getLink(guild.getId());
}
Expand All @@ -143,25 +143,25 @@ public int getNumShards() {
}

@SuppressWarnings("WeakerAccess")
@Nonnull
@NonNull
public Collection<Link> getLinks() {
return links.values();
}

@SuppressWarnings("WeakerAccess")
@Nonnull
@NonNull
public List<LavalinkSocket> getNodes() {
return nodes;
}

@SuppressWarnings("WeakerAccess")
@Nonnull
@NonNull
public JDA getJda(int shardId) {
return jdaProvider.apply(shardId);
}

@SuppressWarnings("WeakerAccess")
@Nonnull
@NonNull
public JDA getJdaFromSnowflake(String snowflake) {
return jdaProvider.apply(LavalinkUtil.getShardFromSnowflake(snowflake, numShards));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@

package lavalink.client.io;

import javax.annotation.Nonnull;
import edu.umd.cs.findbugs.annotations.NonNull;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand All @@ -38,7 +39,7 @@ public class LavalinkLoadBalancer {
this.lavalink = lavalink;
}

@Nonnull
@NonNull
public LavalinkSocket determineBestSocket(long guild) {
LavalinkSocket leastPenalty = null;
int record = Integer.MAX_VALUE;
Expand Down Expand Up @@ -75,6 +76,13 @@ void onNodeDisconnect(LavalinkSocket disconnected) {
}

void onNodeConnect(LavalinkSocket connected) {
long otherAvailableNodes = lavalink.getNodes().stream()
.filter(node -> node != connected)
.filter(LavalinkSocket::isAvailable)
.count();
if (otherAvailableNodes > 0) { //only update links if this is the only connected node
return;
}
lavalink.getLinks().forEach(link -> {
if (link.getNode(false) == null)
link.changeNode(connected);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
package lavalink.client.io;

import com.sedmelluq.discord.lavaplayer.track.AudioTrackEndReason;
import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.Nullable;
import lavalink.client.LavalinkUtil;
import lavalink.client.player.LavalinkPlayer;
import lavalink.client.player.event.PlayerEvent;
Expand All @@ -35,8 +37,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.io.IOException;
import java.net.ConnectException;
import java.net.URI;
Expand All @@ -49,19 +49,19 @@ public class LavalinkSocket extends ReusableWebSocket {
private static final Logger log = LoggerFactory.getLogger(LavalinkSocket.class);

private static final int TIMEOUT_MS = 5000;
@Nonnull
@NonNull
private final String name;
@Nonnull
@NonNull
private final Lavalink lavalink;
@Nullable
private RemoteStats stats;
long lastReconnectAttempt = 0;
private int reconnectsAttempted = 0;
@Nonnull
@NonNull
private final URI remoteUri;
private boolean available = false;

LavalinkSocket(@Nonnull String name, @Nonnull Lavalink lavalink, @Nonnull URI serverUri, Draft protocolDraft, Map<String, String> headers) {
LavalinkSocket(@NonNull String name, @NonNull Lavalink lavalink, @NonNull URI serverUri, Draft protocolDraft, Map<String, String> headers) {
super(serverUri, protocolDraft, headers, TIMEOUT_MS);
this.name = name;
this.lavalink = lavalink;
Expand Down Expand Up @@ -179,7 +179,7 @@ public void send(String text) throws NotYetConnectedException {
}
}

@Nonnull
@NonNull
@SuppressWarnings("unused")
public URI getRemoteUri() {
return remoteUri;
Expand All @@ -204,7 +204,7 @@ public boolean isAvailable() {
return available && isOpen() && !isClosing();
}

@Nonnull
@NonNull
public String getName() {
return name;
}
Expand Down
10 changes: 5 additions & 5 deletions LavalinkClient/src/main/java/lavalink/client/io/Link.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

package lavalink.client.io;

import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.Nullable;
import lavalink.client.player.LavalinkPlayer;
import net.dv8tion.jda.core.JDA;
import net.dv8tion.jda.core.Permission;
Expand All @@ -37,8 +39,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

/**
* Indicates which node we are linked to, what voice channel to use, and what player we are using
Expand Down Expand Up @@ -237,7 +237,7 @@ public State getState() {
return state;
}

void setState(@Nonnull State state) {
void setState(@NonNull State state) {
if (this.state == State.DESTROYED && state != State.DESTROYED)
throw new IllegalStateException("Cannot change state to " + state + " when state is " + State.DESTROYED);
if (this.state == State.DESTROYING && state != State.DESTROYED) {
Expand All @@ -248,7 +248,7 @@ void setState(@Nonnull State state) {
}

@SuppressWarnings("WeakerAccess")
@Nonnull
@NonNull
public JDA getJda() {
return lavalink.getJdaFromSnowflake(String.valueOf(guild));
}
Expand All @@ -260,7 +260,7 @@ private WebSocketClient getMainWs() {
/**
* Setter used by {@link VoiceStateUpdateInterceptor} to change the expected channel
*/
void setChannel(@Nonnull VoiceChannel channel) {
void setChannel(@NonNull VoiceChannel channel) {
this.channel = channel.getId();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package lavalink.client.io.metrics;

import edu.umd.cs.findbugs.annotations.NonNull;
import io.prometheus.client.Collector;
import io.prometheus.client.GaugeMetricFamily;
import lavalink.client.io.Lavalink;
import lavalink.client.io.LavalinkSocket;
import lavalink.client.io.RemoteStats;

import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand All @@ -21,7 +21,7 @@ public class LavalinkCollector extends Collector {

private final Lavalink lavalink;

public LavalinkCollector(@Nonnull Lavalink lavalinkInstance) {
public LavalinkCollector(@NonNull Lavalink lavalinkInstance) {
this.lavalink = lavalinkInstance;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public LavalinkPlayer(Link link) {

/**
* Invoked by {@link Link} to make sure we keep playing music on the new node
*
* <p>
* Used when we are moved to a new socket
*/
public void onNodeChange() {
Expand Down Expand Up @@ -93,6 +93,7 @@ public void playTrack(AudioTrack track) {
json.put("endTime", trackData.endPos);
}
json.put("pause", paused);
json.put("volume", volume);
//noinspection ConstantConditions
link.getNode(true).send(json.toString());

Expand Down
6 changes: 6 additions & 0 deletions LavalinkServer/application.yml.example
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,9 @@ lavalink:
sentryDsn: ""
bufferDurationMs: 400
youtubePlaylistLoadLimit: 600
gc-warnings: true

metrics:
prometheus:
enabled: false
endpoint: /metrics
13 changes: 8 additions & 5 deletions LavalinkServer/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@ apply plugin: 'com.gorylenko.gradle-git-properties'

description = 'Play audio to discord voice channels'
mainClassName = "lavalink.server.Launcher"
version '2.0.1'
version '2.1'
ext {
moduleName = 'Lavalink-Server'
}

bootJar {
archiveName = "Lavalink.jar"

requiresUnpack '**/jda-nas*.jar' //otherwise we get missing classes exceptions
}

bootRun {
Expand All @@ -30,16 +28,21 @@ bootRun {
dependencies {
compile group: 'com.sedmelluq', name: 'lavaplayer', version: lavaplayerVersion
compile group: 'com.github.DV8FromTheWorld', name: 'JDA-Audio', version: jdaAudioVersion
compile group: 'com.github.FredBoat', name: 'jda-nas', version: jdaNasVersion
compile group: 'com.github.FredBoat.jda-nas', name: 'jda-nas', version: jdaNasVersion
compile group: 'com.github.shredder121', name: 'jda-async-packetprovider', version: jappVersion
compile group: 'org.java-websocket', name: 'Java-WebSocket', version: javaWebSocketVersion
compile group: 'ch.qos.logback', name: 'logback-classic', version: logbackVersion
compile group: 'org.slf4j', name: 'slf4j-api', version: slf4jVersion
compile group: 'io.sentry', name: 'sentry-logback', version: sentryLogbackVersion
compile group: 'com.github.oshi', name: 'oshi-core', version: oshiVersion
compile group: 'org.json', name: 'json', version: jsonOrgVersion
compile group: 'com.google.guava', name: 'guava', version: guavaVersion
compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: springBootVersion
compileOnly group: 'com.github.spotbugs', name: 'spotbugs-annotations', version: spotbugsAnnotationsVersion

compile group: 'io.prometheus', name: 'simpleclient', version: prometheusVersion
compile group: 'io.prometheus', name: 'simpleclient_hotspot', version: prometheusVersion
compile group: 'io.prometheus', name: 'simpleclient_logback', version: prometheusVersion
compile group: 'io.prometheus', name: 'simpleclient_servlet', version: prometheusVersion
}

//create a simple version file that we will be reading to create appropriate docker tags
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ public class AudioPlayerConfiguration {
public AudioPlayerManager audioPlayerManager(AudioSourcesConfig sources, ServerConfig serverConfig) {

AudioPlayerManager audioPlayerManager = new DefaultAudioPlayerManager();
audioPlayerManager.enableGcMonitoring();

if (serverConfig.isGcWarnings()) {
audioPlayerManager.enableGcMonitoring();
}

if (sources.isYoutube()) {
YoutubeAudioSourceManager youtube = new YoutubeAudioSourceManager();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package lavalink.server.config;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

/**
* Created by napster on 20.05.18.
*/
@Component
@ConfigurationProperties("metrics.prometheus")
public class MetricsPrometheusConfigProperties {

private boolean enabled = false;
private String endpoint = "";

public boolean isEnabled() {
return enabled;
}

public void setEnabled(boolean enabled) {
this.enabled = enabled;
}

public String getEndpoint() {
return endpoint;
}

public void setEndpoint(String endpoint) {
this.endpoint = endpoint;
}
}
Loading

0 comments on commit fbc2423

Please sign in to comment.