public class CLI extends Object
Handle commands delivered interactively as command strings. For example, the
following loads a Persistit database located in directory /var/lib/data,
selects a volume named xyz, and displays page 42 of that volume:
load datapath=/var/lib/data
select volume=xyz
view page=42
CLI operates in one of two modes: "live" and "standalone".
In live mode you use one of several access methods to invoke commands to be
processed within an actively running server process that has initialized
Persistit. Access methods include the AdminUI utility, the Persistit
management MBean, a simple network server that can receive command lines from
an external tool, or via an application program using the Management
interface.
In stand-alone mode you specify through the open
command a path
on which to find Persistit database files; the open command creates a
read-only version Persistit instance capable of performing read-only
operations such as save
, backup
or
icheck
on the data found in those files.
CLI can set up an extremely simple network server that works with telnet,
curl or the simple client built into the main(String[])
method of
this class. The advantage is that you can then issue commands interactively
from a simple network client using the full facilities of the shell,
including piping the output to tools such as grep and more.
To run the CLI in standalone mode, simply execute
java -cp persisit.jar com.persistit.Persistit cliport=9999
or
java -cp persisit.jar com.persistit.Persistit script=pathname
where persistit.jar contains the Persistit
library. The first option specifies a port on which CLI will listen for
commands. (Use a port number larger than 1024 to avoid permissions problems.)
The second option executes commands from a text file in batch mode.
The following *nix client script works with the network server facility:
#!/bin/sh
java -cp persistit.jar com.persistit.CLI 9999 $*
(Substitute the port number assigned to the
cliport parameter above.)
With this script you can then enter command such as this at the shell:
pcli init datapath=/var/lib/data
pcli select volume=xyz
pcli view page=42
Commands are defined below in methods annotated with @Cmd having parameters
annotated with @Arg. The format of the argument annotation is specified in
ArgParser
. Enter the command 'help' to see a readable list of
commands and their arguments.
Modifier and Type | Class and Description |
---|---|
static interface |
CLI.Arg
Annotation for parameters of command methods
|
static interface |
CLI.Cmd
Annotation for methods that implement commands
|
Constructor and Description |
---|
CLI(Persistit persistit) |
CLI(Persistit persistit,
BufferedReader reader,
PrintWriter writer) |
CLI(Persistit persistit,
int port) |
Modifier and Type | Method and Description |
---|---|
static void |
main(String[] args)
Simple client for CLI server.
|
static List<String> |
pieces(String commandLine)
Parse a command line string consisting of a command followed by flags and
name=value parameters, all separate by spaces.
|
static void |
registerCommands(Class<?> clazz)
Registers command methods provided by the supplied Class.
|
static void |
runScript(Persistit persistit,
BufferedReader reader,
PrintWriter writer)
Invoke lines read from the supplied
BufferedReader as CLI
commands and write any generated output to the supplied
PrintWriter . |
public CLI(Persistit persistit)
public CLI(Persistit persistit, int port) throws IOException
IOException
public CLI(Persistit persistit, BufferedReader reader, PrintWriter writer)
public static void registerCommands(Class<?> clazz)
clazz
- public static void main(String[] args) throws Exception
java -cp classpath com.persistit.CLI port command arg arg arg ...
to execute a CLI command on the CLI server, e.g.,
java -cp persistit.jar com.persistit.CLI 9999 select volume=akiban_data
To execute the select command on a server on port 9999.args
- Exception
public static void runScript(Persistit persistit, BufferedReader reader, PrintWriter writer) throws Exception
BufferedReader
as CLI
commands and write any generated output to the supplied
PrintWriter
.persistit
- reader
- writer
- Exception
public static List<String> pieces(String commandLine)
commandLine
- Copyright © 2025 Open Identity Platform Community. All rights reserved.