Browse Source

new rmi mandelbrot features

master
Sebastian Rieger 6 years ago
parent
commit
0041d3739a
  1. 66
      VerteilteSysteme-Examples/src/verteiltesysteme/mandelbrot/rmi/MGuiRMI.java
  2. 4
      VerteilteSysteme-Examples/src/verteiltesysteme/mandelbrot/rmi/RMIMandelbrotCalculationsInterface.java
  3. 14
      VerteilteSysteme-Examples/src/verteiltesysteme/mandelbrot/rmi/RMIMandelbrotCalculationsServer.java
  4. 16
      VerteilteSysteme-Examples/src/verteiltesysteme/mandelbrot/rmi/RMIMandelbrotCalculationsServer2.java

66
VerteilteSysteme-Examples/src/verteiltesysteme/mandelbrot/rmi/MGuiRMI.java

@ -26,6 +26,7 @@ import javax.swing.JPanel;
import javax.swing.JSlider; import javax.swing.JSlider;
import javax.swing.JTextField; import javax.swing.JTextField;
import javax.swing.border.BevelBorder; import javax.swing.border.BevelBorder;
import javax.swing.border.EmptyBorder;
import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener; import javax.swing.event.ChangeListener;
@ -92,12 +93,20 @@ class RMIMandelbrotCalculationThread extends Thread {
public void run() { public void run() {
try { try {
long timestampStart = System.currentTimeMillis();
this.view.setIcon(new ImageIcon());
long timestampStart = System.currentTimeMillis();
double ULx = this.remoteCalcObj.getULx();
double ULy = this.remoteCalcObj.getULy();
double LRx = this.remoteCalcObj.getLRx();
double LRy = this.remoteCalcObj.getLRy();
//double ULx = -0.16099999999999995, ULy = -0.9365333333333333, LRx = -0.03533333333333327, LRy = -0.8108666666666666;
double ULx = -2;
double ULy = 2;
double LRx = 2;
double LRy = -2;
//double ULx = this.remoteCalcObj.getULx();
//double ULy = this.remoteCalcObj.getULy();
//double LRx = this.remoteCalcObj.getLRx();
//double LRy = this.remoteCalcObj.getLRy();
System.out.println("actual="+ULx + "/" + ULy + "/" + LRx + "/" + LRy); System.out.println("actual="+ULx + "/" + ULy + "/" + LRx + "/" + LRy);
double w = LRx - ULx; double w = LRx - ULx;
double h = LRy - ULy; double h = LRy - ULy;
@ -124,12 +133,12 @@ class RMIMandelbrotCalculationThread extends Thread {
this.boxULy = 0; this.boxULy = 0;
this.boxW = MGuiRMI.RESX; this.boxW = MGuiRMI.RESX;
this.boxH = MGuiRMI.RESY; this.boxH = MGuiRMI.RESY;
this.remoteCalcObj.setView(ULx, ULy, LRx, LRy);
//this.remoteCalcObj.setView(ULx, ULy, LRx, LRy);
// end alex // end alex
int[] colors = null; int[] colors = null;
this.remoteCalcObj.iterateAllPoints(this.maxIterations * 1000, MGuiRMI.RESX, MGuiRMI.RESY/2);
this.remoteCalcObj.iterateAllPoints(this.maxIterations * 1000, MGuiRMI.RESX, MGuiRMI.RESY/2, ULx, ULy, LRx, LRy);
/* /*
int[] lookupTable = generateLookupTable(this.maxIterations.getValue() * 1000); int[] lookupTable = generateLookupTable(this.maxIterations.getValue() * 1000);
@ -179,7 +188,8 @@ public class MGuiRMI implements ActionListener, ChangeListener, MouseListener, M
JButton endButton; JButton endButton;
JButton backButton; JButton backButton;
JButton calcButton; JButton calcButton;
JTextField hostTextField;
JTextField host1TextField;
JTextField host2TextField;
JSlider maxIterations; JSlider maxIterations;
MyJLabel viewUpper; MyJLabel viewUpper;
MyJLabel viewLower; MyJLabel viewLower;
@ -203,21 +213,25 @@ public class MGuiRMI implements ActionListener, ChangeListener, MouseListener, M
// set up GUI // set up GUI
this.frame = new JFrame("Mandelbrotmenge"); this.frame = new JFrame("Mandelbrotmenge");
this.panel = new JPanel(); this.panel = new JPanel();
this.panel.setBorder(new EmptyBorder(0,0,0,0));
this.endButton = new JButton("Ende"); this.endButton = new JButton("Ende");
this.panel.add(this.endButton); this.panel.add(this.endButton);
this.backButton = new JButton("Zurück"); this.backButton = new JButton("Zurück");
this.panel.add(this.backButton); this.panel.add(this.backButton);
this.calcButton = new JButton("Rechnen"); this.calcButton = new JButton("Rechnen");
this.hostTextField = new JTextField(20);
this.hostTextField.setText("localhost");
this.host1TextField = new JTextField(10);
this.host1TextField.setText("localhost");
this.host2TextField = new JTextField(10);
this.host2TextField.setText("localhost");
this.panel.add(this.calcButton); this.panel.add(this.calcButton);
this.panel.add(this.hostTextField);
this.panel.add(this.host1TextField);
this.panel.add(this.host2TextField);
this.frame.add(this.panel); this.frame.add(this.panel);
this.frame.setSize(700, 720); this.frame.setSize(700, 720);
this.frame.setVisible(true); this.frame.setVisible(true);
this.viewUpper = new MyJLabel(); this.viewUpper = new MyJLabel();
this.viewLower = new MyJLabel(); this.viewLower = new MyJLabel();
this.maxIterations = new JSlider(0, 50, 30);
this.maxIterations = new JSlider(0, 100, 30);
this.panel.add(this.maxIterations); this.panel.add(this.maxIterations);
this.panel.add(this.viewUpper); this.panel.add(this.viewUpper);
this.panel.add(this.viewLower); this.panel.add(this.viewLower);
@ -267,11 +281,6 @@ public class MGuiRMI implements ActionListener, ChangeListener, MouseListener, M
if (ae.getSource() == this.backButton) { if (ae.getSource() == this.backButton) {
System.out.println("Zurueck"); System.out.println("Zurueck");
// Zoom und Ausschnitt zurücksetzen // Zoom und Ausschnitt zurücksetzen
double ULx = -2;
double ULy = 2;
double LRx = 2;
double LRy = -2;
this.boxULx = 0; this.boxULx = 0;
this.boxULy = 0; this.boxULy = 0;
this.boxW = MGuiRMI.RESX; this.boxW = MGuiRMI.RESX;
@ -288,12 +297,14 @@ public class MGuiRMI implements ActionListener, ChangeListener, MouseListener, M
} }
else else
{ {
/*
try { try {
this.remoteCalcObj.setView(ULx, ULy, LRx, LRy); this.remoteCalcObj.setView(ULx, ULy, LRx, LRy);
} catch (RemoteException e) { } catch (RemoteException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
} }
*/
this.message.setText("Ausschnitt zurückgesetzt"); this.message.setText("Ausschnitt zurückgesetzt");
} }
if (this.remoteCalcObj2 == null) if (this.remoteCalcObj2 == null)
@ -304,23 +315,31 @@ public class MGuiRMI implements ActionListener, ChangeListener, MouseListener, M
} }
else else
{ {
try {
/*
try {
this.remoteCalcObj2.setView(ULx, ULy, LRx, LRy); this.remoteCalcObj2.setView(ULx, ULy, LRx, LRy);
} catch (RemoteException e) { } catch (RemoteException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
} }
*/
this.message.setText("Ausschnitt zurückgesetzt"); this.message.setText("Ausschnitt zurückgesetzt");
} }
} else } else
if (ae.getSource() == this.calcButton) { if (ae.getSource() == this.calcButton) {
String hostname = this.hostTextField.getText();
System.out.println("Verbinde mit RMI Registry auf Host: " + hostname);
String hostname1 = this.host1TextField.getText();
String hostname2 = this.host2TextField.getText();
System.out.println("Verbinde mit RMI Registry auf Host: " + hostname1);
try { try {
Registry registry = LocateRegistry.getRegistry(hostname);
//double ULx = -0.16099999999999995, ULy = -0.9365333333333333, LRx = -0.03533333333333327, LRy = -0.8108666666666666;
//double ULx = -2, ULy = 2, LRx = 2, LRy = -2;
Registry registry = LocateRegistry.getRegistry(hostname1);
this.remoteCalcObj = (RMIMandelbrotCalculationsInterface) registry.lookup("RMIMandelbrotCalculationsInterface"); this.remoteCalcObj = (RMIMandelbrotCalculationsInterface) registry.lookup("RMIMandelbrotCalculationsInterface");
this.remoteCalcObj2 = (RMIMandelbrotCalculationsInterface) registry.lookup("RMIMandelbrotCalculationsInterface2");
//this.remoteCalcObj.setView(ULx, ULy, LRx, LRy);
Registry registry2 = LocateRegistry.getRegistry(hostname2);
this.remoteCalcObj2 = (RMIMandelbrotCalculationsInterface) registry2.lookup("RMIMandelbrotCalculationsInterface");
//this.remoteCalcObj2.setView(ULx, ULy, LRx, LRy);
/** CODE SEBASTIAN /** CODE SEBASTIAN
System.out.println("Rechnen"); System.out.println("Rechnen");
@ -360,6 +379,7 @@ public class MGuiRMI implements ActionListener, ChangeListener, MouseListener, M
end */ end */
/* Code Alex */ /* Code Alex */
System.out.println("Rechnen"); System.out.println("Rechnen");
this.message.setText("Rechnen");
RMIMandelbrotCalculationThread rmimct = new RMIMandelbrotCalculationThread(true, this.viewUpper, this.remoteCalcObj, maxIterations.getValue()); RMIMandelbrotCalculationThread rmimct = new RMIMandelbrotCalculationThread(true, this.viewUpper, this.remoteCalcObj, maxIterations.getValue());
new Thread(rmimct).start(); new Thread(rmimct).start();
@ -374,7 +394,7 @@ public class MGuiRMI implements ActionListener, ChangeListener, MouseListener, M
} }
} }
// Zoom not wirking for lower...
// Zoom not working for lower...
public void mousePressed(MouseEvent e) { public void mousePressed(MouseEvent e) {
this.boxULx = e.getX(); this.boxULx = e.getX();

4
VerteilteSysteme-Examples/src/verteiltesysteme/mandelbrot/rmi/RMIMandelbrotCalculationsInterface.java

@ -4,11 +4,13 @@ import java.rmi.Remote;
import java.rmi.RemoteException; import java.rmi.RemoteException;
public interface RMIMandelbrotCalculationsInterface extends Remote { public interface RMIMandelbrotCalculationsInterface extends Remote {
void iterateAllPoints(int maxIterations, double nrPointsX, double nrPointsY) throws RemoteException;
void iterateAllPoints(int maxIterations, double nrPointsX, double nrPointsY, double ULx, double ULy, double LRx, double LRy) throws RemoteException;
public int[] getResult() throws RemoteException; public int[] getResult() throws RemoteException;
/*
public double getULx() throws RemoteException; public double getULx() throws RemoteException;
public double getLRx() throws RemoteException; public double getLRx() throws RemoteException;
public double getULy() throws RemoteException; public double getULy() throws RemoteException;
public double getLRy() throws RemoteException; public double getLRy() throws RemoteException;
public void setView(double ULx, double ULy, double LRx, double LRy) throws RemoteException; public void setView(double ULx, double ULy, double LRx, double LRy) throws RemoteException;
*/
} }

14
VerteilteSysteme-Examples/src/verteiltesysteme/mandelbrot/rmi/RMIMandelbrotCalculationsServer.java

@ -84,7 +84,7 @@ public class RMIMandelbrotCalculationsServer implements RMIMandelbrotCalculation
protected int[] result = null; protected int[] result = null;
// der augenblicklich gewaehlte Ausschnitt // der augenblicklich gewaehlte Ausschnitt
double ULx = -2, ULy = 2, LRx = 2, LRy = -2;
//double ULx = -2, ULy = 2, LRx = 2, LRy = -2;
int iterateOnePoint(Complex c, int maxIterations, double maxModulus) { int iterateOnePoint(Complex c, int maxIterations, double maxModulus) {
Complex z = new Complex(0., 0.); Complex z = new Complex(0., 0.);
@ -100,16 +100,16 @@ public class RMIMandelbrotCalculationsServer implements RMIMandelbrotCalculation
return maxIterations; return maxIterations;
} }
public void iterateAllPoints(int maxIterations, double nrPointsX, double nrPointsY) {
public void iterateAllPoints(int maxIterations, double nrPointsX, double nrPointsY, double ULx, double ULy, double LRx, double LRy) {
this.result = new int[(int) (nrPointsX * nrPointsY)]; this.result = new int[(int) (nrPointsX * nrPointsY)];
int counter = 0; int counter = 0;
double stepX = (this.LRx - this.ULx) / nrPointsX;
double stepY = (this.LRy - this.ULy) / nrPointsY;
double i = this.ULy;
double stepX = (LRx - ULx) / nrPointsX;
double stepY = (LRy - ULy) / nrPointsY;
double i = ULy;
for (int cy = 0; cy < nrPointsY; cy++) { for (int cy = 0; cy < nrPointsY; cy++) {
double r = this.ULx;
double r = ULx;
for (int cx = 0; cx < nrPointsX; cx++) { for (int cx = 0; cx < nrPointsX; cx++) {
Complex c = new Complex(r, i); Complex c = new Complex(r, i);
this.result[counter] = maxIterations - this.iterateOnePoint(c, maxIterations, 2.0); this.result[counter] = maxIterations - this.iterateOnePoint(c, maxIterations, 2.0);
@ -124,6 +124,7 @@ public class RMIMandelbrotCalculationsServer implements RMIMandelbrotCalculation
return this.result; return this.result;
} }
/*
public double getULx() { public double getULx() {
return this.ULx; return this.ULx;
} }
@ -146,5 +147,6 @@ public class RMIMandelbrotCalculationsServer implements RMIMandelbrotCalculation
this.LRx = LRx; this.LRx = LRx;
this.LRy = LRy; this.LRy = LRy;
} }
*/
} }

16
VerteilteSysteme-Examples/src/verteiltesysteme/mandelbrot/rmi/RMIMandelbrotCalculationsServer2.java

@ -49,7 +49,7 @@ public class RMIMandelbrotCalculationsServer2 implements RMIMandelbrotCalculatio
protected int[] result = null; protected int[] result = null;
// der augenblicklich gewaehlte Ausschnitt // der augenblicklich gewaehlte Ausschnitt
double ULx = -2, ULy = 2, LRx = 2, LRy = -2;
//double ULx = -2, ULy = 2, LRx = 2, LRy = -2;
int iterateOnePoint(Complex c, int maxIterations, double maxModulus) { int iterateOnePoint(Complex c, int maxIterations, double maxModulus) {
Complex z = new Complex(0., 0.); Complex z = new Complex(0., 0.);
@ -65,16 +65,16 @@ public class RMIMandelbrotCalculationsServer2 implements RMIMandelbrotCalculatio
return maxIterations; return maxIterations;
} }
public void iterateAllPoints(int maxIterations, double nrPointsX, double nrPointsY) {
public void iterateAllPoints(int maxIterations, double nrPointsX, double nrPointsY, double ULx, double ULy, double LRx, double LRy) {
this.result = new int[(int) (nrPointsX * nrPointsY)]; this.result = new int[(int) (nrPointsX * nrPointsY)];
int counter = 0; int counter = 0;
double stepX = (this.LRx - this.ULx) / nrPointsX;
double stepY = (this.LRy - this.ULy) / nrPointsY;
double i = this.ULy;
double stepX = (LRx - ULx) / nrPointsX;
double stepY = (LRy - ULy) / nrPointsY;
double i = ULy;
for (int cy = 0; cy < nrPointsY; cy++) { for (int cy = 0; cy < nrPointsY; cy++) {
double r = this.ULx;
double r = ULx;
for (int cx = 0; cx < nrPointsX; cx++) { for (int cx = 0; cx < nrPointsX; cx++) {
Complex c = new Complex(r, i); Complex c = new Complex(r, i);
this.result[counter] = maxIterations - this.iterateOnePoint(c, maxIterations, 2.0); this.result[counter] = maxIterations - this.iterateOnePoint(c, maxIterations, 2.0);
@ -89,6 +89,7 @@ public class RMIMandelbrotCalculationsServer2 implements RMIMandelbrotCalculatio
return this.result; return this.result;
} }
/*
public double getULx() { public double getULx() {
return this.ULx; return this.ULx;
} }
@ -104,12 +105,15 @@ public class RMIMandelbrotCalculationsServer2 implements RMIMandelbrotCalculatio
public double getLRy() { public double getLRy() {
return this.LRy; return this.LRy;
} }
*/
/*
public void setView(double ULx, double ULy, double LRx, double LRy) { public void setView(double ULx, double ULy, double LRx, double LRy) {
this.ULx = ULx; this.ULx = ULx;
this.ULy = ULy; this.ULy = ULy;
this.LRx = LRx; this.LRx = LRx;
this.LRy = LRy; this.LRy = LRy;
} }
*/
} }
Loading…
Cancel
Save