Search in sources :

Example 1 with TreeTable

use of org.apache.sis.util.collection.TreeTable in project sis by apache.

the class ConverterRegistry method toString.

/**
 * Returns a string representation of registered converters for debugging purpose.
 * The converters are show in a tree where all real converters are leafs. Parents
 * of those leafs are {@link FallbackConverter}s which delegate their work to the
 * leafs.
 *
 * @return a string representation of registered converters.
 */
@Debug
@Override
public String toString() {
    final TreeTable table = Column.createTable();
    final TreeTable.Node root = table.getRoot();
    root.setValue(Column.TARGET, getClass());
    synchronized (converters) {
        for (final Map.Entry<ClassPair<?, ?>, ObjectConverter<?, ?>> entry : converters.entrySet()) {
            TreeTable.Node addTo = root;
            final ClassPair<?, ?> key = entry.getKey();
            final ObjectConverter<?, ?> converter = entry.getValue();
            if (converter.getSourceClass() != key.sourceClass || converter.getTargetClass() != key.targetClass) {
                /*
                     * If we enter this block, then the converter is not really for this
                     * (source, target) classes pair. Instead, we are leveraging a converter
                     * which was defined for an other ClassPair.  We show this fact be first
                     * showing this ClassPair, then the actual converter (source, target) as
                     * below:
                     *
                     *     Number      ← String             (the ClassPair key)
                     *       └─Integer ← String             (the ObjectConverter value)
                     *
                     * This is the same idea than the formatting done by FallbackConverter,
                     * except that there is only one child. Actually this can be though as
                     * a lightweight fallback converter.
                     */
                addTo = addTo.newChild();
                addTo.setValue(Column.SOURCE, key.sourceClass);
                addTo.setValue(Column.TARGET, key.targetClass);
            }
            if (converter instanceof FallbackConverter<?, ?>) {
                ((FallbackConverter<?, ?>) converter).toTree(addTo.newChild(), true);
            } else {
                Column.toTree(converter, addTo);
            }
        }
    }
    return Column.format(table);
}
Also used : ObjectConverter(org.apache.sis.util.ObjectConverter) TreeTable(org.apache.sis.util.collection.TreeTable) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Debug(org.apache.sis.util.Debug)

Example 2 with TreeTable

use of org.apache.sis.util.collection.TreeTable in project sis by apache.

the class StorageConnector method toString.

/**
 * Returns a string representation of this {@code StorageConnector} for debugging purpose.
 * This string representation is for debugging purpose only and may change in any future version.
 *
 * @return a string representation of this {@code StorageConnector} for debugging purpose.
 */
@Debug
@Override
public String toString() {
    final TreeTable table = new DefaultTreeTable(TableColumn.NAME, TableColumn.VALUE);
    final TreeTable.Node root = table.getRoot();
    root.setValue(TableColumn.NAME, Classes.getShortClassName(this));
    root.setValue(TableColumn.VALUE, getStorageName());
    if (options != null) {
        final TreeTable.Node op = root.newChild();
        op.setValue(TableColumn.NAME, "options");
        op.setValue(TableColumn.VALUE, options);
    }
    final Coupled c = getView(null);
    if (c != null) {
        c.append(root.newChild(), views);
    }
    return table.toString();
}
Also used : DefaultTreeTable(org.apache.sis.util.collection.DefaultTreeTable) TreeTable(org.apache.sis.util.collection.TreeTable) DefaultTreeTable(org.apache.sis.util.collection.DefaultTreeTable) Debug(org.apache.sis.util.Debug)

Example 3 with TreeTable

use of org.apache.sis.util.collection.TreeTable in project sis by apache.

the class AboutCommand method run.

/**
 * Prints the information to the output stream.
 *
 * @return 0 on success, or an exit code if the command failed for a reason other than an uncaught Java exception.
 * @throws Exception if an error occurred while executing the sub-command.
 */
@Override
public int run() throws Exception {
    DataDirectory.quiet();
    /*
         * Check the number of arguments, which can be 0 or 1. If present,
         * the argument is the name and port number of a remote machine.
         *
         * In the current implementation, the --brief option is supported only on the local machine.
         */
    final boolean brief = options.containsKey(Option.BRIEF);
    if (hasUnexpectedFileCount(0, brief ? 0 : 1)) {
        return Command.INVALID_ARGUMENT_EXIT_CODE;
    }
    String[] warnings = null;
    final String configuration;
    if (brief && files.isEmpty()) {
        configuration = Vocabulary.getResources(locale).getString(Vocabulary.Keys.Version_2, "Apache SIS", Version.SIS);
    } else {
        final EnumSet<About> sections = EnumSet.allOf(About.class);
        if (!options.containsKey(Option.VERBOSE)) {
            sections.remove(About.LIBRARIES);
        }
        if (files.isEmpty()) {
            /*
                 * Provide information about the local SIS installation.
                 */
            configuration = About.configuration(sections, locale, timezone).toString();
        } else {
            /*
                 * Provide information about a remote SIS installation. Those information are accessible
                 * only if explicitely enabled at JVM startup time.
                 *
                 * Tutorial: http://docs.oracle.com/javase/tutorial/jmx/remote/custom.html
                 */
            final String address = files.get(0);
            final String path = toRemoteURL(address);
            final long time = System.nanoTime();
            final TreeTable table;
            try {
                final JMXServiceURL url = new JMXServiceURL(path);
                try (JMXConnector jmxc = JMXConnectorFactory.connect(url)) {
                    final MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();
                    final SupervisorMBean bean = JMX.newMBeanProxy(mbsc, new ObjectName(Supervisor.NAME), SupervisorMBean.class);
                    table = bean.configuration(sections, locale, timezone);
                    warnings = bean.warnings(locale);
                }
            } catch (IOException e) {
                error(Errors.format(Errors.Keys.CanNotConnectTo_1, path), e);
                return Command.IO_EXCEPTION_EXIT_CODE;
            }
            /*
                 * Logs a message telling how long it took to receive the reply.
                 * Sometime the delay gives a hint about the server charge.
                 */
            // In seconds.
            double delay = (System.nanoTime() - time) / (double) StandardDateFormat.NANOS_PER_SECOND;
            if (delay >= 0.1) {
                final double scale = (delay >= 10) ? 1 : (delay >= 1) ? 10 : 100;
                delay = Math.rint(delay * scale) / scale;
            }
            final LogRecord record = Messages.getResources(locale).getLogRecord(Level.INFO, Messages.Keys.ConfigurationOf_3, address, new Date(), delay);
            record.setLoggerName(Loggers.APPLICATION);
            Logging.log(Command.class, "main", record);
            /*
                 * Replace the root node label from "Local configuration" to "Remote configuration"
                 * before to get the string representation of the configuration as a tree-table.
                 */
            table.getRoot().setValue(TableColumn.NAME, Vocabulary.getResources(locale).getString(Vocabulary.Keys.RemoteConfiguration));
            configuration = table.toString();
        }
    }
    out.println(configuration);
    if (warnings != null) {
        out.println();
        if (colors) {
            out.print(X364.BACKGROUND_RED.sequence());
            out.print(X364.BOLD.sequence());
            out.print(' ');
        }
        Vocabulary.getResources(locale).appendLabel(Vocabulary.Keys.Warnings, out);
        if (colors) {
            out.print(' ');
            out.println(X364.RESET.sequence());
            out.print(X364.FOREGROUND_RED.sequence());
        } else {
            out.println();
        }
        for (final String warning : warnings) {
            out.println(warning);
        }
        if (colors) {
            out.print(X364.FOREGROUND_DEFAULT.sequence());
        }
    }
    out.flush();
    return 0;
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) TreeTable(org.apache.sis.util.collection.TreeTable) IOException(java.io.IOException) Date(java.util.Date) About(org.apache.sis.setup.About) ObjectName(javax.management.ObjectName) LogRecord(java.util.logging.LogRecord) JMXConnector(javax.management.remote.JMXConnector) SupervisorMBean(org.apache.sis.internal.system.SupervisorMBean) MBeanServerConnection(javax.management.MBeanServerConnection)

Example 4 with TreeTable

use of org.apache.sis.util.collection.TreeTable in project sis by apache.

the class FallbackConverter method toString.

/**
 * Returns a tree representation of this converter.
 * The tree leaves represent the backing converters.
 */
@Debug
@Override
public String toString() {
    final TreeTable table = Column.createTable();
    toTree(table.getRoot(), true);
    return Column.format(table);
}
Also used : TreeTable(org.apache.sis.util.collection.TreeTable) Debug(org.apache.sis.util.Debug)

Aggregations

TreeTable (org.apache.sis.util.collection.TreeTable)4 Debug (org.apache.sis.util.Debug)3 IOException (java.io.IOException)1 Date (java.util.Date)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 LogRecord (java.util.logging.LogRecord)1 MBeanServerConnection (javax.management.MBeanServerConnection)1 ObjectName (javax.management.ObjectName)1 JMXConnector (javax.management.remote.JMXConnector)1 JMXServiceURL (javax.management.remote.JMXServiceURL)1 SupervisorMBean (org.apache.sis.internal.system.SupervisorMBean)1 About (org.apache.sis.setup.About)1 ObjectConverter (org.apache.sis.util.ObjectConverter)1 DefaultTreeTable (org.apache.sis.util.collection.DefaultTreeTable)1