<commit_before>/*
 * Copyright 2009 LinkedIn, Inc
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package com.linkedin.norbert.network

import com.google.protobuf.Message
import org.jboss.netty.logging.{InternalLoggerFactory, Log4JLoggerFactory}
import com.linkedin.norbert.cluster.router.NullRouterFactory
import com.linkedin.norbert.protos.NorbertProtos
import com.linkedin.norbert.cluster.ClusterDefaults

object NorbertNetworkServerMain {
  InternalLoggerFactory.setDefaultFactory(new Log4JLoggerFactory)

  def main(args: Array[String]) {
    val main = new Main(args(0), args(1), args(2).toInt)
    main.loop
  }

  private class Main(clusterName: String, zooKeeperUrls: String, nodeId: Int) {
    println("Connecting to cluster...")

    object ComponentRegistry extends {
      val zooKeeperSessionTimeout = ClusterDefaults.ZOOKEEPER_SESSION_TIMEOUT
      val clusterDisconnectTimeout = ClusterDefaults.CLUSTER_DISCONNECT_TIMEOUT
      val maxConnectionsPerNode = NetworkDefaults.MAX_CONNECTIONS_PER_NODE
      val writeTimeout = NetworkDefaults.WRITE_TIMEOUT
      val clusterName = Main.this.clusterName
      val zooKeeperUrls = Main.this.zooKeeperUrls
    } with NullRouterFactory with DefaultNetworkServerComponent {
      val messageRegistry = new DefaultMessageRegistry(Array((NorbertProtos.Ping.getDefaultInstance, pingHandler _)))
      val networkServer = new NetworkServer(nodeId)
    }

    import ComponentRegistry._

    def loop {
      try {
        networkServer.bind
      } catch {
        case ex: NetworkingException =>
          println("Unable to bind to port, exiting: " + ex)
          cluster.shutdown
          System.exit(1)
      }

      Runtime.getRuntime.addShutdownHook(new Thread {
        override def run = shutdown<commit_msg>Better output in sample network server<commit_after>/*
 * Copyright 2009 LinkedIn, Inc
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package com.linkedin.norbert.network

import com.google.protobuf.Message
import org.jboss.netty.logging.{InternalLoggerFactory, Log4JLoggerFactory}
import com.linkedin.norbert.cluster.router.NullRouterFactory
import com.linkedin.norbert.protos.NorbertProtos
import com.linkedin.norbert.cluster.ClusterDefaults

object NorbertNetworkServerMain {
  InternalLoggerFactory.setDefaultFactory(new Log4JLoggerFactory)

  def main(args: Array[String]) {
    val main = new Main(args(0), args(1), args(2).toInt)
    main.loop
  }

  private class Main(clusterName: String, zooKeeperUrls: String, nodeId: Int) {
    println("Connecting to cluster...")

    object ComponentRegistry extends {
      val zooKeeperSessionTimeout = ClusterDefaults.ZOOKEEPER_SESSION_TIMEOUT
      val clusterDisconnectTimeout = ClusterDefaults.CLUSTER_DISCONNECT_TIMEOUT
      val maxConnectionsPerNode = NetworkDefaults.MAX_CONNECTIONS_PER_NODE
      val writeTimeout = NetworkDefaults.WRITE_TIMEOUT
      val clusterName = Main.this.clusterName
      val zooKeeperUrls = Main.this.zooKeeperUrls
    } with NullRouterFactory with DefaultNetworkServerComponent {
      val messageRegistry = new DefaultMessageRegistry(Array((NorbertProtos.Ping.getDefaultInstance, pingHandler _)))
      val networkServer = new NetworkServer(nodeId)
    }

    import ComponentRegistry._

    def loop {
      try {
        networkServer.bind
        println("Connected to cluster and listening for requests")
      } catch {
        case ex: NetworkingException =>
          println("Unable to bind to port, exiting: " + ex)
          cluster.shutdown
          System.exit(1)
      }

      Runtime.getRuntime.addShutdownHook(new Thread {
        override def run = shutdown
{'fraction_non_alphanumeric': 0.07262569832402235, 'fraction_numerical': 0.006016330038676407, 'mean_word_length': 3.864158829676071, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1092841', 'n_tokens_mistral': 1293, 'n_tokens_neox': 1228, 'n_words': 371}