CSE 240 Lecture 8. © Lethbridge/Laganière 2001 Chapter 5: Modelling with classes2 Overview Begin discussing Chapter 3 - Reuse.

Slides:



Advertisements
Similar presentations
COM vs. CORBA.
Advertisements

9.5 Software Architecture
Computer Monitoring System for EE Faculty By Yaroslav Ross And Denis Zakrevsky Supervisor: Viktor Kulikov.
Object-Oriented Software Engineering Practical Software Development using UML and Java Chapter 3: Basing Software Development on Reusable Technology.
1 Pertemuan 13 Servers for E-Business Matakuliah: M0284/Teknologi & Infrastruktur E-Business Tahun: 2005 Versi: >
Software Reuse, Frameworks, and Client-server Systems September 8, 2005 Motivation for Software Reuse Frameworks Definition Object Oriented Model Client-server.
A CHAT CLIENT-SERVER MODULE IN JAVA BY MAHTAB M HUSSAIN MAYANK MOHAN ISE 582 FALL 2003 PROJECT.
1 Java Networking – Part I CS , Spring 2008/9.
WECPP1 Java networking Jim Briggs based on notes by Amanda Peart based on Bell & Parr's bonus chapter
CSCI 4550/8556 Computer Networks Comer, Chapter 3: Network Programming and Applications.
1 L53 Networking (2). 2 OBJECTIVES In this chapter you will learn:  To understand Java networking with URLs, sockets and datagrams.  To implement Java.
Notion of a Project Notes from OOSE Slides - modified.
© Lethbridge/Laganière 2001 Chap. 3: Basing Development on Reusable Technology 1 Let’s get started. Let’s start by selecting an architecture from among.
The Architecture of Transaction Processing Systems
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 25 Networking.
Systems Architecture, Fourth Edition1 Internet and Distributed Application Services Chapter 13.
Object-Oriented Software Engineering Practical Software Development using UML and Java Chapter 3: Basing Software Development on Reusable Technology.
1 First app – simplechat1 Reminder: what’s the point?  To build on ocsf framework.  Simple requirements: echo all messages to all clients.  Use only.
System Architecture: Desing alternatives and methodologies.
Course Instructor: Aisha Azeem
Networking with Java CSc 335 Object-Oriented Programming and Design Spring 2009.
Fundamentals of Python: From First Programs Through Data Structures
Lecture slides prepared for “Business Data Communications”, 7/e, by William Stallings and Tom Case, Chapter 8 “TCP/IP”.
CEG3185 Tutorial 4 Prepared by Zhenxia Zhang Revised by Jiying Zhao (2015w)
INTRODUCTION TO WEB DATABASE PROGRAMMING
The Design Discipline.
TCP/IP protocols Communication over Internet is mostly TCP/IP (Transmission Control Protocol over Internet Protocol) TCP/IP "stack" is software which allows.
Hands-On Microsoft Windows Server 2003 Networking Chapter Three TCP/IP Architecture.
Chapter 17 Networking Dave Bremer Otago Polytechnic, N.Z. ©2008, Prentice Hall Operating Systems: Internals and Design Principles, 6/E William Stallings.
Taken from Chapter 3 of Object-Oriented Software Engineering: Practical Software Development using UML and Java by T. Lethbridge and R. Laganiere Basing.
Internet Software Development Lecture 14: Basing Software Development on Reusable Technology From: Object-Oriented Software Engineering, by Lethbridge.
1 Chapter Client-Server Interaction. 2 Functionality  Transport layer and layers below  Basic communication  Reliability  Application layer.
Understanding the CORBA Model. What is CORBA?  The Common Object Request Broker Architecture (CORBA) allows distributed applications to interoperate.
Remote Access Chapter 4. Learning Objectives Understand implications of IEEE 802.1x and how it is used Understand VPN technology and its uses for securing.
9.4 Software Architecture
Jozef Goetz, Application Layer PART VI Jozef Goetz, Position of application layer The application layer enables the user, whether human.
Cli/Serv.: Chat/121 Client/Server Distributed Systems v Objectives –discuss a client/server based chat system –mention two other ways of chatting.
1 CSC111H Client-Server: An Introduction Dennis Burford
Object-Oriented Software Engineering Practical Software Development using UML and Java Chapter 1: Software and Software Engineering.
Practicum: - Client-Server Computing in Java Fundamental Data Structures and Algorithms Margaret Reid-Miller 13 April 2004.
1. I NTRODUCTION TO N ETWORKS Network programming is surprisingly easy in Java ◦ Most of the classes relevant to network programming are in the java.net.
Module 1 Object-Oriented Software Engineering. Section 1: Software and Software Engineering.
Object-Oriented Software Engineering Practical Software Development using UML and Java Chapter 3: Basing Software Development on Reusable Technology 1.
Object-Oriented Software Engineering Practical Software Development using UML and Java Chapter 3: Basing Software Development on Reusable Technology.
Object-Oriented Software Engineering Practical Software Development using UML and Java Chapter 3: Basing Software Development on Reusable Technology.
CE Operating Systems Lecture 3 Overview of OS functions and structure.
Software Engineering, Lecture 4 Mohamed Elshaikh.
© Lethbridge/Laganière 2005 Chap. 3: Basing Development on Reusable Technology The Client-Server Architecture A distributed system is a system in.
1 Chapter 28 Networking. 2 Objectives F To comprehend socket-based communication in Java (§28.2). F To understand client/server computing (§28.2). F To.
L 2 - 1 3( 1/ 20) : Java Network Programming. The Socket API The previous contents describe client-server interaction that application programs use when.
CS390- Unix Programming Environment CS 390 Unix Programming Environment Java Socket Programming.
9 Systems Analysis and Design in a Changing World, Fourth Edition.
Object-Oriented Software Engineering Practical Software Development using UML and C++ / Java Chapter 3: Basing Software Development on Reusable Technology.
Java Sockets Tutorial Rahul Malik Nov 12, 2005.
Protocols COM211 Communications and Networks CDA College Olga Pelekanou
The Client-Server Model And the Socket API. Client-Server (1) The datagram service does not require cooperation between the peer applications but such.
Object-Oriented Software Engineering Practical Software Development using UML and Java Chapter 3: Basing Software Development on Reusable Technology.
TCP/IP Protocol Stack IP Device Drivers TCPUDP Application Sockets (Gate to network) TCP: –Establish connection –Maintain connection during the communication.
Basing software development on Reusable Technology.
UNIT-6. Basics of Networking TCP/IP Sockets Simple Client Server program Multiple clients Sending file from Server to Client Parallel search server.
Java Networking I IS Outline  Quiz #3  Network architecture  Protocols  Sockets  Server Sockets  Multi-threaded Servers.
Network Programming. These days almost all devices.
Object-Oriented Software Engineering Practical Software Development using UML and Java Chapter 3: Basing Software Development on Reusable Technology.
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 33 Networking.
Module 1 Object-Oriented Software Engineering
Networking COMP
MCA – 405 Elective –I (A) Java Programming & Technology
Chapter 1: Software and Software Engineering
Chapter 3: Windows7 Part 4.
Module 1 Object-Oriented Software Engineering
Presentation transcript:

CSE 240 Lecture 8

© Lethbridge/Laganière 2001 Chapter 5: Modelling with classes2 Overview Begin discussing Chapter 3 - Reuse

Quote of the day “If the automobile had followed the same development cycle as the computer, a Rolls-Royce would today cost $100, get a million miles per gallon, and explode once a year, killing everyone inside. “ Robert X. Cringely, InfoWorld magazine

© Lethbridge/Laganière 2001 Chapter 5: Modelling with classes4 For Next time Finish reading Chapter 3. Read Chapter 6, 6.1 – 6.4

Object-Oriented Software Engineering Practical Software Development using UML and Java Chapter 3: Basing Software Development on Reusable Technology (authors Slides)

© Lethbridge/Laganière 2001 Chapter 5: Modelling with classes6 3.1 Building on the Experience of Others Software engineers should avoid re-developing software already developed Types of reuse: Reuse of expertise Reuse of standard designs and algorithms Reuse of libraries of classes or procedures Reuse of powerful commands built into languages and operating systems Reuse of frameworks Reuse of complete applications

© Lethbridge/Laganière 2001 Chapter 5: Modelling with classes7 3.2 Reusability and Reuse in SE Reuse and design for reusability should be part of the culture of software development organizations. But there are problems to overcome: Why take the extra time needed to develop something that will benefit other projects/customers? Management may only reward the efforts of people who create the visible ‘final products’. Reusable software is often created in a hurry and without enough attention to quality.

© Lethbridge/Laganière 2001 Chapter 5: Modelling with classes8 A vicious cycle Developers tend not to develop high quality reusable components, so there is often little to reuse. To solve the problem, recognize that: This vicious cycle costs money Investment in reusable code is important Attention to quality of reusable components is essential —So that potential reusers have confidence in them —The quality of a software product is only as good as its lowest-quality reusable component Developing reusable components can often simplify design

© Lethbridge/Laganière 2001 Chapter 5: Modelling with classes9 3.3 Frameworks: Reusable Subsystems A framework is reusable software that implements a generic solution to a generalized problem. It provides common facilities applicable to different application programs. Principle: Applications that do different, but related, things tend to have quite similar designs.

© Lethbridge/Laganière 2001 Chapter 5: Modelling with classes10 Frameworks to promote reuse A framework is intrinsically incomplete Certain classes or methods are used by the framework, but are missing (slots) Some functionality is optional — Allowance is made for developer to provide it (hooks) Developers use the services that the framework provides —Taken together the services are called the Application Program Interface (API)

© Lethbridge/Laganière 2001 Chapter 5: Modelling with classes11 Object-oriented frameworks In the object oriented paradigm, a framework is composed of a library of classes. The API is defined by the set of all public methods of these classes. Some of the classes will normally be abstract

© Lethbridge/Laganière 2001 Chapter 5: Modelling with classes12 Examples of frameworks A framework for payroll management A framework for frequent buyer clubs A framework for university registration A framework for e-commerce web sites A framework for controlling microwave ovens

© Lethbridge/Laganière 2001 Chapter 5: Modelling with classes13 Types of frameworks A horizontal framework provides general application facilities that a large number of applications can use A vertical framework (application framework) is more ‘complete’ but still needs some slots to be filled to adapt it to specific application needs

© Lethbridge/Laganière 2001 Chapter 5: Modelling with classes The Client-Server Architecture A distributed system is a system in which: computations are performed by separate programs … normally running on separate pieces of hardware … that co-operate to perform the task of the system. Server: A program that provides a service for other programs that connect to it using a communication channel Client A program that accesses a server (or several servers) to obtain services A server may be accessed by many clients simultaneously

© Lethbridge/Laganière 2001 Chapter 5: Modelling with classes15 Sequence of activities in a client-server system 1.The server starts running 2.The server waits for clients to connect. (listening) 3.Clients start running and perform operations —Some operations involve requests to the server 4.When a client attempts to connect, the server accepts the connection (if it is willing) 5.The server waits for messages to arrive from connected clients 6.When a message from a client arrives, the server takes some action in response, then resumes waiting 7.Clients and servers continue functioning in this manner until they decide to shut down or disconnect

© Lethbridge/Laganière 2001 Chapter 5: Modelling with classes16 A server program communicating with two client programs ServerClient 1Client 2 listen for connections disconnect send message connect send reply connect send message disconnect stop listening

© Lethbridge/Laganière 2001 Chapter 5: Modelling with classes17 Alternatives to the client server architecture Have a single program on one computer that does everything Have no communication — Each computer performs the work separately Have some mechanism other than client-server communication for exchanging information —E.g. one program writes to a database; the other reads from the database

© Lethbridge/Laganière 2001 Chapter 5: Modelling with classes18 Advantages of client-server systems The work can be distributed among different machines The clients can access the server’s functionality from a distance The client and server can be designed separately They can both be simpler All the data can be kept centrally at the server Conversely, data can be distributed among many different geographically-distributed clients or servers The server can be accessed simultaneously by many clients Competing clients can be written to communicate with the same server, and vice-versa

© Lethbridge/Laganière 2001 Chapter 5: Modelling with classes19 Example of client-server systems The World Wide Web Network File System Transaction Processing System Remote Display System Communication System Database System

© Lethbridge/Laganière 2001 Chapter 5: Modelling with classes20 Activities of a server 1 1.Initializes itself 2.Starts listening for clients 3.Handles the following types of events originating from clients 1.accepts connections 2.responds to messages 3.handles client disconnection 4.May stop listening for new client connections but handle current clients 5.Must terminate cleanly

© Lethbridge/Laganière 2001 Chapter 5: Modelling with classes21 Activities of a server 2 1.Initializes itself 2.Starts listening for clients 3.Handles the following types of events originating from clients 1.accepts connections 2.responds to messages 3.handles client disconnection 4.May stop listening for new client connections but handle current clients 5.Must terminate cleanly State Diagram

© Lethbridge/Laganière 2001 Chapter 5: Modelling with classes22 Activities of a client 1 1.Initializes itself 2.Performs work such as 1.initiating a connection 2.sending messages 3.Handles server events such as 1.responding to messages 2.handling a server disconnection 4.Must terminate cleanly initiate a connection to a server respond to events triggered by the server do:respond to messages and handle server disconnection interact with the user, sending messages to the server as necessary terminate initialize

© Lethbridge/Laganière 2001 Chapter 5: Modelling with classes23 Activities of a client 2 1.Initializes itself 2.Performs work such as 1.initiating a connection 2.sending messages 3.Handles server events such as 1.responding to messages 2.handling a server disconnection 4.Must terminate cleanly initiate a connection to a server respond to events triggered by the server do:respond to messages and handle server disconnection interact with the user, sending messages to the server as necessary terminate initialize Interaction Diagram

© Lethbridge/Laganière 2001 Chapter 5: Modelling with classes24 Threads in a client-server system 1

© Lethbridge/Laganière 2001 Chapter 5: Modelling with classes25 Threads in a client-server system 2 Sequence Diagram

© Lethbridge/Laganière 2001 Chapter 5: Modelling with classes26 Thin- versus fat-client systems Thin-client system (a) Client is made as small as possible Most of the work is done in the server. Client easy to download over the network Fat-client system (b) As much work as possible is delegated to the clients. Server can handle more clients

© Lethbridge/Laganière 2001 Chapter 5: Modelling with classes27 Communications protocols The messages the client sends to the server form a language. — The server has to be programmed to understand that language. The messages the server sends to the client also form a language. — The client has to be programmed to understand that language. When a client and server are communicating, they are in effect having a conversation using these two languages The two languages and the rules of the conversation, taken together, are called the protocol

© Lethbridge/Laganière 2001 Chapter 5: Modelling with classes28 Tasks to perform to develop client-server applications 1.Design the primary work to be performed by both client and server 2.Design how the work will be distributed 3.Design the details of the set of messages that will be sent 4.Design the mechanism for 1.Initializing 2.Handling connections 3.Sending and receiving messages 4.Terminating

CSE 240 Lecture 8.5 (actually will be 9.5)

© Lethbridge/Laganière 2001 Chapter 5: Modelling with classes31 Overview Finish Chapter 3 – talks about simple chat

Quote of the day “If the automobile had followed the same development cycle as the computer, a Rolls-Royce would today cost $100, get a million miles per gallon, and explode once a year, killing everyone inside. “ Robert X. Cringely, InfoWorld magazine

Object-Oriented Software Engineering Practical Software Development using UML and Java Chapter 3: Basing Software Development on Reusable Technology (authors Slides) (the leftover half of the slides from Ch3)

© Lethbridge/Laganière 2001 Chapter 5: Modelling with classes34 Quote of the Day Never hold discussions with the monkey when the organ grinder is in the room. -Sir Winston Churchill

© Lethbridge/Laganière 2001 Chapter 5: Modelling with classes Technology Needed to Build Client- Server Systems Internet Protocol (IP) Route messages from one computer to another Long messages are normally split up into small pieces Transmission Control Protocol (TCP) Handles connections between two computers Computers can then exchange many IP messages over a connection Assures that the messages have been satisfactorily received A host has an IP address and a host name Several servers can run on the same host. Each server is identified by a port number (0 to 65535). To initiate communication with a server, a client must know both the host name and the port number

© Lethbridge/Laganière 2001 Chapter 5: Modelling with classes36 Establishing a connection in Java The java.net package Permits the creation of a TCP/IP connection between two applications Before a connection can be established, the server must start listening to one of the ports: ServerSocket serverSocket = new ServerSocket(port); Socket clientSocket = serverSocket.accept(); For a client to connect to a server: Socket clientSocket= new Socket(host, port);

© Lethbridge/Laganière 2001 Chapter 5: Modelling with classes37 Exchanging information in Java Each program uses an instance of — InputStream to receive messages from the other program — OutputStream to send messages to the other program —These are found in package java.io output = new OutputStream(clientSocket.getOutputStream()); input = new InputStream(clientSocket.getInputStream());

© Lethbridge/Laganière 2001 Chapter 5: Modelling with classes38 Sending and receiving messages without any filters output.write(msg); msg = input.read(); or using DataInputStream / DataInputStream filters output.writeDouble(msg); msg = input.readDouble(); or using ObjectInputStream / ObjectInputStream filters output.writeObject(msg); msg = input.readObject();

© Lethbridge/Laganière 2001 Chapter 5: Modelling with classes The Object Client-Server Framework (OCSF) AbstractClient openConnection closeConnection sendToServer connectionEstablished connectionClosed handleMessageFromServer connectionException ****** ConnectionToClient sendToClient close setInfo getInfo AbstractServer listen stopListening close clientConnected clientDisconnected serverStarted handleMessageFromClient serverStopped sendToAllClients getClientConnections serverClosed clientException listeningException

© Lethbridge/Laganière 2001 Chapter 5: Modelling with classes40 Using OCSF Software engineers using OCSF never modify its three classes They: Create subclasses of the abstract classes in the framework Call public methods that are provided by the framework Override certain slot and hook methods (explicitly designed to be overridden)

© Lethbridge/Laganière 2001 Chapter 5: Modelling with classes The Client Side Consists of a single class: AbstractClient Must be subclassed —Any subclass must provide an implementation for handleMessageFromServer -Takes appropriate action when a message is received from a server Implements the Runnable interface —Has a run method which -Contains a loop that executes for the lifetime of the thread

© Lethbridge/Laganière 2001 Chapter 5: Modelling with classes42 The public interface of AbstractClient Controlling methods: openConnection closeConnection sendToServer Accessing methods: isConnected getHost setHost getPort setPort getInetAddress

© Lethbridge/Laganière 2001 Chapter 5: Modelling with classes43 The callback methods of AbstractClient Methods that may be overridden: connectionEstablished connectionClosed connectionException Method that must be overridden: handleMessageFromServer

© Lethbridge/Laganière 2001 Chapter 5: Modelling with classes44 Using AbstractClient Create a subclass of AbstractClient Implement handleMessageFromServer slot method Write code that: —Creates an instance of the new subclass —Calls openConnection —Sends messages to the server using the sendToServer service method Implement the connectionClosed callback Implement the connectionException callback

© Lethbridge/Laganière 2001 Chapter 5: Modelling with classes45 Internals of AbstractClient Instance variables: A Socket that keeps all the information about the connection to the server Two streams, an ObjectOutputStream and an ObjectInputStream A Thread that runs using AbstractClient’s run method A boolean variable used to signal when the thread should stop executing Two variables storing the host and port of the server

© Lethbridge/Laganière 2001 Chapter 5: Modelling with classes The Server Side Two classes: One for the thread which listens for new connections ( AbstractServer ) One for the threads that handle the connections to clients ( ConnectionToClient )

© Lethbridge/Laganière 2001 Chapter 5: Modelling with classes47 The public interface of AbstractServer Controlling methods: listen stopListening close sendToAllClients Accessing methods: isListening getClientConnections getPort setPort setBacklog

© Lethbridge/Laganière 2001 Chapter 5: Modelling with classes48 The callback methods of AbstractServer Methods that may be overridden: serverStarted clientConnected clientDisconnected clientException serverStopped listeningException serverClosed Method that must be overridden: handleMessageFromClient

© Lethbridge/Laganière 2001 Chapter 5: Modelling with classes49 The public interface of ConnectionToClient Controlling methods: sendToClient close Accessing methods: getInetAddress setInfo getInfo

© Lethbridge/Laganière 2001 Chapter 5: Modelling with classes50 Using AbstractServer and ConnectionToClient Create a subclass of AbstractServer Implement the slot method handleMessageFromClient Write code that: —Creates an instance of the subclass of AbstractClient —Calls the listen method —Sends messages to clients, using: - the getClientConnections and sendToClient service methods -or sendToAllClients Implement one or more of the other callback methods

© Lethbridge/Laganière 2001 Chapter 5: Modelling with classes51 Internals of AbstractServer and ConnectionToClient The setInfo and getInfo methods make use of a Java class called HashMap Many methods in the server side are synchronized The collection of instances of ConnectionToClient is stored using a special class called ThreadGroup The server must pause from listening every 500ms to see whether the stopListening method has been called —if not, then it resumes listening immediately

© Lethbridge/Laganière 2001 Chapter 5: Modelling with classes An Instant Messaging Application: SimpleChat EchoServer handleMessageFromClient serverStarted serverStopped main > ChatIF display ChatClient handleMessageFromServer handleMessageFromClientUI quit AbstractServer ClientConsole accept display main AbstractClient ClientConsole can eventually be replaced by ClientGUI

© Lethbridge/Laganière 2001 Chapter 5: Modelling with classes53 The server EchoServer is a subclass of AbstractServer The main method creates a new instance and starts it —It listens for clients and handles connections until the server is stopped The three callback methods just print out a message to the user — handleMessageFromClient, serverStarted and serverStopped The slot method handleMessageFromClient calls sendToAllClients —This echoes any messages

© Lethbridge/Laganière 2001 Chapter 5: Modelling with classes54 Key code in EchoServer public void handleMessageFromClient (Object msg, ConnectionToClient client) { System.out.println( "Message received: " + msg + " from " + client); this.sendToAllClients(msg); }

© Lethbridge/Laganière 2001 Chapter 5: Modelling with classes55 The client When the client program starts, it creates instances of two classes: ChatClient —A subclass of AbstractClient —Overrides handleMessageFromServer -This calls the display method of the user interface ClientConsole —User interface class that implements the interface ChatIF -Hence implements display which outputs to the console —Accepts user input by calling accept in its run method —Sends all user input to the ChatClient by calling its handleMessageFromClientUI -This, in turn, calls sendToServer

© Lethbridge/Laganière 2001 Chapter 5: Modelling with classes56 Key code in ChatClient public void handleMessageFromClientUI( String message){ try { sendToServer(message); } catch(IOException e){ clientUI.display ( "Could not send message. " + "Terminating client."); quit(); }

© Lethbridge/Laganière 2001 Chapter 5: Modelling with classes57 Key code in ChatClient - continued public void handleMessageFromServer(Object msg) { clientUI.display(msg.toString()); }

© Lethbridge/Laganière 2001 Chapter 5: Modelling with classes Risks when reusing technology Poor quality reusable components —Ensure that the developers of the reusable technology: -follow good software engineering practices - are willing to provide active support Compatibility not maintained —Avoid obscure features —Only re-use technology that others are also re-using

© Lethbridge/Laganière 2001 Chapter 5: Modelling with classes59 Risks when developing reusable technology Investment uncertainty —Plan the development of the reusable technology, just as if it was a product for a client The ‘not invented here syndrome’ —Build confidence in the reusable technology by: -Guaranteeing support -Ensuring it is of high quality -Responding to the needs of its users

© Lethbridge/Laganière 2001 Chapter 5: Modelling with classes60 Risk when developing reusable technology – continued Competition —The reusable technology must be as useful and as high quality as possible Divergence (tendency of various groups to change technology in different ways) —Design it to be general enough, test it and review it in advance

© Lethbridge/Laganière 2001 Chapter 5: Modelling with classes61 Risks when adopting a client-server approach Security —Security is a big problem with no perfect solutions: consider the use of encryption, firewalls,... Need for adaptive maintenance —Ensure that all software is forward and backward compatible with other versions of clients and servers