Implement a distributed banking application

Assignment Help JAVA Programming
Reference no: EM13864265

Taking Global Snapshots of a Distributed Banking Application

"Java code"

In this project, you will capture global snapshots for a distributed banking application. You will implement this service using the Apache Thrift framework. I have provided a file, bank.thrift, that defines several basic operations that can be conducted on branches of a distributed bank.

The project consists of two parts, which are described below.

1: A Distributed Banking Application

In the first part, you will implement a distributed banking application. The distributed bank has multiple branches. Every branch knows about all other branches. Each branch starts with some initial balance. It then randomly selects a branch and send a random amount of money to this branch at unpredictable times.

You must implement the following functions for a branch in a distributed bank:

initBranch this method has two input parameters: the initial balance of a branch and a list of all branches in the distributed bank. Upon receving this method, a branch will set its initial balance and record the list of all branches.

transferMoney given a TransferMessage structure that contains the sending branch's BranchID as well as the amount of money, the receiving branch updates its balance accordingly.

A branch can be both a sender and a receiver. Therefore, you need to implement a method that will be called from a separate thead in your branch to perform the sending operation. Intervals between consecutive sending operations should be drawn uniformly at random between 0 and 5 seconds. A sender can only send positive amount of money.

It needs to first decrease its balance, then call the transferMoney method on a remote branch. A branch's balance should not become negative. For simplicity, the amount of money should be drawn randomly between 1% and 5% of the branch's initial balance and can only be an integer.

The branch's main program should spawn both a multi-threaded Thrift server and also the thread that sends money from your branch to other branches. Because the balance of your branch will be read and written by multiple threads, this variable need to be protected by a mutex or another synchronization method. In addition, you can assume that neither the branches nor the communication channels will fail. So you don't need to implement anything to guarantee fault tolerant transactions.

Your branch executable should take two command line inputs. The first one is a human-readable name of the branch, e.g., "branch1". (You can be very creative about this.) The second one specifies the port number the branch runs on.

$./branch branch1 9090

1.1 Controller In this project, we rely on a controller to set a branch's initial balance and notify every branch of all other branches in the distributed bank. This controller takes two command line inputs: the total amount of money in the distributed bank and a local file that stores the names, IP addresses, and port numbers of all branches. An example of how the controller program should operate is provided below:

$./controller 4000 branches.txt

The file (branches.txt) should contain a list of names, IP addresses, and ports, in the format " ", of all of the running branches. For example, if four branches with names: "branch1", "branch2", "branch3", and "branch4" are running on remote01.cs.eastern.edu port 9090, 9091, 9092, and 9093, then branches.txt should contain:

branch1 128.226.180.163 9090
branch2 128.226.180.163 9091
branch3 128.226.180.163 9092
branch4 128.226.180.163 9093

The controller will distribute the total amount of money evenly among all branches, e.g., in the example above, every branch will receive $1,000 initial balance. The controller initiates all branches by individually calling the initBranch method described above. Note that the initial balance must be integer.

2: Taking Global Snapshots of the Bank

In the second part, you will use the Chandy-Lamport global snapshot algorithm take global snapshots of your bank. In case of the distributed bank, a global snapshot will consist of the local state of each branch (i.e., its balance) and the amount of money in transit on all communication channels. Each branch will be responsible for recording and reporting its own local state (balance) as well as the total money in transit on each of its incoming channels.

For simplicity, in this project, the controller will contact one of the branches to initiate the global snapshot. It does so by making ainitSnapshot call to the selected branch. The selected branch will then initiate the snapshot by first recording its own local state and send out marker messages to all other branches. After some time (long enough for the snapshot algorithm to finish), the controller makes retrieveSnapshot calls to all branches to retrieve their recorded local and channel states. Note that if the snapshot is correct, the total amount of money in all branches and in transit should equal to the command line argument given to the controller.

You need to implement the following three functions to add snapshot capability to your distributed bank.

initSnapshot upon receiving this call, a branch records its own local state (balance) and sends out "Marker" messages to all other branches by calling the Marker method on them. To identify multiple snapshots, the controller passes in a snapshot_num to this call, and all the marker messages should include this snapshot_num.

Marker given the sending branch's BranchID and snapshot_num, the receiving branch does the following:

1. if this is the first Marker message with the snapshot_num, the receving branch records its own local state (balance), records the state of the incoming channel from the sender to itself as empty, starts recording on other incoming channels, and sends out Marker messages to all of its outgoing channels (i.e., all branches except itself).

2. otherwise, the receving branch records the state of the incoming channel as the sequence of money transfers that arrived between when it recorded its local state and when it received the Marker.

retrieveSnapshot given the snapshot_num that uniquely identifies a snapshot, a branch retrieves its recorded local and channel states and return them to the caller (i.e., the controller).

The controller should be fully automated. It periodically calls the initSnapshot method with monotonically increasing snapshot_num on a randomly selected branch and outputs to the screen the aggregrated global snapshot retrieved from all branches in a human-readable manner. In addition, the snapshot taken by branches needs to be identified by their names: e.g., "branch1".

What you should include with your project, You should put the following files into this directory:

1. Your source code.

2. A Makefile to compile your source code into two executables, which should be named branch and controller. (It is okay if these executables are bash scripts that call the Java interpreter, as long as the command line arguments follow the format described in Part 1.)

3. A Readme file describing the programming language you are using, your implementation details, and sample input/output.

If you use external libraries in your code, you should also include them in your directory and correctly set the environment variables using absolute path in the Makefile. If your code does not compile on or cannot correctly run on the CS computers, you will receive no points.

Reference no: EM13864265

Questions Cloud

Calculate the manufacturing overhead rate : Continental Company manufactures high quality custom -made furniture. The company has a perpetual inventory system, and uses normal costing in conjunction with job-order costing. Manufacturing overhead is being applied during calendar year 2015 on a ..
The fractional selectivity of ethane to acetaldehyde : In a process to produce 1000 kgmol/h acetaldehyde, ethane is fed to the reactor at 1500 kgmol/h and the fractional conversion is 0.8. The product stream contains 2 mol% CO2. Calculate the molar composition of the product stream and the fractional sel..
Identify type of the circuit : 1. Identify type of the circuit; Mealy or Moore 2. Derive the state table
The regular method and the simplified method : Cindy maintains an office in her home that comprises 8% (200 square feet) of total floor space. Gross income for her business is $42,00, and her residence expenses are as follows: What is Cindy office in the home deduction base on The regular method?..
Implement a distributed banking application : In the first part, you will implement a distributed banking application. The distributed bank has multiple branches. Every branch knows about all other branches.
Cash basis of accounting and accrual basis of acconting : During the year ended December 31, 2016, Jones Inc. received $110,000 cash from customers. The company began the year with a balance in Accounts Receivable of $15,000, all of which was received in 2016. At the end of the year, customers owed Jones In..
The left side of of the mechanical energy equation : The left side of of the mechanical energy equation has three terms: P/p, (1/2)av^2 and gz. show that each of these terms has the dimension of energy per mass of fluid by....a) converting each term to units of Btu/lbm beginning with pressure in psi, d..
Four key clients and their spouses at nightclub : Roberts entertains four key clients and their spouses at a nightclub. Expenses were $200 (limo charge), $120 (cover charge). $700 (drinks and dinner), and $140 (tips to servers). If Roberts is self-employed, how much can he deduct for his event?
An electron falls from the conduction band of silicon : An electron falls from the conduction band of silicon (Si) to the valence band. The band gap of Si is 1.1 eV. What is the wavelength of the photon emitted by this process? Give your answer in nm

Reviews

Write a Review

JAVA Programming Questions & Answers

  Write a java program using array to auto-grade exams

Write a JAVA program using 2D Array to auto-grade exams. For a class of N students, your program should read letter answers (A, B, C, D) for each student.

  Review of classes-objects-arrays and enhance for looping

Write Java code for class Produce that meets the listed requirements

  Write a program with an exception handler

Write a program with an exception handler that deals with nonnumeric operands; then write another program without using an exception handler to achieve the same objective.

  Calculate the percentage wins of a team

Write a program that will calculate the percentage wins of a team. The program will input the number of wins and losses that a team acquired during a season. The wins should be input in a parameter-less value returning function that returns the wi..

  Program implements the functionality of a deck of cards

Write a complete program using "ECLIPS" that implements the functionality of a deck of cards. In writing your program, use the provided DeckDriver and Card classes shown below. Write your own Deck class so that it works in conjunction with the two..

  Create a servlet that displays a form when the doget method

Create a Servlet that displays a form when the doGet method is invoked. The form will contain a post action that directs the form post back to the same servlet, which in the doPost method will append the form data to a random access file. After th..

  1 write an application class that contains several

1 write an application class that contains several methods.nbspthe first method should be named greeting and should

  Create the look for two gui applications

Create the look for two GUI applications. You WILL NOT be getting the applications to do anything. We are only interested in seeing how well you can arrange the GUI components onto the window

  Rewrite the following method using a while loop

Rewrite the following method using a while loop using an Iterator instead of the For each loop, files is an ArrayList storing String objects, also include ANY addition that you would need to have anywhere in the class.

  Prepare a thread function to initialize int array

Prepare a thread function to initialize int array x so that each element receives its index in the array: x[i]=i, and each thread initializes its portion of the array.

  Java write a program that creates a 4 x 6 two-dimensional

Using Java write a program that creates a 4 x 6 two-dimensional array. The program should use loops to populate the array with random numbers between 1 and 100. After the values have populated the array, output the values of the array to the screen i..

  Write java program to enter number of marks

Write a java program called AverageMark.java. This program should allow the user to enter any number of marks and then display the minimum, maximum & average mark.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd