• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Scala SocketTimeoutException类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Scala中java.net.SocketTimeoutException的典型用法代码示例。如果您正苦于以下问题:Scala SocketTimeoutException类的具体用法?Scala SocketTimeoutException怎么用?Scala SocketTimeoutException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了SocketTimeoutException类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。

示例1: StdHttpExceptionHandler

//设置package包名称以及导入依赖的类
package handlers

import java.net.SocketTimeoutException

import com.google.inject.{Inject, Singleton}
import org.apache.http.{ConnectionClosedException, ExceptionLogger}
import org.slf4j.Logger

@Singleton
class StdHttpExceptionHandler @Inject()(logger: Logger) extends ExceptionLogger {

  @Override
  def log(ex :Exception): Unit = {
    ex match {
      case timeOutException: SocketTimeoutException => logger.error("Socket connection has timed out!")
      case connectionClosedException: ConnectionClosedException => logger.error("Lost connection with base!")
      case exception: Exception => logger.warn(exception.getMessage)
    }
  }
} 
开发者ID:jameshforster,项目名称:ToL-Scout-Plugin,代码行数:21,代码来源:StdHttpExceptionHandler.scala


示例2: ShutdownServer

//设置package包名称以及导入依赖的类
package com.github.pheymann.mockit.network

import java.io.ObjectOutputStream
import java.net.{SocketTimeoutException, ServerSocket}

import com.github.pheymann.mockit.core.core._
import com.github.pheymann.mockit.core._
import com.github.pheymann.mockit.logging.Logger


class ShutdownServer(
                        val shutdown: ShutdownLatch
                    )   extends Runnable
                        with    Logger {

    val server = new ServerSocket(MOCKIT_SD_PORT)

    override def run(): Unit = {
        server.setSoTimeout(SERVER_TIMEOUT)

        this > s"[email protected]$MOCKIT_SD_PORT"
        do {
            try {
                this >> "waiting for clients"
                val client      = server.accept
                val outStream   = new ObjectOutputStream(client.getOutputStream)

                this >> "send 'keep alive' message"
                outStream.writeBoolean(true)
                outStream.flush()

                client.close()
            }
            catch {
                case e: SocketTimeoutException  => this >> "server listening interruption occurred"
                case e: Throwable               => this error (null, e)
            }
        } while (shutdown.continue)
        this > stop

        server.close()
    }

} 
开发者ID:simonox,项目名称:MockIt,代码行数:45,代码来源:ShutdownServer.scala


示例3: LogServer

//设置package包名称以及导入依赖的类
package com.github.pheymann.mockit.network

import java.io.ObjectInputStream
import java.net.{SocketTimeoutException, ServerSocket}

import scala.collection.mutable.ListBuffer

import com.github.pheymann.mockit.core.core._
import com.github.pheymann.mockit.logging.{Logger, LogEntry}


class LogServer(
                val logs:           ListBuffer[LogEntry],
                val agentNumber:    Int
               ) extends Runnable
                 with    Logger {

    val logServer = new ServerSocket(MOCKIT_LOG_PORT)

    override def run(): Unit = {
        var counter = 0

        logServer.setSoTimeout(SERVER_TIMEOUT)

        this > s"[email protected]$MOCKIT_LOG_PORT"
        do {
            try {
                this >> "waiting for client"
                val client = logServer.accept
                val address = client.getInetAddress.getHostAddress

                val logStream = new ObjectInputStream(client.getInputStream)
                val size = logStream.readInt

                this >> s"[$address]: collect all $size log entries"
                for (i <- 0 until size)
                    logs += logStream.readObject.asInstanceOf[LogEntry]

                client.close()
                counter += 1
            }
            catch {
                case e: SocketTimeoutException => this >> "server listening interruption occurred"
                case e: Throwable => this error ("disregard of log protocol", e)
            }
        } while (counter < agentNumber)
        this > stop

        logServer.close()
    }

} 
开发者ID:simonox,项目名称:MockIt,代码行数:53,代码来源:LogServer.scala


示例4: MockItDaemonDummy

//设置package包名称以及导入依赖的类
package com.github.pheymann.mockit.util

import java.net.SocketTimeoutException

import com.github.pheymann.mockit.core.{UploadServerDownException, MockFactory}
import com.github.pheymann.mockit.core.{UploadServerDownException, MockFactory}
import com.github.pheymann.mockit.logging.Logger
import com.github.pheymann.mockit.network.ServerListener

class MockItDaemonDummy(
                            val repetitions: Int
                       ) extends Runnable
                        with    Logger {

    override def run(): Unit = {
        for (i <- 0 until repetitions) {
            try {
                val listener = new ServerListener

                val address = listener.waitForInvitation
                val (config, mockClass) = listener.load(address)

                MockFactory.networkClient(config, mockClass)
            }
            catch {
                case e @ (_: SocketTimeoutException | _: UploadServerDownException) =>
                case e: Throwable => this error ("exception during MockIt test run", e)
            }
        }
    }

} 
开发者ID:simonox,项目名称:MockIt,代码行数:33,代码来源:MockItDaemonDummy.scala


示例5: main

//设置package包名称以及导入依赖的类
package com.github.pheymann.mockitdaemon

import java.io.ObjectInputStream
import java.net.{ServerSocket, SocketTimeoutException}

import com.github.pheymann.mockit.core._
import com.github.pheymann.mockit.core.core._
import com.github.pheymann.mockit.logging.Logger
import com.github.pheymann.mockit.network.ServerListener


    def main(args: Array[String]): Unit = {
        val log = new Logger {override lazy val name = "MockItDaemon"}

        var continue = true
        var daemon: Thread = null

        val id     = args(0).toInt
        val server = new ServerSocket(MOCKIT_PORT + id)

        server.setSoTimeout(SERVER_TIMEOUT)

        log > s"start MockIt test client := $id"
        do {
            daemon = new Thread {
                override def run(): Unit = action(log)
            }
            daemon.start()

            try {
                val client = server.accept

                val inStream = new ObjectInputStream(client.getInputStream)

                inStream.readObject match {
                    case ShutdownDaemon() => continue = false
                    case _ =>
                }
                client.getOutputStream.write(0)
                client.getOutputStream.flush()
                client.close()
                if (!continue)
                    server.close()
            }
            catch {
                case e: SocketTimeoutException =>
                case e: Throwable => throw e
            }
            daemon.join()
        } while (continue)
        log > s"stop MockIt test client := $id"
    }

} 
开发者ID:simonox,项目名称:MockIt,代码行数:55,代码来源:MockItDaemon.scala



注:本文中的java.net.SocketTimeoutException类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Scala RequestToken类代码示例发布时间:2022-05-23
下一篇:
Scala EmbeddedHttpProbe类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap