亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? server.java

?? 爬蟲數(shù)據(jù)的改進,并修正了一些bug
?? JAVA
字號:
/* Copyright (c) 2003 The Nutch Organization.  All rights reserved.   */
/* Use subject to the conditions in http://www.nutch.org/LICENSE.txt. */

package net.nutch.ipc;

import java.io.IOException;
import java.io.EOFException;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;

import java.net.Socket;
import java.net.ServerSocket;
import java.net.SocketTimeoutException;

import java.util.LinkedList;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;

import net.nutch.io.Writable;
import net.nutch.io.UTF8;

/** An abstract IPC service.  IPC calls take a single {@link Writable} as a
 * parameter, and return a {@link Writable} as their value.  A service runs on
 * a port and is defined by a parameter class and a value class.
 * 
 * @author Doug Cutting
 * @see Client
 */
public abstract class Server {
  public static final Logger LOG =
    Logger.getLogger("server");

  private int port;                               // port we listen on
  private int handlerCount;                       // number of handler threads
  private int maxQueuedCalls;                     // max number of queued calls
  private Class paramClass;                       // class of call parameters

  private int timeout = 10000;                    // timeout for i/o
  private boolean running = true;                 // true while server runs
  private LinkedList callQueue = new LinkedList(); // queued calls
  private Object callDequeued = new Object();     // used by wait/notify

  /** A call queued for handling. */
  private static class Call {
    private int id;                               // the client's call id
    private Writable param;                       // the parameter passed
    private Connection connection;                // connection to client

    public Call(int id, Writable param, Connection connection) {
      this.id = id;
      this.param = param;
      this.connection = connection;
    }
  }

  /** Listens on the socket, starting new connection threads. */
  private class Listener extends Thread {
    private ServerSocket socket;

    public Listener() throws IOException {
      this.socket = new ServerSocket(port);
      socket.setSoTimeout(timeout);
      this.setDaemon(true);
      this.setName("Server listener on port " + port);
    }

    public void run() {
      LOG.info(getName() + ": starting");
      while (running) {
        try {
          new Connection(socket.accept()).start(); // start a new connection

        } catch (SocketTimeoutException e) {      // ignore timeouts
        } catch (Exception e) {                   // log all other exceptions
          LOG.log(Level.INFO, getName() + " caught: " + e, e);
        }
      }
      try {
        socket.close();
      } catch (IOException e) {}
      LOG.info(getName() + ": exiting");
    }
  }

  /** Reads calls from a connection and queues them for handling. */
  private class Connection extends Thread {
    private Socket socket;
    private DataInputStream in;
    private DataOutputStream out;

    public Connection(Socket socket) throws IOException {
      this.socket = socket;
      socket.setSoTimeout(timeout);
      this.in = new DataInputStream
        (new BufferedInputStream(socket.getInputStream()));
      this.out = new DataOutputStream
        (new BufferedOutputStream(socket.getOutputStream()));
      this.setDaemon(true);
      this.setName("Server connection on port " + port + " from "
                   + socket.getInetAddress().getHostAddress());
    }

    public void run() {
      LOG.info(getName() + ": starting");
      try {
        while (running) {
          int id;
          try {
            id = in.readInt();                    // try to read an id
          } catch (SocketTimeoutException e) {
            continue;
          }
          
//          if (LOG.isLoggable(Level.FINE))
//            LOG.fine(getName() + " got #" + id);
          LOG.info(">>> server: "+ id + " ["+ paramClass.getName()+"]");
        
          Writable param = makeParam();           // read param
          param.readFields(in);        
        
          Call call = new Call(id, param, this);
        
          synchronized (callQueue) {
            callQueue.addLast(call);              // queue the call
            callQueue.notify();                   // wake up a waiting handler
          }
        
          while (running && callQueue.size() >= maxQueuedCalls) {
            synchronized (callDequeued) {         // queue is full
              callDequeued.wait(timeout);         // wait for a dequeue
            }
          }
        }
      } catch (EOFException eof) {
          // This is what happens when the other side shuts things down
      } catch (Exception e) {
        LOG.log(Level.INFO, getName() + " caught: " + e, e);
      } finally {
        try {
          socket.close();
        } catch (IOException e) {}
        LOG.info(getName() + ": exiting");
      }
    }

  }

  /** Handles queued calls . */
  public class Handler extends Thread {
    public Handler() {
      this.setDaemon(true);
      this.setName("Server handler on " + port);
    }

    public void run() {
      LOG.info(getName() + ": starting");
      while (running) {
        try {
          Call call;
          synchronized (callQueue) {
            while (running && callQueue.size()==0) { // wait for a call
              callQueue.wait(timeout);
            }
            if (!running) break;
            call = (Call)callQueue.removeFirst(); // pop the queue
          }

          synchronized (callDequeued) {           // tell others we've dequeued
            callDequeued.notify();
          }

          //if (LOG.isLoggable(Level.FINE))
          //  LOG.fine(getName() + ": has #" + call.id + " from " +
          //           call.connection.socket.getInetAddress().getHostAddress());
          
          String error = null;
          Writable value = null;
          try {
            value = call(call.param);             // make the call
          } catch (Exception e) {
            LOG.log(Level.INFO, getName() + " call error: " + e, e);
            error = e.toString();
          }
            
          DataOutputStream out = call.connection.out;
          synchronized (out) {
            out.writeInt(call.id);                // write call id
            out.writeBoolean(error!=null);        // write error flag
            if (error != null)
              value = new UTF8(error);
            value.write(out);                     // write value
            out.flush();
          }

        } catch (Exception e) {
          LOG.log(Level.INFO, getName() + " caught: " + e, e);
        }
      }
      LOG.info(getName() + ": exiting");
    }

  }
  
  /** Constructs a server listening on the named port.  Parameters passed must
   * be of the named class.  The <code>handlerCount</handlerCount> determines
   * the number of handler threads that will be used to process calls.
   */
  protected Server(int port, Class paramClass, int handlerCount) {
    this.port = port;
    this.paramClass = paramClass;
    this.handlerCount = handlerCount;
    this.maxQueuedCalls = handlerCount;
  }

  /** Sets the timeout used for network i/o. */
  public void setTimeout(int timeout) { this.timeout = timeout; }

  /** Starts the service.  Must be called before any calls will be handled. */
  public synchronized void start() throws IOException {
    Listener listener = new Listener();
    listener.start();
    
    for (int i = 0; i < handlerCount; i++) {
      Handler handler = new Handler();
      handler.start();
    }
  }

  /** Stops the service.  No calls will be handled after this is called.  All
   * threads will exit. */
  public synchronized void stop() {
    LOG.info("Stopping server on " + port);
    running = false;
    try {
      Thread.sleep(timeout);                        // let all threads exit
    } catch (InterruptedException e) {}
    notify();
  }

  /** Wait for the server to be stopped. */
  public synchronized void join() throws InterruptedException {
    wait();
  }

  /** Called for each call. */
  public abstract Writable call(Writable param) throws IOException;

  
  private Writable makeParam() {
    Writable param;                               // construct param
    try {
      param = (Writable)paramClass.newInstance();
    } catch (InstantiationException e) {
      throw new RuntimeException(e.toString());
    } catch (IllegalAccessException e) {
      throw new RuntimeException(e.toString());
    }
    return param;
  }

}

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产精品欧美一区二区三区| 国产91丝袜在线播放九色| 美洲天堂一区二卡三卡四卡视频 | 成人深夜福利app| 欧美片在线播放| 中文字幕电影一区| 国内精品在线播放| 欧美一区二区三区爱爱| 亚洲视频免费观看| 成人午夜在线免费| 精品国免费一区二区三区| 午夜激情一区二区| 欧美无砖专区一中文字| 亚洲欧洲中文日韩久久av乱码| 国产伦理精品不卡| 日韩美女在线视频 | 捆绑紧缚一区二区三区视频| 色综合久久综合| 一区在线中文字幕| 成人免费观看男女羞羞视频| 久久精品视频免费观看| 国内精品嫩模私拍在线| 欧美一区二区免费观在线| 亚洲成av人在线观看| 在线精品视频小说1| 樱桃视频在线观看一区| 色综合av在线| 一区二区三区中文免费| 色国产精品一区在线观看| 亚洲人成伊人成综合网小说| 99re66热这里只有精品3直播| 国产精品第13页| 91视频免费看| 一区二区三区在线播放| 欧美亚洲禁片免费| 日韩制服丝袜先锋影音| 91精品午夜视频| 精品综合久久久久久8888| 久久综合精品国产一区二区三区| 麻豆国产欧美日韩综合精品二区| 日韩欧美国产wwwww| 黄页网站大全一区二区| 国产亚洲精品aa| 一本久道中文字幕精品亚洲嫩| 一个色综合网站| 欧美日韩精品欧美日韩精品一| 日韩精品乱码免费| 精品成人a区在线观看| 国产成人免费视频 | 久久久不卡影院| a美女胸又www黄视频久久| 亚洲免费在线观看| 日韩一级二级三级| 国产精品一区二区男女羞羞无遮挡| 中文字幕乱码日本亚洲一区二区 | 欧美一三区三区四区免费在线看| 久久国产精品99久久人人澡| 国产精品日韩精品欧美在线| 欧美伊人久久久久久久久影院| 日韩av一区二区三区| 久久久久久久久久电影| 91色九色蝌蚪| 麻豆精品一二三| 亚洲免费在线视频| 精品日韩一区二区| 97se亚洲国产综合在线| 免费一级欧美片在线观看| 国产精品三级久久久久三级| 51久久夜色精品国产麻豆| 丰满少妇在线播放bd日韩电影| 亚洲国产精品综合小说图片区| 欧美va亚洲va在线观看蝴蝶网| 99免费精品在线| 国产一区在线看| 亚洲成a人片综合在线| 国产亚洲污的网站| 欧美一区二区在线不卡| gogo大胆日本视频一区| 久久精品久久精品| 亚洲网友自拍偷拍| 国产精品久久久久久福利一牛影视| 欧美久久一区二区| 91猫先生在线| 国产毛片精品国产一区二区三区| 一区二区三区在线视频观看58| 欧美精品一区二区三| 欧美日韩久久不卡| 日本精品免费观看高清观看| 激情五月婷婷综合| 五月婷婷另类国产| 亚洲最新在线观看| 中文字幕日韩一区| 久久新电视剧免费观看| 67194成人在线观看| 欧美在线三级电影| 95精品视频在线| 成人丝袜18视频在线观看| 国产一区福利在线| 美女视频网站久久| 日韩黄色片在线观看| 亚洲一区在线视频观看| 一区二区三区在线看| 亚洲欧美色图小说| 亚洲三级久久久| 国产精品妹子av| 国产精品天天看| 国产精品久久久一区麻豆最新章节| 337p粉嫩大胆色噜噜噜噜亚洲| 日韩手机在线导航| 日韩一区二区三区在线| 日韩欧美国产午夜精品| 欧美一区二区免费视频| 日韩三级伦理片妻子的秘密按摩| 欧美一区二区大片| 日韩欧美中文字幕制服| 精品免费日韩av| 久久这里只有精品首页| 久久久久久久性| 国产精品欧美久久久久一区二区 | 亚洲成av人片www| 日韩在线a电影| 老司机精品视频线观看86| 久久不见久久见免费视频1| 日本va欧美va精品发布| 国产一区二区三区观看| 国产成人精品网址| 91网站在线观看视频| 在线亚洲人成电影网站色www| 在线视频中文字幕一区二区| 欧美视频在线播放| 精品国产一区a| 国产精品久久久久久久裸模| 亚洲欧美日韩国产手机在线| 偷拍日韩校园综合在线| 狠狠色丁香婷婷综合| 国产sm精品调教视频网站| 一本一道久久a久久精品综合蜜臀| 欧美怡红院视频| 久久综合九色综合97婷婷女人 | 久久综合色综合88| 国产精品天天摸av网| 性欧美疯狂xxxxbbbb| 韩国精品一区二区| 色呦呦日韩精品| 精品三级在线观看| 亚洲天堂免费看| 免费不卡在线视频| 福利一区在线观看| 欧美精品久久99| 一区在线观看免费| 毛片基地黄久久久久久天堂| 成人网页在线观看| 欧美一区二区在线播放| 国产精品乱人伦一区二区| 三级不卡在线观看| 成人动漫一区二区| 欧美一级欧美三级| 亚洲欧美日韩一区| 国产麻豆9l精品三级站| 欧美日韩国产高清一区二区三区 | 日韩免费看网站| 一区二区三区精品在线| 国产成人精品网址| 日韩视频在线观看一区二区| 亚洲女厕所小便bbb| 国产成人av电影免费在线观看| 欧美精品乱码久久久久久按摩| 一色屋精品亚洲香蕉网站| 国模少妇一区二区三区| 884aa四虎影成人精品一区| 亚洲色图19p| 国产成人亚洲精品狼色在线| 欧美一级在线免费| 亚洲二区视频在线| 日本丰满少妇一区二区三区| 国产亚洲综合在线| 日本大胆欧美人术艺术动态| 91久久香蕉国产日韩欧美9色| 欧美激情中文不卡| 国产福利一区二区三区视频在线| 91精品国产综合久久久蜜臀粉嫩| 一区二区在线免费| 91丨porny丨国产| 国产精品国产三级国产a| 国产成人免费视频网站高清观看视频 | 亚洲少妇中出一区| 国产成人福利片| 久久品道一品道久久精品| 美女mm1313爽爽久久久蜜臀| 日韩一区二区影院| 免费高清在线一区| 日韩一区二区免费在线电影| 日本va欧美va瓶| 日韩欧美一区在线| 久久疯狂做爰流白浆xx| 精品黑人一区二区三区久久 | 久久天堂av综合合色蜜桃网| 裸体健美xxxx欧美裸体表演| 欧美大片国产精品| 激情小说欧美图片|