-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Started BungeeCord channels implementation and generic handler list
- Loading branch information
Showing
15 changed files
with
767 additions
and
160 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
63 changes: 63 additions & 0 deletions
63
...rc/main/java/es/karmadev/locklogin/api/plugin/service/network/ChannelProviderService.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,63 @@ | ||
package es.karmadev.locklogin.api.plugin.service.network; | ||
|
||
import es.karmadev.locklogin.api.network.communication.packet.NetworkChannel; | ||
import es.karmadev.locklogin.api.plugin.service.PluginService; | ||
import es.karmadev.locklogin.api.task.FutureTask; | ||
|
||
import java.util.Collection; | ||
|
||
/** | ||
* Represents a channel provider service. This | ||
* service is responsible for creating {@link es.karmadev.locklogin.api.network.communication.packet.NetworkChannel channels}, | ||
* those channels are the ones who manage the | ||
* network communication. | ||
*/ | ||
public abstract class ChannelProviderService implements PluginService { | ||
|
||
/** | ||
* Get the service name | ||
* | ||
* @return the service name | ||
*/ | ||
public final String name() { | ||
return "plugin-messaging"; | ||
} | ||
|
||
/** | ||
* Get a collection of the registered | ||
* channels from this provider. | ||
* | ||
* @return the provider created channels | ||
*/ | ||
public abstract Collection<? extends NetworkChannel> getChannels(); | ||
|
||
/** | ||
* Get a channel | ||
* | ||
* @param channelName the channel name | ||
* @return the channel. Implementations should | ||
* return an existing channel if there was one | ||
* created with the same name previously. As that | ||
* what the plugin internally expects from the | ||
* channel | ||
*/ | ||
public abstract FutureTask<? extends NetworkChannel> getChannel(final String channelName); | ||
|
||
/** | ||
* Destroy a channel | ||
* | ||
* @param channelName the channel name to destroy | ||
* @return if the channel was destroyed | ||
*/ | ||
public abstract boolean destroyChannel(final String channelName); | ||
|
||
/** | ||
* Implementations may relay on 3rd party services | ||
* such as redis to create channels. This method verifies | ||
* that the provider is connected to that service | ||
* | ||
* @return if the provider is connected to all the | ||
* third party services it depends on | ||
*/ | ||
public abstract boolean isConnected(); | ||
} |
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
89 changes: 89 additions & 0 deletions
89
LockLoginBungee/src/main/java/es/karmadev/locklogin/bungee/network/BungeeChannel.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,89 @@ | ||
package es.karmadev.locklogin.bungee.network; | ||
|
||
import es.karmadev.locklogin.api.extension.module.Module; | ||
import es.karmadev.locklogin.api.network.communication.packet.NetworkChannel; | ||
import es.karmadev.locklogin.api.network.communication.packet.listener.NetworkListener; | ||
import es.karmadev.locklogin.api.network.communication.packet.listener.event.NetworkEvent; | ||
import es.karmadev.locklogin.api.network.server.packet.NetworkChannelQue; | ||
import es.karmadev.locklogin.common.util.generic.GenericHandlerList; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
/** | ||
* Represents a BungeeCord channel. The BungeeCord channel | ||
* is the default implementation which allows communication | ||
* between plugin instances. The implementation is potentially | ||
* compatible with multi-bungee instances, but it's recommended | ||
* to use Redis or Channels instead. | ||
*/ | ||
@RequiredArgsConstructor | ||
public class BungeeChannel implements NetworkChannel { | ||
|
||
private final String channel; | ||
private final BungeeMessagingQue que = new BungeeMessagingQue(); | ||
|
||
private final GenericHandlerList handlerList = new GenericHandlerList(); | ||
|
||
/** | ||
* Get the channel name this | ||
* network channel works at | ||
* | ||
* @return the channel name | ||
*/ | ||
@Override | ||
public String getChannel() { | ||
return channel; | ||
} | ||
|
||
/** | ||
* Get the channel que | ||
* | ||
* @return the channel que | ||
*/ | ||
@Override | ||
public NetworkChannelQue getProcessingQue() { | ||
return que; | ||
} | ||
|
||
/** | ||
* Handle a network event | ||
* | ||
* @param event the event to handle | ||
*/ | ||
@Override | ||
public void handle(final NetworkEvent event) { | ||
handlerList.handle(event); | ||
} | ||
|
||
/** | ||
* Add a listener | ||
* | ||
* @param module the module listener owner | ||
* @param listener the listener | ||
*/ | ||
@Override | ||
public void addListener(final Module module, final NetworkListener listener) { | ||
handlerList.addListeners(module, listener); | ||
} | ||
|
||
/** | ||
* Remove a single listener | ||
* | ||
* @param listener the listener to remove | ||
*/ | ||
@Override | ||
public void removeListener(final NetworkListener listener) { | ||
handlerList.removeListener(listener); | ||
} | ||
|
||
/** | ||
* Remove all the listeners registered | ||
* on the module | ||
* | ||
* @param module the module to remove listeners | ||
* from | ||
*/ | ||
@Override | ||
public void removeListeners(final Module module) { | ||
handlerList.removeListeners(module); | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
LockLoginBungee/src/main/java/es/karmadev/locklogin/bungee/network/BungeeMessagingQue.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,77 @@ | ||
package es.karmadev.locklogin.bungee.network; | ||
|
||
import es.karmadev.locklogin.api.network.server.packet.NetworkChannelQue; | ||
import es.karmadev.locklogin.api.network.server.packet.NetworkPacket; | ||
|
||
/** | ||
* Represents the BungeeCord messaging que | ||
*/ | ||
public class BungeeMessagingQue implements NetworkChannelQue { | ||
|
||
/** | ||
* Append a packet | ||
* | ||
* @param packet the packet to append | ||
* @throws SecurityException if there's no module trying to send the packet | ||
*/ | ||
@Override | ||
public void appendPacket(final NetworkPacket packet) throws SecurityException { | ||
|
||
} | ||
|
||
/** | ||
* Get the next packet | ||
* | ||
* @return the next packet | ||
*/ | ||
@Override | ||
public NetworkPacket nextPacket() { | ||
return null; | ||
} | ||
|
||
/** | ||
* Get the previous packet | ||
* | ||
* @return the previous packet | ||
*/ | ||
@Override | ||
public NetworkPacket previousPacket() { | ||
return null; | ||
} | ||
|
||
/** | ||
* Get if the queue is processing a packet | ||
* | ||
* @return if the queue is occupied | ||
*/ | ||
@Override | ||
public boolean processing() { | ||
return false; | ||
} | ||
|
||
/** | ||
* Cancel the current packet processing, and | ||
* move it to the latest in the queue | ||
*/ | ||
@Override | ||
public void shiftPacket() { | ||
|
||
} | ||
|
||
/** | ||
* Consume the current packet | ||
*/ | ||
@Override | ||
public void consumePacket() { | ||
|
||
} | ||
|
||
/** | ||
* Cancel the current packet processing, and | ||
* do nothing to it | ||
*/ | ||
@Override | ||
public void cancelPacket() { | ||
|
||
} | ||
} |
Oops, something went wrong.