Skip navigation links

Package ax.antpick.k2hdkc

Provides classes that are fundamental to the applications to communicate with a k2hdk clustering system.

See: Description

Package ax.antpick.k2hdkc Description

Provides classes that are fundamental to the applications to communicate with a k2hdk clustering system.

Primary Packages

Contains 3 primary classes.

  1. The class Cluster holds configurations to connect a chmpx slave process and it provides simple methods to set a value to a k2hdk and get a value from it. You can extends the Cluster class if you want to add more methods.
  2. The class Session provides a connection with a chmpx slave process which communicate with a k2hdk clustering system.
  3. Subclasses of CmdBase provide an operation against a k2hdk clustering system and holds the result of the operation in Result object.

Usage Examples

Please see each class document for the each example.

Using Native C Libraries by using JNA

The class K2hdkcLibrary, ChmpxLibrary and K2hashLibrary implements Java Native Access's Library interface. Their visibilities are mostly package private because we think it is hard to control for application programmers. So they are not extensible currently.

Logging

The Logback is a successor to the popular log4j project. Suppose you want to write logs to stdout in the "debug" level, you could write a logback.xml as:


 <configuration>

  <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
    <!-- encoders are assigned the type
         ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
    <encoder>
      <!-- <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern> -->
      <pattern>%-5level [%thread] %date{ISO8601} %F:%L - %msg%n</pattern>
    </encoder>
  </appender>

  <root level="debug">
    <appender-ref ref="STDOUT" />
  </root>
 
Please see the logback manual more details.

In addtion, we use native C API libraries. We sometimes want to see how they work. The class Cluster provides methods to change log levels. The following code works as:

  1. Logs are written to /tmp/native.log
  2. Change the k2hdkc native library's loglevel to the info level.

   try (Cluster cluster = Cluster.of("slave.yaml");
       Session sess = Session.of(cluster); ) {
     cluster.setNativeLogLevel(
         "/tmp/native.log",
         Cluster.NativeStackLogLevel.StackK2hdkc,
         Cluster.NativeLogLevel.SeverityInfo);
     // ...
   } catch (IOException ex) {
     logger.error("message {}", ex.getMessage());
   }
 
 }
Author:
Hirotaka Wakabayashi
Skip navigation links

Copyright © 2020. All rights reserved.