Skip to content

Commit

Permalink
fix procedure syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
xuwei-k committed Jan 7, 2017
1 parent ee4224b commit 582ccb6
Show file tree
Hide file tree
Showing 52 changed files with 132 additions and 132 deletions.
Expand Up @@ -44,7 +44,7 @@ class ScalatraBroadcasterFactory(var cfg: AtmosphereConfig, bCfg: BroadcasterCon
private[this] val logger = Logger[ScalatraBroadcasterFactory]
private[this] val store: ConcurrentMap[Any, Broadcaster] = new ConcurrentHashMap[Any, Broadcaster]().asScala

override def configure(clazz: Class[_ <: Broadcaster], broadcasterLifeCyclePolicy: String, c: AtmosphereConfig = cfg) {
override def configure(clazz: Class[_ <: Broadcaster], broadcasterLifeCyclePolicy: String, c: AtmosphereConfig = cfg): Unit = {
this.cfg = c
}

Expand Down Expand Up @@ -89,7 +89,7 @@ class ScalatraBroadcasterFactory(var cfg: AtmosphereConfig, bCfg: BroadcasterCon

def add(b: Broadcaster, id: Any): Boolean = store.put(id, b).isEmpty

def destroy() {
def destroy(): Unit = {
val s = cfg.getInitParameter(ApplicationConfig.SHARED)
if (s != null && s.equalsIgnoreCase("TRUE")) {
logger.warn("Factory shared, will not be destroyed. That can possibly cause memory leaks if" +
Expand Down Expand Up @@ -162,7 +162,7 @@ class ScalatraBroadcasterFactory(var cfg: AtmosphereConfig, bCfg: BroadcasterCon

def remove(id: Any): Boolean = store.remove(id).isDefined

def removeAllAtmosphereResource(r: AtmosphereResource) {
def removeAllAtmosphereResource(r: AtmosphereResource): Unit = {
// Remove inside all Broadcaster as well.
try {
if (store.nonEmpty) {
Expand Down
Expand Up @@ -82,7 +82,7 @@ trait AtmosphereSupport extends Initializable with Handler with CometProcessor w
}
}

abstract override def initialize(config: ConfigT) {
abstract override def initialize(config: ConfigT): Unit = {
super.initialize(config)
val cfg: ServletConfig = config match {
case c: FilterConfig => c
Expand Down Expand Up @@ -118,7 +118,7 @@ trait AtmosphereSupport extends Initializable with Handler with CometProcessor w
atmosphereFramework.interceptor(new TrackMessageSizeInterceptor)
}

private[this] def setupAtmosphereHandlerMappings(cfg: ServletConfig) {
private[this] def setupAtmosphereHandlerMappings(cfg: ServletConfig): Unit = {
// TODO: also support filters?
val servletRegistration = ScalatraBase.getServletRegistration(this)
servletRegistration foreach { reg =>
Expand All @@ -139,7 +139,7 @@ trait AtmosphereSupport extends Initializable with Handler with CometProcessor w
* $ 3. Binds the current `request`, `response`, and `multiParams`, and calls
* `executeRoutes()`.
*/
abstract override def handle(request: HttpServletRequest, response: HttpServletResponse) {
abstract override def handle(request: HttpServletRequest, response: HttpServletResponse): Unit = {
withRequestResponse(request, response) {
val atmoRoute = atmosphereRoute(request)
if (atmoRoute.isDefined) {
Expand All @@ -163,15 +163,15 @@ trait AtmosphereSupport extends Initializable with Handler with CometProcessor w
matched <- route(requestPath)
} yield matched).headOption

private[this] def configureBroadcasterFactory() {
private[this] def configureBroadcasterFactory(): Unit = {
val factory = new ScalatraBroadcasterFactory(
atmosphereFramework.getAtmosphereConfig,
broadcasterConfig)
atmosphereFramework.setDefaultBroadcasterClassName(broadcasterConfig.broadcasterClass.getName)
atmosphereFramework.setBroadcasterFactory(factory)
}

private[this] def configureBroadcasterCache() {
private[this] def configureBroadcasterCache(): Unit = {
if (atmosphereFramework.getBroadcasterCacheClassName.isBlank)
atmosphereFramework.setBroadcasterCacheClassName(classOf[UUIDBroadcasterCache].getName)
}
Expand All @@ -197,7 +197,7 @@ trait AtmosphereSupport extends Initializable with Handler with CometProcessor w
*/
@throws(classOf[IOException])
@throws(classOf[ServletException])
def event(cometEvent: org.apache.catalina.CometEvent) {
def event(cometEvent: org.apache.catalina.CometEvent): Unit = {
val req = cometEvent.getHttpServletRequest
val res = cometEvent.getHttpServletResponse
req.setAttribute(TomcatCometSupport.COMET_EVENT, cometEvent)
Expand All @@ -216,7 +216,7 @@ trait AtmosphereSupport extends Initializable with Handler with CometProcessor w
*/
@throws(classOf[IOException])
@throws(classOf[ServletException])
def event(cometEvent: org.apache.catalina.comet.CometEvent) {
def event(cometEvent: org.apache.catalina.comet.CometEvent): Unit = {
val req = cometEvent.getHttpServletRequest
val res = cometEvent.getHttpServletResponse
req.setAttribute(Tomcat7CometSupport.COMET_EVENT, cometEvent)
Expand All @@ -241,7 +241,7 @@ trait AtmosphereSupport extends Initializable with Handler with CometProcessor w
*/
@throws(classOf[IOException])
@throws(classOf[ServletException])
def event(httpEvent: HttpEvent) {
def event(httpEvent: HttpEvent): Unit = {
val req = httpEvent.getHttpServletRequest
val res = httpEvent.getHttpServletResponse
req.setAttribute(JBossWebCometSupport.HTTP_EVENT, httpEvent)
Expand Down
Expand Up @@ -34,7 +34,7 @@ final class RedisScalatraBroadcaster()(implicit wireFormat: WireFormat, protecte
broadcast(wrappedMessageString).map(_ => msg)
}

override protected def broadcastReceivedMessage(message: AnyRef) {
override protected def broadcastReceivedMessage(message: AnyRef): Unit = {
try {
val messageString = message.asInstanceOf[String]
val redisMessage = read[Message](messageString)
Expand Down
Expand Up @@ -8,7 +8,7 @@ import org.atmosphere.cpr.{ AtmosphereFramework, Action => AtmoAction }
class ScalatraAtmosphereFramework(isFilter: Boolean = false, autoDetectHandlers: Boolean = false) extends AtmosphereFramework(isFilter, autoDetectHandlers) {

private[this] val logger = Logger[ScalatraAtmosphereFramework]
def setupTomcat7() {
def setupTomcat7(): Unit = {
if (!getAsyncSupport.supportWebSocket) {
if (!isCometSupportSpecified && !isCometSupportConfigured.getAndSet(true)) {
asyncSupport.synchronized {
Expand All @@ -18,7 +18,7 @@ class ScalatraAtmosphereFramework(isFilter: Boolean = false, autoDetectHandlers:
}
}

def setupTomcat() {
def setupTomcat(): Unit = {
if (!getAsyncSupport.supportWebSocket) {
if (!isCometSupportSpecified && !isCometSupportConfigured.getAndSet(true)) {
asyncSupport.synchronized {
Expand All @@ -28,7 +28,7 @@ class ScalatraAtmosphereFramework(isFilter: Boolean = false, autoDetectHandlers:
}
}

def setupJBoss() {
def setupJBoss(): Unit = {
if (!isCometSupportSpecified && !isCometSupportConfigured.getAndSet(true)) {
asyncSupport.synchronized {
asyncSupport = new JBossWebCometSupport(config)
Expand Down
Expand Up @@ -21,21 +21,21 @@ object ScalatraAtmosphereHandler {
def client(resource: AtmosphereResource) =
Option(resource.session()).flatMap(_.get(org.scalatra.atmosphere.AtmosphereClientKey)).map(_.asInstanceOf[AtmosphereClient])

def onPreSuspend(event: AtmosphereResourceEvent) {}
def onPreSuspend(event: AtmosphereResourceEvent): Unit = {}

def onHeartbeat(event: AtmosphereResourceEvent) {
def onHeartbeat(event: AtmosphereResourceEvent): Unit = {
client(event.getResource) foreach (_.receive.lift(Heartbeat))
}

def onBroadcast(event: AtmosphereResourceEvent) {
def onBroadcast(event: AtmosphereResourceEvent): Unit = {
val resource = event.getResource
resource.transport match {
case JSONP | AJAX | LONG_POLLING =>
case _ => resource.getResponse.flushBuffer()
}
}

def onDisconnect(event: AtmosphereResourceEvent) {
def onDisconnect(event: AtmosphereResourceEvent): Unit = {
val disconnector = if (event.isCancelled) ClientDisconnected else ServerDisconnected
client(event.getResource) foreach (_.receive.lift(Disconnected(disconnector, Option(event.throwable))))
// if (!event.getResource.isResumed) {
Expand All @@ -45,15 +45,15 @@ object ScalatraAtmosphereHandler {
// }
}

def onResume(event: AtmosphereResourceEvent) {}
def onResume(event: AtmosphereResourceEvent): Unit = {}

def onSuspend(event: AtmosphereResourceEvent) {}
def onSuspend(event: AtmosphereResourceEvent): Unit = {}

def onThrowable(event: AtmosphereResourceEvent) {
def onThrowable(event: AtmosphereResourceEvent): Unit = {
client(event.getResource) foreach (_.receive.lift(Error(Option(event.throwable()))))
}

def onClose(event: AtmosphereResourceEvent) {}
def onClose(event: AtmosphereResourceEvent): Unit = {}
}
}

Expand All @@ -63,7 +63,7 @@ class ScalatraAtmosphereHandler(scalatraApp: ScalatraBase)(implicit wireFormat:

private[this] val internalLogger = Logger(getClass)

def onRequest(resource: AtmosphereResource) {
def onRequest(resource: AtmosphereResource): Unit = {
implicit val req = resource.getRequest
implicit val res = resource.getResponse
val route = Option(req.getAttribute(org.scalatra.atmosphere.AtmosphereRouteKey)).map(_.asInstanceOf[MatchedRoute])
Expand Down Expand Up @@ -125,17 +125,17 @@ class ScalatraAtmosphereHandler(scalatraApp: ScalatraBase)(implicit wireFormat:
if (u.endsWith("/")) u + "*" else u + "/*"
}

private[this] def configureBroadcaster(resource: AtmosphereResource) {
private[this] def configureBroadcaster(resource: AtmosphereResource): Unit = {
val bc = ScalatraBroadcasterFactory.getDefault.get.get(requestUri(resource))
resource.setBroadcaster(bc)
}

private[this] def handleIncomingMessage(req: AtmosphereRequest, client: AtmosphereClient) {
private[this] def handleIncomingMessage(req: AtmosphereRequest, client: AtmosphereClient): Unit = {
val parsed: InboundMessage = wireFormat.parseInMessage(readBody(req))
handleIncomingMessage(parsed, client)
}

private[this] def handleIncomingMessage(msg: InboundMessage, client: AtmosphereClient) {
private[this] def handleIncomingMessage(msg: InboundMessage, client: AtmosphereClient): Unit = {
// the ScalatraContext provides the correct request/response values to the AtmosphereClient.receive method
// this can be later refactored to a (Request, Response) => Any
client.receiveWithScalatraContext(scalatraApp).lift(msg)
Expand All @@ -152,7 +152,7 @@ class ScalatraAtmosphereHandler(scalatraApp: ScalatraBase)(implicit wireFormat:
body.toString()
}

private[this] def addEventListener(resource: AtmosphereResource) {
private[this] def addEventListener(resource: AtmosphereResource): Unit = {
resource.addEventListener(new ScalatraResourceEventListener)
}

Expand All @@ -167,7 +167,7 @@ class ScalatraAtmosphereHandler(scalatraApp: ScalatraBase)(implicit wireFormat:
None
}

private[this] def resumeIfNeeded(resource: AtmosphereResource) {
private[this] def resumeIfNeeded(resource: AtmosphereResource): Unit = {
import org.atmosphere.cpr.AtmosphereResource.TRANSPORT._
resource.transport match {
case JSONP | AJAX | LONG_POLLING => resource.resumeOnBroadcast(true)
Expand Down
Expand Up @@ -48,7 +48,7 @@ package object atmosphere {
}

// See here: http://stackoverflow.com/questions/11529145/how-do-i-wrap-a-java-util-concurrent-future-in-an-akka-future
private[atmosphere] def pollJavaFutureUntilDoneOrCancelled[T](javaFuture: java.util.concurrent.Future[T], promise: Promise[T], maybeTimeout: Option[Deadline] = None)(implicit system: ActorSystem) {
private[atmosphere] def pollJavaFutureUntilDoneOrCancelled[T](javaFuture: java.util.concurrent.Future[T], promise: Promise[T], maybeTimeout: Option[Deadline] = None)(implicit system: ActorSystem): Unit = {
implicit val execContext = system.dispatcher
if (maybeTimeout.exists(_.isOverdue())) javaFuture.cancel(true)

Expand Down
Expand Up @@ -54,7 +54,7 @@ class AtmosphereSpecServlet(implicit override protected val scalatraActorSystem:
case t: Throwable => t.printStackTrace()
}

override def handle(request: HttpServletRequest, response: HttpServletResponse) {
override def handle(request: HttpServletRequest, response: HttpServletResponse): Unit = {
withRequestResponse(request, response) {
println(request.headers)
println("routeBasePath: " + routeBasePath(request))
Expand Down Expand Up @@ -154,7 +154,7 @@ class AtmosphereSpec extends MutableScalatraSpec {

}

private def stopSystem {
private def stopSystem: Unit = {
system.shutdown()
system.awaitTermination(Duration(1, TimeUnit.MINUTES))
}
Expand Down
20 changes: 10 additions & 10 deletions auth/src/main/scala/org/scalatra/auth/Scentry.scala
Expand Up @@ -17,16 +17,16 @@ object Scentry {
private val _globalStrategies = new mutable.HashMap[String, StrategyFactory[_ <: AnyRef]]()

@deprecated("Use method `register` with strings instead.", "2.0")
def registerStrategy[UserType <: AnyRef](name: Symbol, strategyFactory: StrategyFactory[UserType]) {
def registerStrategy[UserType <: AnyRef](name: Symbol, strategyFactory: StrategyFactory[UserType]): Unit = {
_globalStrategies += (name.name -> strategyFactory)
}

def register[UserType <: AnyRef](name: String, strategyFactory: StrategyFactory[UserType]) {
def register[UserType <: AnyRef](name: String, strategyFactory: StrategyFactory[UserType]): Unit = {
_globalStrategies += (name -> strategyFactory)
}

def globalStrategies = _globalStrategies
def clearGlobalStrategies() { _globalStrategies.clear() }
def clearGlobalStrategies(): Unit = { _globalStrategies.clear() }

val scentryAuthKey = "scentry.auth.default.user"
val ScentryRequestKey = "org.scalatra.auth.Scentry"
Expand All @@ -49,7 +49,7 @@ class Scentry[UserType <: AnyRef](
request.get(scentryAuthKey).orNull.asInstanceOf[UserType]

def store = _store
def store_=(newStore: ScentryAuthStore) {
def store_=(newStore: ScentryAuthStore): Unit = {
_store = newStore
}

Expand All @@ -59,15 +59,15 @@ class Scentry[UserType <: AnyRef](

//def session = app.session
def params(implicit request: HttpServletRequest): Params = app.params(request)
def redirect(uri: String)(implicit request: HttpServletRequest, response: HttpServletResponse) {
def redirect(uri: String)(implicit request: HttpServletRequest, response: HttpServletResponse): Unit = {
app.redirect(uri)(request, response)
}

def register(strategy: => ScentryStrategy[UserType]) {
def register(strategy: => ScentryStrategy[UserType]): Unit = {
register(strategy.name, ((_: ScalatraBase) => strategy))
}

def register(name: String, strategyFactory: StrategyFactory) {
def register(name: String, strategyFactory: StrategyFactory): Unit = {
_strategies += (name -> strategyFactory)
}

Expand Down Expand Up @@ -145,19 +145,19 @@ class Scentry[UserType <: AnyRef](

private[this] var defaultUnauthenticated: Option[() Unit] = None

def unauthenticated(callback: Unit) {
def unauthenticated(callback: Unit): Unit = {
defaultUnauthenticated = Some(() callback)
}

def logout()(implicit request: HttpServletRequest, response: HttpServletResponse) {
def logout()(implicit request: HttpServletRequest, response: HttpServletResponse): Unit = {
val usr = user
runCallbacks() { _.beforeLogout(usr) }
request -= scentryAuthKey
store.invalidate()
runCallbacks() { _.afterLogout(usr) }
}

private[this] def runCallbacks(guard: StrategyType Boolean = s true)(which: StrategyType Unit) {
private[this] def runCallbacks(guard: StrategyType Boolean = s true)(which: StrategyType Unit): Unit = {
strategies foreach {
case (_, v) if guard(v) which(v)
case _ // guard failed
Expand Down
8 changes: 4 additions & 4 deletions auth/src/main/scala/org/scalatra/auth/ScentryAuthStore.scala
Expand Up @@ -17,11 +17,11 @@ object ScentryAuthStore {

def get(implicit request: HttpServletRequest, response: HttpServletResponse) = app.cookies.get(Scentry.scentryAuthKey) getOrElse ""

def set(value: String)(implicit request: HttpServletRequest, response: HttpServletResponse) {
def set(value: String)(implicit request: HttpServletRequest, response: HttpServletResponse): Unit = {
app.cookies.update(Scentry.scentryAuthKey, value)(cookieOptions)
}

def invalidate()(implicit request: HttpServletRequest, response: HttpServletResponse) {
def invalidate()(implicit request: HttpServletRequest, response: HttpServletResponse): Unit = {
app.cookies.delete(Scentry.scentryAuthKey)(cookieOptions)
}

Expand All @@ -32,10 +32,10 @@ object ScentryAuthStore {
def get(implicit request: HttpServletRequest, response: HttpServletResponse): String = {
app.session.get(Scentry.scentryAuthKey).map(_.asInstanceOf[String]).orNull
}
def set(value: String)(implicit request: HttpServletRequest, response: HttpServletResponse) {
def set(value: String)(implicit request: HttpServletRequest, response: HttpServletResponse): Unit = {
app.session(Scentry.scentryAuthKey) = value
}
def invalidate()(implicit request: HttpServletRequest, response: HttpServletResponse) {
def invalidate()(implicit request: HttpServletRequest, response: HttpServletResponse): Unit = {
app.session.invalidate()
}
}
Expand Down

0 comments on commit 582ccb6

Please sign in to comment.