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

📄 dispatcherdb.java

📁 分布式计算平台P2HP-1的源代码;P2HP-1是基于P2P的高性能计算平台
💻 JAVA
字号:
package cn.edu.hust.cgcl.biogrid.dispatcher;


import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2004</p>
 * <p>Company: </p>
 * @author not attributable
 * @version 1.0
 */

public class DispatcherDB
{
    protected final static String DEF_NAME = "/dispatcherDB.txt";

    protected String fileName;

    public DispatcherDB()
        throws IOException
    {
        this(DEF_NAME);
    }

    public DispatcherDB(String fn)
        throws IOException
    {
        fileName = fn;
    }

    public DispatcherInfo rebuild()
        throws IOException
    {
        File f = new File(fileName);
        if (!f.exists())
        {
           return null;
        }
        BufferedReader is = new BufferedReader(new FileReader(fileName));
        String line;
        if ( (line = is.readLine()) != null)
        {
            String[] result = line.split(":");
            DispatcherInfo d=new DispatcherInfo(result[0],
                                          result[1], result[2]);
            return d;
        }
        return null;
    }

    protected PrintWriter pw;

    public synchronized void createDB(DispatcherInfo di)
        throws IOException
    {
        File f = new File(fileName);
        if (!f.exists())
        {
            f.createNewFile();
        }
        else
        {
            f.delete();
            f.createNewFile();
        }
        if (pw == null)
        {
            pw = new PrintWriter(new FileWriter(fileName, true));
        }
        pw.println(toDB(di));
        pw.flush();
    }

    protected String toDB(DispatcherInfo di)
    {
        return new StringBuffer().append(di.getDispatcherId()).append(':').
            append(di.getFirstMonitorId()).append(':').append(di.getSecondMonitorId()).
            append(':').
            toString();
    }

}

⌨️ 快捷键说明

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