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

Allow more configuration on data caching #1042

Draft
wants to merge 14 commits into
base: development
Choose a base branch
from
Draft
40 changes: 31 additions & 9 deletions src/main/java/net/dv8tion/jda/api/JDABuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,21 @@
import net.dv8tion.jda.annotations.Incubating;
import net.dv8tion.jda.api.audio.factory.IAudioSendFactory;
import net.dv8tion.jda.api.entities.Activity;
import net.dv8tion.jda.api.entities.data.MutableGuildData;
import net.dv8tion.jda.api.entities.data.MutableMemberData;
import net.dv8tion.jda.api.entities.data.id.MemberId;
import net.dv8tion.jda.api.entities.data.provider.DataProvider;
import net.dv8tion.jda.api.entities.data.provider.SnowflakeDataProvider;
import net.dv8tion.jda.api.exceptions.AccountTypeException;
import net.dv8tion.jda.api.hooks.IEventManager;
import net.dv8tion.jda.api.hooks.VoiceDispatchInterceptor;
import net.dv8tion.jda.api.requests.RestAction;
import net.dv8tion.jda.api.utils.ChunkingFilter;
import net.dv8tion.jda.api.utils.Compression;
import net.dv8tion.jda.api.utils.SessionController;
import net.dv8tion.jda.api.utils.SessionControllerAdapter;
import net.dv8tion.jda.api.utils.*;
import net.dv8tion.jda.api.utils.cache.CacheFlag;
import net.dv8tion.jda.internal.JDAImpl;
import net.dv8tion.jda.internal.managers.PresenceImpl;
import net.dv8tion.jda.internal.utils.Checks;
import net.dv8tion.jda.internal.utils.config.AuthorizationConfig;
import net.dv8tion.jda.internal.utils.config.MetaConfig;
import net.dv8tion.jda.internal.utils.config.SessionConfig;
import net.dv8tion.jda.internal.utils.config.ThreadingConfig;
import net.dv8tion.jda.internal.utils.config.*;
import net.dv8tion.jda.internal.utils.config.flags.ConfigFlag;
import okhttp3.OkHttpClient;

Expand All @@ -58,6 +57,7 @@ public class JDABuilder
{
protected final List<Object> listeners;
protected final AccountType accountType;
protected final DataProviderConfig dataProviderConfig = new DataProviderConfig();

protected ScheduledExecutorService rateLimitPool = null;
protected boolean shutdownRateLimitPool = true;
Expand Down Expand Up @@ -853,6 +853,28 @@ public JDABuilder setVoiceDispatchInterceptor(@Nullable VoiceDispatchInterceptor
return this;
}

@Nonnull
public JDABuilder setDataProviderMode(@Nonnull DataMode mode)
{
Checks.notNull(mode, "Mode");
dataProviderConfig.setMode(mode);
return this;
}

@Nonnull
public JDABuilder setGuildDataProvider(@Nullable SnowflakeDataProvider<? extends MutableGuildData> provider)
{
this.dataProviderConfig.setGuildProvider(provider);
return this;
}

@Nonnull
public JDABuilder setMemberDataProvider(@Nullable DataProvider<? super MemberId, ? extends MutableMemberData> provider)
{
this.dataProviderConfig.setMemberProvider(provider);
return this;
}

/**
* The {@link ChunkingFilter} to filter which guilds should use member chunking.
* <br>By default this uses {@link ChunkingFilter#ALL}.
Expand Down Expand Up @@ -991,7 +1013,7 @@ public JDA build() throws LoginException
SessionConfig sessionConfig = new SessionConfig(controller, httpClient, wsFactory, voiceDispatchInterceptor, flags, maxReconnectDelay, largeThreshold);
MetaConfig metaConfig = new MetaConfig(maxBufferSize, contextMap, cacheFlags, flags);

JDAImpl jda = new JDAImpl(authConfig, sessionConfig, threadingConfig, metaConfig);
JDAImpl jda = new JDAImpl(authConfig, sessionConfig, threadingConfig, metaConfig, dataProviderConfig);
jda.setChunkingFilter(chunkingFilter);

if (eventManager != null)
Expand Down
1 change: 0 additions & 1 deletion src/main/java/net/dv8tion/jda/api/entities/SelfUser.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
*/
public interface SelfUser extends User
{

/**
* The status of this account's verification.
* (Have you accepted the verification email)
Expand Down
58 changes: 58 additions & 0 deletions src/main/java/net/dv8tion/jda/api/entities/data/GuildData.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright 2015-2019 Austin Keener, Michael Ritter, Florian Spieß, and the JDA contributors
*
* 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 net.dv8tion.jda.api.entities.data;

import net.dv8tion.jda.api.entities.Guild;

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

public interface GuildData
{
@Nonnull
GuildData copy();

@Nullable
String getIconId();
@Nullable
String getSplashId();
@Nullable
String getDescription();
@Nullable
String getBannerId();
@Nonnull
Guild.BoostTier getBoostTier();
int getBoostCount();
int getMaxMembers();
int getMaxPresences();
long getAfkChannelId();
long getSystemChannelId();
@Nonnull
Guild.Timeout getAfkTimeout();
@Nonnull
Guild.VerificationLevel getVerificationLevel();
@Nonnull
Guild.NotificationLevel getNotificationLevel();
@Nonnull
Guild.MFALevel getMFALevel();
@Nonnull
Guild.ExplicitContentLevel getExplicitContentLevel();
@Nonnull
String getRegion();
@Nullable
String getVanityCode();
}
42 changes: 42 additions & 0 deletions src/main/java/net/dv8tion/jda/api/entities/data/MemberData.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright 2015-2019 Austin Keener, Michael Ritter, Florian Spieß, and the JDA contributors
*
* 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 net.dv8tion.jda.api.entities.data;

import net.dv8tion.jda.api.OnlineStatus;
import net.dv8tion.jda.api.entities.Activity;
import net.dv8tion.jda.api.entities.ClientType;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.List;

public interface MemberData
{
@Nonnull
MemberData copy();

@Nullable
String getNickname();
long getTimeJoined();
long getTimeBoosted();
@Nonnull
List<Activity> getActivities();
@Nonnull
OnlineStatus getOnlineStatus();
@Nonnull
OnlineStatus getOnlineStatus(ClientType type);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright 2015-2019 Austin Keener, Michael Ritter, Florian Spieß, and the JDA contributors
*
* 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 net.dv8tion.jda.api.entities.data;

import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.data.light.LightGuildData;
import net.dv8tion.jda.api.entities.data.provider.SnowflakeDataProvider;
import net.dv8tion.jda.api.entities.data.rich.RichGuildData;

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

public interface MutableGuildData extends GuildData
{
SnowflakeDataProvider<MutableGuildData> LIGHT_PROVIDER = (id, flags) -> LightGuildData.SINGLETON;
SnowflakeDataProvider<MutableGuildData> RICH_PROVIDER = (id, flags) -> new RichGuildData();

void setIconId(@Nullable String id);
void setSplashId(@Nullable String id);
void setDescription(@Nullable String description);
void setBannerId(@Nullable String id);
void setBoostTier(@Nonnull Guild.BoostTier tier);
void setBoostCount(int count);
void setMaxMembers(int members);
void setMaxPresences(int presences);
void setAfkChannelId(long id);
void setSystemChannelId(long id);
void setAfkTimeout(@Nonnull Guild.Timeout timeout);
void setVerificationLevel(@Nonnull Guild.VerificationLevel level);
void setNotificationLevel(@Nonnull Guild.NotificationLevel level);
void setExplicitContentLevel(@Nonnull Guild.ExplicitContentLevel level);
void setMFALevel(@Nonnull Guild.MFALevel level);
void setRegion(@Nonnull String region);
void setVanityCode(@Nullable String code);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright 2015-2019 Austin Keener, Michael Ritter, Florian Spieß, and the JDA contributors
*
* 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 net.dv8tion.jda.api.entities.data;

import net.dv8tion.jda.api.OnlineStatus;
import net.dv8tion.jda.api.entities.Activity;
import net.dv8tion.jda.api.entities.ClientType;
import net.dv8tion.jda.api.entities.data.id.MemberId;
import net.dv8tion.jda.api.entities.data.light.LightMemberData;
import net.dv8tion.jda.api.entities.data.provider.DataProvider;
import net.dv8tion.jda.api.entities.data.rich.RichMemberData;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.List;

public interface MutableMemberData extends MemberData
{
DataProvider<MemberId, MutableMemberData> LIGHT_PROVIDER = (id, flags) -> LightMemberData.SINGLETON;
DataProvider<MemberId, MutableMemberData> RICH_PROVIDER = (id, flags) -> new RichMemberData(flags);

void setNickname(@Nullable String nickname);
void setTimeJoined(long time);
void setTimeBoosted(long time);
void setActivities(@Nonnull List<Activity> activities);
void setOnlineStatus(@Nonnull OnlineStatus status);
void setOnlineStatus(@Nonnull ClientType type, @Nonnull OnlineStatus status);

}
39 changes: 39 additions & 0 deletions src/main/java/net/dv8tion/jda/api/entities/data/id/MemberId.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright 2015-2020 Austin Keener, Michael Ritter, Florian Spieß, and the JDA contributors
*
* 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 net.dv8tion.jda.api.entities.data.id;

public class MemberId
{
private final long userId;
private final long guildId;

public MemberId(long userId, long guildId)
{
this.userId = userId;
this.guildId = guildId;
}

public long getUserId()
{
return userId;
}

public long getGuildId()
{
return guildId;
}
}