<commit_before>package org.scalatra
package atmosphere

import org.atmosphere.cpr._
import org.json4s._
import org.scalatra.util.RicherString._
import grizzled.slf4j.Logger


trait AtmosphereClient {

  @volatile private[atmosphere] var resource: AtmosphereResource = _
  private[this] val internalLogger = Logger[AtmosphereClient]

  final protected def SkipSelf: ClientFilter = _.uuid != uuid
  final protected def OnlySelf: ClientFilter = _.uuid == uuid
  final protected val Everyone: ClientFilter = _ => true

  protected def requestUri = {
    val u = resource.getRequest.getRequestURI.blankOption getOrElse "/"
    if (u.endsWith("/")) u + "*" else u + "/*"
  }

  final def uuid: String = resource.uuid()

  def receive: AtmoReceive

  final def send(msg: OutboundMessage) = broadcast(msg, OnlySelf)

  final def broadcast(msg: OutboundMessage, filter: ClientFilter = SkipSelf) = {
    if (resource == null) {
      internalLogger.warn("The resource is null, can't publish")
    }
    if (resource != null && resource.getBroadcaster == null)
      internalLogger.warn("The broadcaster is null, can't publish")
    val broadcaster = resource.getBroadcaster.asInstanceOf[ScalatraBroadcaster]
    broadcaster.broadcast(msg, filter)
  }

  final def disconnect() { resource.resume() }
}<commit_msg>Docs on Atmosphere client class.<commit_after>package org.scalatra
package atmosphere

import org.atmosphere.cpr._
import org.json4s._
import org.scalatra.util.RicherString._
import grizzled.slf4j.Logger

/**
 * Provides a handle for a single Atmosphere connection. 
 * 
 * Each browser or other device which connects to an `atmosphere` route is
 * assigned its own AtmosphereClient, with a uuid. This is a good bet for
 * subclassing if you need to implement your own message distribution logic.
 * Subclasses may define their own ClientFilter logic in addition to the
 * stock ClientFilters already defined, in order to segment message delivery.
 */
trait AtmosphereClient {

  @volatile private[atmosphere] var resource: AtmosphereResource = _
  private[this] val internalLogger = Logger[AtmosphereClient]

  /**
   * Deliver the message to everyone except the current user.
   */
  final protected def SkipSelf: ClientFilter = _.uuid != uuid
  
  /**
   * Deliver the message only to the current user.
   */
  final protected def OnlySelf: ClientFilter = _.uuid == uuid
  
  /**
   * Deliver the message to all connected users.
   */
  final protected val Everyone: ClientFilter = _ => true

  protected def requestUri = {
    val u = resource.getRequest.getRequestURI.blankOption getOrElse "/"
    if (u.endsWith("/")) u + "*" else u + "/*"
  }

  /**
   * A unique identifier for a given connection. Can be used for filtering
   * purposes.
   */
  final def uuid: String = resource.uuid()

  /**
   * Receive an inbound message. 
   */
  def receive: AtmoReceive

  /**
   * A convenience method which sends a message only to the current client,
   * using a broadcast filter.
   */
  final def send(msg: OutboundMessage) = broadcast(msg, OnlySelf)

  /**
   * Broadcast a message to all clients, skipping the current client by default
   * (i.e. normal chat server behaviour). Optionally filter the clients to
   * deliver the message to by applying a filter.
   */
  final def broadcast(msg: OutboundMessage, filter: ClientFilter = SkipSelf) = {
    if (resource == null) {
      internalLogger.warn("The resource is null, can't publish")
    }
    if (resource != null && resource.getBroadcaster == null)
      internalLogger.warn("The broadcaster is null, can't publish")
    val broadcaster = resource.getBroadcaster.asInstanceOf[ScalatraBroadcaster]
    broadcaster.broadcast(msg, filter)
  }

  final def disconnect() { resource.resume() }
}
{'fraction_non_alphanumeric': 0.093691775352675, 'fraction_numerical': 0.001064679265371307, 'mean_word_length': 3.7033792240300376, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '4443143', 'n_tokens_mistral': 1093, 'n_tokens_neox': 1055, 'n_words': 366}