สามารถใช้เหตุการณ์ที่กำหนดในโค้ดฝั่งเซิร์ฟเวอร์ใน RMI (โค้ดฝั่งไคลเอ็นต์) ได้อย่างไร

ใน RMI (โค้ดฝั่งไคลเอ็นต์) ฉันจะใช้เหตุการณ์ที่กำหนดไว้ในโค้ดฝั่งเซิร์ฟเวอร์ได้อย่างไร

ตัวอย่างเช่น โค้ดฝั่งเซิร์ฟเวอร์ต่อไปนี้จะกำหนดเหตุการณ์ PropertyChangeSupport

สามารถนำไปใช้ในฝั่งไคลเอ็นต์ได้อย่างไร

package rmiservice.services.calculator;

import java.beans.PropertyChangeSupport;
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.util.LinkedList;
import java.util.Queue;

public class CalculatorService extends UnicastRemoteObject implements ICalculator {
private Queue<Integer> numbers = new LinkedList<Integer>();
private Integer result;
***private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this);***


public CalculatorService() throws RemoteException {
    super();

}


public void start() throws Exception {
    java.rmi.registry.LocateRegistry.createRegistry(1099);
    Naming.bind("CalculatorService", this);
    System.out.println("Calculator Service is Run  . . .");
}

public void stop() throws Exception {

    Naming.unbind("CalculatorService");
    UnicastRemoteObject.unexportObject(this, true);

    System.out.println("Calculator Service is Stop . . .");

}

//-------------------------------------------------------------------
//------------------------------ Implements ICalculator -------------

public void addNumber(Integer number) throws Exception {
    numbers.add(number);
}

public Integer getResult() throws Exception {
    return this.result;
}

public void setResult(Integer result) throws Exception {
    Integer oldResult = this.getResult();
    this.result = result;
    ***propertyChangeSupport.firePropertyChange("result", oldResult, result);***
}

public void calculate(Operation operation) throws Exception {
    Integer _result = 0;

    if (numbers.size() < 2)
        return;

    switch (operation) {
        case Add: {
            _result = 0;
            while (numbers.size() > 0) {
                _result += numbers.poll();
            }
            break;
        }

        case Substract: {
            _result = numbers.poll();
            while (numbers.size() > 0) {
                _result -= numbers.poll();
            }
            break;
        }

    }

    this.setResult(_result);

}
//-------------------------------------------------------------------

}


person user2049371    schedule 12.02.2013    source แหล่งที่มา
comment
หากค่าคุณสมบัติมีการเปลี่ยนแปลงบนฝั่งเซิร์ฟเวอร์ ไคลเอนต์จะได้รับแจ้งการเปลี่ยนแปลงได้อย่างไร?   -  person user2049371    schedule 12.02.2013
comment
ลองค้นหาการเรียกกลับ RMI   -  person MadProgrammer    schedule 12.02.2013
comment
คุณไม่ต้องการที่จะทำเช่นนี้ ค่าใช้จ่ายมีมหาศาล คุณต้องทำให้วิธีการระยะไกลของคุณมีเนื้อหาหยาบมากขึ้น เพื่อให้คุ้มค่าแก่การดำเนินการเมื่อพิจารณาถึงโอเวอร์เฮดและความล่าช้าของเครือข่าย   -  person user207421    schedule 11.09.2014


คำตอบ (3)


RMI ไม่รองรับการแจ้งเตือน แต่คุณสามารถใช้ JMX Beans ที่รองรับ Event ซึ่งสามารถใช้กับ RMI ได้

อินเทอร์เฟซ MBean ของคุณต้องขยาย NotificationEmitter เพื่อดำเนินการนี้ .

person R Kaja Mohideen    schedule 12.02.2013
comment
หากค่าคุณสมบัติมีการเปลี่ยนแปลงบนฝั่งเซิร์ฟเวอร์ ไคลเอนต์จะได้รับแจ้งการเปลี่ยนแปลงได้อย่างไร? - person user2049371; 12.02.2013
comment
อย่างที่ผมบอกไปแล้ว คุณต้องใช้การแจ้งเตือน คุณสามารถอ่านเพิ่มเติมเกี่ยวกับเรื่องนี้ได้จากไซต์ Oracle - docs.oracle.com/ javase/tutorial/jmx/notifs/index.html - person R Kaja Mohideen; 12.02.2013

อย่าใช้ colSums หรือนำไปใช้กับ data.frame เช่นกัน
person julien.giband    schedule 10.04.2014
comment
ไม่จำเป็นต้องเป็นคลาสย่อยของ UnicastRemoteObject. โดยสามารถส่งออกได้ด้วยตนเอง - person user207421; 12.09.2014
comment
ฉันไม่ได้รับการลงคะแนนเสียงจริง ๆ : มันเป็นวิธีแก้ปัญหาที่ใช้งานได้จริง อธิบายอย่างละเอียด และไม่มีคำอธิบายว่าทำไมมันถึงแย่! - person julien.giband; 15.03.2016

ฉันอาจเข้าใจผิดคำถาม

แต่เท่าที่ฉันรู้ว่า RMI ไม่ได้เกี่ยวข้องกับเหตุการณ์แบบที่คุณถาม

โดยพื้นฐานแล้วไคลเอนต์จะค้นหาอ็อบเจ็กต์ที่ลงทะเบียนใน RMI Registry และเรียกใช้เมธอดในนั้น

คุณจะต้องใช้โค้ดการจัดการเหตุการณ์ด้วยตัวเอง

หากคุณกำลังถามวิธีเรียกใช้เมธอดของวัตถุที่ถูกผูกไว้ RMI คุณสามารถค้นหาได้ใน

http://en.wikipedia.org/wiki/Java_remote_method_invocation

person Thihara    schedule 12.02.2013
comment
หากค่าคุณสมบัติมีการเปลี่ยนแปลงบนฝั่งเซิร์ฟเวอร์ ไคลเอนต์จะได้รับแจ้งการเปลี่ยนแปลงได้อย่างไร? - person user2049371; 12.02.2013
comment
ตัวเลือกเดียวหากคุณใช้ RMI เท่านั้นคือการสำรวจความคิดเห็นอย่างต่อเนื่อง หรือมี RMI Registry อื่นในไคลเอนต์... แต่นั่นยุ่งมาก... - person Thihara; 12.02.2013
comment
เขาไม่ต้องการ Registry ในไคลเอนต์ ลูกค้าสามารถลงทะเบียนการติดต่อกลับกับเซิร์ฟเวอร์ได้ - person user207421; 13.02.2013
comment
ด้วย RMI เพียงอย่างเดียว? สามารถชี้ให้ฉันดูแหล่งข้อมูลเกี่ยวกับเรื่องนั้นได้หรือไม่? ฉันไม่รู้ว่ามันเป็นไปได้.... - person Thihara; 13.02.2013
comment
ไม่เป็นไร googled แล้วพบว่ามัน.. docs.oracle.com/cd /E13211_01/wle/rmi/callbak.htm - person Thihara; 13.02.2013