Browse Source

initial version of rmi scale-out

master
Sebastian Rieger 6 years ago
parent
commit
4871ede84f
  1. 202
      VerteilteSysteme-Examples/src/verteiltesysteme/mandelbrot/rmi/MGuiRMI.java
  2. 3
      VerteilteSysteme-Examples/src/verteiltesysteme/mandelbrot/rmi/RMIMandelbrotCalculationsServer.java

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

@ -62,6 +62,115 @@ class MyJLabel extends JLabel {
} }
class RMIMandelbrotCalculationThread extends Thread {
MyJLabel view;
RMIMandelbrotCalculationsInterface remoteCalcObj;
int boxULx, boxULy, boxW, boxH;
public static int RESX = 600;
public static int RESY = 600;
Boolean upperPart;
int maxIterations;
RMIMandelbrotCalculationThread(Boolean upperPart, MyJLabel view, RMIMandelbrotCalculationsInterface remoteCalcObj, int maxIterations) {
this.view = view;
this.remoteCalcObj = remoteCalcObj;
this.upperPart = upperPart;
this.maxIterations = maxIterations;
}
// visualization related stuff, do not touch!
int[] generateLookupTable(int nrHues) {
int[] tmp = new int[nrHues + 1];
int cycle = 2048;
for (int i = 0; i < nrHues; i++) {
float hue = 1 * ((float) (i % cycle)) / cycle/* ((float)nrHues) */ ;
tmp[i] = Color.HSBtoRGB(hue, 0.8f, 1.0f);
}
tmp[0] = Color.HSBtoRGB(0f, 1.0f, 0.0f);
return tmp;
}
public void run() {
try {
long timestampStart = System.currentTimeMillis();
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);
double w = LRx - ULx;
double h = LRy - ULy;
// AG change define box such that it contains only upper half of apple man :-)
if (this.upperPart == true)
{
boxULx = 0 ; boxULy = 0; boxW = MGuiRMI.RESX ; boxH = MGuiRMI.RESY/2;
}
else
{
// for lower half:
boxULx = 0 ; boxULy = RESY/2; boxW = RESX ; boxH = RESY/2;
}
ULx = ULx + w * this.boxULx / (double) MGuiRMI.RESX;
ULy = ULy + h * this.boxULy / (double) MGuiRMI.RESY;
w *= this.boxW / (double) (RESX);
h *= this.boxH / (double) (RESY);
LRx = ULx + w;
LRy = ULy + h;
System.out.println("computed="+ULx + "/" + ULy + "/" + LRx + "/" + LRy);
this.boxULx = 0;
this.boxULy = 0;
this.boxW = MGuiRMI.RESX;
this.boxH = MGuiRMI.RESY;
this.remoteCalcObj.setView(ULx, ULy, LRx, LRy);
// end alex
int[] colors = null;
this.remoteCalcObj.iterateAllPoints(this.maxIterations * 1000, MGuiRMI.RESX, MGuiRMI.RESY/2);
/*
int[] lookupTable = generateLookupTable(this.maxIterations.getValue() * 1000);
colors = new int[MGuiRMI.RESX * MGuiRMI.RESY];
MGuiRMI.applyLookupTable(remoteCalcObj.getResult(), colors, lookupTable);
BufferedImage colorImage = new BufferedImage(MGuiRMI.RESX, MGuiRMI.RESY, BufferedImage.TYPE_INT_ARGB);
colorImage.setRGB(0, 0, MGuiRMI.RESX, MGuiRMI.RESY, colors, 0, MGuiRMI.RESX);
this.view.setIcon(new ImageIcon(colorImage));
this.view.setBox(this.boxULx, this.boxULy, this.boxW, this.boxH);
this.view.repaint();
long timestampEnd = System.currentTimeMillis();
String timeElapsed = "Dauer: " + ((timestampEnd - timestampStart) / 1000.0) + " sec";
System.out.println(timeElapsed);
this.message.setText(timeElapsed);
* */
int[] lookupTable = generateLookupTable(this.maxIterations * 1000);
colors = new int[MGuiRMI.RESX * MGuiRMI.RESY/2];
MGuiRMI.applyLookupTable(remoteCalcObj.getResult(), colors, lookupTable);
BufferedImage colorImage = new BufferedImage(MGuiRMI.RESX, MGuiRMI.RESY/2, BufferedImage.TYPE_INT_ARGB);
colorImage.setRGB(0, 0, MGuiRMI.RESX, MGuiRMI.RESY/2, colors, 0, MGuiRMI.RESX);
this.view.setIcon(new ImageIcon(colorImage));
long timestampEnd = System.currentTimeMillis();
String timeElapsed = "Zeit: " + ((timestampEnd - timestampStart) / 1000.0) + " sec";
System.out.println(timeElapsed);
//this.view.setText(timeElapsed);
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public class MGuiRMI implements ActionListener, ChangeListener, MouseListener, MouseMotionListener { public class MGuiRMI implements ActionListener, ChangeListener, MouseListener, MouseMotionListener {
// GUI elements // GUI elements
@ -72,7 +181,8 @@ public class MGuiRMI implements ActionListener, ChangeListener, MouseListener, M
JButton calcButton; JButton calcButton;
JTextField hostTextField; JTextField hostTextField;
JSlider maxIterations; JSlider maxIterations;
MyJLabel view;
MyJLabel viewUpper;
MyJLabel viewLower;
JLabel message; JLabel message;
int nrIterations; int nrIterations;
@ -82,6 +192,7 @@ public class MGuiRMI implements ActionListener, ChangeListener, MouseListener, M
// this one does all the calculating work // this one does all the calculating work
RMIMandelbrotCalculationsInterface remoteCalcObj; RMIMandelbrotCalculationsInterface remoteCalcObj;
RMIMandelbrotCalculationsInterface remoteCalcObj2;
// how many points in the image? // how many points in the image?
// change if you want a higher resolution // change if you want a higher resolution
@ -104,10 +215,12 @@ public class MGuiRMI implements ActionListener, ChangeListener, MouseListener, M
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.view = new MyJLabel();
this.viewUpper = new MyJLabel();
this.viewLower = new MyJLabel();
this.maxIterations = new JSlider(0, 50, 30); this.maxIterations = new JSlider(0, 50, 30);
this.panel.add(this.maxIterations); this.panel.add(this.maxIterations);
this.panel.add(this.view);
this.panel.add(this.viewUpper);
this.panel.add(this.viewLower);
this.message = new JLabel("Status"); this.message = new JLabel("Status");
this.message.setBorder(new BevelBorder(BevelBorder.LOWERED)); this.message.setBorder(new BevelBorder(BevelBorder.LOWERED));
this.frame.add(this.message,BorderLayout.SOUTH); this.frame.add(this.message,BorderLayout.SOUTH);
@ -121,8 +234,10 @@ public class MGuiRMI implements ActionListener, ChangeListener, MouseListener, M
this.maxIterations.setPaintTicks(true); this.maxIterations.setPaintTicks(true);
this.maxIterations.setPaintLabels(true); this.maxIterations.setPaintLabels(true);
this.view.addMouseListener(this);
this.view.addMouseMotionListener(this);
this.viewUpper.addMouseListener(this);
this.viewUpper.addMouseMotionListener(this);
this.viewLower.addMouseListener(this);
this.viewLower.addMouseMotionListener(this);
this.boxULx = 0; this.boxULx = 0;
this.boxULy = 0; this.boxULy = 0;
@ -135,18 +250,6 @@ public class MGuiRMI implements ActionListener, ChangeListener, MouseListener, M
this.nrIterations = 1000; this.nrIterations = 1000;
} }
// visualization related stuff, do not touch!
int[] generateLookupTable(int nrHues) {
int[] tmp = new int[nrHues + 1];
int cycle = 2048;
for (int i = 0; i < nrHues; i++) {
float hue = 1 * ((float) (i % cycle)) / cycle/* ((float)nrHues) */ ;
tmp[i] = Color.HSBtoRGB(hue, 0.8f, 1.0f);
}
tmp[0] = Color.HSBtoRGB(0f, 1.0f, 0.0f);
return tmp;
}
// visualization // visualization
static void applyLookupTable(int[] data, int[] dest, int[] lookupTable) { static void applyLookupTable(int[] data, int[] dest, int[] lookupTable) {
for (int i = 0; i < data.length; i++) { for (int i = 0; i < data.length; i++) {
@ -164,16 +267,19 @@ 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 = -0.16099999999999995;
double ULy = -0.9365333333333333;
double LRx = -0.03533333333333327;
double LRy = -0.8108666666666666;
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;
this.boxH = MGuiRMI.RESY; this.boxH = MGuiRMI.RESY;
this.view.setBox(this.boxULx, this.boxULy, this.boxW, this.boxH);
this.view.repaint();
this.viewUpper.setBox(this.boxULx, this.boxULy, this.boxW, this.boxH);
this.viewUpper.repaint();
this.viewLower.setBox(this.boxULx, this.boxULy, this.boxW, this.boxH);
this.viewLower.repaint();
if (this.remoteCalcObj == null) if (this.remoteCalcObj == null)
{ {
String message = "Fehler: noch nicht verbunden, noch keine Berechnung durchgeführt"; String message = "Fehler: noch nicht verbunden, noch keine Berechnung durchgeführt";
@ -190,6 +296,22 @@ public class MGuiRMI implements ActionListener, ChangeListener, MouseListener, M
} }
this.message.setText("Ausschnitt zurückgesetzt"); this.message.setText("Ausschnitt zurückgesetzt");
} }
if (this.remoteCalcObj2 == null)
{
String message = "Fehler: noch nicht verbunden, noch keine Berechnung durchgeführt";
this.message.setText(message);
System.out.println(message);
}
else
{
try {
this.remoteCalcObj2.setView(ULx, ULy, LRx, LRy);
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
this.message.setText("Ausschnitt zurückgesetzt");
}
} else } else
if (ae.getSource() == this.calcButton) { if (ae.getSource() == this.calcButton) {
@ -198,6 +320,9 @@ public class MGuiRMI implements ActionListener, ChangeListener, MouseListener, M
try { try {
Registry registry = LocateRegistry.getRegistry(hostname); Registry registry = LocateRegistry.getRegistry(hostname);
this.remoteCalcObj = (RMIMandelbrotCalculationsInterface) registry.lookup("RMIMandelbrotCalculationsInterface"); this.remoteCalcObj = (RMIMandelbrotCalculationsInterface) registry.lookup("RMIMandelbrotCalculationsInterface");
this.remoteCalcObj2 = (RMIMandelbrotCalculationsInterface) registry.lookup("RMIMandelbrotCalculationsInterface2");
/** CODE SEBASTIAN
System.out.println("Rechnen"); System.out.println("Rechnen");
long timestampStart = System.currentTimeMillis(); long timestampStart = System.currentTimeMillis();
@ -231,23 +356,16 @@ public class MGuiRMI implements ActionListener, ChangeListener, MouseListener, M
//this.remoteCalcObj.setView(ULx, ULy, LRx, LRy); //this.remoteCalcObj.setView(ULx, ULy, LRx, LRy);
this.remoteCalcObj.setView(ULx, ULy, LRx, LRy); this.remoteCalcObj.setView(ULx, ULy, LRx, LRy);
this.remoteCalcObj.iterateAllPoints(this.maxIterations.getValue() * 1000, MGuiRMI.RESX, MGuiRMI.RESY);
int[] lookupTable = generateLookupTable(this.maxIterations.getValue() * 1000);
colors = new int[MGuiRMI.RESX * MGuiRMI.RESY];
MGuiRMI.applyLookupTable(remoteCalcObj.getResult(), colors, lookupTable);
BufferedImage colorImage = new BufferedImage(MGuiRMI.RESX, MGuiRMI.RESY, BufferedImage.TYPE_INT_ARGB);
colorImage.setRGB(0, 0, MGuiRMI.RESX, MGuiRMI.RESY, colors, 0, MGuiRMI.RESX);
this.view.setIcon(new ImageIcon(colorImage));
this.view.setBox(this.boxULx, this.boxULy, this.boxW, this.boxH);
this.view.repaint();
end */
/* Code Alex */
System.out.println("Rechnen");
long timestampEnd = System.currentTimeMillis();
RMIMandelbrotCalculationThread rmimct = new RMIMandelbrotCalculationThread(true, this.viewUpper, this.remoteCalcObj, maxIterations.getValue());
new Thread(rmimct).start();
RMIMandelbrotCalculationThread rmimct2 = new RMIMandelbrotCalculationThread(false, this.viewLower, this.remoteCalcObj2, maxIterations.getValue());
new Thread(rmimct2).start();
String timeElapsed = "Dauer: " + ((timestampEnd - timestampStart) / 1000.0) + " sec";
System.out.println(timeElapsed);
this.message.setText(timeElapsed);
} catch (RemoteException | NotBoundException e) { } catch (RemoteException | NotBoundException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
@ -256,12 +374,14 @@ public class MGuiRMI implements ActionListener, ChangeListener, MouseListener, M
} }
} }
// Zoom not wirking for lower...
public void mousePressed(MouseEvent e) { public void mousePressed(MouseEvent e) {
this.boxULx = e.getX(); this.boxULx = e.getX();
this.boxULy = e.getY(); this.boxULy = e.getY();
this.boxW = 1; this.boxW = 1;
this.boxH = 1; this.boxH = 1;
this.view.setBox(this.boxULx, this.boxULy, this.boxW, this.boxH);
this.viewUpper.setBox(this.boxULx, this.boxULy, this.boxW, this.boxH);
this.message.setText("boxULx: " + this.boxULx + " boxULy: " + this.boxULy + " boxW: " + this.boxW + " boxH: " + this.boxH); this.message.setText("boxULx: " + this.boxULx + " boxULy: " + this.boxULy + " boxW: " + this.boxW + " boxH: " + this.boxH);
} }
@ -271,15 +391,15 @@ public class MGuiRMI implements ActionListener, ChangeListener, MouseListener, M
int m = Math.min(boxW, boxH); int m = Math.min(boxW, boxH);
this.boxW = m; this.boxW = m;
this.boxH = m; this.boxH = m;
this.view.setBox(this.boxULx, this.boxULy, this.boxW, this.boxH);
this.viewUpper.setBox(this.boxULx, this.boxULy, this.boxW, this.boxH);
this.message.setText("boxULx: " + this.boxULx + " boxULy: " + this.boxULy + " boxW: " + this.boxW + " boxH: " + this.boxH); this.message.setText("boxULx: " + this.boxULx + " boxULy: " + this.boxULy + " boxW: " + this.boxW + " boxH: " + this.boxH);
this.view.repaint();
this.viewUpper.repaint();
} }
public void mouseReleased(MouseEvent e) { public void mouseReleased(MouseEvent e) {
if (e.getButton() == MouseEvent.BUTTON1) { if (e.getButton() == MouseEvent.BUTTON1) {
this.view.repaint();
this.viewUpper.repaint();
this.message.setText("Gesetzt: boxULx: " + this.boxULx + " boxULy: " + this.boxULy + " boxW: " + this.boxW + " boxH: " + this.boxH); this.message.setText("Gesetzt: boxULx: " + this.boxULx + " boxULy: " + this.boxULy + " boxW: " + this.boxW + " boxH: " + this.boxH);
} }
} }

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

@ -84,8 +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 = -0.16099999999999995, ULy = -0.9365333333333333, LRx = -0.03533333333333327, LRy = -0.8108666666666666;
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.);

Loading…
Cancel
Save