Reduce line duplication due to moved class
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
This commit is contained in:
parent
fe8f0212ea
commit
7a2991acc1
@ -4,46 +4,8 @@
|
|||||||
*/
|
*/
|
||||||
package net.bigeon.gclc.socket;
|
package net.bigeon.gclc.socket;
|
||||||
|
|
||||||
/*-
|
|
||||||
* #%L
|
|
||||||
* GCLC Socket
|
|
||||||
* %%
|
|
||||||
* Copyright (C) 2016 - 2018 Bigeon
|
|
||||||
* %%
|
|
||||||
* This software is governed by the CeCILL license under French law and
|
|
||||||
* abiding by the rules of distribution of free software. You can use,
|
|
||||||
* modify and/ or redistribute the software under the terms of the CeCILL
|
|
||||||
* license as circulated by CEA, CNRS and INRIA at the following URL
|
|
||||||
* "http://www.cecill.info".
|
|
||||||
*
|
|
||||||
* As a counterpart to the access to the source code and rights to copy,
|
|
||||||
* modify and redistribute granted by the license, users are provided only
|
|
||||||
* with a limited warranty and the software's author, the holder of the
|
|
||||||
* economic rights, and the successive licensors have only limited
|
|
||||||
* liability.
|
|
||||||
*
|
|
||||||
* In this respect, the user's attention is drawn to the risks associated
|
|
||||||
* with loading, using, modifying and/or developing or reproducing the
|
|
||||||
* software by the user in light of its specific status of free software,
|
|
||||||
* that may mean that it is complicated to manipulate, and that also
|
|
||||||
* therefore means that it is reserved for developers and experienced
|
|
||||||
* professionals having in-depth computer knowledge. Users are therefore
|
|
||||||
* encouraged to load and test the software's suitability as regards their
|
|
||||||
* requirements in conditions enabling the security of their systems and/or
|
|
||||||
* data to be ensured and, more generally, to use and operate it in the
|
|
||||||
* same conditions as regards security.
|
|
||||||
*
|
|
||||||
* The fact that you are presently reading this means that you have had
|
|
||||||
* knowledge of the CeCILL license and that you accept its terms.
|
|
||||||
* #L%
|
|
||||||
*/
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.text.MessageFormat;
|
|
||||||
import java.util.Collection;
|
|
||||||
|
|
||||||
import net.bigeon.gclc.command.Command;
|
import net.bigeon.gclc.command.Command;
|
||||||
import net.bigeon.gclc.exception.CommandRunException;
|
import net.bigeon.gclc.exception.CommandRunException;
|
||||||
import net.bigeon.gclc.exception.CommandRunExceptionType;
|
|
||||||
import net.bigeon.gclc.manager.ConsoleInput;
|
import net.bigeon.gclc.manager.ConsoleInput;
|
||||||
import net.bigeon.gclc.manager.ConsoleOutput;
|
import net.bigeon.gclc.manager.ConsoleOutput;
|
||||||
|
|
||||||
@ -56,11 +18,7 @@ import net.bigeon.gclc.manager.ConsoleOutput;
|
|||||||
@Deprecated
|
@Deprecated
|
||||||
public final class RemoteDisconnectCommand<T> extends Command {
|
public final class RemoteDisconnectCommand<T> extends Command {
|
||||||
|
|
||||||
/** The connexion manager. */
|
private final net.bigeon.gclc.socket.cmd.RemoteDisconnectCommand real;
|
||||||
private final ConnexionManager<T> manager;
|
|
||||||
/** If all connexion should be disconnected when no argument have been
|
|
||||||
* specified. */
|
|
||||||
private final boolean all;
|
|
||||||
|
|
||||||
/** Create the disconnection command.
|
/** Create the disconnection command.
|
||||||
*
|
*
|
||||||
@ -71,8 +29,8 @@ public final class RemoteDisconnectCommand<T> extends Command {
|
|||||||
public RemoteDisconnectCommand(final String name, final ConnexionManager<T> manager,
|
public RemoteDisconnectCommand(final String name, final ConnexionManager<T> manager,
|
||||||
final boolean all) {
|
final boolean all) {
|
||||||
super(name);
|
super(name);
|
||||||
this.manager = manager;
|
real = new net.bigeon.gclc.socket.cmd.RemoteDisconnectCommand<>(name, manager,
|
||||||
this.all = all;
|
all);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
@ -81,52 +39,20 @@ public final class RemoteDisconnectCommand<T> extends Command {
|
|||||||
@Override
|
@Override
|
||||||
public void execute(final ConsoleOutput out, final ConsoleInput in,
|
public void execute(final ConsoleOutput out, final ConsoleInput in,
|
||||||
final String... args) throws CommandRunException {
|
final String... args) throws CommandRunException {
|
||||||
if (args.length == 0 && all) {
|
real.execute(out, in, args);
|
||||||
final Collection<String> coll = manager.getConnected();
|
|
||||||
for (final String string : coll) {
|
|
||||||
manager.disconnect(string);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (final String string : args) {
|
|
||||||
if (manager.isConnected(string)) {
|
|
||||||
manager.disconnect(string);
|
|
||||||
} else {
|
|
||||||
print(out,
|
|
||||||
MessageFormat.format("[WARNING] {0} is not connected", string)); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Print a message if the output is defined.
|
|
||||||
*
|
|
||||||
* @param out the output
|
|
||||||
* @param string the message
|
|
||||||
* @throws CommandRunException if the output exists but cannot be printed to */
|
|
||||||
private static void print(final ConsoleOutput out, final String string)
|
|
||||||
throws CommandRunException {
|
|
||||||
if (out != null) {
|
|
||||||
try {
|
|
||||||
out.println(string);
|
|
||||||
} catch (final IOException e) {
|
|
||||||
throw new CommandRunException(CommandRunExceptionType.INTERACTION,
|
|
||||||
"Unable to print to existing output", e); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see fr.bigeon.gclc.command.ICommand#tip() */
|
* @see fr.bigeon.gclc.command.ICommand#tip() */
|
||||||
@Override
|
@Override
|
||||||
public String tip() {
|
public String tip() {
|
||||||
return "Close a connexion."; //$NON-NLS-1$
|
return real.tip();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see fr.bigeon.gclc.command.Command#usageDetail() */
|
* @see fr.bigeon.gclc.command.Command#usageDetail() */
|
||||||
@Override
|
@Override
|
||||||
protected String usageDetail() {
|
protected String usageDetail() {
|
||||||
return MessageFormat.format(
|
return "";
|
||||||
" If arguments are provided the corresponding connexions are closed, otherwise\n{0} are.",
|
|
||||||
all ? "all connexions" : "none");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user