use of jline.ConsoleReader in project distributedlog by twitter.
the class ConsoleProxyRRMultiWriter method main.
public static void main(String[] args) throws Exception {
if (2 != args.length) {
System.out.println(HELP);
return;
}
String finagleNameStr = args[0];
final String streamList = args[1];
DistributedLogClient client = DistributedLogClientBuilder.newBuilder().clientId(ClientId$.MODULE$.apply("console-proxy-writer")).name("console-proxy-writer").thriftmux(true).finagleNameStr(finagleNameStr).build();
String[] streamNameList = StringUtils.split(streamList, ',');
RRMultiWriter<Integer, String> writer = new RRMultiWriter(streamNameList, client);
ConsoleReader reader = new ConsoleReader();
String line;
while ((line = reader.readLine(PROMPT_MESSAGE)) != null) {
writer.write(line).addEventListener(new FutureEventListener<DLSN>() {
@Override
public void onFailure(Throwable cause) {
System.out.println("Encountered error on writing data");
cause.printStackTrace(System.err);
Runtime.getRuntime().exit(0);
}
@Override
public void onSuccess(DLSN value) {
// done
}
});
}
client.close();
}
use of jline.ConsoleReader in project distributedlog by twitter.
the class ConsoleProxyWriter method main.
public static void main(String[] args) throws Exception {
if (2 != args.length) {
System.out.println(HELP);
return;
}
String finagleNameStr = args[0];
final String streamName = args[1];
DistributedLogClient client = DistributedLogClientBuilder.newBuilder().clientId(ClientId$.MODULE$.apply("console-proxy-writer")).name("console-proxy-writer").thriftmux(true).finagleNameStr(finagleNameStr).build();
ConsoleReader reader = new ConsoleReader();
String line;
while ((line = reader.readLine(PROMPT_MESSAGE)) != null) {
client.write(streamName, ByteBuffer.wrap(line.getBytes(UTF_8))).addEventListener(new FutureEventListener<DLSN>() {
@Override
public void onFailure(Throwable cause) {
System.out.println("Encountered error on writing data");
cause.printStackTrace(System.err);
Runtime.getRuntime().exit(0);
}
@Override
public void onSuccess(DLSN value) {
// done
}
});
}
client.close();
}
use of jline.ConsoleReader in project distributedlog by twitter.
the class ConsoleWriter method main.
public static void main(String[] args) throws Exception {
if (2 != args.length) {
System.out.println(HELP);
return;
}
String dlUriStr = args[0];
final String streamName = args[1];
URI uri = URI.create(dlUriStr);
DistributedLogConfiguration conf = new DistributedLogConfiguration();
conf.setImmediateFlushEnabled(true);
conf.setOutputBufferSize(0);
conf.setPeriodicFlushFrequencyMilliSeconds(0);
conf.setLockTimeout(DistributedLogConstants.LOCK_IMMEDIATE);
DistributedLogNamespace namespace = DistributedLogNamespaceBuilder.newBuilder().conf(conf).uri(uri).regionId(DistributedLogConstants.LOCAL_REGION_ID).clientId("console-writer").build();
// open the dlm
System.out.println("Opening log stream " + streamName);
DistributedLogManager dlm = namespace.openLog(streamName);
try {
AsyncLogWriter writer = null;
try {
writer = FutureUtils.result(dlm.openAsyncLogWriter());
ConsoleReader reader = new ConsoleReader();
String line;
while ((line = reader.readLine(PROMPT_MESSAGE)) != null) {
writer.write(new LogRecord(System.currentTimeMillis(), line.getBytes(UTF_8))).addEventListener(new FutureEventListener<DLSN>() {
@Override
public void onFailure(Throwable cause) {
System.out.println("Encountered error on writing data");
cause.printStackTrace(System.err);
Runtime.getRuntime().exit(0);
}
@Override
public void onSuccess(DLSN value) {
// done
}
});
}
} finally {
if (null != writer) {
FutureUtils.result(writer.asyncClose(), Duration.apply(5, TimeUnit.SECONDS));
}
}
} finally {
dlm.close();
namespace.close();
}
}
use of jline.ConsoleReader in project eiger by wlloyd.
the class CliMain method main.
public static void main(String[] args) throws IOException {
// process command line arguments
CliOptions cliOptions = new CliOptions();
cliOptions.processArgs(sessionState, args);
// connect to cassandra server if host argument specified.
if (sessionState.hostName != null) {
try {
connect(sessionState.hostName, sessionState.thriftPort);
} catch (RuntimeException e) {
sessionState.err.println(e.getMessage());
System.exit(-1);
}
}
if (cliClient == null) {
// Connection parameter was either invalid or not present.
// User must connect explicitly using the "connect" CLI statement.
cliClient = new CliClient(sessionState, null);
}
// load statements from file and process them
if (sessionState.inFileMode()) {
FileReader fileReader;
try {
fileReader = new FileReader(sessionState.filename);
} catch (IOException e) {
sessionState.err.println(e.getMessage());
return;
}
evaluateFileStatements(new BufferedReader(fileReader));
return;
}
ConsoleReader reader = new ConsoleReader();
if (!sessionState.batch) {
reader.addCompletor(completer);
reader.setBellEnabled(false);
String historyFile = System.getProperty("user.home") + File.separator + HISTORYFILE;
try {
History history = new History(new File(historyFile));
reader.setHistory(history);
} catch (IOException exp) {
sessionState.err.printf("Unable to open %s for writing %n", historyFile);
}
} else if (// if in batch mode but no verbose flag
!sessionState.verbose) {
sessionState.out.close();
}
cliClient.printBanner();
String prompt;
String line = "";
String currentStatement = "";
boolean inCompoundStatement = false;
while (line != null) {
prompt = (inCompoundStatement) ? "...\t" : getPrompt(cliClient);
try {
line = reader.readLine(prompt);
} catch (IOException e) {
// retry on I/O Exception
}
if (line == null)
return;
line = line.trim();
// skipping empty and comment lines
if (line.isEmpty() || line.startsWith("--"))
continue;
currentStatement += line;
if (line.endsWith(";") || line.equals("?")) {
processStatementInteractive(currentStatement);
currentStatement = "";
inCompoundStatement = false;
} else {
// ready for new line
currentStatement += " ";
inCompoundStatement = true;
}
}
}
use of jline.ConsoleReader in project tomee by apache.
the class CliRunnable method run.
@Override
public void run() {
clean();
try {
final StreamManager streamManager = new StreamManager(out, err, lineSep);
final ConsoleReader reader = new ConsoleReader(sin, streamManager.getSout());
reader.addCompletor(new FileNameCompletor());
reader.addCompletor(new SimpleCompletor(COMMANDS.keySet().toArray(new String[COMMANDS.size()])));
// TODO : add completers
String line;
final StringBuilder builtWelcome = new StringBuilder("Apache OpenEJB ").append(OpenEjbVersion.get().getVersion()).append(" build: ").append(OpenEjbVersion.get().getDate()).append("-").append(OpenEjbVersion.get().getTime()).append(lineSep);
if (tomee) {
builtWelcome.append(OS_LINE_SEP).append(PROPERTIES.getProperty(WELCOME_TOMEE_KEY));
} else {
builtWelcome.append(OS_LINE_SEP).append(PROPERTIES.getProperty(WELCOME_OPENEJB_KEY));
}
builtWelcome.append(lineSep).append(PROPERTIES.getProperty(WELCOME_COMMON_KEY));
streamManager.writeOut(OpenEjbVersion.get().getUrl());
streamManager.writeOut(builtWelcome.toString().replace("$bind", bind).replace("$port", Integer.toString(port)).replace("$name", NAME).replace(OS_LINE_SEP, lineSep));
while ((line = reader.readLine(prompt())) != null) {
// do we need a command for it?
if (EXIT_COMMAND.equals(line)) {
break;
}
Class<?> cmdClass = null;
String key = null;
for (final Map.Entry<String, Class<?>> cmd : COMMANDS.entrySet()) {
if (line.startsWith(cmd.getKey())) {
cmdClass = cmd.getValue();
key = cmd.getKey();
break;
}
}
if (cmdClass != null) {
final ObjectRecipe recipe = new ObjectRecipe(cmdClass);
recipe.setProperty("streamManager", streamManager);
recipe.setProperty("command", line);
recipe.setProperty("scripter", scripter);
recipe.setProperty("commands", COMMANDS);
recipe.allow(Option.CASE_INSENSITIVE_PROPERTIES);
recipe.allow(Option.IGNORE_MISSING_PROPERTIES);
recipe.allow(Option.NAMED_PARAMETERS);
try {
final AbstractCommand cmdInstance = (AbstractCommand) recipe.create();
cmdInstance.execute(trunc(line, key));
} catch (Exception e) {
streamManager.writeErr(e);
}
} else {
streamManager.writeErr("sorry i don't understand '" + line + "'");
}
}
clean();
} catch (IOException e) {
clean();
throw new CliRuntimeException(e);
}
}
Aggregations