-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Expose ChannelInitializerHolder in protocol module #3776
Open
Outfluencer
wants to merge
9
commits into
SpigotMC:master
Choose a base branch
from
Outfluencer:make-channel-init-accessable
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+175
−33
Open
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c688495
Make all ChannelInitializer more accessible
Outfluencer f46349a
Null check channelInitializer
Outfluencer 582e08e
Remove unused code
Outfluencer 6e11b0f
Fix import
Outfluencer 8f30738
Improve comment in ChannelInitializerHolder (#6)
FlorianMichael ba5bffa
Full imports
Outfluencer 93e0e3c
Use a proper factory design
Outfluencer c02566b
Merge remote-tracking branch 'origin/make-channel-init-accessable' in…
Outfluencer 7963f79
Remove static instances
Outfluencer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
84 changes: 84 additions & 0 deletions
84
protocol/src/main/java/net/md_5/bungee/protocol/channel/BungeeChannelInitializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package net.md_5.bungee.protocol.channel; | ||
|
||
import com.google.common.base.Preconditions; | ||
import io.netty.channel.Channel; | ||
import io.netty.channel.ChannelInitializer; | ||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
/* | ||
* This class holds all minecraft related channel initializers. BungeeCord will set these values | ||
* on startup, and they can be used by third party plugins to modify the channel pipeline. | ||
* | ||
* Please note that this API is unsafe and doesn't provide any guarantees about the stability of the | ||
* channel pipeline. Use at your own risk. | ||
*/ | ||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
public abstract class BungeeChannelInitializer | ||
{ | ||
/** | ||
* Holds the channel initializer for incoming connections | ||
*/ | ||
@Getter | ||
private static BungeeChannelInitializer frontendHolder; | ||
/** | ||
* Holds the channel initializer for the connection to the backend server | ||
*/ | ||
@Getter | ||
private static BungeeChannelInitializer backendHolder; | ||
/** | ||
* Holds the channel initializer for server info requests to the backend server | ||
*/ | ||
@Getter | ||
private static BungeeChannelInitializer serverInfoHolder; | ||
|
||
public abstract ChannelAcceptor getChannelAcceptor(); | ||
public abstract ChannelInitializer<Channel> getChannelInitializer(); | ||
|
||
/** | ||
* Creates a new instance of BungeeChannelInitializer | ||
* | ||
* @param acceptor the {@link ChannelAcceptor} that will accept the channel and initializer the pipeline | ||
* @return {@link BungeeChannelInitializer} containing a cached {@link ChannelInitializer} that will call the acceptor | ||
*/ | ||
public static BungeeChannelInitializer create(ChannelAcceptor acceptor) | ||
{ | ||
return new BungeeChannelInitializer() | ||
{ | ||
@Getter | ||
private final ChannelAcceptor channelAcceptor = acceptor; | ||
|
||
@Getter // cache the ChannelInitializer | ||
private final ChannelInitializer<Channel> channelInitializer = new ChannelInitializer<Channel>() | ||
{ | ||
@Override | ||
protected void initChannel(Channel channel) throws Exception | ||
{ | ||
if ( !getChannelAcceptor().accept( channel ) ) | ||
{ | ||
channel.close(); | ||
} | ||
} | ||
}; | ||
}; | ||
} | ||
|
||
public static void setFrontendHolder(BungeeChannelInitializer channelInitializer) | ||
{ | ||
Preconditions.checkNotNull( channelInitializer, "channelInitializer" ); | ||
frontendHolder = channelInitializer; | ||
} | ||
|
||
public static void setBackendHolder(BungeeChannelInitializer channelInitializer) | ||
{ | ||
Preconditions.checkNotNull( channelInitializer, "channelInitializer" ); | ||
backendHolder = channelInitializer; | ||
} | ||
|
||
public static void setServerInfoHolder(BungeeChannelInitializer channelInitializer) | ||
{ | ||
Preconditions.checkNotNull( channelInitializer, "channelInitializer" ); | ||
serverInfoHolder = channelInitializer; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
protocol/src/main/java/net/md_5/bungee/protocol/channel/ChannelAcceptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package net.md_5.bungee.protocol.channel; | ||
|
||
import io.netty.channel.Channel; | ||
|
||
@FunctionalInterface | ||
public interface ChannelAcceptor | ||
{ | ||
/** | ||
* Inside this method the pipeline should be initialized. | ||
* | ||
* @param channel the channel to be accepted and initialized | ||
* @return if the channel was accepted | ||
*/ | ||
boolean accept(Channel channel); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these shouldn't be static
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should i put the non static objects into BungeeCord.java and make them accessable via
ProxyServer.getInstance().unsafe()?