Assignment 1 - Introduction to Java RMI

Download Solution Order New Solution

Marks

The marks awarded for this assignment are worth 10% of the total mark for DS.

Please Note: If your code does not compile or run as described in your README file, or if the teaching team is unable to execute your submission, your mark will be automatically zero. Our expectation is that you submit a tested, working copy of your code, accompanied by a clear and complete README file. A well-written README is a standard part of any code submission.

Assignment Description

Objective

To gain an understanding of how remote method invocation in Java works, synchronisation, and to develop a working example of a Java RMI system. This will be essential in developing future applications as you will quickly learn all of the pitfalls inherent in developing standards-based clients and multi-threaded servers.

To gain an understanding of how a distributed system works, this first assignment phase involves developing a simple Java RMI application. This will involve developing both the client and server side of a distributed application: a simple calculator server.

Calculator Server

The calculator server operates a stack and clients push values and operations on to the stack. While, usually, each client should have its own stack, you may use a single stack on the server.

Assumptions:

  • You may assume that operations are always sensible:
    • We will only push an operator after pushing at least one value.
    • We will only pop when there is a value on the stack.
  • You may also assume that the operator provided will only be one of the four displayed types.
  • The values are always integers.

Java RMI Server Remote Methods

Following the directions discussed in lectures, you should create a Java RMI Server that supports the following remote methods:

1. pushValue(int val)

 
  void pushValue(int val);
 

This method will take val and push it on to the top of the stack.

2. pushOperation(String operator)

 
  void pushOperation(String operator);
 

This method will push a String containing an operator ("min", "max", "lcm", "gcd") to the stack, which will cause the server to pop all the values on the stack and:

  • for min - push the min value of all the popped values;
  • for max - push the max value of all the popped values;
  • for lcm - push the least common multiple of all the popped values;
  • for gcd - push the greatest common divisor of all the popped values.

3. pop()

 
  int pop();
 

This method will pop the top of the stack and return it to the client.

4. isEmpty()

 
  boolean isEmpty();
 

This method will return true if the stack is empty, false otherwise.

5. delayPop(int millis)

 
  int delayPop(int millis);
 

This method will wait millis milliseconds before carrying out the pop operation as above.

Implementation Details

Importantly: Your implementation should use the following files:

  • Calculator.java - the interface that defines the remote operations implemented by your remote service.
  • CalculatorImplementation.java - the implementation class for the remote operations.
  • CalculatorServer.java - the server class.
  • CalculatorClient.java - a test client that should connect to the server, and test its operation.

You will need to create and add these files to your repository.

Note: Don’t forget to commit your work frequently and to submit before the due date!

Assessment

Your assignment will be marked out of 10 points, as following:

1. Functionality of your code (5 points)

  • All clients access the same stack on the server
  • pushValue works – one client, many clients (more than 3)
  • pushOperation works – one client, many clients (more than 3)
  • pop works – one client, many clients (more than 3)
  • delayPop works – one client, many clients (more than 3)

2. Quality of automated testing (3.5 points)

Points awarded for the quality of your automated testing, both in testing the server with single and multiple clients.

3. Quality of your code (1.5 points)

Points awarded for the readability, structure, and clarity of your implementation.

Code Quality Checklist

Do!

  • Write comments above the header of each of your methods, describing:
    • What the method is doing
    • What are its inputs and expected outputs
  • Describe in the comments any special cases
  • Create modular code, following cohesion and coupling principles

Don’t!

  • Use magic numbers
  • Use comments as structural elements (see video)
  • Mis-spell your comments
  • Use incomprehensible variable names
  • Have long methods (not more than 80 lines)
  • Allow TODO blocks

Bonus Marks (Extra 1 Point)

  • Clients have their own stack on the server: each client accesses their own stack, rather than the common one

HandIn

Students must submit the following files to Gradescope:

1. Java Source Files:

  • Calculator.java (interface)
  • CalculatorImplementation.java (server-side implementation)
  • CalculatorServer.java (server bootstrap)
  • CalculatorClient.java (client-side code)
  • Any additional Java files you use for client-side or server-side functionality.

2. Automated Testing Files:

  • Include any files, scripts, or tools you have used to test the functionality of your system , including tests for both single-client and multi-client scenarios.
  • You may use any appropriate testing approach (e.g., additional Java clients, shell scripts, test harnesses, or other frameworks), but your tests should clearly demonstrate that all remote methods ( pushValue pushOperation pop delayPop isEmpty ) behave correctly under various conditions.

3. README.txt or README.md :

A clear and concise guide explaining how to:

  • Compile all Java files using javac
  • Start the RMI registry and launch the server
  • Run the client(s) and test all remote operations
  • Simulate multiple clients (if applicable)

Assessment Requirements Summary

The "Introduction to Java RMI" assignment is an assessment for a Distributed Systems (DS) course, worth 10% of the total course grade. It focuses on evaluating a student's understanding of Java Remote Method Invocation (RMI) synchronization , and distributed system development . The core task is to create a simple RMI-based calculator server.

The key pointers to be covered in this assessment are:

  • Server Functionality: Develop a calculator server that operates a single stack. It must implement five specific remote methods: pushValue(int val) pushOperation(String operator) pop() isEmpty() , and delayPop(int millis) .

  • Implementation Files: The solution must be structured using four specific Java files: Calculator.java (interface), CalculatorImplementation.java (server implementation), CalculatorServer.java (server bootstrap), and CalculatorClient.java (test client).

  • Code Quality & Structure: The code must be well-structured, readable, and commented correctly. It should avoid "magic numbers," incomprehensible variable names, and excessively long methods.

  • Automated Testing: Students must provide robust automated tests for both single-client and multi-client scenarios to demonstrate the correct functionality of all remote methods.

  • Documentation: A comprehensive README.txt or README.md file is required, detailing how to compile, run, and test the entire system.

  • Submission: The submission must be a working, compilable, and executable solution submitted to Gradescope, including all source files, testing files, and the README file. Bonus points are available for implementing a separate stack for each client instead of a single shared one.

Academic Mentor's Approach

The academic mentor approached this assessment by guiding the student through a step-by-step process , breaking down the complex task of creating a distributed application into manageable phases. This method ensured a logical progression from foundational concepts to the final, complete solution. The learning objectives were achieved by focusing on one key component at a time, reinforcing both theoretical knowledge and practical application.

The process followed these steps:

  1. Understanding the RMI Basics : The mentor first ensured the student understood the fundamental concepts of Java RMI. This involved explaining what a remote interface is ( Calculator.java ), what a remote object is ( CalculatorImplementation.java ), and the roles of the client and server ( CalculatorClient.java and CalculatorServer.java ). This step laid the theoretical groundwork before any coding began.

  2. Developing the Interface ( Calculator.java : The mentor guided the student to first define the Calculator interface. This was a critical first step as it clearly outlines the "contract" for the remote service. The mentor explained why each method must throw RemoteException and why the interface must extend java.rmi.Remote . This step solidified the student's understanding of the RMI's foundational structure.

  3. Implementing the Server-Side Logic ( CalculatorImplementation.java : Once the interface was defined, the mentor focused on implementing the core business logic. This included:

    • Data Structure: Advising the use of a Stack data structure to store integers and operators.

    • Method Implementation: Guiding the implementation of each remote method ( pushValue pushOperation pop isEmpty delayPop ). For pushOperation , the mentor walked through the logic for min max lcm , and gcd operations, emphasizing the need to pop all values, calculate the result, and push it back.

    • Synchronization: A key learning objective was synchronization. The mentor explained the pitfalls of multiple clients accessing a shared resource and guided the student to use synchronized methods or blocks to prevent race conditions on the single stack, ensuring thread safety.

  4. Creating the Server Bootstrap ( CalculatorServer.java : With the implementation complete, the next step was to make it a functional RMI service. The mentor explained how to:

    • Start the RMI Registry: Explain the purpose of LocateRegistry.createRegistry() .

    • Instantiate the Remote Object: Create an instance of CalculatorImplementation .

    • Export the Remote Object: Explain the UnicastRemoteObject.exportObject() method and its role in making the object available for remote calls.

    • Bind to the Registry: Use Naming.rebind() to register the remote object with a unique name in the RMI registry.

  5. Building the Test Client ( CalculatorClient.java : The mentor then helped the student develop the client-side code. This involved:

    • Looking up the Remote Object: Using Naming.lookup() to retrieve the remote object from the registry.

    • Method Invocation: Calling the remote methods on the returned stub object and handling RemoteException . The mentor emphasized how the RMI framework seamlessly handles the communication between the client and the remote server.

  6. Developing Automated Tests : This step addressed the requirement for testing. The mentor guided the student to create test cases that covered both:

    • Single-client scenarios: Testing each method's functionality in isolation.

    • Multi-client scenarios: Writing a test harness or shell script to launch multiple clients concurrently to test the server's thread safety and synchronization. This specifically demonstrated the correct working of the synchronized methods.

  7. Documentation ( README.md ) and Code Refinement : Finally, the mentor emphasized the importance of good documentation and code quality. The student was instructed to write a detailed README file covering the compilation and execution steps. The mentor also reviewed the code to ensure it was clean, well-commented, and followed the specified standards, addressing the readability and clarity requirements.

Outcome & Learning Objectives

The systematic approach resulted in a fully functional and well-documented solution that met all the assessment requirements. The student successfully created a distributed calculator system using Java RMI, demonstrating a solid grasp of the core concepts.

The key learning objectives achieved were:

  • Understanding Distributed Systems: The student gained practical experience in building a simple distributed application, understanding the client-server architecture and the communication between them.

  • Java RMI Proficiency: The student mastered the RMI framework, including defining remote interfaces, implementing remote objects, and using the RMI registry for binding and lookup.

  • Concurrency and Synchronization: By addressing the multi-client requirement, the student learned about thread safety and the critical role of synchronization in a shared-state distributed system.

  • Software Engineering Principles: The assignment reinforced principles of good code quality, modularity, and the importance of thorough automated testing and clear documentation.

Ready to Ace Your Assignment?

You've just seen a top-tier solution that shows you exactly what a perfect assignment looks like. Now you can get your hands on this and other high-quality examples.

Before You Go... A Quick Word on Plagiarism

We get it—it's tempting to use this sample as your own. But submitting someone else's work is a serious academic offense. This sample is a learning tool, not a shortcut. It's meant to guide your understanding, help you with formatting, and show you how to structure a great answer. Use it for reference only to ensure your own work meets the highest standards.

Want a Unique Solution That's 100% Yours?

Why risk it? Our team of professional academic writers can craft a brand-new, plagiarism-free solution tailored specifically to your assignment brief. Get a custom paper that's guaranteed to be original, perfectly formatted, and ready for you to submit with confidence.

Download Sample Solution

Order Fresh Assignment

Get It Done! Today

Country
Applicable Time Zone is AEST [Sydney, NSW] (GMT+11)
+

Every Assignment. Every Solution. Instantly. Deadline Ahead? Grab Your Sample Now.