Run multiple clients and one server

Assignment Help Programming Languages
Reference no: EM13306267

Assignment that requires to run multiple clients and one server ( Corba)

This file might help you to create your client side and server .

import Inter.*;

import java.util.Vector;

import java.util.Iterator;

 

public class DBControlServerImpl extends DBControlServerPOA

{

    private Vector clients = new Vector(); // The clients currently connected

    private CallingThread ct = null;

 

    public DBControlServerImpl()

    {

        ct = new CallingThread(this);

    }

 

    public void requestConnect(DBClientListener dbcl)

    {

        System.out.println("A client has connected.");

        clients.add(dbcl);

    }

 

    public void startCallingThread()

    {

        ct.start();

    }

 

    public int getClientCount()

    {

        return clients.size();

    }

 

    public void sendWorkMessages()

    {

        Iterator it = clients.iterator();

        while (it.hasNext())

        {

            DBClientListener dbcl = (DBClientListener) it.next();

            dbcl.doWork();

        }

    }

}

import Inter.*;

import java.io.BufferedReader;

import java.io.File;

import java.io.FileReader;

 

public class DBClientListenerImpl extends DBClientListenerPOA

{

    public void doWork()

    {

        File rDir = new File(System.getProperty("user.dir"));

        rDir = new File(rDir.getAbsolutePath() + File.separatorChar);

        File inFile = new File(rDir.getAbsolutePath() + File.separatorChar

                + "Database.dat");

        if (inFile.exists())

        {

            try

            {

                BufferedReader in = new BufferedReader(new FileReader(inFile));

                String tmp = ""; // Temp line holder.

                long timeElapsed = 0;

                long startTime = System.currentTimeMillis();

                tmp = in.readLine();

                while (tmp != null)

                {

                    tmp = in.readLine();

                }

                long endTime = System.currentTimeMillis();

                timeElapsed = endTime - startTime;

                System.out.println("Client finished computations on file in "

                        + timeElapsed + " ms.");

            } catch (Exception e)

            {

                e.printStackTrace();

            }

        } else {

            System.out.println("Database file was not found");

        }

    }

}

import org.omg.CORBA.ORB;

import org.omg.PortableServer.POA;

import org.omg.PortableServer.POAHelper;

import Inter.*;

 

public class Client

{

    public static void main(String[] args)

    {

        try

        {

            // initialize orb

            ORB orb = ORB.init(args, null);

            System.out.println("Initialized ORB");

 

            // Instantiate Servant and create reference

            POA rootPOA = POAHelper.narrow(orb

                    .resolve_initial_references("RootPOA"));

            DBClientListenerImpl listener = new DBClientListenerImpl();

            rootPOA.activate_object(listener);

            DBClientListener ref = DBClientListenerHelper.narrow(rootPOA

                    .servant_to_reference(listener));

 

            // Resolve DBControlServer

            DBControlServer dbcServer = DBControlServerHelper

                    .narrow(orb.string_to_object(

                    "corbaname:iiop:1.2@localhost:1050#DBControlServer"));

 

            // Register listener reference (callback object) with MessageServer

            dbcServer.requestConnect(ref);

            System.out.println("Registered with DBControlServer.");

 

            // Activate rootPOA

            rootPOA.the_POAManager().activate();

 

            // Wait for work request

            System.out.println("Waiting for work request.");

            orb.run();

 

        } catch (Exception e)

        {

            e.printStackTrace();

        }

    }

}

import java.io.BufferedReader;

import java.io.InputStreamReader;

 

public class CallingThread extends Thread

{

    DBControlServerImpl dbcsiImpl = null;

 

    public CallingThread(DBControlServerImpl dbcsiImpl)

    {

        this.dbcsiImpl = dbcsiImpl;

    }

 

    public void run()

    {

        int userInput = 0;

        try

        {

            BufferedReader read = new BufferedReader(new InputStreamReader(

                    System.in));

            try

            {

                System.out.print("Please enter the number of clients you wish to connect: ");

                userInput = Integer.parseInt(read.readLine());

                System.out.println("Waiting for " + userInput + " clients to connect...");

            } catch (Exception e)

            {

                e.printStackTrace();

            }

            boolean completed = false;

            for (;;)

            {

                if (dbcsiImpl.getClientCount() >= userInput && !completed)

                {

                    System.out.println(userInput + " clients connected, starting work; check client screens...");

                    dbcsiImpl.sendWorkMessages();

                    completed = true;

                }

            }

        } catch (Exception e)

        {

            e.printStackTrace();

        }

    }

}

import java.io.BufferedReader;

import java.io.InputStreamReader;

 

public class CallingThread extends Thread

{

    DBControlServerImpl dbcsiImpl = null;

 

    public CallingThread(DBControlServerImpl dbcsiImpl)

    {

        this.dbcsiImpl = dbcsiImpl;

    }

 

    public void run()

    {

        int userInput = 0;

        try

        {

            BufferedReader read = new BufferedReader(new InputStreamReader(

                    System.in));

            try

            {

                System.out.print("Please enter the number of clients you wish to connect: ");

                userInput = Integer.parseInt(read.readLine());

                System.out.println("Waiting for " + userInput + " clients to connect...");

            } catch (Exception e)

            {

                e.printStackTrace();

            }

            boolean completed = false;

            for (;;)

            {

                if (dbcsiImpl.getClientCount() >= userInput && !completed)

                {

                    System.out.println(userInput + " clients connected, starting work; check client screens...");

                    dbcsiImpl.sendWorkMessages();

                    completed = true;

                }

            }

        } catch (Exception e)

        {

            e.printStackTrace();

        }

    }

}

Reference no: EM13306267

Questions Cloud

Determine the thermal efficiency of this heat engine : A heat engine using a diatomic ideal gas goes through the following closed cycle: Isothermal compression until the volume is halved. What is the thermal efficiency of this heat engine
What frequency is being emitted by both speakers : Two in phase speakers are set up in a field 10.0 meters apart. you stand directly in between the speakers with one on your left and the other on your right. What frequency is being emitted by both speakers
Characterize multilateral negotiations : 1. What are the three key stages and phases that characterize multilateral negotiations?
Determine the total axil deformation of the shaft : A solid composite shaft is subjected to a 2MN force. Section AB is red brass (E= 120 Gpa), and section BC is AISI 1010 steel (E=200GPa). Find the normal stress in each section and the total axil deformation of the shaft.
Run multiple clients and one server : Run multiple clients and one server - create your client side and server
Where do the pulses first meet : A 10.0-m long wire whose total mass is 39.5 grams is under a tension of 577N. Where do the pulses first meet
List the volcanic hazards associated with shield volcanoes : You have been hired to plan and build a subdivision on the volcanic island of Hawaii. As you know, this island is made of several shielf volcanoes. A) List the volcanic hazards associated with shield volcanoes.
What is probability that the wave height will exceed 6 meter : A nuclear facility in a coastal region is built to withstand ocean wave forces. Suppose the annual maximum wave height of the ocean waves (above the sea level) is a lognormal random variable with mean height of 4.0 meters and a c.o.v. of 0.8
Discuss the benefits of traditional linux file permissions : Discuss the benefits of the traditional Linux file permissions scheme. How might it be superior to permission methodologies employed in other operating systems and what are the differences in overall approach to permissions, privilege, and securit..

Reviews

Write a Review

Programming Languages Questions & Answers

  Write program for real estate agent

Write a program for a real estate agent. The program should perform the following tasks: ask users for the average house price for the each of past 5 years for a single family residence of 1500 square feet.

  Abstract syntax for interpretation in haskell or prolog

State an abstract syntax of the while language appropriate for interpretation in either Haskell or Prolog. In Haskell, the definition must be the code of a few data types.

  Write program to enter name-number of planet from sun

Write down the program which permits the user to enter name of planet, and then prints message stating that planet's number when counted outward from sun.

  Program-customer-s names phone numbers in alphabetical order

Load file into parallel arrays and display list of customers' names and phone numbers in alphabetical order.

  Write pseudocode and flowchart for program

Write pseudocode and flowchart for program that will prompt the user for a number, prompt the user for an operator (+,-,*,/).

  Write subclass for constructor accepting a double

Write a (non-abstract) subclass, ApartmentHouse, containing: a constructor accepting a double, passed to the superclass constructor, and an int used to initialize numberOfApartments

  Which functions perform assignment score to private member

Consider this class definition: class quiz { public: quiz( ); int f( ); int g( ) const; private: double score; }; Which functions can carry out an assignment score=1.0; to the private member variable score?

  Design main driver class to instantiate-compute sum-objects

Design a main driver class to instantiate and calculate sum of several MonetaryCoin objects. Demonstrate that monetary coin inherits its parent's ability to be flipped.

  Determining smallest possible number people in parade

Group of people are arranging themselves for parade. Determine the smallest possible number people?

  Program to compute net pay of employee

A program to compute net pay of employee. It must permit one to read deposit number, account name, amount deposited, and yesr.check.

  Payroll program for a company

Write complete PAYROLL program for a company in which each employee falls into one of 3 categories - Administrative, Factory Employee or Salesperson.

  Prepare console application to examine contents of text file

Prepare the C++ console application which examines the contents of a text file. Your program must count the number of: * lines (hint: use getline).

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