⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 d_communication.java

📁 分布式计算平台P2HP-1的源代码;P2HP-1是基于P2P的高性能计算平台
💻 JAVA
字号:
/*
 * Created on 2004-10-27
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package cn.edu.hust.cgcl.biogrid.dispatcher;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.PrintWriter;
import java.net.Socket;

//communicate to other dispatcher node 
public class D_Communication {
  private static final int TIME_OUT = 1000;

  private Socket nodeSocket;
  private String ipAddr; //target dispatcher node's ipaddr and port
  private int dispatcherPort;
  protected Item D_item;


  protected ObjectInputStream iob;
  protected ObjectOutputStream oob;
  protected PrintWriter os;
  protected BufferedReader is;

  public D_Communication(String _ipAddr, int _Port) {
    this.ipAddr = _ipAddr;
    this.dispatcherPort = _Port;
    nodeSocket=null;
    os=null; 
    is=null;
    //tmpDispatcherInfo=new DispatcherInfo();
  }
  
  protected D_Communication(){}


public boolean onpoll() {
  if (nodeSocket == null) {
    if (!initCommunication()) {
      return false;
    }
  }
  if (process()) return true;
  return false;
}

  protected boolean process()
  {
  	return true;
  }

  private boolean initCommunication() {
    try {
      this.nodeSocket = new Socket(ipAddr, dispatcherPort);
      nodeSocket.setSoTimeout(TIME_OUT);
      is = new BufferedReader(new InputStreamReader(nodeSocket.getInputStream()));
      os = new PrintWriter(nodeSocket.getOutputStream());
      oob=new ObjectOutputStream(nodeSocket.getOutputStream());
      iob=new ObjectInputStream(nodeSocket.getInputStream());
  }
  catch (Exception e) {
    if (nodeSocket!=null) 
    {try{nodeSocket.close();}
       catch(IOException e1) {e1.printStackTrace();} }
    if(os!=null) os.close();
    if(is!=null) 
    {try{is.close();}
    catch(IOException e1) {e1.printStackTrace();} }
    if(iob!=null) 
    {try{iob.close();}
    catch(IOException e1) {e1.printStackTrace();} }
    if(oob!=null) 
    {try{oob.close();}
    catch(IOException e1) {e1.printStackTrace();} }
    return false;
  }
  return true;
} //initDispatcher

    public void log(Exception e)
    {
    e.printStackTrace();
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -