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.

115 lines
3.2 KiB

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