Skip to content
Snippets Groups Projects
Select Git revision
  • a27ab784026afba0386f17956443c9ef53f7b0a4
  • master default protected
2 results

RMIMandelbrotCalculationsServer2.java

Blame
  • RMIMandelbrotCalculationsServer2.java 3.18 KiB
    package verteiltesysteme.mandelbrot.rmi;
    
    //import java.io.IOException;
    //import java.net.InetAddress;
    //import java.net.ServerSocket;
    //import java.net.Socket;
    import java.rmi.registry.LocateRegistry;
    import java.rmi.registry.Registry;
    //import java.rmi.server.RMISocketFactory;
    import java.rmi.server.UnicastRemoteObject;
    
    /*
    class LoopbackSocketFactory extends RMISocketFactory {
        public ServerSocket createServerSocket(int port) throws IOException {
            return new ServerSocket(port, 5, InetAddress.getByName("127.0.0.1"));
        }
    
        public Socket createSocket(String host, int port) throws IOException {
            // just call the default client socket factory
            return RMISocketFactory.getDefaultSocketFactory()
                                   .createSocket(host, port);
        }
    }
    */
    
    public class RMIMandelbrotCalculationsServer2 implements RMIMandelbrotCalculationsInterface {
        public RMIMandelbrotCalculationsServer2() {}
    
        public static void main(String args[]) {
    
            try {
              //RMISocketFactory.setSocketFactory(new LoopbackSocketFactory());
    
              RMIMandelbrotCalculationsServer2 obj = new RMIMandelbrotCalculationsServer2();
              RMIMandelbrotCalculationsInterface stub = (RMIMandelbrotCalculationsInterface) UnicastRemoteObject.exportObject(obj, 0);
    
                // Bind the remote object's stub in the registry
                Registry registry = LocateRegistry.getRegistry();
                registry.bind("RMIMandelbrotCalculationsInterface2", stub);
    
                System.err.println("Server ready");
            } catch (Exception e) {
                System.err.println("Server exception: " + e.toString());
                e.printStackTrace();
            }
        }
    
      // hier wird das Ergebnis von iterateAll() gespeichert
      protected int[] result = null;
    
      // der augenblicklich gewaehlte Ausschnitt
      double ULx = -2, ULy = 2, LRx = 2, LRy = -2;
    
      int iterateOnePoint(Complex c, int maxIterations, double maxModulus) {
        Complex z = new Complex(0., 0.);
    
        for (int i = 0; i < maxIterations; i++) {
          z.mulBy(z);
          z.add(c);
          double m = z.absValue();
          if (m > maxModulus) {
            return i;
          }
        }
        return maxIterations;
      }
    
      public void iterateAllPoints(int maxIterations, double nrPointsX, double nrPointsY) {
    
        this.result = new int[(int) (nrPointsX * nrPointsY)];