(1) A Proposal for the Java Public Middleware API Vito Baggiolini SL/CO.

Slides:



Advertisements
Similar presentations
A C++ Crash Course Part II UW Association for Computing Machinery Questions & Feedback.
Advertisements

AITI Lecture 19 Linked List Adapted from MIT Course 1.00 Spring 2003 Lecture 26 and Tutorial Note 9 (Teachers: Please do not erase the above note)
STRING AN EXAMPLE OF REFERENCE DATA TYPE. 2 Primitive Data Types  The eight Java primitive data types are:  byte  short  int  long  float  double.
CERTIFICATION OBJECTIVES Use Class Members Develop Wrapper Code & Autoboxing Code Determine the Effects of Passing Variables into Methods Recognize when.
Chapter 10 Introduction to Arrays
Generic programming in Java
Road Map Introduction to object oriented programming. Classes
PZ12CX Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ12CX- Java Programming Language Design and Implementation.
Java Syntax Primitive data types Operators Control statements.
Objects vs. Primitives Primitive Primitive byte, short, int, long byte, short, int, long float, double float, double char char boolean boolean Object (instance.
Terms and Rules Professor Evan Korth New York University (All rights reserved)
29-Jun-15 Java Concurrency. Definitions Parallel processes—two or more Threads are running simultaneously, on different cores (processors), in the same.
Factory Design Pattern, cont’d COMP 401 Fall 2014 Lecture 13 10/2/2014.
1 CMSC 132: Object-Oriented Programming II Java Constructs Department of Computer Science University of Maryland, College Park.
Peter Juszczyk CS 492/493 - ISGS. // Is this C# or Java? class TestApp { static void Main() { int counter = 0; counter++; } } The answer is C# - In C#
Differences between C# and C++ Dr. Catherine Stringfellow Dr. Stewart Carpenter.
JavaServer Pages Syntax Harry Richard Erwin, PhD CSE301/CIT304.
Classes, Objects, Arrays, Collections and Autoboxing Dr. Andrew Wallace PhD BEng(hons) EurIng
CSCI 6962: Server-side Design and Programming JDBC Database Programming.
Chapter 3 Introduction to Collections – Stacks Modified
COSC 1P03 Data Structures and Abstraction 4.1 Abstract Data Types The advantage of a bad memory is that one enjoys several times the same good things for.
Files and Streams. Java I/O File I/O I/O streams provide data input/output solutions to the programs. A stream can represent many different kinds of sources.
P Object type and wrapper classes p Object methods p Generic classes p Interfaces and iterators Generic Programming Data Structures and Other Objects Using.
Operators Using Java operators An operator takes one or more arguments and produces a new value. All operators produce a value from their.
Basic Java Syntax CSE301 University of Sunderland Harry R Erwin, PhD.
GENERIC COLLECTIONS. Type-Wrapper Classes  Each primitive type has a corresponding type- wrapper class (in package java.lang).  These classes are called.
1162 JDK 5.0 Features Christian Kemper Principal Architect Borland.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Netprog: Java Intro1 Crash Course in Java. Netprog: Java Intro2 Why Java? Network Programming in Java is very different than in C/C++ –much more language.
Checking Equality of Reference Variables. Arrays and objects are both “reference” types n They are allocated a chunk of memory in the address space n.
The PS/SL Middleware Project. 28 July 2000Alessandro RISSO The PS/SL Middleware Project Outline What is Middleware ? Project Overview Technical description.
Objects, Classes and Syntax Dr. Andrew Wallace PhD BEng(hons) EurIng
Java 5 Part 1 CSE301 University of Sunderland Harry Erwin, PhD.
1/20/03A2-1 CS494 Interfaces and Collection in Java.
1 Lecture 5 (part2) : “Interprocess communication” n reasons for process cooperation n types of message passing n direct and indirect message passing n.
C# EMILEE KING. HISTORY OF C# In the late 1990’s Microsoft recognized the need to be able to develop applications that can run on multiple operating system.
Generic Programming  Object Type  Autoboxing  Bag of Objects  JCL Collections  Nodes of Objects  Iterators.
1 Generics Chapter 21 Liang, Introduction to Java Programming.
ArrayList Class An ArrayList is an object that contains a sequence of elements that are ordered by position. An ArrayList is an object that contains a.
Exceptions, cont’d. Factory Design Pattern COMP 401 Fall 2014 Lecture 12 9/30/2014.
Types in programming languages1 What are types, and why do we need them?
Server-side Programming The combination of –HTML –JavaScript –DOM is sometimes referred to as Dynamic HTML (DHTML) Web pages that include scripting are.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
Java Basics Opening Discussion zWhat did we talk about last class? zWhat are the basic constructs in the programming languages you are familiar.
Exceptions Chapter 16 This chapter explains: What as exception is Why they are useful Java exception facilities.
© 2001 By Default! A Free sample background from Slide 1 The Equipment Access API WG Report 6 th February 2003 V. Baggiolini,
1 CSE 331 Generics (Parametric Polymorphism) slides created by Marty Stepp based on materials by M. Ernst, S. Reges, D. Notkin, R. Mercer, Wikipedia
Comunication&Synchronization threads 1 Programación Concurrente Benemérita Universidad Autónoma de Puebla Facultad de Ciencias de la Computación Comunicación.
Spring 2009 Programming Fundamentals I Java Programming XuanTung Hoang Lecture No. 8.
Puzzle 2 1  what does the following program print? public class Puzzle02 { public static void main(String[] args) { final long MICROS_PER_DAY = 24 * 60.
Preferences. 2 Persistent storage Information is persistent if it is kept between one invocation of a program and the next Many programs keep user preferences.
Chapter 9 Introduction to Arrays Fundamentals of Java.
Object Oriented Programming Lecture 2: BallWorld.
(1) The (Draft) Public Client API for Device-Oriented Middleware Communication The Middleware Project Team.
 It is a pure oops language and a high level language.  It was developed at sun microsystems by James Gosling.
JAVA MULTIPLE CHOICE QUESTION.
Introduction to Classes and Objects
Prof. Leonardo Mostarda University of Camerino
Objectives You should be able to describe: Interactive Keyboard Input
Threads Chate Patanothai.
null, true, and false are also reserved.
Arrays of Objects Fall 2012 CS2302: Programming Principles.
From C++ to Java Java history: Oak, toaster-ovens, internet language, panacea What it is O-O language, not a hybrid (cf. C++) compiled to byte-code, executed.
Programs and Classes A program is made up from classes
Java Programming Review 1
Object Oriented Programming in java
Java Programming Language
Preferences.
Java’s Central Casting
Preferences.
Presentation transcript:

(1) A Proposal for the Java Public Middleware API Vito Baggiolini SL/CO

(2) Outline Requirements Set/Get –basic principle –Interaction diagrams –Java data types –Overloaded vs. simple methods –Exceptions MonitorOn/Off Data conversions Synchronization between threads

(3) Premisses This is a proposal –intended as a productive compromise –quite some work, but needs to be discussed This is not the BeansAPI –rather an enhanced version of Java CDEV API –BeansApi can be placed on top of this Integration with Private MoM Client API is necessary

(4) Outline Requirements Set/Get –basic principle –Interaction diagrams –Java data types –Overloaded vs. simple methods –Exceptions MonitorOn/Off Data conversions Synchronization between threads

(5) Requirements Functional Requirements –Set/get access to (virtual) devices sync and async cycle-dependent or immediate –Monitoring of device properties on-change or cycle-dependent Non-functional requirements –Simple but complete –Generic (use in different types of applications) –“True” Java –Type safe (as far as possible)

(6) “Simple” and “True Java” Object instead of Data/DataEntry (user should not have to pack and unpack structures) Use normal Java classes (not Data ) for compo- site data structures Overloaded methods where appropriate Use return to return value in get() operations Use Exceptions for error handling Use Reflection for generic stuff

(7) Design Overview One generic RemoteDevice class –one RemoteDevice object per device instance –set/get, monitorOn/Off methods –no Context! Constructor: RemoteDevice(String devClass, String devInstance); Set/Get methods: setXXX(PropName, Value, …); XXX = Int, Double, Object etc. Value = getXXX(PropName,…); Monitoring methods: MonToken = monitorOn(PropName, Listener); MonToken = monitorOn(PropName, CycleSel, Listener); monitorOff(MonToken); Almost all methods throw exceptions!

(8) Outline Requirements Set/Get –basic principle –Interaction diagrams –Java data types –Overloaded vs. simple methods –Exceptions MonitorOn/Off Data conversions Synchronization between threads

(9) Set/Get Synchronous get/set int getInt(String propName); void setInt(String propName, int value); Asynchronous get/set void getInt(String propName, ReplyListener rl); Cycle-dependent, asynchronous get/set void getInt(String propName, CycleSelector sel, ReplyListener rl); Filtered 1, cycle-dependent, asynchronous get/set void getInt(String propName, CycleSelector sel, Filter f, ReplyListener rl); 1) Filter is for server-side filtering of property data

(10) Set/Get Variants void getInt(String propName, CycleSelector sel, Filter f, ReplyListener rl); CycleSelector == null: same as cycle-independent Filter == null: no filtering ReplyListener == null: one-way (“fire&forget”)

(11) : RemoteDeviceClient : Data : OrbClient : DataEntry setInt(String, int) DeviceProxy(String) insertInt( ) add( ) set(IoPoint, Data) Synchronous set

(12) : RemoteDeviceClient : Data : OrbClient : DataEntry DeviceProxy(String) getInt(String) get(IoPoint) remove( ) extractInt( ) Synchronous get

(13) : RemoteDevice : ResultHandle getInt(String, ReplyHandler) Client do other things... : OrbClient : Data get(IoPoint) slow get action Async get handle(Data)

(14) Data Types in Java Java has the following data types: –8 primitive types (int, long, float, double, byte, boolean, char) they cannot be accessed as Object –All the rest can be treated as Object (even an Array of primitive types is an Object) –Java 1.1 defines Classes corresponding to primitive types (Integer, Long, Float, Double, Byte Boolean, Character) these can be accessed as Object! Design Issue: separate or combined methods ?

(15) Proposal: separate methods One group of methods per primitive type setInt() setLong() setFloat() setDouble() setByte() setChar() setBoolean() One group of methods for Object types setObject() can be used for anything, including Arrays and Data/DataEntry Complex data types are passed with setObject() they are extracted and packed into Data/Data- Entry using Reflection

(16) Why Methods for primitive Types? Why not use setObject() also for primitive types? Example: set/get of an int –set: setInt(value); setObject(new Integer(value)); –get: value = getInt(); value = ((Integer)getObject()).intValue();  A bit clumsy, isn’t it? Many methods are no problem! –for user: as long as they are consistent and logical (and: IDE’s represent overloaded methods as one) –for performance: methods are dispatched with hashtable

(17) Multiple Methods in JBuilder

(18) Exceptions java.rmi.RemoteException : if a problem is encountered in Middleware or in device java.lang.InvalidArgumentException : if bad information is passed to a method, (e.g. an object with bad contents to setObject)

(19) Outline Requirements & Design Principles Set/Get –basic principle –Java data types –Overloaded vs. simple methods –Exceptions –Interaction diagrams MonitorOn/Off Data conversions Synchronization between threads

(20) MonitorOn/Off Monitor a property on-change: MonToken monitorOn(String propName, monListener l); void monitorOff(MonToken mt); Monitor with CycleSelector: MonToken monitorOn(String propName, CycleSelector cs, monListener l); Monitor all properties of an Instance (required?) MonToken MonitorAll(monListener l); MonitorToken automatically unsubscribes if abandoned –Based on Java Garbage Collection ( finalize )

(21) client : MonitoringToken : SubscriptionHandle : DataListener : Mom/Orb? : RemoteDevice monitorOn(String, DataListener) monitorOn(IoPoint, Listener) MonitorOn

(22) Client : RemoteDeviceJVM : SubscriptionHandle : MonitoringToken monitorOff(MonitoringToken) getSubHandle( ) monitorOff(SubscriptionHandle) Client-initiated monitorOff finalize( ) getSubHandle( ) monitorOff(SubscriptionHandle) Automatic monitorOff Garbage Collection via Java : Mom/Orb? monitorOff(SubscriptionHandle) MonitorOff

(23) Outline Requirements & Design Principles Set/Get –basic principle –Java data types –Overloaded vs. simple methods –Exceptions –Interaction diagrams MonitorOn/Off Data conversions Synchronization between threads

(24) Conversion Data  Java types With a static DataConverter class Methods: Converter.getAsData(Object val); Converter.getAsObject(Data val); Converter.getAsData(int val); Converter.getAsInt(Data val); etc... Based on Java Reflection

(25) Outline Requirements & Design Principles Set/Get –basic principle –Java data types –Overloaded vs. simple methods –Exceptions –Interaction diagrams MonitorOn/Off Data conversions Synchronization between threads

(26) Callbacks and Synchronization Problem: primary and callback thread need to be synchronized Synchronization can be tricky!  Provide synchronization facilities in Middleware Framework Pattern “FutureReply” for Async set/get

(27) FutureReply Pattern By Greg Lavender and Doug Lea A pattern... –Based on a 1-slot buffer with locking –Enables a producer and a consumer thread to reliably exchange data items 3 Methods: –put() : for producer to put data item into buffer –get(timeout) : for consumer to wait and take data item when it’s ready (blocking) –isReady() : for consumer to check if data is there

(28) : RemoteDevice FutureReply : ResultHandle getInt(String, ReplyHandler) Client do other things... : OrbClient : Data get(IoPoint) slow get action Async get with FutureReply (1)

(29) : RemoteDevice FutureReply : ResultHandle : OrbClient : Data isReady( ) handle(Data) getInt(timeout) Check if result is avaliable Block until result is available (with timeout) Client do other things... slow get action Async get with FutureReply (2)

(30) Our FutureReply Variant Should have get methods similar to those of RemoteDevice –FutureReply’s getXxx() method matches type of retrieved value –Sync: double res = device.getDouble(propName); –Async: void getString(propName, futureReply); double res = futureReply.getDouble(); FutureReply’s getXxx() methods throw Exceptions

(31)