Package ej.rcommand.impl
Class DefaultRemoteCommandManager
- java.lang.Object
-
- ej.rcommand.impl.DefaultRemoteCommandManager
-
- All Implemented Interfaces:
CommandSenderProvider,RemoteCommandManager
- Direct Known Subclasses:
GatewayRemoteCommandManager
public class DefaultRemoteCommandManager extends Object implements RemoteCommandManager
-
-
Constructor Summary
Constructors Constructor Description DefaultRemoteCommandManager()Creates a default remote command manager.DefaultRemoteCommandManager(boolean overwrite)Creates a default remote command manager.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Collection<? extends CommandSender>getCommandSenders(String command)Returns the command senders that handle the given command.protected RemoteCommandListenergetListenerFor(String command)Returns theRemoteConnectionListenerfor the given command.Collection<String>getRegisteredCommands()Gets the collections of registered commands withCommandSenderProvider.registerListener(RemoteCommandListener).voidonError(RemoteConnection connection)Called when an error occurs in the given connectionvoidregisterListener(RemoteCommandListener listener)Registers a listener that will be called when command managed by the listener is read.voidsendNotification(RemoteNotification notification)Sends the given notification to all connected clients.voidstartReading(RemoteConnection connection)Can be called once.voidstartReading(RemoteConnection connection, RemoteConnectionListener listener)Can be called once.voidstartReading(RemoteConnection connection, String connectionName)Can be called once.voidstartReading(RemoteConnection connection, String connectionName, RemoteConnectionListener listener)Can be called once.voidstopAll()Stops all the connections.voidstopReading(RemoteConnection connection)Stops reading the commands from the givenCommandReader.
-
-
-
Constructor Detail
-
DefaultRemoteCommandManager
public DefaultRemoteCommandManager(boolean overwrite)
Creates a default remote command manager.It is possible to choose the policy when a listener is registered that manage the same command as another one. Either drop the new one or overwrite the old one.
- Parameters:
overwrite- the listener policy,trueto overwrite the old one,falseotherwise.
-
DefaultRemoteCommandManager
public DefaultRemoteCommandManager()
Creates a default remote command manager.Equivalent as calling
DefaultRemoteCommandManager(boolean)withfalseas parameter.
-
-
Method Detail
-
registerListener
public void registerListener(RemoteCommandListener listener) throws IllegalStateException
Description copied from interface:CommandSenderProviderRegisters a listener that will be called when command managed by the listener is read.- Specified by:
registerListenerin interfaceCommandSenderProvider- Parameters:
listener- the listener to register- Throws:
IllegalStateException- if a listener is already registered for a command managed by the listener
-
getListenerFor
@Nullable protected RemoteCommandListener getListenerFor(String command)
Returns theRemoteConnectionListenerfor the given command.
-
startReading
public void startReading(RemoteConnection connection)
Can be called once.- Specified by:
startReadingin interfaceRemoteCommandManager- Parameters:
connection- the connection to read.
-
startReading
public void startReading(RemoteConnection connection, RemoteConnectionListener listener)
Can be called once.- Specified by:
startReadingin interfaceRemoteCommandManager- Parameters:
connection- the connection to read.listener- the associated listener.
-
startReading
public void startReading(RemoteConnection connection, String connectionName)
Can be called once.- Specified by:
startReadingin interfaceRemoteCommandManager- Parameters:
connection- the connection to read.connectionName- the name of the connection to read.
-
startReading
public void startReading(RemoteConnection connection, String connectionName, @Nullable RemoteConnectionListener listener)
Can be called once.- Specified by:
startReadingin interfaceRemoteCommandManager- Parameters:
connection- the connection to read.connectionName- the name of the connection to read.listener- the associated listener.
-
stopReading
public void stopReading(RemoteConnection connection)
Description copied from interface:RemoteCommandManagerStops reading the commands from the givenCommandReader.- Specified by:
stopReadingin interfaceRemoteCommandManager- Parameters:
connection- the connection to stop to read.
-
onError
public void onError(RemoteConnection connection)
Called when an error occurs in the given connection
-
stopAll
public void stopAll()
Description copied from interface:RemoteCommandManagerStops all the connections.- Specified by:
stopAllin interfaceRemoteCommandManager
-
getCommandSenders
public Collection<? extends CommandSender> getCommandSenders(String command)
Description copied from interface:CommandSenderProviderReturns the command senders that handle the given command.Synchronize on this
CommandSenderProviderwhile using the returned collection to avoid concurrent modifications of the collection.- Specified by:
getCommandSendersin interfaceCommandSenderProvider
-
getRegisteredCommands
public Collection<String> getRegisteredCommands()
Description copied from interface:CommandSenderProviderGets the collections of registered commands withCommandSenderProvider.registerListener(RemoteCommandListener).- Specified by:
getRegisteredCommandsin interfaceCommandSenderProvider- Returns:
- the collections of registered commands
-
sendNotification
public void sendNotification(RemoteNotification notification)
Description copied from interface:RemoteCommandManagerSends the given notification to all connected clients.- Specified by:
sendNotificationin interfaceRemoteCommandManager- Parameters:
notification- the notification to send.
-
-