Search in sources :

Example 1 with Server

use of ru.compscicenter.hpc2016.ha1.server.Server in project hpcourse by cscenter.

the class Main method main.

public static void main(String[] args) {
    new Server().start();
    try {
        TrainClient client = new TrainClient();
        client.start();
        client.sendTask(new Parameter(42), new Parameter(43), new Parameter(44), new Parameter(55), 66);
        client.sendTask(new Parameter(8), new Parameter(15), new Parameter(16), new Parameter(23), 42);
        client.sendTask(new Parameter(18), new Parameter(11), new Parameter(19), new Parameter(93), 666);
        client.sendTask(new Parameter(8), new Parameter(15), new Parameter(16), new Parameter(23), 42);
        client.sendTask(new Parameter(18), new Parameter(11), new Parameter(19), new Parameter(93), 666);
        client.listAllTasks();
        client.subscribeToTask(1);
        client.listAllTasks();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : Server(server.Server) Parameter(communication.Parameter) IOException(java.io.IOException)

Example 2 with Server

use of ru.compscicenter.hpc2016.ha1.server.Server in project hpcourse by cscenter.

the class Main method main.

public static void main(String[] args) {
    int serverPort = 4242;
    try {
        new Server(serverPort);
    } catch (IOException e) {
        e.printStackTrace();
        System.exit(1);
    }
    try {
        Client client1 = new Client("localhost", serverPort, "#1");
        client1.sendSubmitTaskRequest(42, 20, 30, 0, 0);
        client1.sendSubscribeRequest(1);
        client1.sendSubscribeRequest(2);
        client1.sendSubscribeRequest(1);
        Client client2 = new Client("localhost", serverPort, "#2");
        client2.sendSubmitTaskRequest(10, 20, 40, 1, 1000000000);
        client2.sendSubscribeRequest(2);
        client2.sendSubscribeRequest(1);
        client2.sendSubscribeRequest(2);
    } catch (IOException e) {
        e.printStackTrace();
        System.exit(2);
    }
}
Also used : Server(ru.compscicenter.hpc2016.ha1.server.Server) IOException(java.io.IOException) Client(ru.compscicenter.hpc2016.ha1.client.Client)

Example 3 with Server

use of ru.compscicenter.hpc2016.ha1.server.Server in project DistributedFractalNetwork by Budder21.

the class NetworkCreationTool method createNetwork.

/**
 * This method, when called, will bring the user through a series of menus helping them
 * configure the Network they wish to set up.
 * @return whether or not the network was successfully created.
 */
public boolean createNetwork() {
    File[] fractals = new File(Constants.FRACTAL_FILEPATH).listFiles();
    List<String> choices = new ArrayList<>();
    for (File f : fractals) {
        if (!f.getName().equals("palettes"))
            choices.add(f.getName());
    }
    ChoiceDialog<String> dialog1 = null;
    try {
        dialog1 = new ChoiceDialog<>(choices.get(0), choices);
    } catch (IndexOutOfBoundsException e) {
        AlertMenu alarm = new AlertMenu("Cannot create network: no fractal found on this computer.", "Fractals are searched for in the fractals folder. Please save a fractal to that folder and try again.");
    }
    dialog1.setTitle("Create Network");
    dialog1.setHeaderText("Step 1");
    dialog1.setContentText("Choose a fractal:");
    System.out.println("here...");
    RenderManager fractal = null;
    try {
        fractal = new RenderManager(dialog1.showAndWait().get());
    } catch (Exception e) {
        return false;
    }
    Pair<Integer, Integer> dimension = displayDialog2();
    if (dimension == null)
        return false;
    fractal.setScreenResolution(new Dimension(dimension.getKey(), dimension.getValue()));
    Pair<Double, Double> params = getParams();
    if (params == null)
        return false;
    if (params.getKey() == null)
        return false;
    if (params.getValue() == null)
        return false;
    fractal.setZoom(params.getKey());
    Alert alert = new Alert(AlertType.CONFIRMATION);
    alert.setTitle("Create Network");
    alert.setHeaderText("Step 4");
    alert.setContentText("Choose a directory:");
    ButtonType buttonTypeOne = new ButtonType("Choose");
    ButtonType buttonTypeCancel = new ButtonType("Cancel", ButtonData.CANCEL_CLOSE);
    alert.getButtonTypes().setAll(buttonTypeOne, buttonTypeCancel);
    Optional<ButtonType> result = alert.showAndWait();
    String directory = "";
    if (result.get() == buttonTypeOne) {
        DirectoryChooser directoryChooser = new DirectoryChooser();
        File selectedDirectory = directoryChooser.showDialog(null);
        if (selectedDirectory == null) {
            return false;
        } else {
            directory = selectedDirectory.getPath();
        }
    } else {
        return false;
    }
    this.server = new Server(fractal, params.getValue(), directory);
    return true;
}
Also used : Server(server.Server) ArrayList(java.util.ArrayList) Dimension(java.awt.Dimension) Alert(javafx.scene.control.Alert) File(java.io.File) RenderManager(fractal.RenderManager) ButtonType(javafx.scene.control.ButtonType) DirectoryChooser(javafx.stage.DirectoryChooser)

Example 4 with Server

use of ru.compscicenter.hpc2016.ha1.server.Server in project hpcourse by cscenter.

the class SimpleTests method SimpleTest.

@Test
public void SimpleTest() throws InterruptedException {
    Thread serverThread = new Thread(new Server("localhost", 1500));
    serverThread.start();
    Thread.sleep(1000);
    Client client = new Client("localhost", 1500);
    for (int i = 0; i < 4; i++) submitHardTask();
    Thread.sleep(100);
    client.getList();
    new Thread(new Runnable() {

        @Override
        public void run() {
            Client client = new Client("localhost", 1500);
            client.submitTask(getDependTask(1, 2, 3, 4));
        }
    }).start();
    Thread.sleep(100);
    client.getList();
    new Thread(new Runnable() {

        @Override
        public void run() {
            Client client = new Client("localhost", 1500);
            client.submitTask(getDependTask(1, 2, 3, 5));
        }
    }).start();
    for (int i = 0; i < 4; i++) subscribeTask();
    long actual = client.subscribe(6);
    client.getList();
    assertEquals(0, actual);
}
Also used : Server(server.Server) Client(client.Client) Test(org.junit.Test)

Aggregations

Server (server.Server)3 IOException (java.io.IOException)2 Client (client.Client)1 Parameter (communication.Parameter)1 RenderManager (fractal.RenderManager)1 Dimension (java.awt.Dimension)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 Alert (javafx.scene.control.Alert)1 ButtonType (javafx.scene.control.ButtonType)1 DirectoryChooser (javafx.stage.DirectoryChooser)1 Test (org.junit.Test)1 Client (ru.compscicenter.hpc2016.ha1.client.Client)1 Server (ru.compscicenter.hpc2016.ha1.server.Server)1