You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

129 lines
3.0 KiB

  1. package verteiltesysteme.mandelbrot.rmi;
  2. import java.rmi.registry.LocateRegistry;
  3. import java.rmi.registry.Registry;
  4. import java.rmi.server.UnicastRemoteObject;
  5. class Complex {
  6. double r;
  7. double i;
  8. Complex() {
  9. r = 0.0;
  10. i = 0.0;
  11. }
  12. Complex(double r, double i) {
  13. this.r = r;
  14. this.i = i;
  15. }
  16. void mulBy(Complex other) {
  17. double rTmp = this.r * other.r - this.i * other.i;
  18. this.i = this.r * other.i + this.i * other.r;
  19. this.r = rTmp;
  20. }
  21. void add(Complex other) {
  22. this.r += other.r;
  23. this.i += other.i;
  24. }
  25. void sub(Complex other) {
  26. this.r -= other.r;
  27. this.i -= other.i;
  28. }
  29. double absValue() {
  30. return Math.sqrt(this.r * this.r + this.i * this.i);
  31. }
  32. }
  33. public class RMIMandelbrotCalculationsServer implements RMIMandelbrotCalculationsInterface {
  34. public RMIMandelbrotCalculationsServer() {}
  35. public static void main(String args[]) {
  36. try {
  37. RMIMandelbrotCalculationsServer obj = new RMIMandelbrotCalculationsServer();
  38. RMIMandelbrotCalculationsInterface stub = (RMIMandelbrotCalculationsInterface) UnicastRemoteObject.exportObject(obj, 0);
  39. // Bind the remote object's stub in the registry
  40. Registry registry = LocateRegistry.getRegistry();
  41. registry.bind("RMIMandelbrotCalculationsInterface", stub);
  42. System.err.println("Server ready");
  43. } catch (Exception e) {
  44. System.err.println("Server exception: " + e.toString());
  45. e.printStackTrace();
  46. }
  47. }
  48. // hier wird das Ergebnis von iterateAll() gespeichert
  49. protected int[] result = null;
  50. // der augenblicklich gewaehlte Ausschnitt
  51. //double ULx = -2, ULy = -2, LRx = 2, LRy = 2;
  52. double ULx = -0.16099999999999995, ULy = -0.9365333333333333, LRx = -0.03533333333333327, LRy = -0.8108666666666666;
  53. int iterateOnePoint(Complex c, int maxIterations, double maxModulus) {
  54. Complex z = new Complex(0., 0.);
  55. for (int i = 0; i < maxIterations; i++) {
  56. z.mulBy(z);
  57. z.add(c);
  58. double m = z.absValue();
  59. if (m > maxModulus) {
  60. return i;
  61. }
  62. }
  63. return maxIterations;
  64. }
  65. public void iterateAllPoints(int maxIterations, double nrPointsX, double nrPointsY) {
  66. this.result = new int[(int) (nrPointsX * nrPointsY)];
  67. int counter = 0;
  68. double stepX = (this.LRx - this.ULx) / nrPointsX;
  69. double stepY = (this.LRy - this.ULy) / nrPointsY;
  70. double i = this.ULy;
  71. for (int cy = 0; cy < nrPointsY; cy++) {
  72. double r = this.ULx;
  73. for (int cx = 0; cx < nrPointsX; cx++) {
  74. Complex c = new Complex(r, i);
  75. this.result[counter] = maxIterations - this.iterateOnePoint(c, maxIterations, 2.0);
  76. counter += 1;
  77. r += stepX;
  78. }
  79. i += stepY;
  80. }
  81. }
  82. public int[] getResult() {
  83. return this.result;
  84. }
  85. public double getULx() {
  86. return this.ULx;
  87. }
  88. public double getLRx() {
  89. return this.LRx;
  90. }
  91. public double getULy() {
  92. return this.ULy;
  93. }
  94. public double getLRy() {
  95. return this.LRy;
  96. }
  97. public void setView(double ULx, double ULy, double LRx, double LRy) {
  98. this.ULx = ULx;
  99. this.ULy = ULy;
  100. this.LRx = LRx;
  101. this.LRy = LRy;
  102. }
  103. }