[CT414]: Assignment 1 working
This commit is contained in:
@ -21,10 +21,10 @@ public class ApplicationClient {
|
|||||||
System.out.println("ApplicationHandler found in registry");
|
System.out.println("ApplicationHandler found in registry");
|
||||||
|
|
||||||
// login
|
// login
|
||||||
System.out.println("Enter your username\n> ");
|
System.out.printf("Enter your username\n> ");
|
||||||
String username = scanner.nextLine();
|
String username = scanner.nextLine();
|
||||||
|
|
||||||
System.out.println("Enter your password\n> ");
|
System.out.printf("Enter your password\n> ");
|
||||||
String password = scanner.nextLine();
|
String password = scanner.nextLine();
|
||||||
|
|
||||||
long sessionID = handler.login(username, password);
|
long sessionID = handler.login(username, password);
|
||||||
@ -43,7 +43,7 @@ public class ApplicationClient {
|
|||||||
// answer questiosn
|
// answer questiosn
|
||||||
for (int i = 0; i < form.getTotalQuestions(); i++) {
|
for (int i = 0; i < form.getTotalQuestions(); i++) {
|
||||||
System.out.println("Q" + i + ": " + form.getQuestion(i));
|
System.out.println("Q" + i + ": " + form.getQuestion(i));
|
||||||
System.out.println("A> ");
|
System.out.printf("A> ");
|
||||||
form.answerQuestion(i, scanner.nextLine());
|
form.answerQuestion(i, scanner.nextLine());
|
||||||
}
|
}
|
||||||
System.out.println("Form filled successfully.");
|
System.out.println("Form filled successfully.");
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
package implementations;
|
package implementations;
|
||||||
|
|
||||||
import interfaces.*;
|
import interfaces.*;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.rmi.*;
|
import java.rmi.*;
|
||||||
|
|
||||||
public class ApplicationFormV1 implements ApplicationForm {
|
public class ApplicationFormV1 implements ApplicationForm, Serializable {
|
||||||
private String formInfo = "University of Galway Application Form - Version 1";
|
private String formInfo = "University of Galway Application Form - Version 1";
|
||||||
private String[] questions = new String[5];
|
private String[] questions = new String[5];
|
||||||
private String[] answers = new String[5];
|
private String[] answers = new String[5];
|
||||||
|
@ -38,7 +38,7 @@ public class ApplicationHandlerImpl implements ApplicationHandler {
|
|||||||
@Override
|
@Override
|
||||||
public void submitApplicationForm(long sessionID, ApplicationForm applicationForm) throws RemoteException, InvalidSessionIDException {
|
public void submitApplicationForm(long sessionID, ApplicationForm applicationForm) throws RemoteException, InvalidSessionIDException {
|
||||||
if (sessions.contains(sessionID)) {
|
if (sessions.contains(sessionID)) {
|
||||||
String filename = applicationForm.getName().replace("\\s", "_") + ".txt";
|
String filename = applicationForm.getName().replaceAll("\\s", "_") + ".txt";
|
||||||
|
|
||||||
try (BufferedWriter writer = new BufferedWriter(new FileWriter(filename))) {
|
try (BufferedWriter writer = new BufferedWriter(new FileWriter(filename))) {
|
||||||
System.out.println("Saving application form to file: " + filename);
|
System.out.println("Saving application form to file: " + filename);
|
||||||
|
@ -1,14 +1,17 @@
|
|||||||
#!/bin/sh
|
#!/bin/bash
|
||||||
|
|
||||||
src_path="/home/andrew/edu/year4/semester2/CT414/assignments/assignment1/code/src"
|
src_path="/home/andrew/edu/year4/semester2/CT414/assignments/assignment1/code/src"
|
||||||
|
|
||||||
# compile code
|
# compile code
|
||||||
javac -d . server/*.java client/*.java interfaces/*.java implementations/*.java
|
javac -d . server/*.java client/*.java interfaces/*.java implementations/*.java
|
||||||
|
|
||||||
# start rmi registry
|
# start rmi registry (in a new terminal)
|
||||||
rmiregistry -J-Djava.rmi.server.codebase=file:$src_path &
|
$TERM -e rmiregistry -J-Djava.rmi.server.codebase=file:$src_path &
|
||||||
trap "kill $! 2>/dev/null" EXIT
|
sleep 1
|
||||||
|
|
||||||
# start server
|
# start server (in a new terminal)
|
||||||
java -cp $src_path -Djava.rmi.server.codebase=file:$src_path/ server.ApplicationServer &
|
$TERM -e java -cp $src_path -Djava.rmi.server.codebase=file:$src_path/ server.ApplicationServer &
|
||||||
trap "kill $! 2>/dev/null" EXIT
|
sleep 1
|
||||||
|
|
||||||
|
# start client (in a new terminal)
|
||||||
|
$TERM -e java -cp $src_path -Djava.rmi.server.codebase=file:$src_path/ client.ApplicationClient
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package server;
|
package server;
|
||||||
|
|
||||||
import implementations.ApplicationHandlerImpl;
|
import implementations.ApplicationHandlerImpl;
|
||||||
|
import interfaces.ApplicationHandler;
|
||||||
|
|
||||||
import java.rmi.Naming;
|
import java.rmi.Naming;
|
||||||
import java.rmi.registry.LocateRegistry;
|
import java.rmi.registry.LocateRegistry;
|
||||||
@ -14,10 +15,10 @@ public class ApplicationServer {
|
|||||||
Registry registry = LocateRegistry.getRegistry();
|
Registry registry = LocateRegistry.getRegistry();
|
||||||
|
|
||||||
// create applicationhandlerstub and bind it
|
// create applicationhandlerstub and bind it
|
||||||
ApplicationHandlerImpl applicationHandler = new ApplicationHandlerImpl();
|
ApplicationHandler applicationHandler = new ApplicationHandlerImpl();
|
||||||
System.out.println("Instance of ApplicationHandlerImpl created");
|
System.out.println("Instance of ApplicationHandlerImpl created");
|
||||||
|
|
||||||
ApplicationHandlerImpl stub = (ApplicationHandlerImpl) UnicastRemoteObject.exportObject(applicationHandler, 0);
|
ApplicationHandler stub = (ApplicationHandler) UnicastRemoteObject.exportObject(applicationHandler, 0);
|
||||||
Naming.rebind("ApplicationHandler", stub);
|
Naming.rebind("ApplicationHandler", stub);
|
||||||
System.out.println("Name rebind completed");
|
System.out.println("Name rebind completed");
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user