锘??xml version="1.0" encoding="utf-8" standalone="yes"?>中文字幕亚洲激情,3p在线观看,91免费综合在线http://www.aygfsteel.com/wangxinsh55/category/30592.htmlzh-cnThu, 03 Apr 2008 07:00:58 GMTThu, 03 Apr 2008 07:00:58 GMT60java RMI 鐩稿叧http://www.aygfsteel.com/wangxinsh55/archive/2008/04/03/190605.htmlSIMONESIMONEThu, 03 Apr 2008 05:32:00 GMThttp://www.aygfsteel.com/wangxinsh55/archive/2008/04/03/190605.htmlhttp://www.aygfsteel.com/wangxinsh55/comments/190605.htmlhttp://www.aygfsteel.com/wangxinsh55/archive/2008/04/03/190605.html#Feedback0http://www.aygfsteel.com/wangxinsh55/comments/commentRss/190605.htmlhttp://www.aygfsteel.com/wangxinsh55/services/trackbacks/190605.html闃呰鍏ㄦ枃

SIMONE 2008-04-03 13:32 鍙戣〃璇勮
]]>
JAVA-RMI瀛︿範蹇冨緱http://www.aygfsteel.com/wangxinsh55/archive/2008/04/03/190600.htmlSIMONESIMONEThu, 03 Apr 2008 05:25:00 GMThttp://www.aygfsteel.com/wangxinsh55/archive/2008/04/03/190600.htmlhttp://www.aygfsteel.com/wangxinsh55/comments/190600.htmlhttp://www.aygfsteel.com/wangxinsh55/archive/2008/04/03/190600.html#Feedback0http://www.aygfsteel.com/wangxinsh55/comments/commentRss/190600.htmlhttp://www.aygfsteel.com/wangxinsh55/services/trackbacks/190600.html瀛︿範java tutorial涓殑rmi绔犺妭錛岃涔︾瑪璁?/p>

JAVA-RMI 鎵閲囩敤鐨勬満鍒訛細

1. 鏌怬bject闇瑕乺emote call 錛屽垯瀹冩墍鏈夌殑鏂規硶閮芥斁鍦ㄤ竴涓柊澹版槑鐨勬帴鍙d腑錛岃鎺ュ彛蹇呴』extends          Remote鎺ュ彛

   Compute鎺ュ彛涓瓨鏀炬墍鏈夐渶瑕佽繘琛岃繙紼嬭皟鐢ㄧ殑鏂規硶錛岃瀹炵幇璇ユ帴鍙g殑綾繪潵瀹炵幇榪欎簺琚繙紼嬭皟鐢ㄧ殑鏂規硶

package compute;

import java.rmi.Remote;
import java.rmi.RemoteException;

public interface Compute extends Remote {
    Object executeTask(Task t) throws RemoteException;
}


2.閲囩敤榪滅▼璋冪敤鐨勬柟娉曞悓鏍鋒湁涓浜涘弬鏁板拰榪斿洖鍊鹼紝瀵逛簬榪欎簺鍙傛暟鍜岃繑鍥炲鹼紝鍦ㄤ笉鍚孞AVA铏氭嫙鏈洪棿浼犺緭錛孯M  I閲囧彇鐨勬槸鍊間紶閫掞紝鎵浠ユ墍鏈夌殑鍙傛暟鍜岃繑鍥炲煎繀欏籩xtends Serializable

package compute;

import java.io.Serializable;

public interface Task extends Serializable {
    Object execute();
}


/*******************************************************************************************
涓婇潰涓虹涓閮ㄥ垎錛屽湪榪欏綋涓紝鎴戜滑璁捐浜嗕竴涓帴鍙o紝鍏朵腑鍖呭惈闇瑕佽繙紼嬭皟鐢ㄧ殑鏂規硶錛岀劧鍚庤璇ユ帴鍙g殑瀹炵幇鑰咃紙鍗寵繙紼嬪璞$殑owner錛夋潵瀹炵幇榪欎簺鏂規硶
*******************************************************************************************/


3. 鐜板湪鎴戜滑涓轟簡寰楀埌榪滅▼瀵硅薄錛屽氨鏉ュ疄鐜頒竴涓嬩笂闈㈠畾涔夌殑鎺ュ彛錛?br />    main鍑芥暟涓紝鏂板緩涓涓繙紼嬪璞ngine,騫跺皢瀹冧笌鍚嶅瓧name閭﹀畾錛歂aming.rebind(name, engine);

娉細The superclass UnicastRemoteObject supplies implementations for a number of     java.lang.Object methods (equals, hashCode, toString) so that they are defined     appropriately for remote objects. UnicastRemoteObjectalso includes constructors and     static methods used to export a remote object, that is, make the remote object available     to receive incoming calls from clients.

package engine;

import java.rmi.*;
import java.rmi.server.*;
import compute.*;

public class ComputeEngine extends UnicastRemoteObject
                           implements Compute
{
    public ComputeEngine() throws RemoteException {
        super();
    }

    public Object executeTask(Task t) {
        return t.execute();
    }

    public static void main(String[] args) {
        if (System.getSecurityManager() == null) {
            System.setSecurityManager(new RMISecurityManager());
        }
        String name = "http://host/Compute";
        try {
            Compute engine = new ComputeEngine();
            Naming.rebind(name, engine);
            System.out.println("ComputeEngine bound");
        } catch (Exception e) {
            System.err.println("ComputeEngine exception: " +
          e.getMessage());
            e.printStackTrace();
        }
    }
}

/*******************************************************************************************
涓婇潰涓虹浜岄儴鍒嗭紝鍦ㄨ繖褰撲腑錛屾垜浠緱鍒頒簡涓涓疄鐜頒簡Compute鎺ュ彛鐨勮繙紼嬪璞ngine錛屾敞鎰忥細engine涓彧鏈夐偅浜汣ompute鎺ュ彛涓殑鏂規硶鑳藉琚繙紼嬭皟鐢紝鍏朵粬鏂規硶鍙兘鏈湴璋冪敤銆傜幇鍦紝灝嗚繙紼嬪璞ngine閭﹀畾鍒癛MI Registry 銆?client鍙互浠巖egistry閭i噷寰楀埌engine鐨勫紩鐢紝瀹為檯涓婃槸涓涓猻tub錛岀浉褰撲簬涓涓猠ngine鐨勪唬鐞嗭紝榪滅▼鏂規硶琚玞lient璋冪敤浠ュ悗錛屽彲浠ユ敼鍙榚ngine鐨勭姸鎬?br /> *******************************************************************************************/
  
4. 涓嬮潰鎴戜滑瀹炵幇閭d簺榪滅▼鏂規硶璋冪敤鏃舵墍瑕佺敤鍒扮殑鍙傛暟錛歍ask

package client;

import compute.*;
import java.math.*;

public class Pi implements Task {

    /** constants used in pi computation */
    private static final BigDecimal ZERO =
        BigDecimal.valueOf(0);
    private static final BigDecimal  ONE =
        BigDecimal.valueOf(1);
    private static final BigDecimal FOUR =
        BigDecimal.valueOf(4);

    /** rounding mode to use during pi computation */
    private static final int roundingMode =
        BigDecimal.ROUND_HALF_EVEN;

    /** digits of precision after the decimal point */
    private int digits;
   
    /**
     * Construct a task to calculate pi to the specified
     * precision.
     */
    public Pi(int digits) {
        this.digits = digits;
    }

    /**
     * Calculate pi.
     */
    public Object execute() {
        return computePi(digits);
    }

    /**
     * Compute the value of pi to the specified number of
     * digits after the decimal point.  The value is
     * computed using Machin's formula:
     *
     *          pi/4 = 4*arctan(1/5) - arctan(1/239)
     *
     * and a power series expansion of arctan(x) to
     * sufficient precision.
     */
    public static BigDecimal computePi(int digits) {
        int scale = digits + 5;
        BigDecimal arctan1_5 = arctan(5, scale);
        BigDecimal arctan1_239 = arctan(239, scale);
        BigDecimal pi = arctan1_5.multiply(FOUR).subtract(
                                  arctan1_239).multiply(FOUR);
        return pi.setScale(digits,
                           BigDecimal.ROUND_HALF_UP);
    }
    /**
     * Compute the value, in radians, of the arctangent of
     * the inverse of the supplied integer to the speficied
     * number of digits after the decimal point.  The value
     * is computed using the power series expansion for the
     * arc tangent:
     *
     * arctan(x) = x - (x^3)/3 + (x^5)/5 - (x^7)/7 +
     *     (x^9)/9 ...
     */  
    public static BigDecimal arctan(int inverseX,
                                  int scale)
    {
        BigDecimal result, numer, term;
        BigDecimal invX = BigDecimal.valueOf(inverseX);
        BigDecimal invX2 =
            BigDecimal.valueOf(inverseX * inverseX);

        numer = ONE.divide(invX, scale, roundingMode);

        result = numer;
        int i = 1;
        do {
            numer =
                numer.divide(invX2, scale, roundingMode);
            int denom = 2 * i + 1;
            term =
                numer.divide(BigDecimal.valueOf(denom),
                             scale, roundingMode);
            if ((i % 2) != 0) {
                result = result.subtract(term);
            } else {
                result = result.add(term);
            }
            i++;
        } while (term.compareTo(ZERO) != 0);
        return result;
    }
}

5. 鏈鍚庢垜浠疄鐜癱lient瀵硅薄
   榪滅▼瀵硅薄comp鏄氳繃RMI鐨勬敞鍐岃〃鏉ユ煡鎵懼埌鐨?/p>

package client;

import java.rmi.*;
import java.math.*;
import compute.*;

public class ComputePi {
    public static void main(String args[]) {
        if (System.getSecurityManager() == null) {
            System.setSecurityManager(new RMISecurityManager());
        }
        try {
            String name = "http://" + args[0] + "/Compute";
            Compute comp = (Compute) Naming.lookup(name);
            Pi task = new Pi(Integer.parseInt(args[1]));
            BigDecimal pi = (BigDecimal) (comp.executeTask(task));
            System.out.println(pi);
        } catch (Exception e) {
            System.err.println("ComputePi exception: " +
                               e.getMessage());
            e.printStackTrace();
        }
    }
}



SIMONE 2008-04-03 13:25 鍙戣〃璇勮
]]>
主站蜘蛛池模板: 和硕县| 东乡| 三门峡市| 绵竹市| 新田县| 卓资县| 白沙| 曲阜市| 镇沅| 清新县| 积石山| 南丰县| 武陟县| 西畴县| 孝义市| 福州市| 呼和浩特市| 西安市| 曲靖市| 姚安县| 镇沅| 香格里拉县| 永登县| 河源市| 松阳县| 宝应县| 中西区| 水富县| 定远县| 报价| 宜宾县| 大安市| 洪雅县| 盖州市| 且末县| 买车| 平邑县| 凤凰县| 安多县| 比如县| 斗六市|