Skip to content
Snippets Groups Projects
Select Git revision
  • 0781e1fa9204335503a6a7046a0e1dd45274795a
  • master default protected
  • pipeline
  • dev
  • quality
  • docs
  • issue-65
  • issue-30
  • issue-19
  • issue-28
  • 0.1.1
  • 0.1.0
12 results

guide_developer.rst

Blame
  • Controller.java 3.78 KiB
    package ftp;
    
    import java.io.IOException;
    import java.net.Socket;
    import java.util.*;
    import java.util.stream.Collectors;
    import java.util.stream.Stream;
    
    public class Controller extends Server {
    
        private int r;
        private int rbPeriod;
        private int nextID = 0;
    
        private DStoreIndex dStoreIndex;
        private FileIndex fileIndex;
    
    
        /**
         * @desc constructs a controller
         * @param cport to listen on
         * @param r replication factor
         * @param timeout timeout (ms)
         * @param rbPeriod rebalance period (ms)
         */
        public Controller(int cport, int r, int timeout, int rbPeriod) throws IOException {
            this.port = cport;
            this.r = r;
            this.timeout = timeout;
            this.rbPeriod = rbPeriod;
    
            dStoreIndex = new DStoreIndex();
            fileIndex = new FileIndex();
    
            start();
        }
    
    
    
        public static void main(String args[]) {
            Stream<String> str = Arrays.stream(args);
    
            List<Integer> intArgs = str.map(x -> {return Integer.parseInt(x);})
                    .collect(Collectors.toList());
    
            try {
                Controller ctrl = new Controller(intArgs.get(0), intArgs.get(1), intArgs.get(2), intArgs.get(3));
            } catch (IOException e) {
                System.out.println("IOException " + e.getMessage());
            }
        }
    
    
    
        @Override
        protected void handleRequest(String request, Socket client) {
            String args[] = request.split(" ");
    
    
            String command = args[0];
    
            if (command.equals("JOIN")) {
                Integer port = Integer.parseInt(args[1]);
    
                send("LIST", client);
    
                String files = readSocket(client);
    
                DStoreConnection dStore;