public String getName() { return command.getName(); }
public String getName() { return command.getName(); }
@Override public void register(Object service) { synchronized (services) { services.put(service, service); if (service instanceof Command) { Command cmd = (Command) service; String key = cmd.getScope() + ":" + cmd.getName(); commands.computeIfAbsent(key, k -> new ArrayList<>()).add(cmd); } } }
@Override public void register(Object service) { synchronized (services) { services.put(service, service); if (service instanceof Command) { Command cmd = (Command) service; String key = cmd.getScope() + ":" + cmd.getName(); commands.computeIfAbsent(key, k -> new ArrayList<>()).add(cmd); } } }
@Override public void register(Object service) { synchronized (services) { services.put(service, service); if (service instanceof Command) { Command cmd = (Command) service; String key = cmd.getScope() + ":" + cmd.getName(); commands.computeIfAbsent(key, k -> new ArrayList<>()).add(cmd); } } }
@Override public void register(Object service) { synchronized (services) { services.put(service, service); if (service instanceof Command) { Command cmd = (Command) service; String key = cmd.getScope() + ":" + cmd.getName(); commands.computeIfAbsent(key, k -> new ArrayList<>()).add(cmd); } } }
@Override public void unregister(Object service) { synchronized (services) { services.remove(service); if (service instanceof Command) { Command cmd = (Command) service; String key = cmd.getScope() + ":" + cmd.getName(); List<Command> cmds = commands.get(key); if (cmds != null) { cmds.remove(cmd); if (cmds.isEmpty()) { commands.remove(key); } } } } }
@Override public void unregister(Object service) { synchronized (services) { services.remove(service); if (service instanceof Command) { Command cmd = (Command) service; String key = cmd.getScope() + ":" + cmd.getName(); List<Command> cmds = commands.get(key); if (cmds != null) { cmds.remove(cmd); if (cmds.isEmpty()) { commands.remove(key); } } } } }
@Override public void unregister(Object service) { synchronized (services) { services.remove(service); if (service instanceof Command) { Command cmd = (Command) service; String key = cmd.getScope() + ":" + cmd.getName(); List<Command> cmds = commands.get(key); if (cmds != null) { cmds.remove(cmd); if (cmds.isEmpty()) { commands.remove(key); } } } } }
@Override public void unregister(Object service) { synchronized (services) { services.remove(service); if (service instanceof Command) { Command cmd = (Command) service; String key = cmd.getScope() + ":" + cmd.getName(); List<Command> cmds = commands.get(key); if (cmds != null) { cmds.remove(cmd); if (cmds.isEmpty()) { commands.remove(key); } } } } }
@Override public Set<String> getCommands() { return factory.getRegistry().getCommands().stream() .map(c -> c.getScope() + ":" + c.getName()) .collect(Collectors.toSet()); } @Override
@Override public Set<String> getCommands() { return factory.getRegistry().getCommands().stream() .map(c -> c.getScope() + ":" + c.getName()) .collect(Collectors.toSet()); } @Override
@Override protected boolean isVisible(Object service) { if (this.serviceVisibleMap.get() == null) { this.serviceVisibleMap.set(new HashMap<>()); } if (this.serviceVisibleMap.get().get(service) != null) { return this.serviceVisibleMap.get().get(service); } if (service instanceof Command) { Command cmd = (Command) service; boolean ret = isVisible(cmd.getScope(), cmd.getName()); this.serviceVisibleMap.get().put(service, ret); return ret; } else { boolean ret = super.isVisible(service); this.serviceVisibleMap.get().put(service, ret); return ret; } }
@Override public int complete(Session session, CommandLine commandLine, List<String> candidates) { // TODO: optimize List<Command> list = session.getRegistry().getCommands(); Set<String> names = new HashSet<>(); for (Command command : list) { names.add(command.getScope() + ":" + command.getName()); names.add(command.getName()); } int res = new StringsCompleter(names).complete(session, commandLine, candidates); Collections.sort(candidates); return res; }
@Override public int complete(Session session, CommandLine commandLine, List<String> candidates) { // TODO: optimize List<Command> list = session.getRegistry().getCommands(); Set<String> names = new HashSet<>(); for (Command command : list) { names.add(command.getScope() + ":" + command.getName()); names.add(command.getName()); } int res = new StringsCompleter(names).complete(session, commandLine, candidates); Collections.sort(candidates); return res; }
@Override public String resolveCommand(String name) { // TODO: optimize if (!name.contains(":")) { String[] scopes = ((String) get(Session.SCOPE)).split(":"); List<Command> commands = registry.getCommands(); for (String scope : scopes) { for (Command command : commands) { if ((Session.SCOPE_GLOBAL.equals(scope) || command.getScope().equals(scope)) && command.getName().equals(name)) { return command.getScope() + ":" + name; } } } } return name; }
@Override public String resolveCommand(String name) { // TODO: optimize if (!name.contains(":")) { String[] scopes = ((String) get(Session.SCOPE)).split(":"); List<Command> commands = registry.getCommands(); for (String scope : scopes) { for (Command command : commands) { if ((Session.SCOPE_GLOBAL.equals(scope) || command.getScope().equals(scope)) && command.getName().equals(name)) { return command.getScope() + ":" + name; } } } } return name; }
@Override public String resolveCommand(String name) { // TODO: optimize if (!name.contains(":")) { String[] scopes = ((String) get(Session.SCOPE)).split(":"); List<Command> commands = registry.getCommands(); for (String scope : scopes) { boolean globalScope = Session.SCOPE_GLOBAL.equals(scope); for (Command command : commands) { if ((globalScope || command.getScope().equals(scope)) && command.getName().equals(name)) { return command.getScope() + ":" + name; } } } } return name; }
@Override public String resolveCommand(String name) { // TODO: optimize if (!name.contains(":")) { String[] scopes = ((String) get(Session.SCOPE)).split(":"); List<Command> commands = registry.getCommands(); for (String scope : scopes) { boolean globalScope = Session.SCOPE_GLOBAL.equals(scope); for (Command command : commands) { if ((globalScope || command.getScope().equals(scope)) && command.getName().equals(name)) { return command.getScope() + ":" + name; } } } } return name; }
@Override public void unregister(Object service) { synchronized (services) { super.unregister(service); if (service instanceof Command) { Command command = (Command) service; String scope = command.getScope(); String name = command.getName(); commandProcessor.removeCommand(scope, name); if (!Session.SCOPE_GLOBAL.equals(scope)) { if (subshells.get(scope).decrement() == 0) { SubShellCommand subShell = subshells.remove(scope); unregister(subShell); } } } } }