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

  Create a 2-dimensional array for the volume of concrete

Your Company constructs concrete hemispherical domes that range in diameter from 40 to 90 feet and increments of 5 feet.

  The williamsburg women''s club

The Williamsburg Women's Club offers scholarships to local high school students who meet any of several criteria. Write an application that prompts the user for a student's numeric high school grade point average (for example, 3.2), the student's num..

  Write a java application that allows the user to read

Write a java application that allows the user to read, validate, store, display, sort and search the account number and balance for N bank customers.

  Template files contain the message text

Template files contain the message text, together with variable fields(such as Dear [Title] [Last Name ] ...). A database (stored as a text file) contains the field values for each recipient. Use HTML as the output file format. Then design and implem..

  Write a program in java that reads contents of two vectors

Write a program in Java that reads contents of two vectors, and then displays the sum of these two vectors. The program should prompt the user to enter the size of the vectors first.

  Write a menu-driven java program

Write a menu-driven JAVA program that performs the following array/vector operations:

  Die class that can hold an integer

Design a die class that can hold an integer from 1 to 6. use the dice class to create a dice game. in this game, the user chooses a number between 2 and 12 inclusive

  Assessment taskyour task is to develop a java application

assessment taskyour task is to develop a java application that allows the user to read travel booking data from a text

  Executing stringed musical instrument class

Create and execute a stringed musical instrument class.

  What are differences between instance and class variables

What are the differences between instance and class variables? What is an overloaded method?

  Explain java-oriented microprocessors presented by sun

Research the latest Java-oriented microprocessors presented by Sun. In what ways are they optimized to implement Java programs?

  Create a java class named headphone

Create a Java class named HeadPhone to represent a headphone set. The class contains: ? Three constants named LOW, MEDIUM and HIGH with values of 1, 2 and 3 to denote the headphone volume.

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