G53ACC Advanced Computer Communications - PowerPoint PPT Presentation

1 / 12
About This Presentation
Title:

G53ACC Advanced Computer Communications

Description:

Advanced Computer Communications. Remote Method Invocation. Dynamic Class Loading ... public class SchoolGradesServer extends UnicastRemoteObject implements ... – PowerPoint PPT presentation

Number of Views:31
Avg rating:3.0/5.0
Slides: 13
Provided by: Brai155
Category:

less

Transcript and Presenter's Notes

Title: G53ACC Advanced Computer Communications


1
G53ACC Advanced Computer Communications
  • Remote Method Invocation
  • Dynamic Class Loading
  • From the book Beginning Java Networking by
    Darby et al.

2
School Grading System
  • Remote interface
  • import java.rmi.
  • public interface SchoolGrades extends Remote
  • public int getAverage ()
  • throws RemoteException

3
School Grading SystemServer Implementation
  • Implement defined interface
  • import java.rmi.
  • public class SchoolGradesServer extends
    UnicastRemoteObject implements SchoolGrades
  • static int subjectGrades
  • .... initialises subject grades from database
    ....
  • public SchoolGradesServer() throws
    RemoteException
  • super()
  • public int getAverage ()
  • throws RemoteException
  • method for calculating average
  • return (sumOfAllSubjects / numOfSubjects)

4
School Grading SystemServer Implementation (Cont)
  • public static void main(String args)
  • try
  • SchoolGradesServer server new
    SchoolGradesServer()
  • Naming.rebind(/GradingService, server)
  • ... ...

5
School Grading SystemClient Implementation
  • import java.rmi.
  • public class SchoolGradesClient
  • Static SchoolGrades g null
  • public static void main(String args)
  • try
  • g (SchoolGrades) Naming.lookup
    (//host/GradingService)
  • System.out.println(Avarage grade is
    g.getAverage() out of 100)
  • ... ...

6
Flexible School Grading System
  • Remote interface
  • import java.rmi.
  • public interface FlexSchoolGrades extends Remote
  • public int getAverage (GradingScheme scheme)
  • throws RemoteException

7
Flexible School Grading System
  • GradingScheme interface
  • import java.rmi.
  • public interface GradingScheme
  • public int computeAverage (int subjectScores)

8
Flexible School Grading System
  • Define first computation method
  • public class AverageScheme implements
    GradingScheme, java.io.Serializable
  • public int computeAverage (int subjectScores)
  • ... algorithm 1 ...
  • return (sumOfAllSubjects / numOfSubjects)

9
Flexible School Grading System
  • Define second computation method
  • public class WeightedScheme implements
    GradingScheme, java.io.Serializable
  • public int computeAverage (int subjectScores)
  • ... algorithm 2 ...
  • return (WeightedSumOfAllSubjects / sumOfWeights)

10
Flexible School Grading System
  • Implement defined interface for server
  • import java.rmi.
  • public class FlexSchoolGradesServer extends
    UnicastRemoteObject implements FlexSchoolGrades
  • static int subjectGrades
  • .... initialises subject grades from database
    ....
  • public FlexSchoolGradesServer() throws
    RemoteException
  • super()
  • public int getAverage (GradingScheme scheme)
  • throws RemoteException
  • return (scheme.computeAverage (subjectGrades))

11
Flexible School Grading System
  • public static void main(String args)
  • if (System.getSecurityManager() null)
  • System.SetSecurityManage(new RMISecurityManage())
  • try
  • FlexSchoolGradesServer server new
    FlexSchoolGradesServer()
  • Naming.rebind(/FlexGradingService, server)
  • ... ...

12
Flexible School Grading SystemClient
Implemetation
  • import java.rmi.
  • public class FlexSchoolGradesClient
  • static FlexSchoolGrades g null
  • public static void main(String args)
  • GradingScheme scheme null
  • try
  • g (FlexSchoolGrades) Naming.lookup
    (//host/FlexGradingService)
  • if ((args.length gt 0) (args0.equals(-w)))
  • scheme new WeightedScheme()
  • else
  • scheme new AverageScheme()
  • System.out.println(Avarage grade is
    g.getAverage(scheme) out of 100)
  • ... ...
Write a Comment
User Comments (0)
About PowerShow.com