Overloading Java Interface Callback Protocol User Command Handler Concurrent Thread

Size: px
Start display at page:

Download "Overloading Java Interface Callback Protocol User Command Handler Concurrent Thread"

Transcription

1 Overloading Java Interface Callback Protocol User Command Handler Concurrent Thread 1

2 Code refactoring is the process of changing a computer program s internal structure without modifying its external functional behavior or existing functionality, in order to improve internal non-functional properties of the software. For example, refactoring is done to improve: Code readability Code structure Change code to adhere to a given programming paradigm Improve maintainability Improve performance Improve extensibility. 2

3 Current Server Basic Multi-threaded Version << TCP/IP network, Data >> Client << TCP/IP network, Connection Request >> * ClientConnection UserCommandHandler myui myserver execute StandardIO mycommmandhandler ServerTest Server Server startserver stopserver listen setdolisten stoplistening setport getport sendmessagetoui run ClientConnection getclientsocket sendmessagetoclient disconnectclient stopthisthread run ClientCommandHandler setcommandhandler getuserinput display run execute 3

4 Refactoring: ClientConnection Currently, the run() method in the ClientConnection object receives two types of messages: 1. Commands from the Client, requesting a service of the Server 2. Exceptional events, such as unexpected TCP disconnection or unexpected client disconnection. while (stopthisthread == false) { try { msg = (byte) input.read(); thestring = bytetostring(msg); myclientcommandhandler.execute(this, thestring); } catch (IOException e) { myserver.sendmessagetoui( Unexpected disconnection; stopping thread and disconnecting client: "+ clientsocket.getremotesocketaddress()); disconnectclient(); stopthisthread = true; } } 4

5 Refactoring: ClientConnection Currently, the run method sends client command messages to the ClientCommandHandler class, and exceptional event messages to the Server class. A better object oriented design would be that if both types of messages were sent to the same destination, namely, the ClientCommandHandler class. It would be better OO design because the handler should decide and handle what to do with any kind of message received from the client. Better yet, the ClientCommandHandler class should be named ClientMessageHandler to indicate that it can receive any type of message from a client, i.e., both client commands and exceptional events associated with the client. The run method should send both types of messages to the ClientMessageHandler, but to different methods, one method for receiving client commands and a different method for receiving exceptional events associated with the client. This can be done by overloading a method in the ClientMessageHandler class. 5

6 Refactoring: Changing Name (1) Refactor: change the name of the clientcommandhandler package to clientmessagehandler 6

7 Refactoring: Changing Name (2) Refactor: change the name of the ClientCommandHandler.java to ClientMessageHandler.java ClientMessageHandler 7

8 Refactoring: Changing Name (3) Refactor: change the name of handleclientcommand to handleclientmessage 8

9 Refactoring: Changing Name (4) Refactor: change the name of theclientcommand to theclientmessage.java 9

10 Overloading means that the same method name can be defined with more than one signature the list of formal parameters (and their types). In Java, overloading means that there can be different versions of a function and the compiler can tell which one is intended by looking at the types of parameters in a call to the function (method). 10

11 Overloaded Method in ClientMessageHandler public void handleclientmessage(clientconnection.clientconnection myclientconnection, String thecommand) { if (thecommand.equals("d")) { myserver.sendmessagetoui("disconnect command received from client + myclientconnection.getclientsocket().getremotesocketaddress()); myclientconnection.clientdisconnect(); myserver.sendmessagetoui("\tdisconnect successful. "); } else if (thecommand.equals("q")) { This processes This processes } an exceptional a client } event command public void handleclientmessage(string theexceptionalevent) { myserver.sendmessagetoui(theexceptionalevent); } 11

12 Refactoring: ClientConnection Now, after refactoring, the run method calls one of two overloaded methods to handle the different types of client messages: while (stopthisthread == false) { try { msg = (byte) input.read(); theclientmessage = bytetostring(msg); myclientcommandhandler.handleclientmessage(this, theclientmessage); } catch (IOException e) { myclientcommandhandler.handleclientmessage("ioexception: " +e.tostring() + ". Stopping thread and disconnecting client: " +clientsocket.getremotesocketaddress()); disconnectclient(); stopthisthread = true; } } 12

13 UML Class Diagram of Server With Overloaded Method in ClientMessageHandler << TCP/IP network, Data >> Client << TCP/IP network, Connection Request >> UserCommandHandler myui myserver execute StandardIO mycommmandhandler setcommand getuserinput display run ServerTest Server Server startserver stopserver listen setdolisten stoplistening setport getport sendmessagetoui run * ClientConnection ClientConnection getclientsocket sendmessagetoclient disconnectclient stopthisthread run ClientMessageHandler handleclientmessage(clientconnection, String) handleclientmessage(string) 13

14 Next Topic: Adding a Java Interface 14

15 Modeling Server User Messages Notice that, currently, all messages to be sent to the server-user are sent to the Server object s sendmessagetoui() method: public void sendmessagetoui(string thestring) { myui.display(thestring); } Is myui.display(thestring)the best way to send messages to the server-user? However, the method should NOT Assume a particular user interface, such as standard IO or a custom graphical user interface. Configure, manipulate, or modify the message as may be required by the specific interface. Send a configured message to a particular interface. Why? Because, if the user interface changes, then sendmessagetoui would have to change, as well. The method sendmessagetoui should not have any application specific code in it, because, in that case, the Server class would be difficult to reuse in a different application that uses different user interfaces or does not have a user interface. 15

16 Modeling Server User Messages Current way would require changing the myuserinterface field when the user interface is changed. Specifically, the Server would need to be recompiled, since the type of the reference variable would need to be changed. Under some circumstances, recompiling the Server is acceptable, but in others it is not. For example, the reusable Server software may be provided only in *.class files, or as a library, in which case recompiling is not an option. Server User <<receives messages>> Plugin User Interface StandardIO console getuserinput display run Server userinterface.standardio myui sendmessagetoui Server User <<receives messages>> Plugin User Interface GUI getuserinput display run Server userinterface.gui myui sendmessagetoui 16

17 Current Server Code for Standard IO User Interface 17

18 Change Needed for Graphical User Interface 18

19 A better way is to use the Java Interface type The server would declare a Java interface type as the reference variable to reference the user interface. Should the user interface change, the Server code does not change since the user interface reference variable refers to the Java interface type and not to the actual user interface object. The server would send a generic String message to the Java interface type. The UserInterface object would implement the Java interface and input the generic String message and configure or manipulate it to fit the specific type of user interface that it handles. The Server will not know, and does not need to know, what particular user interface is being used. It just sends the message to the <<interface>> object. In this case, if the user interface changes in the future, then the UserInterface object changes of course, but the <<interface>> type would not change, and the link that the Server object uses to reference the <<interface>> would not change as well. 19

20 The Server method invokes myuserinterface.update(message) to send a message to the server user. The StandardIO object handles the message, since it is required to implement the interface. The update method of the object inputs the string and configures or manipulates it to fit the specific type of user interface that it handles., i.e., it sends the string to the monitor, with no manipulation, in this case. If the user interface changes in the future, then The Server object does not change at all (specifically, the myuserinterface type does not change) The UserInterface <<interface>> does not change. The only change that is made is the UserInterface object. Server User <<receives messages>> Plugin User Interface StandardIO console getuserinput update display run <<interface>> UserInterface update(string) Server myuserinterface sendmessagetoui 20

21 The Server method invokes myuserinterface.update(message) to send a message to the server user. The GUI object handles the message, since it is required to implement the interface. The update method of the object inputs the string and configures or manipulates it to fit the specific type of user interface that it handles., i.e., it manipulates the String to display in the TextBox. If the user interface changes in the future, then The Server object does not change at all (specifically, the myuserinterface type does not change) The UserInterface <<interface>> does not change. The only change that is made is the UserInterface object. Server User <<receives messages>> Plugin User Interface GUI mytextbox setcommand update run <<interface>> UserInterface update(string) Server myuserinterface sendmessagetoui 21

22 Interface: Step 1 Rename the userinterface package to standardiouserinterface 22

23 Interface: Step 2 Create a new package named: userinterface Create a new Java Interface type in the package: name it UserInterface. Create a new abstract method in UserInterface: name it update(). 23

24 Interface: Step 3 Make StandardIO.java implement UserInterface. 24

25 Interface: Step 4 Change types in Server, and invoke update in sendmessagetoui(). Generic user interface type 25

26 Interface: Step 5 Change types in UserCommandHandler, and invoke update. 26

27 Server Application Class Diagram After Adding User Interface <<Interface>> << TCP/IP network, Data >> Client << TCP/IP network, Connection Request >> ServerTest UserCommandHandler myui myserver handleusercommand Server Server startserver stopserver listen setdolisten stoplistening setport getport sendmessagetoui run * ClientConnection ClientConnection getclientsocket sendmessagetoclient disconnectclient stopthisthread run StandardIO mycommmandhandler setcommand getuserinput update run <<interface>> UserInterface update(string) ClientMessageHandler handleclientmessage(clientconnection, String) handleclientmessage(string) 27

28 Client Application Class Diagram After Adding User Interface <<Interface>> << TCP/IP network, Data >> Server << TCP/IP network, Connection Request >> ClientTest UserCommandHandler myui myclient handleusercommand Client Client connecttoserver disconnectfromserver sendmessagetoserver isconnected stopthread setport getport sendmessagetoui run Client User <<use cases>> GUI myusercommandhandler setcommandhandler update run <<interface>> UserInterface update(string) ServerMessageHandler handleservermessage() 28

29 Next Topic: Callback 29

30 A Callback method/function can be explained using a telephone system analogy. Bob calls Alice on a telephone, and asks her a question. Alice knows she needs to do a lot of research to find an answer and asks Bob if he can give her a callback number to call once she has found the answer to his question. The telephone call is then terminated. At some time later, when Alice has found an answer to Bob s question, she calls Bob s callback number and provides him with the answer to his question. In Java, Your code calls one of your methods Method A, which in turn calls some other heavy-weight code Method B to perform a task that may take a relatively long time to complete. Instead of waiting until the heavy-weight work has been completed, Method B is made to run as a concurrent thread, control is returned back to Method A immediately. Your code then continues with other tasks, with the understanding that when the heavy-weight work has been completed, the heavy-weight thread will call the callback method Method C to inform your code of its completion. 30

31 Example: The connectionestablished Callback Add a connectionestablished callback method to the Server class. Initially, the server software calls the startlisten method to allow client connections. The server software would also like to know if and when a client connects. Instead of waiting for a client connection, like we did in the single threaded server application, we arranged that the startlisten code starts a thread to listen for client connections, and returns immediately without any notification of a client connection request, and the server software proceeded to do other things, like interacting with the server user. Now, at some time later, a client may make a connection request, and the listen thread will accept it and then invoke the callback method to notify the server software that a client has connected. 31

32 Refactoring: adding the connectionestablished callback in Server Currently, the run method in the Server calls the sendmessagetoui method when a client makes a connection request: try { clientsocket = serversocket.accept(); sendmessagetoui("client connected: +clientinfo); It would be better object oriented design if the code invoked a specific callback method associated with the event: try { clientsocket = serversocket.accept(); connectionestablished(clientinfo); We would define the callback method, also contained in the server class to do the following: public void connectionestablished(clientinfo(string clientinfo) { sendmessagetoui( Client has connected: + clientinfo); } 32

33 Possible Server Callbacks serversocketstarted connectionestablished clientdisconnected clientexception serverstopped listeningexception serverstopped 33

34 Next Topic: Java Server Protocol The current protocol is too simple and not robust enough. For example, it is not clear when a command or message ends, i.e., there is no termination code. This limits to the commands communicated between the client and server to be each one byte long. In the future, there may be a need to have commands longer than one byte, and the current design would make adding longer commands not possible. For Instance: if (thecommand.equals("d")) { } else if (thecommand.equals("q")) { } else if (thecommand.equals("t")) { } 34

35 One solution is to terminate each message, either sent by the client or the server, with a termination code, which is not used in any message, like 0xFF. 0xFF is not a well used ASCII code, so it may be used in this application. Other termination code are possible, such as: 0x04, which is the ASCII code for end of transmission 35

36 Client Command String Sent to Server (each terminated by 0xFF) Server Interprets the Command as: Server Sends the Client the Ack/Response String (each terminated by 0xFF) q Quit Quit: /IP Address:port d Disconnect From Server Disconnect: /IP Address:port t Request the time The time is: HOUR:MIN:SEC L1on Switch LED1 ON L1on L2on Switch LED2 ON L2on L3on Switch LED3 ON L3on L4on Switch LED4 ON L4on L1off Switch LED1 OFF L1off L2off Switch LED2 OFF L2off L3off Switch LED3 OFF L3off L4off Switch LED4 OFF L4off gpb1 Return the state of PB 1 PB1<Down, Up> gpb2 Return the state of PB 2 PB2<Down, Up> 36

37 Client Disconnects from Server ServerUser Server Client ClientUser d d 0xFF Client Disconnected Disconnect Client Disconnect 0xFF Disconnect From Server Server Ack 37

38 Client Command: LED 1 On ServerUser Server Client ClientUser L1on L1on 0xFF Switch LED 1 On Led 1 On L1on 0xFF Server Ack 38

39 Client Command: PB1? ServerUser Server Client ClientUser gpb1 gpb1 0xFF Get Push Button State Push Button 1 Requested PB1<Down, Up> 0xFF Push Button 1 is Down/Up 39

40 Next Topic: Adding a User Command Concurrent Thread. First, Demonstrating the Problem (Example, StartServer): Getting Input From The User userinput = console.readline(); <<Command>> <<startserversocket>> User Currently, the time taken to process a server-user command may be relatively a long time: the user might notice and complain that the interface seems sluggish. For example, consider a server user selecting the Start Server command on the StandardIO interface. In response the software will temporarily stop getting input from the user and execute the command, through a sequence of method invocations, called a method trace. mycommandhandler.handleusercommand() Integer.parseInt(theCommand) myserver.startserver() myclient.clientsocket = new Socket() myui.update() Getting Input From The User userinput = console.readline(); User 40

41 Measuring actual time for the initial start Server Socket command was 20 ms on my desktop computer. 41

42 the Solution: Introduce a User Command Handler Concurrent Thread User Getting Input From the User Resume Getting Input From the User <<Command>> <<startserversocket>> mycommandhandler.handleusercommand() Start User Command Handler Thread(Command) User Start Thread A solution is to process the command in a different concurrent thread. In this way, the user interaction thread returns to interacting with the user sooner. User Command Handler Thread: Example start server socket Integer.parseInt(theCommand) myserver.startserver() myclient.clientsocket = new Socket() myui.update() Exit Thread 42

43 First modify the UserCommandHandler class to implement Runnable and add a run method to the class. Put the actual processing of the user command in the run method. Make a String usermessage instance variable. When invoked, the handleusercommand method sets the usermessage instance variable to the message string it receives as a parameter (i.e., the user command), and then it starts the executecommand thread. The handleusercommand method then returns to interacting with the user. Meanwhile, when run, the concurrent thread in the UserCommandHandler class (i.e., the run method) reads the string instance variable, and then processes the command as before. 43

44 Modified User Command Handler Class 44

45 the Problem Solved Measuring actual time for the initial start Server Socket command was now 0 ms on my desktop computer, compared to 20 ms without the concurrent thread. 45

46 Server Application Class Diagram After Adding User Command Handler Thread << TCP/IP network, Data >> Client << TCP/IP network, Connection Request >> ServerTest StandardIO UserCommandHandler myui myserver thecommand handleusercommand run Server Server startserver stopserver listen setdolisten stoplistening setport getport sendmessagetoui run * ClientConnection ClientConnection getclientsocket sendmessagetoclient disconnectclient stopthisthread run mycommmandhandler setcommand getuserinput update run <<interface>> UserInterface update(string) ClientMessageHandler handleclientmessage(clientconnection, String) handleclientmessage(string) 46

47 Client Application Class Diagram After Adding User Command Handler Thread << TCP/IP network, Data >> Server << TCP/IP network, Connection Request >> ClientTest UserCommandHandler myui myclient thecommand handleusercommand run Client Client connecttoserver disconnectfromserver sendmessagetoserver isconnected stopthread setport getport sendmessagetoui run Client User <<use cases>> GUI myusercommandhandler setcommandhandler update run <<interface>> UserInterface update(string) ServerMessageHandler handleservermessage() 47

Studying software design patterns is an effective way to learn from the experience of others

Studying software design patterns is an effective way to learn from the experience of others Studying software design patterns is an effective way to learn from the experience of others 1 Parties have different ways of presenting the results. Presentation of results Coupling Computation of results

More information

Java Support for developing TCP Network Based Programs

Java Support for developing TCP Network Based Programs Java Support for developing TCP Network Based Programs 1 How to Write a Network Based Program (In Java) As mentioned, we will use the TCP Transport Protocol. To communicate over TCP, a client program and

More information

Android Tutorial: Part 3

Android Tutorial: Part 3 Android Tutorial: Part 3 Adding Client TCP/IP software to the Rapid Prototype GUI Project 5.2 1 Step 1: Copying the TCP/IP Client Source Code Quit Android Studio Copy the entire Android Studio project

More information

3.1 Building on the Experience of Others. Object-Oriented Software Engineering Practical Software Development using UML and Java

3.1 Building on the Experience of Others. Object-Oriented Software Engineering Practical Software Development using UML and Java 3.1 Building on the Experience of Others Object-Oriented Software Engineering Practical Software Development using UML and Java Chapter 3: Basing Software Development on Reusable Software engineers should

More information

Android Tutorial: Part 2

Android Tutorial: Part 2 Android Tutorial: Part 2 Creating a TCP/IP Client App Using the TCP Client Developed in this Course: Android OS Development Issues 1 Outline Permissions UI Thread UI Widget Access by External Thread Android

More information

OOP Lab Chat Application using OCSF Framework Page 1 Purpose Files

OOP Lab Chat Application using OCSF Framework Page 1 Purpose Files OOP Lab Chat Application using OCSF Framework Page 1 Purpose Files Overview Learn to apply a framework in developing an application Download the ocsf-231.jar to your project directory (or anywhere). Project

More information

Chapter 14. Exception Handling and Event Handling

Chapter 14. Exception Handling and Event Handling Chapter 14 Exception Handling and Event Handling Chapter 14 Topics Introduction to Exception Handling Exception Handling in Ada Exception Handling in C++ Exception Handling in Java Introduction to Event

More information

M257 Past Paper Oct 2007 Attempted Solution

M257 Past Paper Oct 2007 Attempted Solution M257 Past Paper Oct 2007 Attempted Solution Part 1 Question 1 The compilation process translates the source code of a Java program into bytecode, which is an intermediate language. The Java interpreter

More information

Java for Programmers Course (equivalent to SL 275) 36 Contact Hours

Java for Programmers Course (equivalent to SL 275) 36 Contact Hours Java for Programmers Course (equivalent to SL 275) 36 Contact Hours Course Overview This course teaches programmers the skills necessary to create Java programming system applications and satisfies the

More information

Introduction to Programming Using Java (98-388)

Introduction to Programming Using Java (98-388) Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;

More information

Networking, Java threads and synchronization. PRIS lecture 4 Fredrik Kilander

Networking, Java threads and synchronization. PRIS lecture 4 Fredrik Kilander Networking, Java threads and synchronization PRIS lecture 4 Fredrik Kilander OSI Application Presentation Session Transport Network Data link Physical TCP/IP Application Transport Internet Host-to-network

More information

Chapter 14. Exception Handling and Event Handling ISBN

Chapter 14. Exception Handling and Event Handling ISBN Chapter 14 Exception Handling and Event Handling ISBN 0-321-49362-1 Chapter 14 Topics Introduction to Exception Handling Exception Handling in Ada Exception Handling in C++ Exception Handling in Java Introduction

More information

Advanced Flow of Control -- Introduction

Advanced Flow of Control -- Introduction Advanced Flow of Control -- Introduction Two additional mechanisms for controlling process execution are exceptions and threads Chapter 14 focuses on: exception processing catching and handling exceptions

More information

Chapter 14. Exception Handling and Event Handling 异常处理和事件处理. 孟小亮 Xiaoliang MENG, 答疑 ISBN

Chapter 14. Exception Handling and Event Handling 异常处理和事件处理. 孟小亮 Xiaoliang MENG, 答疑   ISBN Chapter 14 Exception Handling and Event Handling 异常处理和事件处理 孟小亮 Xiaoliang MENG, 答疑 EMAIL: 1920525866@QQ.COM ISBN 0-321-49362-1 Chapter 14 Topics Introduction to Exception Handling Exception Handling in

More information

M257 Past Paper Oct 2008 Attempted Solution

M257 Past Paper Oct 2008 Attempted Solution M257 Past Paper Oct 2008 Attempted Solution Part 1 Question 1 A version of Java is a particular release of the language, which may be succeeded by subsequent updated versions at a later time. Some examples

More information

Operating Systems Design Exam 3 Review: Spring 2011

Operating Systems Design Exam 3 Review: Spring 2011 Operating Systems Design Exam 3 Review: Spring 2011 Paul Krzyzanowski pxk@cs.rutgers.edu 1 1. Why does an IP driver need to use ARP, the address resolution protocol? IP is a logical network. An IP address

More information

CS11 Java. Fall Lecture 4

CS11 Java. Fall Lecture 4 CS11 Java Fall 2014-2015 Lecture 4 Java File Objects! Java represents files with java.io.file class " Can represent either absolute or relative paths! Absolute paths start at the root directory of the

More information

CSC207 Week 4. Larry Zhang

CSC207 Week 4. Larry Zhang CSC207 Week 4 Larry Zhang 1 Logistics A1 Part 1, read Arnold s emails. Follow the submission schedule. Read the Q&A session in the handout. Ask questions on the discussion board. Submit on time! Don t

More information

ICOM 4015-Advanced Programming. Spring Instructor: Dr. Amir H. Chinaei. TAs: Hector Franqui, Jose Garcia, and Antonio Tapia. Reference: Big Java

ICOM 4015-Advanced Programming. Spring Instructor: Dr. Amir H. Chinaei. TAs: Hector Franqui, Jose Garcia, and Antonio Tapia. Reference: Big Java ICOM 4015-Advanced Programming Spring 2014 Instructor: Dr. Amir H. Chinaei TAs: Hector Franqui, Jose Garcia, and Antonio Tapia Reference: Big Java By Hortsmann, Ed 4 Lab 7 Continuation of HTTP and Introduction

More information

Zhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson

Zhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson Zhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson Introduction History, Characteristics of Java language Java Language Basics Data types, Variables, Operators and Expressions Anatomy of a Java Program

More information

CSC 4900 Computer Networks:

CSC 4900 Computer Networks: CSC 4900 Computer Networks: Email Professor Henry Carter Fall 2017 Villanova University Department of Computing Sciences Review Last week we talked about design principles, and the application protocols

More information

A Socket-Based Manifestation of Streams

A Socket-Based Manifestation of Streams A Socket-Based Manifestation of Streams Marc A. Criley Quadrus Corporation, Huntsville, AL adamac95@earthlink.net Introduction The Ada.Streams package, hereafter referred to simply as the Streams package,

More information

Konark - Writing a KONARK Sample Application

Konark - Writing a KONARK Sample Application icta.ufl.edu http://www.icta.ufl.edu/konarkapp.htm Konark - Writing a KONARK Sample Application We are now going to go through some steps to make a sample application. Hopefully I can shed some insight

More information

1.1 The Nature of Software... Object-Oriented Software Engineering Practical Software Development using UML and Java. The Nature of Software...

1.1 The Nature of Software... Object-Oriented Software Engineering Practical Software Development using UML and Java. The Nature of Software... 1.1 The Nature of Software... Object-Oriented Software Engineering Practical Software Development using UML and Java Chapter 1: Software and Software Engineering Software is intangible Hard to understand

More information

COMP 401 ANIMATION, THREADS, COMMAND OBJECTS. Instructor: Prasun Dewan

COMP 401 ANIMATION, THREADS, COMMAND OBJECTS. Instructor: Prasun Dewan COMP 401 ANIMATION, THREADS, COMMAND OBJECTS Instructor: Prasun Dewan PREREQUISITE Animation MVC 2 TOPICS Animation Command Object Object representing an action invocation such as Do your homework. Threads

More information

JAVA Network API. 2 - Connection-Oriented vs. Connectionless Communication

JAVA Network API. 2 - Connection-Oriented vs. Connectionless Communication JAVA Network API To be discussed 1 - java.net... 1 2 - Connection-Oriented vs. Connectionless Communication... 1 3 - Connectionless:... 1 4 - Networking Protocols... 2 5 - Sockets... 2 6 - Multicast Addressing...

More information

Software Development & Education Center. Java Platform, Standard Edition 7 (JSE 7)

Software Development & Education Center. Java Platform, Standard Edition 7 (JSE 7) Software Development & Education Center Java Platform, Standard Edition 7 (JSE 7) Detailed Curriculum Getting Started What Is the Java Technology? Primary Goals of the Java Technology The Java Virtual

More information

Universal Communication Component on Symbian Series60 Platform

Universal Communication Component on Symbian Series60 Platform Universal Communication Component on Symbian Series60 Platform Róbert Kereskényi, Bertalan Forstner, Hassan Charaf Department of Automation and Applied Informatics Budapest University of Technology and

More information

Java Threads. COMP 585 Noteset #2 1

Java Threads. COMP 585 Noteset #2 1 Java Threads The topic of threads overlaps the boundary between software development and operation systems. Words like process, task, and thread may mean different things depending on the author and the

More information

Object-Oriented Programming Design Topic : Exception Programming

Object-Oriented Programming Design Topic : Exception Programming Electrical and Computer Engineering Object-Oriented Topic : Exception Maj Joel Young Joel.Young@afit.edu 18-Sep-03 Maj Joel Young Error Handling General error handling options Notify the user, and Return

More information

Chapter 5 Methods. public class FirstMethod { public static void main(string[] args) { double x= -2.0, y; for (int i = 1; i <= 5; i++ ) { y = f( x );

Chapter 5 Methods. public class FirstMethod { public static void main(string[] args) { double x= -2.0, y; for (int i = 1; i <= 5; i++ ) { y = f( x ); Chapter 5 Methods Sections Pages Review Questions Programming Exercises 5.1 5.11 142 166 1 18 2 22 (evens), 30 Method Example 1. This is of a main() method using a another method, f. public class FirstMethod

More information

University of Waterloo Midterm Examination Solutions

University of Waterloo Midterm Examination Solutions University of Waterloo Midterm Examination Solutions Term: Winter Year: 2013 Student Name UW Student ID Number Course Abbreviation and Number ECE 155 Course Title Engineering Design with Embedded Systems

More information

E-cash. Cryptography. Professor: Marius Zimand. e-cash. Benefits of cash: anonymous. difficult to copy. divisible (you can get change)

E-cash. Cryptography. Professor: Marius Zimand. e-cash. Benefits of cash: anonymous. difficult to copy. divisible (you can get change) Cryptography E-cash Professor: Marius Zimand e-cash Benefits of cash: anonymous difficult to copy divisible (you can get change) easily transferable There are several protocols for e-cash. We will discuss

More information

EXCEPTION HANDLING. Summer 2018

EXCEPTION HANDLING. Summer 2018 EXCEPTION HANDLING Summer 2018 EXCEPTIONS An exception is an object that represents an error or exceptional event that has occurred. These events are usually errors that occur because the run-time environment

More information

Problems with Concurrency

Problems with Concurrency with Concurrency February 14, 2012 1 / 27 s with concurrency race conditions deadlocks GUI source of s non-determinism deterministic execution model interleavings 2 / 27 General ideas Shared variable Shared

More information

protocols September 15,

protocols  September 15, Contents SCI 351 4 Protocols, WWW Internet applications WWW, document technology Lennart Herlaar Original slides by Piet van Oostrum September 15, 2003 SCI351-4 1 X SCI351-4 1 X Internet applications How

More information

Programming with the Service Control Engine Subscriber Application Programming Interface

Programming with the Service Control Engine Subscriber Application Programming Interface CHAPTER 5 Programming with the Service Control Engine Subscriber Application Programming Interface Revised: July 28, 2009, Introduction This chapter provides a detailed description of the Application Programming

More information

Appendix A - Glossary(of OO software term s)

Appendix A - Glossary(of OO software term s) Appendix A - Glossary(of OO software term s) Abstract Class A class that does not supply an implementation for its entire interface, and so consequently, cannot be instantiated. ActiveX Microsoft s component

More information

Programming with the Service Control Engine Subscriber Application Programming Interface

Programming with the Service Control Engine Subscriber Application Programming Interface CHAPTER 5 Programming with the Service Control Engine Subscriber Application Programming Interface Revised: November 20, 2012, Introduction This chapter provides a detailed description of the Application

More information

Design Document Template TCP Server To Upper Server

Design Document Template TCP Server To Upper Server Design Document Template TCP Server To Upper Server 1 What is a Template TCP Server? Students can use this template design of a TCP server as a starting point in their TCP Server programs to e used on

More information

Chapter 8: I/O functions & socket options

Chapter 8: I/O functions & socket options Chapter 8: I/O functions & socket options 8.1 Introduction I/O Models In general, there are normally two phases for an input operation: 1) Waiting for the data to arrive on the network. When the packet

More information

I101/B100 Problem Solving with Computers

I101/B100 Problem Solving with Computers I101/B100 Problem Solving with Computers By: Dr. Hossein Hakimzadeh Computer Science and Informatics IU South Bend 1 What is Visual Basic.Net Visual Basic.Net is the latest reincarnation of Basic language.

More information

Bob Flegel (Utah) Lamar G. Farquar (Utah) June 1970

Bob Flegel (Utah) Lamar G. Farquar (Utah) June 1970 Network Working Group Request for Comments: 56 Ed Belove (Harvard) Dave Black (Harvard) Bob Flegel (Utah) Lamar G. Farquar (Utah) June 1970 Third Level Protocol Logger Protocol General Description In our

More information

Patterns for Asynchronous Invocations in Distributed Object Frameworks

Patterns for Asynchronous Invocations in Distributed Object Frameworks Patterns for Asynchronous Invocations in Distributed Object Frameworks Patterns for Asynchronous Invocations in Distributed Object Frameworks Markus Voelter Michael Kircher Siemens AG, Corporate Technology,

More information

Lecture 5: Methods CS2301

Lecture 5: Methods CS2301 Lecture 5: Methods NADA ALZAHRANI CS2301 1 Opening Problem Find the sum of integers from 1 to 10, from 20 to 30, and from 35 to 45, respectively. 2 Solution public static int sum(int i1, int i2) { int

More information

Lecture 1: Overview of Java

Lecture 1: Overview of Java Lecture 1: Overview of Java What is java? Developed by Sun Microsystems (James Gosling) A general-purpose object-oriented language Based on C/C++ Designed for easy Web/Internet applications Widespread

More information

Message Passing vs. Distributed Objects. 5/15/2009 Distributed Computing, M. L. Liu 1

Message Passing vs. Distributed Objects. 5/15/2009 Distributed Computing, M. L. Liu 1 Message Passing vs. Distributed Objects 5/15/2009 Distributed Computing, M. L. Liu 1 Distributed Objects M. L. Liu 5/15/2009 Distributed Computing, M. L. Liu 2 Message Passing versus Distributed Objects

More information

Research on the Novel and Efficient Mechanism of Exception Handling Techniques for Java. Xiaoqing Lv 1 1 huihua College Of Hebei Normal University,

Research on the Novel and Efficient Mechanism of Exception Handling Techniques for Java. Xiaoqing Lv 1 1 huihua College Of Hebei Normal University, International Conference on Informatization in Education, Management and Business (IEMB 2015) Research on the Novel and Efficient Mechanism of Exception Handling Techniques for Java Xiaoqing Lv 1 1 huihua

More information

EECS168 Exam 3 Review

EECS168 Exam 3 Review EECS168 Exam 3 Review Exam 3 Time: 2pm-2:50pm Monday Nov 5 Closed book, closed notes. Calculators or other electronic devices are not permitted or required. If you are unable to attend an exam for any

More information

Patterns for polymorphic operations

Patterns for polymorphic operations Patterns for polymorphic operations Three small object structural patterns for dealing with polymorphism Alexander A. Horoshilov hor@epsylontech.com Abstract Polymorphism is one of the main elements of

More information

OS06: Monitors in Java

OS06: Monitors in Java OS06: Monitors in Java Based on Chapter 4 of [Hai17] Jens Lechtenbörger Computer Structures and Operating Systems 2018 1 Introduction 1.1 OS Plan ˆ OS Motivation (Wk 23) ˆ OS Introduction (Wk 23) ˆ Interrupts

More information

Chapter 13 Exception Handling

Chapter 13 Exception Handling Chapter 13 Exception Handling 1 Motivations When a program runs into a runtime error, the program terminates abnormally. How can you handle the runtime error so that the program can continue to run or

More information

Object Explorer. Atacama Large Millimeter Array

Object Explorer. Atacama Large Millimeter Array Atacama Large Millimeter Array KGB DOC 01/09 Revision: 1.7 2006 11 07 User s manual Mihael Kadunc Object Explorer User s manual Mihael Kadunc Josef Stefan Institute, Ljubljana Gašper Tkačik Josef Stefan

More information

Objective and Subjective Specifications

Objective and Subjective Specifications 2017-7-10 0 Objective and Subjective Specifications Eric C.R. Hehner Department of Computer Science, University of Toronto hehner@cs.utoronto.ca Abstract: We examine specifications for dependence on the

More information

Chat Channels Via Kafka (with Grading Notes)

Chat Channels Via Kafka (with Grading Notes) SE424: Distributed Systems Assignment 2 Semester 1 5778 Due: 10 Jan 2017 Chat Channels Via Kafka (with Grading Notes) In this assignment, we ll take the work from the previous assignment on channelized

More information

CSSE 220 Day 19. Object-Oriented Design Files & Exceptions. Check out FilesAndExceptions from SVN

CSSE 220 Day 19. Object-Oriented Design Files & Exceptions. Check out FilesAndExceptions from SVN CSSE 220 Day 19 Object-Oriented Design Files & Exceptions Check out FilesAndExceptions from SVN A practical technique OBJECT-ORIENTED DESIGN Object-Oriented Design We won t use full-scale, formal methodologies

More information

Multi-threaded Web Server (Assignment 1) Georgios Georgiadis

Multi-threaded Web Server (Assignment 1) Georgios Georgiadis Multi-threaded Web Server (Assignment 1) Georgios Georgiadis Overview Multi-threaded Web Server What to do and how to do it HTTP messages Processes and threads ComputerComm '09 2 Multi-threaded Web Server

More information

Interactive Programming In Java

Interactive Programming In Java IPIJ: Chapter Outlines Page 1 Front Matter I. Table of Contents 2. Preface Introduction to Interactive Programming by Lynn Andrea Stein A Rethinking CS101 Project Interactive Programming In Java Chapter

More information

Midterm assessment - MAKEUP Fall 2010

Midterm assessment - MAKEUP Fall 2010 M257 MTA Faculty of Computer Studies Information Technology and Computing Date: /1/2011 Duration: 60 minutes 1-Version 1 M 257: Putting Java to Work Midterm assessment - MAKEUP Fall 2010 Student Name:

More information

CS348: Computer Networks (SMTP, POP3, IMAP4); FTP

CS348: Computer Networks  (SMTP, POP3, IMAP4); FTP CS348: Computer Networks E-MAIL (SMTP, POP3, IMAP4); FTP Dr. Manas Khatua Assistant Professor Dept. of CSE, IIT Guwahati E-mail: manaskhatua@iitg.ac.in Electronic mail (E-mail) Allows users to exchange

More information

M/s. Managing distributed workloads. Language Reference Manual. Miranda Li (mjl2206) Benjamin Hanser (bwh2124) Mengdi Lin (ml3567)

M/s. Managing distributed workloads. Language Reference Manual. Miranda Li (mjl2206) Benjamin Hanser (bwh2124) Mengdi Lin (ml3567) 1 M/s Managing distributed workloads Language Reference Manual Miranda Li (mjl2206) Benjamin Hanser (bwh2124) Mengdi Lin (ml3567) Table of Contents 1. Introduction 2. Lexical elements 2.1 Comments 2.2

More information

Principles, Models, and Applications for Distributed Systems M

Principles, Models, and Applications for Distributed Systems M Università degli Studi di Bologna Facoltà di Ingegneria Principles, Models, and Applications for Distributed Systems M Exercitation 3 Connected Java Sockets Jacopo De Benedetto Distributed architecture

More information

Multiple Inheritance, Abstract Classes, Interfaces

Multiple Inheritance, Abstract Classes, Interfaces Multiple Inheritance, Abstract Classes, Interfaces Written by John Bell for CS 342, Spring 2018 Based on chapter 8 of The Object-Oriented Thought Process by Matt Weisfeld, and other sources. Frameworks

More information

Component-Based Software Engineering

Component-Based Software Engineering Component-Based Software Engineering More stuff on Threads Paul Krause Lecture 7 - Contents Basics of threads and synchronization Waiting - releasing locks Collection Plate example Choices when pausing

More information

Introduction to computer networking

Introduction to computer networking Introduction to computer networking First part of the assignment Academic year 2017-2018 Abstract In this assignment, students will have to implement a client-server application using Java Sockets. The

More information

CSE 70 Final Exam Fall 2009

CSE 70 Final Exam Fall 2009 Signature cs70f Name Student ID CSE 70 Final Exam Fall 2009 Page 1 (10 points) Page 2 (16 points) Page 3 (22 points) Page 4 (13 points) Page 5 (15 points) Page 6 (20 points) Page 7 (9 points) Page 8 (15

More information

Chapter III AN END TO END EXAMPLE

Chapter III AN END TO END EXAMPLE 44 Chapter III AN END TO END EXAMPLE Chapter Summary All of the stages of using the Ultraman tool and run-time to create a new view from an existing view are explained in this chapter by working through

More information

CSSE 220 Day 19. Object-Oriented Design Files & Exceptions. Check out FilesAndExceptions from SVN

CSSE 220 Day 19. Object-Oriented Design Files & Exceptions. Check out FilesAndExceptions from SVN CSSE 220 Day 19 Object-Oriented Design Files & Exceptions Check out FilesAndExceptions from SVN A practical technique OBJECT-ORIENTED DESIGN Object-Oriented Design We won t use full-scale, formal methodologies

More information

WWW Applications for an Internet Integrated Service Architecture

WWW Applications for an Internet Integrated Service Architecture WWW Applications for an Internet Integrated Service Architecture T. V. Do, B. Kálmán, Cs. Király, Zs. Mihály, Zs. Molnár, Zs. Pándi Department of Telecommunications Technical University of Budapest Fax:

More information

CS 351 Design of Large Programs Java and Socket Communication

CS 351 Design of Large Programs Java and Socket Communication CS 351 Design of Large Programs Java and Socket Communication Instructor: Joel Castellanos e-mail: joel@unm.edu 4/6/2017 Transmission Control Protocol The Transmission Control Protocol (TCP) is one of

More information

Interprocess Communication

Interprocess Communication Interprocess Communication Nicola Dragoni Embedded Systems Engineering DTU Informatics 4.2 Characteristics, Sockets, Client-Server Communication: UDP vs TCP 4.4 Group (Multicast) Communication The Characteristics

More information

Which of the following syntax used to attach an input stream to console?

Which of the following syntax used to attach an input stream to console? Which of the following syntax used to attach an input stream to console? FileReader fr = new FileReader( input.txt ); FileReader fr = new FileReader(FileDescriptor.in); FileReader fr = new FileReader(FileDescriptor);

More information

Protocols SPL/ SPL

Protocols SPL/ SPL Protocols 1 Application Level Protocol Design atomic units used by protocol: "messages" encoding reusable, protocol independent, TCP server, LinePrinting protocol implementation 2 Protocol Definition set

More information

SELF-STUDY. Glossary

SELF-STUDY. Glossary SELF-STUDY 231 Glossary HTML (Hyper Text Markup Language - the language used to code web pages) tags used to embed an applet. abstract A class or method that is incompletely defined,

More information

CS321: Computer Networks ELECTRONIC MAIL

CS321: Computer Networks ELECTRONIC MAIL CS321: Computer Networks ELECTRONIC MAIL Dr. Manas Khatua Assistant Professor Dept. of CSE IIT Jodhpur E-mail: manaskhatua@iitj.ac.in Electronic mail (E-mail) It allows users to exchange messages. In HTTP

More information

Java Socket Application. Distributed Systems IT332

Java Socket Application. Distributed Systems IT332 Java Socket Application Distributed Systems IT332 Outline Socket Communication Socket packages in Java Multithreaded Server Socket Communication A distributed system based on the client server model consists

More information

Character Stream : It provides a convenient means for handling input and output of characters.

Character Stream : It provides a convenient means for handling input and output of characters. Be Perfect, Do Perfect, Live Perfect 1 1. What is the meaning of public static void main(string args[])? public keyword is an access modifier which represents visibility, it means it is visible to all.

More information

Exception-Handling Overview

Exception-Handling Overview م.عبد الغني أبوجبل Exception Handling No matter how good a programmer you are, you cannot control everything. Things can go wrong. Very wrong. When you write a risky method, you need code to handle the

More information

Ch 9: Control flow. Sequencers. Jumps. Jumps

Ch 9: Control flow. Sequencers. Jumps. Jumps Ch 9: Control flow Sequencers We will study a number of alternatives traditional sequencers: sequential conditional iterative jumps, low-level sequencers to transfer control escapes, sequencers to transfer

More information

Techniques of Java Programming: Concurrent Programming in Java

Techniques of Java Programming: Concurrent Programming in Java Techniques of Java Programming: Concurrent Programming in Java Manuel Oriol May 11, 2006 1 Introduction Threads are one of the fundamental structures in Java. They are used in a lot of applications as

More information

Multitasking Multitasking allows several activities to occur concurrently on the computer. A distinction is usually made between: Process-based multit

Multitasking Multitasking allows several activities to occur concurrently on the computer. A distinction is usually made between: Process-based multit Threads Multitasking Multitasking allows several activities to occur concurrently on the computer. A distinction is usually made between: Process-based multitasking Thread-based multitasking Multitasking

More information

Network Applications Principles of Network Applications

Network Applications Principles of Network Applications Network Applications Principles of Network Applications A Network application is an application running on one host and provides communication to another application running on a different host. At the

More information

Server Component of the Chat Room Lab

Server Component of the Chat Room Lab Chat Room Server Dr. Tom Hicks - Trinity University Page 1 of 41 Server Component of the Chat Room Lab This lab is designed to show students how they may can do socket programming in a step by step process

More information

model (ontology) and every DRS and CMS server has a well-known address (IP and port).

model (ontology) and every DRS and CMS server has a well-known address (IP and port). 7 Implementation In this chapter we describe the Decentralized Reasoning Service (DRS), a prototype service implementation that performs the cooperative reasoning process presented before. We present also

More information

Exceptions. References. Exceptions. Exceptional Conditions. CSE 413, Autumn 2005 Programming Languages

Exceptions. References. Exceptions. Exceptional Conditions. CSE 413, Autumn 2005 Programming Languages References Exceptions "Handling Errors with Exceptions", Java tutorial http://java.sun.com/docs/books/tutorial/essential/exceptions/index.html CSE 413, Autumn 2005 Programming Languages http://www.cs.washington.edu/education/courses/413/05au/

More information

CS113: Lecture 4. Topics: Functions. Function Activation Records

CS113: Lecture 4. Topics: Functions. Function Activation Records CS113: Lecture 4 Topics: Functions Function Activation Records 1 Why functions? Functions add no expressive power to the C language in a formal sense. Why have them? Breaking tasks into smaller ones make

More information

Events and Exceptions

Events and Exceptions Events and Exceptions Analysis and Design of Embedded Systems and OO* Object-oriented programming Jan Bendtsen Automation and Control Lecture Outline Exceptions Throwing and catching Exceptions creating

More information

Internet Application Developer

Internet Application Developer Internet Application Developer SUN-Java Programmer Certification Building a Web Presence with XHTML & XML 5 days or 12 evenings $2,199 CBIT 081 J A V A P R O G R A M M E R Fundamentals of Java and Object

More information

Full file at

Full file at Chapter 1 Primitive Java Weiss 4 th Edition Solutions to Exercises (US Version) 1.1 Key Concepts and How To Teach Them This chapter introduces primitive features of Java found in all languages such as

More information

Lecture 20. Java Exceptional Event Handling. Dr. Martin O Connor CA166

Lecture 20. Java Exceptional Event Handling. Dr. Martin O Connor CA166 Lecture 20 Java Exceptional Event Handling Dr. Martin O Connor CA166 www.computing.dcu.ie/~moconnor Topics What is an Exception? Exception Handler Catch or Specify Requirement Three Kinds of Exceptions

More information

Agent Interaction SDK Java Developer Guide. Voice Interactions

Agent Interaction SDK Java Developer Guide. Voice Interactions Agent Interaction SDK Java Developer Guide Voice Interactions 11/22/2017 Contents 1 Voice Interactions 1.1 Voice Interaction Design 1.2 Six Steps to an AIL Client Application 1.3 SimplePlace 1.4 SimpleVoiceInteraction

More information

Reading from URL. Intent - open URL get an input stream on the connection, and read from the input stream.

Reading from URL. Intent - open URL  get an input stream on the connection, and read from the input stream. Simple Networking Loading applets from the network. Applets are referenced in a HTML file. Java programs can use URLs to connect to and retrieve information over the network. Uniform Resource Locator (URL)

More information

Object-Oriented Software Engineering Practical Software Development using UML and Java. Chapter 2: Review of Object Orientation

Object-Oriented Software Engineering Practical Software Development using UML and Java. Chapter 2: Review of Object Orientation Object-Oriented Software Engineering Practical Software Development using UML and Java Chapter 2: Review of Object Orientation 2.1 What is Object Orientation? Procedural paradigm: Software is organized

More information

How Developers Use the Dynamic Features of Programming Languages: The Case of Smalltalk

How Developers Use the Dynamic Features of Programming Languages: The Case of Smalltalk How Developers Use the Dynamic Features of Programming Languages: The Case of Smalltalk Oscar Callaú, Romain Robbes, Éric Tanter (University of Chile) David Röthlisberger (University of Bern) Proceedings

More information

Exceptions. CSE 142, Summer 2002 Computer Programming 1.

Exceptions. CSE 142, Summer 2002 Computer Programming 1. Exceptions CSE 142, Summer 2002 Computer Programming 1 http://www.cs.washington.edu/education/courses/142/02su/ 12-Aug-2002 cse142-19-exceptions 2002 University of Washington 1 Reading Readings and References»

More information

Exceptions. Readings and References. Exceptions. Exceptional Conditions. Reading. CSE 142, Summer 2002 Computer Programming 1.

Exceptions. Readings and References. Exceptions. Exceptional Conditions. Reading. CSE 142, Summer 2002 Computer Programming 1. Readings and References Exceptions CSE 142, Summer 2002 Computer Programming 1 http://www.cs.washington.edu/education/courses/142/02su/ Reading» Chapter 18, An Introduction to Programming and Object Oriented

More information

WBSCM Forums: a. Click on the Home tab in the upper left-hand portion of the screen.

WBSCM Forums: a. Click on the Home tab in the upper left-hand portion of the screen. WBSCM Forums: WBSCM allows you to set up notification settings, so you will receive an email message when a new item is posted. You can identify one or more specific forums, threads, and/or users to follow.

More information

CS313D: ADVANCED PROGRAMMING LANGUAGE

CS313D: ADVANCED PROGRAMMING LANGUAGE CS313D: ADVANCED PROGRAMMING LANGUAGE Computer Science Department Lecture 3: C# language basics Lecture Contents 2 C# basics Conditions Loops Methods Arrays Dr. Amal Khalifa, Spr 2015 3 Conditions and

More information

7. System Design: Addressing Design Goals

7. System Design: Addressing Design Goals 7. System Design: Addressing Design Goals Outline! Overview! UML Component Diagram and Deployment Diagram! Hardware Software Mapping! Data Management! Global Resource Handling and Access Control! Software

More information

CS 455/655 Computer Networks Fall Programming Assignment 1: Implementing a Social Media App Due: Thursday, October 5 th, 2017 (1pm)

CS 455/655 Computer Networks Fall Programming Assignment 1: Implementing a Social Media App Due: Thursday, October 5 th, 2017 (1pm) CS 455/655 Computer Networks Fall 2017 Programming Assignment 1: Implementing a Social Media App Due: Thursday, October 5 th, 2017 (1pm) To be completed individually. Please review Academic Honesty noted

More information