18 package network.httppush.twinprimes;
20 import java.math.BigInteger;
25 import static ca.uqac.lif.cep.Connector.INPUT;
26 import static ca.uqac.lif.cep.Connector.LEFT;
27 import static ca.uqac.lif.cep.Connector.RIGHT;
28 import static ca.uqac.lif.cep.Connector.OUTPUT;
29 import ca.uqac.lif.cep.Connector;
30 import ca.uqac.lif.cep.ProcessorException;
31 import ca.uqac.lif.cep.UtilityMethods;
32 import ca.uqac.lif.cep.functions.ApplyFunction;
33 import ca.uqac.lif.cep.functions.FunctionTree;
34 import ca.uqac.lif.cep.functions.StreamVariable;
35 import ca.uqac.lif.cep.http.HttpDownstreamGateway;
36 import ca.uqac.lif.cep.io.Print;
37 import ca.uqac.lif.cep.tmf.Filter;
38 import ca.uqac.lif.cep.tmf.Fork;
39 import ca.uqac.lif.jerrydog.RequestCallback.Method;
47 public static void main(String[] args)
throws ProcessorException
52 HttpDownstreamGateway dn_gateway =
new HttpDownstreamGateway(12312,
"/bigprime", Method.POST);
57 ApplyFunction big_int_plus_2 =
new ApplyFunction(
new FunctionTree(
59 new FunctionTree(StringToBigInteger.instance, StreamVariable.X)));
60 Connector.connect(dn_gateway, big_int_plus_2);
63 Fork fork =
new Fork(2);
64 Connector.connect(big_int_plus_2, fork);
67 ApplyFunction is_prime =
new ApplyFunction(IsPrime.instance);
68 Connector.connect(fork, LEFT, is_prime, INPUT);
72 Filter filter =
new Filter();
73 Connector.connect(fork, RIGHT, filter, LEFT);
74 Connector.connect(is_prime, OUTPUT, filter, RIGHT);
77 Print print =
new Print();
78 Connector.connect(filter, print);
86 System.out.println(
"Machine B listening for requests. Every number displayed below");
87 System.out.println(
"is the second of a twin prime pair. Press Ctrl+C to end.");
90 UtilityMethods.pause(10000);
Send events from one processor to another over a network.
The code for Machine B in the twin prime example.
Contains a few utility functions for manipulating Java's BigInteger objects.
Use HTTP gateways in push mode.
Checks if a BigInteger is prime.
Increments a BigInteger by a specific value.
Converts a string into a BigInteger.
Compute twin primes by distributing the computation across two machines over a network.