Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import org.apache.xmlrpc.WebServer;
- import java.util.Calendar;
- import java.util.Locale;
- import java.util.TimeZone;
- public class RPCserver {
- /***
- * Method that give inforamtion about available methods
- * @return String with methods(parameters) - short description
- */
- public String show(){
- return "Available methods: \n" +
- "1. asy(int) - with given time parameter, returns value of time delayed by this value \n" +
- "2. echo(int, int) - returns sum of parameters \n" +
- "3. multiply(int, int) - returns multiplication of parameters \n" +
- "4. parseIntAndDoubleToString(int, double) - return concatenated parameters as string \n" +
- "5. upperAndConcatenate(string, string) - returns uppercase of concatenated strings \n";
- }
- /***
- * Method calculates sum of given two parameters
- * @param x int, is the first parameter to sum
- * @param y int, is the second parameter to sum
- * @return int sum of given parameters
- */
- public Integer echo(int x, int y){
- return x + y;
- }
- /***
- * Method calculates multiplication of two given parameters
- * @param x double first parameter to multiply
- * @param y double second parameter to multiply
- * @return double multiplication of givent Parameters
- */
- public Double multiply(double x, double y) {
- return x * y;
- }
- /***
- * Method create new string with capital letters from given two strings
- * @param s1 String first parameter to concatenate
- * @param s2 String second parameter to concatenate
- * @return concatenated two strings in uppercase
- */
- public String upperAndConcatenate(String s1, String s2) {
- return (s1 + s2).toUpperCase();
- }
- /***
- * Method parses int and double parameters to string as one string with space between then
- * @param i int parameter to parse
- * @param d double parameter to parse
- * @return concatenated with space two given parameters
- */
- public String parseIntAndDoubleToString(int i, double d) {
- return String.valueOf(i) + " " + String.valueOf(d);
- }
- /***
- * Return formatted place and time with the given place and language
- * @param place String named place that is returned with
- * @param language String two letters from the month display language is depend
- * @return concatenated place and data with format 'place, year month_in_language day hour-minute-second'
- */
- public static String getTime(String place, String language) {
- Locale lo = new Locale(language);
- Calendar calendar = Calendar.getInstance();
- return place + ", " + calendar.get(Calendar.YEAR) + " " + calendar.getDisplayName(Calendar.MONTH, Calendar.LONG, lo) + " " + calendar.get(Calendar.DAY_OF_MONTH) + " " + calendar.get(calendar.HOUR_OF_DAY) + "-" + calendar.get(calendar.MINUTE) + (String.format("-%02d",calendar.get(calendar.SECOND)));
- }
- public Integer asy(int x, int y, int z) {
- System.out.println("Generowanie liczb pierwszych");
- try {
- Thread.sleep(z);
- } catch (InterruptedException e) {
- e.printStackTrace();
- Thread.currentThread().interrupt();
- }
- System.out.println("Wygenerowano!");
- List <Integer> list = primeNumbersTill(x, y);
- for(Integer asd : list){
- System.out.print(asd +" ");
- }
- }
- public static List<Integer> primeNumbersTill(int z, int n) {
- return IntStream.rangeClosed(z, n)
- .filter(x -> isPrime(x)).boxed()
- .collect(Collectors.toList());
- }
- private static boolean isPrime(int number) {
- return IntStream.rangeClosed(2, (int) (Math.sqrt(number)))
- .filter(n -> (n & 0X1) != 0)
- .allMatch(n -> x % n != 0);
- }
- public static void main(String[] args) {
- try {
- System.out.println("Starting server XML-RPC");
- int port = 10008;
- WebServer server = new WebServer(port);
- server.addHandler("myServer", new RPCserver());
- server.start();
- System.out.println("Server succesfully started");
- System.out.println("Listening to the port " + port);
- System.out.println("To stop server, press ctrl+c");
- } catch (Exception e) {
- System.err.println("Server XML-RPC: " + e);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement