This file was deleted.

@@ -0,0 +1,6 @@
package org.jpos.q2;

public interface CLICommand
{
public void exec(CLIContext cli, String[] strings) throws Exception;
}
@@ -0,0 +1,184 @@
package org.jpos.q2;

import jline.ConsoleReader;
import org.jpos.iso.ISOUtil;
import org.jpos.q2.CLI.Command;

import java.io.IOException;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
import java.util.WeakHashMap;

public class CLICommandInterface
{
CLIContext ctx;
List<String> prefixes = new ArrayList<String>();
WeakHashMap<String, Object> commandCache = new WeakHashMap<String, Object>(100);

public List<String> getPrefixes()
{
return prefixes;
}

public CLICommandInterface(CLIContext ctx)
{
this.ctx = ctx;
}

public void addPrefix(String prefix)
{
prefixes.add(prefix);
}

public void execCommand(String line) throws IOException
{
for (String prefix : prefixes)
{
try
{
execCommand(prefix, line);
}
catch (ClassNotFoundException e)
{
}
}
}

private void execCommand(String prefix, String line) throws IOException, ClassNotFoundException
{
String args[] = parseCommand(line);
if (args.length == 0)
{
return;
}
String command = args[0].toUpperCase();
String className = command;

if (command.indexOf(".") < 0)
{
className = prefix + command;
}

try
{
Object cmd = getCommand(className);
if (cmd != null)
{
try
{
long t1 = System.currentTimeMillis();

args[0] = ISOUtil.unPadLeft(line, ' '); // full line
if (cmd instanceof Command)
{
((Command) cmd).exec(new LegacyCommandAdapter(ctx), args);
}
else if (cmd instanceof CLICommand)
{
((CLICommand) cmd).exec(ctx, args);
}
long elapsed = System.currentTimeMillis() - t1;
}
catch (Exception ex)
{
ctx.printThrowable(ex);
}
}
}
catch (ClassNotFoundException ex)
{
throw ex;
}
catch (Exception ex)
{
ctx.println("Invalid command '" + command + "'");
ex.printStackTrace();
}
}

private Object getCommand(String className) throws ClassNotFoundException, InstantiationException, IllegalAccessException
{
Object cmd = commandCache.get(className);
if (cmd == null)
{
Class<?> clazz = getClazz(className);
final Object o = clazz.newInstance();
if (o instanceof Command || o instanceof CLICommand)
{
commandCache.put(className, o);
cmd = o;
}
}
return cmd;
}

private Class<?> getClazz(String className) throws ClassNotFoundException
{
return Thread.currentThread().getContextClassLoader().loadClass(className);
}

private String[] parseCommand(String line) throws IOException
{
if (line == null)
{
return new String[0];
}

StringTokenizer st = new StringTokenizer(line);
String[] args = new String[st.countTokens()];
for (int i = 0; st.hasMoreTokens(); i++)
{
args[i] = new String(st.nextToken());
}
return args;
}

public static class LegacyCommandAdapter extends CLI
{
CLIContext ctx;

public LegacyCommandAdapter(CLIContext ctx) throws IOException
{
super(null, null, false);
this.ctx = ctx;
}

@Override
public void print(String s)
{
ctx.print(s);
}

@Override
public void println(String s)
{
ctx.println(s);
}

@Override
public boolean confirm(String prompt) throws IOException
{
return ctx.confirm(prompt);
}

@Override
public Q2 getQ2()
{
return ctx.getQ2();
}

@Override
public ConsoleReader getConsoleReader()
{
return ctx.getConsoleReader();
}

@Override
public PrintStream getOutputStream()
{
return ctx.getOutputStream();
}
}
}
@@ -0,0 +1,92 @@
package org.jpos.q2;

import jline.ConsoleReader;

import java.io.IOException;
import java.io.PrintStream;

public class CLIContext
{
Q2 q2;
ConsoleReader consoleReader;
PrintStream outputStream;
boolean stopped = false;

public boolean isStopped()
{
return stopped;
}

public void setStopped(boolean stopped)
{
this.stopped = stopped;
}

public Q2 getQ2()
{
return q2;
}

public void setQ2(Q2 q2)
{
this.q2 = q2;
}

public ConsoleReader getConsoleReader()
{
return consoleReader;
}

public void setConsoleReader(ConsoleReader consoleReader)
{
this.consoleReader = consoleReader;
}

public PrintStream getOutputStream()
{
return outputStream;
}

public void setOutputStream(PrintStream outputStream)
{
this.outputStream = outputStream;
}

public void printThrowable(Throwable t)
{
t.printStackTrace(outputStream);
outputStream.flush();
}

public void print(String s)
{
try
{
consoleReader.printString(s);
}
catch (IOException e)
{
e.printStackTrace(outputStream);
outputStream.flush();
}
}

public void println(String s)
{
try
{
consoleReader.printString(s);
consoleReader.printNewline();
}
catch (IOException e)
{
e.printStackTrace(outputStream);
outputStream.flush();
}
}

public boolean confirm(String prompt) throws IOException
{
return "yes".equalsIgnoreCase(consoleReader.readLine(prompt));
}
}
@@ -0,0 +1,152 @@
package org.jpos.q2;

import jline.SimpleCompletor;

import java.io.File;
import java.io.IOException;
import java.net.JarURLConnection;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import java.util.jar.JarEntry;

public class CLIPrefixedClassNameCompletor extends SimpleCompletor
{
public CLIPrefixedClassNameCompletor(Collection<String> prefixes)
throws IOException
{
super(getClassNames(prefixes), new CmdFilter(prefixes));
setDelimiter(".");
}

private static String[] getClassNames(Collection<String> prefixes) throws IOException
{
Set<String> classes = new HashSet<String>();
for (String prefix : prefixes)
{
classes.addAll(getClassEntries(prefix));
}

// now filter classes by changing "/" to "." and trimming the
// trailing ".class"
Set<String> classNames = new TreeSet<String>();

for (Iterator i = classes.iterator(); i.hasNext(); )
{
String name = (String) i.next();
if (name.endsWith(".class"))
{
classNames.add(name.replace('/', '.').
substring(0, name.length() - 6));
}
}

return classNames.toArray(new String[classNames.size()]);
}

private static List<String> getClassEntries(String prefix) throws IOException
{
final String p = prefix.replaceAll("\\.", "\\/");
List<String> result = new ArrayList<String>();

Enumeration<URL> urls = CLIPrefixedClassNameCompletor.class.getClassLoader().getResources(p);
while (urls.hasMoreElements())
{
URL url = urls.nextElement();
if (url == null) { return Collections.emptyList(); }

try
{
final List<String> lst = url.getProtocol().equals("jar") ?
resolveModuleEntriesFromJar(url, p) :
resolveModuleEntriesFromFiles(url, p);
result.addAll(lst);
}
catch (URISyntaxException e)
{
throw new IOException("Bad URL", e);
}
}
return result;
}

private static List<String> resolveModuleEntriesFromFiles(URL url, String _prefix) throws IOException, URISyntaxException
{
final String prefix = _prefix.endsWith("/") ? _prefix : _prefix + "/";

List<String> resourceList = new ArrayList<String>();

final URI uri = url.toURI();
File f = new File(uri);
addFiles(f, prefix, resourceList);

return resourceList;
}

private static void addFiles(File f, String prefix, List<String> resourceList)
{
File files[] = f.listFiles();
if (files == null) { return; }

for (File file : files)
{
if (file.isDirectory())
{
addFiles(file, prefix + file.getName() + "/", resourceList);
}
else
{
resourceList.add(prefix + file.getName());
}
}
}

private static List<String> resolveModuleEntriesFromJar(URL url, String _prefix) throws IOException
{
final String prefix = _prefix.endsWith("/") ? _prefix : _prefix + "/";

List<String> resourceList = new ArrayList<String>();

JarURLConnection conn = (JarURLConnection) url.openConnection();
Enumeration entries = conn.getJarFile().entries();
while (entries.hasMoreElements())
{
JarEntry entry = (JarEntry) entries.nextElement();
String name = entry.getName();
if (name.startsWith(prefix) && !entry.isDirectory())
{
resourceList.add(name);
}
}
return resourceList;
}

public static class CmdFilter implements SimpleCompletorFilter
{
Collection<String> prefixes;

public CmdFilter(Collection<String> prefixes)
{
this.prefixes = prefixes;
}

public String filter(String element)
{
for (String prefix : prefixes)
{
final String p = prefix;
if (element.startsWith(p)) { return element.substring(p.length()).toLowerCase(); }
}
return null;
}
}
}
@@ -18,11 +18,14 @@

package org.jpos.q2.cli;

import org.jpos.q2.CLI;
import org.jpos.q2.CLICommand;
import org.jpos.q2.CLIContext;

public class CLR implements CLI.Command {
public void exec (CLI cli, String[] args) throws Exception {
cli.getConsoleReader().clearScreen();
public class CLR implements CLICommand
{
public void exec(CLIContext ctx, String[] args) throws Exception
{
ctx.getConsoleReader().clearScreen();
}
}

@@ -18,22 +18,29 @@

package org.jpos.q2.cli;

import org.jpos.q2.CLI;
import org.jpos.q2.CLICommand;
import org.jpos.q2.CLIContext;

import java.io.IOException;
import java.io.InputStream;

public class COPYRIGHT implements CLI.Command {
public void exec (CLI cli, String[] args) throws IOException {
display (cli, MAN.class.getResourceAsStream("/COPYRIGHT"));
cli.println ("");
public class COPYRIGHT implements CLICommand
{
public void exec(CLIContext ctx, String[] args) throws IOException
{
display(ctx, MAN.class.getResourceAsStream("/COPYRIGHT"));
ctx.println("");
}
private void display (CLI cli, InputStream is) throws IOException {
if (is != null) {
while (is.available() > 0) {

private void display(CLIContext ctx, InputStream is) throws IOException
{
if (is != null)
{
while (is.available() > 0)
{
byte[] b = new byte[is.available()];
is.read (b);
cli.print (new String(b, "ISO8859_1"));
is.read(b);
ctx.print(new String(b, "ISO8859_1"));
}
}
}
@@ -18,13 +18,16 @@

package org.jpos.q2.cli;

import org.jpos.q2.CLI;
import org.jpos.q2.CLICommand;
import org.jpos.q2.CLIContext;

import java.util.Date;

public class DATE implements CLI.Command {
public void exec (CLI cli, String[] args) {
cli.println (new Date().toString());
public class DATE implements CLICommand
{
public void exec(CLIContext ctx, String[] args)
{
ctx.println(new Date().toString());
}
}

@@ -19,12 +19,15 @@
package org.jpos.q2.cli;

import org.jpos.iso.ISOUtil;
import org.jpos.q2.CLI;
import org.jpos.q2.CLICommand;
import org.jpos.q2.CLIContext;

public class ECHO implements CLI.Command {
public void exec (CLI cli, String[] args) {
public class ECHO implements CLICommand
{
public void exec(CLIContext cli, String[] args)
{
String s = ISOUtil.unPadLeft(args[0].substring(4), ' ');
cli.println (s);
cli.println(s);
}
}

@@ -18,12 +18,15 @@

package org.jpos.q2.cli;

import org.jpos.q2.CLI;
import org.jpos.q2.CLICommand;
import org.jpos.q2.CLIContext;

public class HELP implements CLI.Command {
public void exec (CLI cli, String[] args) {
cli.println ("Type tab to see list of available commands");
cli.println ("Type 'man command-name' to see man page");
public class HELP implements CLICommand
{
public void exec(CLIContext cli, String[] args)
{
cli.println("Type tab to see list of available commands");
cli.println("Type 'man command-name' to see man page");
}
}

@@ -18,22 +18,29 @@

package org.jpos.q2.cli;

import org.jpos.q2.CLI;
import org.jpos.q2.CLICommand;
import org.jpos.q2.CLIContext;

import java.io.IOException;
import java.io.InputStream;

public class LICENSE implements CLI.Command {
public void exec (CLI cli, String[] args) throws IOException {
display (cli, MAN.class.getResourceAsStream("/LICENSE"));
cli.println ("");
public class LICENSE implements CLICommand
{
public void exec(CLIContext cli, String[] args) throws IOException
{
display(cli, MAN.class.getResourceAsStream("/LICENSE"));
cli.println("");
}
private void display (CLI cli, InputStream is) throws IOException {
if (is != null) {
while (is.available() > 0) {

private void display(CLIContext cli, InputStream is) throws IOException
{
if (is != null)
{
while (is.available() > 0)
{
byte[] b = new byte[is.available()];
is.read (b);
cli.print (new String(b, "ISO8859_1"));
is.read(b);
cli.print(new String(b, "ISO8859_1"));
}
}
}
@@ -18,26 +18,33 @@

package org.jpos.q2.cli;

import org.jpos.q2.CLI;
import org.jpos.q2.CLICommand;
import org.jpos.q2.CLIContext;

import java.io.InputStream;

public class MAN implements CLI.Command {
public void exec (CLI cli, String[] args) throws Exception {
if (args.length < 2) {
cli.println ("What manual page do you want?");
public class MAN implements CLICommand
{
public void exec(CLIContext cli, String[] args) throws Exception
{
if (args.length < 2)
{
cli.println("What manual page do you want?");
return;
}
String command = args[1];
InputStream is = MAN.class.getResourceAsStream(
command.toUpperCase()+".man"
command.toUpperCase() + ".man"
);
if (is != null) {
if (is != null)
{
byte[] b = new byte[is.available()];
is.read (b);
cli.print (new String(b, "ISO8859_1"));
} else {
cli.println ("No manual entry for " + command);
is.read(b);
cli.print(new String(b, "ISO8859_1"));
}
else
{
cli.println("No manual entry for " + command);
}
}
}
@@ -18,19 +18,26 @@

package org.jpos.q2.cli;

import org.jpos.q2.CLI;
import org.jpos.q2.CLICommand;
import org.jpos.q2.CLIContext;

public class MEM implements CLI.Command {
public void exec (CLI cli, String[] args) throws Exception {
if (args.length > 1 && "--gc".equals (args[1])) {
public class MEM implements CLICommand
{
public void exec(CLIContext cli, String[] args) throws Exception
{
if (args.length > 1 && "--gc".equals(args[1]))
{
System.gc();
}
Runtime r = Runtime.getRuntime();
StringBuffer sb = new StringBuffer();
sb.append ("total="); sb.append (r.totalMemory());
sb.append (" free="); sb.append (r.freeMemory());
sb.append (" in-use="); sb.append (r.totalMemory()-r.freeMemory());
cli.println (sb.toString());
sb.append("total=");
sb.append(r.totalMemory());
sb.append(" free=");
sb.append(r.freeMemory());
sb.append(" in-use=");
sb.append(r.totalMemory() - r.freeMemory());
cli.println(sb.toString());
}
}

@@ -19,54 +19,68 @@
package org.jpos.q2.cli;

import org.jpos.iso.ISOUtil;
import org.jpos.q2.CLI;
import org.jpos.q2.CLICommand;
import org.jpos.q2.CLIContext;
import org.jpos.util.Loggeable;
import org.jpos.util.NameRegistrar;

import java.util.Iterator;
import java.util.Map;

public class SHOWNR implements CLI.Command {
public void exec (CLI cli, String[] args) throws Exception {
boolean all = args.length > 1 && "-a".equals (args[1]);
public class SHOWNR implements CLICommand
{
public void exec(CLIContext cli, String[] args) throws Exception
{
boolean all = args.length > 1 && "-a".equals(args[1]);
int i = 1;
if (all)
i++;
{ i++; }
if (args.length > i)
showOne (cli, args[i], all);
{ showOne(cli, args[i], all); }
else
showAll (cli, all);
{ showAll(cli, all); }
}
private void showOne (CLI cli, String name, boolean detail) {
try {
Object obj = NameRegistrar.get (name);
cli.println (name + " : " + obj.toString());
if (detail && obj instanceof Loggeable) {
((Loggeable)obj).dump (cli.getOutputStream(), " ");

private void showOne(CLIContext cli, String name, boolean detail)
{
try
{
Object obj = NameRegistrar.get(name);
cli.println(name + " : " + obj.toString());
if (detail && obj instanceof Loggeable)
{
((Loggeable) obj).dump(cli.getOutputStream(), " ");
cli.getOutputStream().flush();
}
} catch (NameRegistrar.NotFoundException e) {
cli.println ("Object not found in NameRegistrar");
}
catch (NameRegistrar.NotFoundException e)
{
cli.println("Object not found in NameRegistrar");
}
}
private void showAll (CLI cli, boolean detail) {

private void showAll(CLIContext cli, boolean detail)
{
NameRegistrar nr = NameRegistrar.getInstance();
int maxw = 0;
Iterator iter = nr.getMap().entrySet().iterator();
while (iter.hasNext()) {
Map.Entry entry = (Map.Entry) iter.next ();
maxw = Math.max (maxw, entry.getKey().toString().length());
while (iter.hasNext())
{
Map.Entry entry = (Map.Entry) iter.next();
maxw = Math.max(maxw, entry.getKey().toString().length());
}
iter = nr.getMap().entrySet().iterator();
maxw++;
while (iter.hasNext()) {
Map.Entry entry = (Map.Entry) iter.next ();
cli.println (
ISOUtil.strpad (entry.getKey().toString(), maxw) +
entry.getValue().toString()
while (iter.hasNext())
{
Map.Entry entry = (Map.Entry) iter.next();
cli.println(
ISOUtil.strpad(entry.getKey().toString(), maxw) +
entry.getValue().toString()
);
if (detail && entry.getValue() instanceof Loggeable) {
((Loggeable)entry.getValue()).dump (cli.getOutputStream(), " ");
if (detail && entry.getValue() instanceof Loggeable)
{
((Loggeable) entry.getValue()).dump(cli.getOutputStream(), " ");
cli.getOutputStream().flush();
}
}
@@ -18,24 +18,28 @@

package org.jpos.q2.cli;

import org.jpos.q2.CLI;
import org.jpos.q2.CLICommand;
import org.jpos.q2.CLIContext;

import java.io.IOException;

public class SHUTDOWN implements CLI.Command {
public void exec (CLI cli, String[] args) throws IOException {
public class SHUTDOWN implements CLICommand
{
public void exec(CLIContext cli, String[] args) throws IOException
{
boolean shutdown = false;
if (args.length == 2 && "--force".equals (args[1]))
shutdown = true;
else
shutdown = cli.confirm ("Confirm shutdown (Yes/No) ? ");
if (args.length == 2 && "--force".equals(args[1]))
{ shutdown = true; }
else
{ shutdown = cli.confirm("Confirm shutdown (Yes/No) ? "); }

if (shutdown) {
cli.println ("Shutting down.");
if (shutdown)
{
cli.println("Shutting down.");
cli.getQ2().shutdown();
}
else
cli.println ("Q2 will continue running.");
else
{ cli.println("Q2 will continue running."); }
}
}

@@ -18,14 +18,20 @@

package org.jpos.q2.cli;

import org.jpos.q2.CLI;
import org.jpos.q2.CLICommand;
import org.jpos.q2.CLIContext;

public class SLEEP implements CLI.Command {
public void exec (CLI cli, String[] args) throws Exception {
if (args.length > 1) {
Thread.sleep (Long.parseLong (args[1])*1000);
} else {
cli.println ("Usage: sleep number-of-seconds");
public class SLEEP implements CLICommand
{
public void exec(CLIContext cli, String[] args) throws Exception
{
if (args.length > 1)
{
Thread.sleep(Long.parseLong(args[1]) * 1000);
}
else
{
cli.println("Usage: sleep number-of-seconds");
}
}
}
@@ -18,15 +18,21 @@

package org.jpos.q2.cli;

import org.jpos.q2.CLI;
import org.jpos.q2.CLICommand;
import org.jpos.q2.CLIContext;

public class SMCONSOLE implements CLI.Command {
public void exec (CLI cli, String[] args) {
try {
String[] params = new String[args.length-1];
System.arraycopy (args, 1, params, 0, params.length);
org.jpos.security.jceadapter.Console.main (params);
} catch (Exception e) {
public class SMCONSOLE implements CLICommand
{
public void exec(CLIContext cli, String[] args)
{
try
{
String[] params = new String[args.length - 1];
System.arraycopy(args, 1, params, 0, params.length);
org.jpos.security.jceadapter.Console.main(params);
}
catch (Exception e)
{
e.printStackTrace();
}
}
@@ -18,12 +18,15 @@

package org.jpos.q2.cli;

import org.jpos.q2.CLI;
import org.jpos.q2.CLICommand;
import org.jpos.q2.CLIContext;
import org.jpos.util.SystemMonitor;

public class SYSMON implements CLI.Command {
public void exec (CLI cli, String[] args) throws Exception {
new SystemMonitor().dump (cli.getOutputStream(), " ");
public class SYSMON implements CLICommand
{
public void exec(CLIContext cli, String[] args) throws Exception
{
new SystemMonitor().dump(cli.getOutputStream(), " ");
}
}

@@ -19,7 +19,8 @@
package org.jpos.q2.cli;

import jline.ANSIBuffer;
import org.jpos.q2.CLI;
import org.jpos.q2.CLICommand;
import org.jpos.q2.CLIContext;
import org.jpos.util.LogEvent;
import org.jpos.util.LogListener;
import org.jpos.util.Logger;
@@ -30,69 +31,88 @@
import java.util.Iterator;
import java.util.Map;

public class TAIL implements CLI.Command, LogListener {
public class TAIL implements CLICommand, LogListener
{
PrintStream p;
CLI cli;
CLIContext cli;
boolean ansi;

public void exec (CLI cli, String[] args) throws Exception {

public void exec(CLIContext cli, String[] args) throws Exception
{
this.p = cli.getOutputStream();
this.cli = cli;
this.ansi = cli.getConsoleReader().getTerminal().isANSISupported();
if (args.length == 1) {
if (args.length == 1)
{
usage(cli);
return;
}
for (int i=1; i<args.length; i++) {
try {
Logger logger = (Logger) NameRegistrar.get ("logger." + args[i]);
logger.addListener (this);
} catch (NameRegistrar.NotFoundException e) {
cli.println ("Logger " + args[i] + " not found -- ignored.");
for (int i = 1; i < args.length; i++)
{
try
{
Logger logger = (Logger) NameRegistrar.get("logger." + args[i]);
logger.addListener(this);
}
catch (NameRegistrar.NotFoundException e)
{
cli.println("Logger " + args[i] + " not found -- ignored.");
}
}
cli.getConsoleReader().readCharacter(new char[] { 'q', 'Q' });
for (int i=1; i<args.length; i++) {
try {
Logger logger = (Logger) NameRegistrar.get ("logger." + args[i]);
logger.removeListener (this);
} catch (NameRegistrar.NotFoundException e) { }
cli.getConsoleReader().readCharacter(new char[]{'q', 'Q'});
for (int i = 1; i < args.length; i++)
{
try
{
Logger logger = (Logger) NameRegistrar.get("logger." + args[i]);
logger.removeListener(this);
}
catch (NameRegistrar.NotFoundException e) { }
}
}
public void usage (CLI cli) {
cli.println ("Usage: tail [log-name] [log-name] ...");
showLoggers (cli);

public void usage(CLIContext cli)
{
cli.println("Usage: tail [log-name] [log-name] ...");
showLoggers(cli);
}
public synchronized LogEvent log (LogEvent ev) {
if (p != null) {
Date d = new Date (System.currentTimeMillis());

public synchronized LogEvent log(LogEvent ev)
{
if (p != null)
{
Date d = new Date(System.currentTimeMillis());
ANSIBuffer ab = new ANSIBuffer();
ab.setAnsiEnabled (ansi);
cli.println (
ab.bold (
ev.getSource().getLogger().getName() +
": " + ev.getRealm() + " " + d.toString() +"." + d.getTime() % 1000
).toString (ansi)
ab.setAnsiEnabled(ansi);
cli.println(
ab.bold(
ev.getSource().getLogger().getName() +
": " + ev.getRealm() + " " + d.toString() + "." + d.getTime() % 1000
).toString(ansi)
);
ev.dump (p, " ");
ev.dump(p, " ");
p.flush();
}
return ev;
}
private void showLoggers (CLI cli) {

private void showLoggers(CLIContext cli)
{
NameRegistrar nr = NameRegistrar.getInstance();
int maxw = 0;
Iterator iter = nr.getMap().entrySet().iterator();
StringBuffer sb = new StringBuffer ("available loggers:");
while (iter.hasNext()) {
Map.Entry entry = (Map.Entry) iter.next ();
StringBuffer sb = new StringBuffer("available loggers:");
while (iter.hasNext())
{
Map.Entry entry = (Map.Entry) iter.next();
String key = (String) entry.getKey();
if (key.startsWith ("logger.") && entry.getValue() instanceof Logger) {
sb.append (' ');
sb.append (key.substring(7));
if (key.startsWith("logger.") && entry.getValue() instanceof Logger)
{
sb.append(' ');
sb.append(key.substring(7));
}
}
cli.println (sb.toString());
cli.println(sb.toString());
}
}

@@ -18,81 +18,97 @@

package org.jpos.q2.cli;

import jline.ANSIBuffer;
import org.jpos.q2.CLI;
import org.jpos.q2.CLICommand;
import org.jpos.q2.CLIContext;
import org.jpos.transaction.TransactionManager;
import org.jpos.transaction.TransactionStatusEvent;
import org.jpos.transaction.TransactionStatusListener;
import org.jpos.util.LogEvent;
import org.jpos.util.LogListener;
import org.jpos.util.Logger;
import org.jpos.util.NameRegistrar;

import java.io.PrintStream;
import java.util.Date;
import java.util.Iterator;
import java.util.Map;

@SuppressWarnings("unused")
public class TMMON implements CLI.Command, TransactionStatusListener {
public class TMMON implements CLICommand, TransactionStatusListener
{
PrintStream p;
CLI cli;
CLIContext cli;
boolean ansi;

public void exec (CLI cli, String[] args) throws Exception {

public void exec(CLIContext cli, String[] args) throws Exception
{
this.p = cli.getOutputStream();
this.cli = cli;
this.ansi = cli.getConsoleReader().getTerminal().isANSISupported();
if (args.length == 1) {
if (args.length == 1)
{
usage(cli);
return;
}
for (int i=1; i<args.length; i++) {
try {
Object obj = NameRegistrar.get (args[i]);
if (obj instanceof TransactionManager) {
((TransactionManager) obj).addListener (this);
for (int i = 1; i < args.length; i++)
{
try
{
Object obj = NameRegistrar.get(args[i]);
if (obj instanceof TransactionManager)
{
((TransactionManager) obj).addListener(this);
}
else {
cli.println ("Object '" + args[i]
+ "' is not an instance of TransactionManager (" + obj.toString() + ")");
else
{
cli.println("Object '" + args[i]
+ "' is not an instance of TransactionManager (" + obj.toString() + ")");
}
} catch (NameRegistrar.NotFoundException e) {
cli.println ("TransactionManager '" + args[i] + "' not found -- ignored.");
}
catch (NameRegistrar.NotFoundException e)
{
cli.println("TransactionManager '" + args[i] + "' not found -- ignored.");
}
}
cli.getConsoleReader().readCharacter(new char[] { 'q', 'Q' });
for (int i=1; i<args.length; i++) {
try {
Object obj = NameRegistrar.get (args[i]);
if (obj instanceof TransactionManager) {
((TransactionManager) obj).removeListener (this);
cli.getConsoleReader().readCharacter(new char[]{'q', 'Q'});
for (int i = 1; i < args.length; i++)
{
try
{
Object obj = NameRegistrar.get(args[i]);
if (obj instanceof TransactionManager)
{
((TransactionManager) obj).removeListener(this);
}
} catch (NameRegistrar.NotFoundException ignored) { }
}
catch (NameRegistrar.NotFoundException ignored) { }
}
}
public void usage (CLI cli) {
cli.println ("Usage: tmmon [tm-name] [tm-name] ...");
showTMs (cli);

public void usage(CLIContext cli)
{
cli.println("Usage: tmmon [tm-name] [tm-name] ...");
showTMs(cli);
}
private void showTMs (CLI cli) {

private void showTMs(CLIContext cli)
{
NameRegistrar nr = NameRegistrar.getInstance();
int maxw = 0;
Iterator iter = NameRegistrar.getMap().entrySet().iterator();
StringBuffer sb = new StringBuffer ("available transaction managers:");
while (iter.hasNext()) {
Map.Entry entry = (Map.Entry) iter.next ();
StringBuffer sb = new StringBuffer("available transaction managers:");
while (iter.hasNext())
{
Map.Entry entry = (Map.Entry) iter.next();
String key = (String) entry.getKey();
if (entry.getValue() instanceof TransactionManager) {
sb.append (' ');
sb.append (key);
if (entry.getValue() instanceof TransactionManager)
{
sb.append(' ');
sb.append(key);
}
}
cli.println (sb.toString());
cli.println(sb.toString());
}

public void update(TransactionStatusEvent e) {
cli.println (e.toString());
public void update(TransactionStatusEvent e)
{
cli.println(e.toString());
}
}

@@ -18,12 +18,14 @@

package org.jpos.q2.cli;

import org.jpos.iso.ISOException;
import org.jpos.iso.ISOUtil;
import org.jpos.q2.CLI;
import org.jpos.q2.CLICommand;
import org.jpos.q2.CLIContext;

public class UPTIME implements CLI.Command {
public void exec (CLI cli, String[] args) throws Exception {
cli.println (ISOUtil.millisToString (cli.getQ2().getUptime()));
public class UPTIME implements CLICommand
{
public void exec(CLIContext cli, String[] args) throws Exception
{
cli.println(ISOUtil.millisToString(cli.getQ2().getUptime()));
}
}
@@ -18,10 +18,13 @@

package org.jpos.q2.cli;

import org.jpos.q2.CLI;
import org.jpos.q2.CLICommand;
import org.jpos.q2.CLIContext;

public class VERSION implements CLI.Command {
public void exec (CLI cli, String[] args) {
cli.println (cli.getQ2().getVersionString());
public class VERSION implements CLICommand
{
public void exec(CLIContext cli, String[] args)
{
cli.println(cli.getQ2().getVersionString());
}
}