Browse Source
Merge branch 'master' of ssh://git@gogs.informatik.hs-fulda.de/srieger/verteilte-systeme-bsc-ai-examples.git
master
Merge branch 'master' of ssh://git@gogs.informatik.hs-fulda.de/srieger/verteilte-systeme-bsc-ai-examples.git
master
Sebastian Rieger
6 years ago
19 changed files with 666 additions and 400 deletions
-
BINVerteilteSysteme-Examples/build/RMIEchoServer.jar
-
BINVerteilteSysteme-Examples/build/RMIMandelbrotCalculationsServer.jar
-
BINVerteilteSysteme-Examples/build/TCPPerfServer.jar
-
BINVerteilteSysteme-Examples/build/TCPServer.jar
-
BINVerteilteSysteme-Examples/build/TCPServerMulti.jar
-
BINVerteilteSysteme-Examples/build/TCPTimeCounterRESTServer.jar
-
BINVerteilteSysteme-Examples/build/TCPTimeCounterServer.jar
-
BINVerteilteSysteme-Examples/build/UDPServer.jar
-
BINVerteilteSysteme-Examples/build/UDPServerMulti.jar
-
BINVerteilteSysteme-Examples/build/UDPTimeCounterServer.jar
-
64VerteilteSysteme-Examples/src/verteiltesysteme/aws/TCPTimeCounterRESTServer.java
-
27VerteilteSysteme-Examples/src/verteiltesysteme/aws/TCPTimeCounterRESTService.java
-
636VerteilteSysteme-Examples/src/verteiltesysteme/mandelbrot/rmi/MGuiRMI.java
-
203VerteilteSysteme-Examples/src/verteiltesysteme/mandelbrot/rmi/RMIMandelbrotCalculationsServer.java
-
115VerteilteSysteme-Examples/src/verteiltesysteme/mandelbrot/rmi/RMIMandelbrotCalculationsServer2.java
-
2VerteilteSysteme-Examples/src/verteiltesysteme/socket/simple/TCPClient.java
-
4VerteilteSysteme-Examples/src/verteiltesysteme/socket/simple/TCPServer.java
-
2VerteilteSysteme-Examples/src/verteiltesysteme/socket/simple/UDPClient.java
-
3VerteilteSysteme-Examples/src/verteiltesysteme/socket/simple/UDPServer.java
@ -1,32 +1,52 @@ |
|||||
/* Beispiel angelehnt an http://www.torsten-horn.de/techdocs/jee-rest.htm */ |
/* Beispiel angelehnt an http://www.torsten-horn.de/techdocs/jee-rest.htm */ |
||||
package verteiltesysteme.aws; |
package verteiltesysteme.aws; |
||||
|
|
||||
|
import java.io.ByteArrayOutputStream; |
||||
import java.io.IOException; |
import java.io.IOException; |
||||
|
import java.io.PrintStream; |
||||
import java.net.URI; |
import java.net.URI; |
||||
|
|
||||
|
import org.glassfish.grizzly.http.server.ErrorPageGenerator; |
||||
import org.glassfish.grizzly.http.server.HttpServer; |
import org.glassfish.grizzly.http.server.HttpServer; |
||||
|
import org.glassfish.grizzly.http.server.Request; |
||||
import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory; |
import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory; |
||||
import org.glassfish.jersey.server.ResourceConfig; |
import org.glassfish.jersey.server.ResourceConfig; |
||||
|
|
||||
public class TCPTimeCounterRESTServer |
|
||||
{ |
|
||||
public static void main( String[] args ) throws IOException, InterruptedException |
|
||||
{ |
|
||||
String baseUrl = ( args.length > 0 ) ? args[0] : "http://0.0.0.0:36042"; |
|
||||
|
|
||||
final HttpServer server = GrizzlyHttpServerFactory.createHttpServer( |
|
||||
URI.create( baseUrl ), new ResourceConfig( TCPTimeCounterRESTService.class ), false ); |
|
||||
Runtime.getRuntime().addShutdownHook( new Thread( new Runnable() { |
|
||||
@Override |
|
||||
public void run() { |
|
||||
server.shutdownNow(); |
|
||||
} |
|
||||
} ) ); |
|
||||
server.start(); |
|
||||
|
|
||||
System.out.println("Grizzly-HTTP-Server gestartet"); |
|
||||
System.out.println("Stoppen des Grizzly-HTTP-Servers mit: Strg+C\n"); |
|
||||
System.out.println("RESTful Web Service URL: " + baseUrl + TCPTimeCounterRESTService.webContextPath); |
|
||||
|
|
||||
Thread.currentThread().join(); |
|
||||
} |
|
||||
|
public class TCPTimeCounterRESTServer { |
||||
|
public static void main(String[] args) throws IOException, InterruptedException { |
||||
|
String baseUrl = (args.length > 0) ? args[0] : "http://0.0.0.0:36042"; |
||||
|
|
||||
|
final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(URI.create(baseUrl), |
||||
|
new ResourceConfig(TCPTimeCounterRESTService.class), false); |
||||
|
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { |
||||
|
@Override |
||||
|
public void run() { |
||||
|
server.shutdownNow(); |
||||
|
} |
||||
|
})); |
||||
|
|
||||
|
ErrorPageGenerator epg = new ErrorPageGenerator() { |
||||
|
@Override |
||||
|
public String generate(Request request, int status, String reasonPhrase, String description, |
||||
|
Throwable exception) { |
||||
|
StringBuilder sb = new StringBuilder(); |
||||
|
ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
||||
|
PrintStream ps = new PrintStream(baos); |
||||
|
exception.printStackTrace(ps); |
||||
|
ps.close(); |
||||
|
sb.append(new String(baos.toByteArray())); |
||||
|
System.out.println(sb.toString()); |
||||
|
return sb.toString(); |
||||
|
} |
||||
|
}; |
||||
|
server.getServerConfiguration().setDefaultErrorPageGenerator(epg); |
||||
|
|
||||
|
server.start(); |
||||
|
|
||||
|
System.out.println("Grizzly-HTTP-Server gestartet"); |
||||
|
System.out.println("Stoppen des Grizzly-HTTP-Servers mit: Strg+C\n"); |
||||
|
System.out.println("RESTful Web Service URL: " + baseUrl + TCPTimeCounterRESTService.webContextPath); |
||||
|
|
||||
|
Thread.currentThread().join(); |
||||
|
} |
||||
} |
} |
@ -0,0 +1,115 @@ |
|||||
|
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)]; |
||||
|
|
||||
|
int counter = 0; |
||||
|
double stepX = (this.LRx - this.ULx) / nrPointsX; |
||||
|
double stepY = (this.LRy - this.ULy) / nrPointsY; |
||||
|
double i = this.ULy; |
||||
|
for (int cy = 0; cy < nrPointsY; cy++) { |
||||
|
double r = this.ULx; |
||||
|
for (int cx = 0; cx < nrPointsX; cx++) { |
||||
|
Complex c = new Complex(r, i); |
||||
|
this.result[counter] = maxIterations - this.iterateOnePoint(c, maxIterations, 2.0); |
||||
|
counter += 1; |
||||
|
r += stepX; |
||||
|
} |
||||
|
i += stepY; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public int[] getResult() { |
||||
|
return this.result; |
||||
|
} |
||||
|
|
||||
|
public double getULx() { |
||||
|
return this.ULx; |
||||
|
} |
||||
|
|
||||
|
public double getLRx() { |
||||
|
return this.LRx; |
||||
|
} |
||||
|
|
||||
|
public double getULy() { |
||||
|
return this.ULy; |
||||
|
} |
||||
|
|
||||
|
public double getLRy() { |
||||
|
return this.LRy; |
||||
|
} |
||||
|
|
||||
|
public void setView(double ULx, double ULy, double LRx, double LRy) { |
||||
|
this.ULx = ULx; |
||||
|
this.ULy = ULy; |
||||
|
this.LRx = LRx; |
||||
|
this.LRy = LRy; |
||||
|
} |
||||
|
|
||||
|
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue