text:
package ly.stealth.mesos.kafka

import java.util
import scala.util.parsing.json.{JSONArray, JSONObject}
import scala.collection.JavaConversions._
import scala.collection.mutable
import scala.collection.mutable.ListBuffer
import java.util.Collections
import java.io.{FileWriter, File}
import org.I0Itec.zkclient.ZkClient
import kafka.utils.ZKStringSerializer
import org.I0Itec.zkclient.exception.ZkNodeExistsException

class Cluster {
  private val brokers: util.List[Broker] = new util.concurrent.CopyOnWriteArrayList[Broker]()
  private[kafka] var rebalancer: Rebalancer = new Rebalancer()
  private[kafka] var topics: Topics = new Topics()
  private[kafka] var frameworkId: String = null

  def getBrokers:util.List[Broker] = Collections.unmodifiableList(brokers)

  def getBroker(id: String): Broker = {
    for (broker <- brokers)
      if (broker.id == id) return broker
    null
  }

  def addBroker(broker: Broker): Broker = {
    brokers.add(broker)
    broker
  }

  def removeBroker(broker: Broker): Unit = brokers.remove(broker)

  def clear(): Unit = brokers.clear()
  def load() = Cluster.storage.load(this)
  def save() = Cluster.storage.save(this)

  def fromJson(root: Map[String, Object]): Unit = {
    if (root.contains("brokers")) {
      for (brokerNode <- root("brokers").asInstanceOf[List[Map[String, Object]]]) {
        val broker: Broker = new Broker()
        broker.fromJson(brokerNode)
        brokers.add(broker)
      }
    }

    if (root.contains("frameworkId"))
      frameworkId = root("frameworkId").asInstanceOf[String]
  }

  def toJson: JSONObject = {
    val obj = new mutable.LinkedHashMap[String, Object]()

    if (!brokers.isEmpty) {
      val brokerNodes = new ListBuffer[JSONObject]()
      for (broker <- brokers)
        brokerNodes.add(broker.toJson)
      obj("brokers") = new JSONArray(brokerNodes.toList)
    }

    if (frameworkId != null) obj("frameworkId") = frameworkId
    new JSONObject(obj.toMap)
  }
}

object Cluster {
  var storage: Storage = newStorage(Config.storage)

  def newStorage(s: String): Storage = {
    if (s.startsWith("file:")) return new FsStorage(new File(s.substring("file:".length)))
    else if (s.startsWith("zk:")) return new ZkStorage(s.substring("zk:".length))
    throw new IllegalStateException("Unsupported storage " + s)
  }

  abstract class Storage {
    def load(cluster: Cluster): Unit = {
      val json: String = loadJson
      if (json == null) return

      val node: Map[String, Object] = Util.parseJson(json)
      cluster.brokers.clear()
      cluster.fromJson(node)
    }

    def save(cluster: Cluster): Unit = {
      saveJson("" + cluster.toJson)
    }

    protected def loadJson: String
    protected def saveJson(json: String): Unit
  }

  class FsStorage(val file: File) extends Storage {
    protected def loadJson: String = {
      if (!file.exists) return null
      val source = scala.io.Source.fromFile(file)
      try source.mkString finally source.close()
    }

    protected def saveJson(json: String): Unit = {
      val writer  = new FileWriter(file)
      try { writer.write(json) }
      finally { writer.close() }
    }
  }

  object FsStorage {
    val DEFAULT_FILE: File = new File("kafka-mesos.json")
  }

  class ZkStorage(val path: String) extends Storage {
    createChrootIfRequired()

    def zkClient: ZkClient = new ZkClient(Config.zk, 30000, 30000, ZKStringSerializer)

    private def createChrootIfRequired(): Unit = {
      val slashIdx: Int = Config.zk.indexOf('/')
      if (slashIdx == -1) return

      val chroot = Config.zk.substring(slashIdx)
      val zkConnect = Config.zk.substring(0, slashIdx)

      val client = new ZkClient(zkConnect, 30000, 30000, ZKStringSerializer)
      try { client.createPersistent(chroot, true) }
      finally { client.close() }
    }

    protected def loadJson: String = {
      val zkClient = this.zkClient
      try { zkClient.readData(path, true).asInstanceOf[String] }
      finally { zkClient.close() }
    }

    protected def saveJson(json: String): Unit = {
      val zkClient = this.zkClient
      try { zkClient.createPersistent(path, json) }
      catch { case e: ZkNodeExistsException => zkClient.writeData(path, json) }
      finally { zkClient.close() }
    }
  }
}


text:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>Chinese Morphological Analyzer(Chen): cma::POCTagUnit Struct Reference</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>

Main Page

Classes

Files

Class List

Class Hierarchy

Class Members

cma::POCTagUnit

cma::POCTagUnit Struct Reference

to hold the objects in the N-best algorithm
More...

#include <CMAPOCTagger.h>

List of all members.

Public Attributes

uint8_t 	pocCode

double 	score

int 	index

int 	previous

Detailed Description

to hold the objects in the N-best algorithm

Member Data Documentation

          int cma::POCTagUnit::index

the candidate number

Referenced by cma::SegTagger::seg_sentence().

          uint8_t cma::POCTagUnit::pocCode

the poc code (B/E)

Referenced by cma::SegTagger::seg_sentence().

          int cma::POCTagUnit::previous

Previous index in the candidate list. -1 if not exists

Referenced by cma::SegTagger::seg_sentence().

          double cma::POCTagUnit::score

the score for the current poc

Referenced by cma::SegTagger::seg_sentence().

The documentation for this struct was generated from the following file:

/home/vernkin/projects/chinese-ma-chen/source/include/CMAPOCTagger.h

<address style="text-align: right;">Generated on Tue Jan 26 13:00:42 2010 for Chinese Morphological Analyzer(Chen) by

 1.6.1 </address>

redpajama_set_name: RedPajamaGithub