(1) Dynamic Proxies in Java And so on into winter Till even I have ceased To come as a foot printer, And only some slight beast So mousy or foxy Shall.

Slides:



Advertisements
Similar presentations
1 Dynamic Proxies Explained Simply. 2 Dynamic Proxies License Copyright © 2008 Ciaran McHale. Permission is hereby granted, free of charge, to any person.
Advertisements

Building Distributed Applications using JAVA - RMI
RMI Varun SainiYing Chen. What is RMI? RMI is the action of invoking a method of a remote interface on a remote object. It is used to develop applications.
Copyright © 2001 Qusay H. Mahmoud RMI – Remote Method Invocation Introduction What is RMI? RMI System Architecture How does RMI work? Distributed Garbage.
The road to reliable, autonomous distributed systems
Notes to the presenter. I would like to thank Jim Waldo, Jon Bostrom, and Dennis Govoni. They helped me put this presentation together for the field.
Sapana Mehta (CS-6V81) Overview Of J2EE & JBoss Sapana Mehta.
Remote Method Invocation Chin-Chih Chang. Java Remote Object Invocation In Java, the object is serialized before being passed as a parameter to an RMI.
Dynamic Proxies Amit Shabtay. March 3rd, 2004 Object Oriented Design Course 2 Dynamic Proxies Main idea: The proxy wraps objects and adds functionality.
Introduction to Remote Method Invocation (RMI)
Dynamic Proxies David Rabinowitz. March 3rd, 2004 Object Oriented Design Course 2 Dynamic Proxies Support for creating classes at runtime Each such class.
Communication in Distributed Systems –Part 2
A Framework for Smart Proxies and Interceptors in RMI Nuno Santos P. Marques, L. Silva CISUC, University of Coimbra, Portugal
© JBoss Inc JBoss Clustering An Overview Bela Ban Lead JGroups, Manager Clustering Group.
EJB Overview Celsina Bignoli Distributed Business Applications Server DB Client DB Server DB.
Java RMI Essentials Based on Mastering RMI Rickard Oberg.
1 3. Implementing Web Services 1.Create SOAP proxy interfaces and WSDL based service descriptions 2.Register/publish services 3.Stores service descriptions.
Original work by David Moran JMX Update Scott Molenaar 11/08/2004.
Ing. Ignacio Roqueta ARTech GeneXus and J2EE.
Entity Java Beans Jorg Janke Open Source ERP & CRM.
Bologna, September 2003 Giorgia Lodi Department of Computer Science University of Bologna V.Ghini, F. Panzieri.
Architecture of Software Systems RMI and Distributed Components Martin Rehák.
+ A Short Java RMI Tutorial Usman Saleem
Cli/Serv.: rmiCORBA/131 Client/Server Distributed Systems v Objectives –introduce rmi and CORBA , Semester 1, RMI and CORBA.
1 22 August 2001 The Security Architecture of the M&M Mobile Agent Framework P. Marques, N. Santos, L. Silva, J. Silva CISUC, University of Coimbra, Portugal.
11 Web Services. 22 Objectives You will be able to Say what a web service is. Write and deploy a simple web service. Test a simple web service. Write.
Design Patterns Part two. Structural Patterns Concerned with how classes and objects are composed to form larger structures Concerned with how classes.
DaveAndAl.net Do Application Design Patterns Make Sense in ASP.NET? Alex Homer You may like to write these down now...
In the name of Allah The Proxy Pattern Elham moazzen.
1 Java RMI G53ACC Chris Greenhalgh. 2 Contents l Java RMI overview l A Java RMI example –Overview –Walk-through l Implementation notes –Argument passing.
Tu sca ny 1 Extending The Tuscany Java SCA Runtime 21 August 2006.
Copyright © The OWASP Foundation Permission is granted to copy, distribute and/or modify this document under the terms of the OWASP License. The OWASP.
Spring/2002 Distributed Software Engineering C:\unocourses\4350\slides\DefiningThreads 1 RMI.
RMI RMI is the java API that facilitate distributed computing by allowing remote method calls. A remote method call represents a method invocation between.
(c) University of Washington01-1 CSC 143 Java Programming as Modeling Reading: Ch. 1-6.
Client Call Back Client Call Back is useful for multiple clients to keep up to date about changes on the server Example: One auction server and several.
 Remote Method Invocation  A true distributed computing application interface for Java, written to provide easy access to objects existing on remote.
Java Dynamic Proxy Bibliography: reflection/proxy.html
© Keren Kalif Advanced Java Topics Written by Keren Kalif, Edited by Liron Blecher.
The Proxy Pattern SE-2811 Dr. Mark L. Hornick 1. The Proxy Pattern has many variations, but in general: The Proxy Pattern uses an proxy object as a surrogate.
08 - StructuralCSC4071 Structural Patterns concerned with how classes and objects are composed to form larger structures –Adapter interface converter Bridge.
Structural Patterns1 Nour El Kadri SEG 3202 Software Design and Architecture Notes based on U of T Design Patterns class.
Proxy.
JS (Java Servlets). Internet evolution [1] The internet Internet started of as a static content dispersal and delivery mechanism, where files residing.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 JSP Application Models.
Modern Programming Language. Web Container & Web Applications Web applications are server side applications The most essential requirement.
Proxy Pattern defined The Proxy Pattern provides a surrogate or placeholder for another object to control access to it by creating a representative object.
Proxy Pattern. What’s a Proxy? A remote proxy acts as a local representative of a remote object Remote Object: instantiated in a different JVM heap (a.
Remote Method Invocation A Client Server Approach.
UMBC Distributed Computing with Objects RMI/Corba CMSC 432 Shon Vick.
Java Distributed Object Model A remote object is one whose methods can be invoked from another JVM on a different host. It implements one or more remote.
Distributed programming in Java Faculty:Nguyen Ngoc Tu Session 5 - RMI.
SOAP RMI Aleksander Slominski, Madhusudhan Govindaraju, Randall Bramley, Dennis Gannon Indiana University Extreme! Lab A New-Old Programming Model for.
RMI1 Remote Method Invocation Adapted from “Core Java 2” by Cay Horstmann.
Leveraging ColdSpring to build a robust Flex applications Chris Scott, Cynergy Systems.
RMI (Java RMI) P 460 in text UUIDs / system wide references Transparent: all objects either by ref. or by value. Not efficient, especially int, bool, etc.
January 26, Ann Wollrath Copyright 1999 Sun Microsystems, Inc., all rights reserved. Java ™ RMI Overview Ann Wollrath Senior Staff Engineer Sun Microsystems,
The Java Dynamic Proxy.
Dynamic Proxy Proxy: Addition to the Java 1.3 reflection package:
Extending Java RMI for Dynamic Reconfiguration
Presentation on Object Oriented programming Topic
Knowledge Byte In this section, you will learn about:
Overview of RMI Architecture
WebServices Using JAX-RPC
Introduction to Web Services
Java Remote Method Invocation
Software Design Lecture : 38.
15. Proxy SE2811 Software Component Design
Overview of RMI Architecture
Java Chapter 5 (Estifanos Tilahun Mihret--Tech with Estif)
Presentation transcript:

(1) Dynamic Proxies in Java And so on into winter Till even I have ceased To come as a foot printer, And only some slight beast So mousy or foxy Shall print there as my proxy. Robert Frost “Closed for Good” Joe Dane April 28, 2004

(2) What’s a Proxy? “The agency for another who acts through the agent; authority to act for another” (Webster) “Provide a surrogate or placeholder for another object to control access to it” (GoF) Types of proxies mentioned: remote “virtual” (e.g. loading on demand) protection “smart references” - e.g. ref counting, locking, etc.

(3) “static” proxies Interface “real” server Proxy Factory Client implements Forwards touses By way of Generates or obtains

(4) General Proxy comments Using static proxies means tracking changes in interfaces, writing dummy methodsm recompiling. Also implies that we can’t use a framework that doesn’t know about our interfaces. Can’t use a Constructor GoF doesn’t mention this Must use a factory or registry

(5) Dynamic What? “Proxy”, because we create an object to “stand in” for another object “Dynamic” because the object is defined at runtime. Means we must have JVM support. Bottom line: at runtime, create objects which wrap other objects (services) and add functionality.

(6) Why proxies? Enhance services w/o changing either clients or servers If you need to look at the method, you probably don’t want a D.P. Explicit control over method invocation. No need to explicitly implement all methods in an interface. You’re probably already using them. App servers, Axis, hibernate

(7) Some Examples Logging, failover “Memoization” XML data binding Enforce security restrictions Transaction management

(8) Our model Services Interfaces which define behaviors Servers Programs which provide (implement) one or more services Clients Obtain references to services (cf factory pattern) No knowledge of server details Services may be local or remote

(9) Digression: Reflection Basics java.lang.reflect package Classes which represent the basic units of Java. Class, Method, Constructor From a Class, we can get a Method. From a Method, we can ‘invoke’ on an object and arguments. - object.methodname(arg1, arg2, …) - method.invoke(object, args[]) Syntax: Foo.class

(10) Creating a proxy Things you need A ClassLoader An array of interfaces to implement An InvocationHandler What’s the InvocationHandler? Basically, a single method. Could do anything Doesn’t usually implement any essential business logic Dispatches to an underlying service, possibly after (or before) providing some additional service. Note: underlying service may itself be a proxy!

(11) Creating a proxy (short) TheInterface object = (TheInterface) Proxy.newProxyInstance( TheInterface.class.getClassLoader(), new Class[] { TheInterface.class }, new SimpleHandler() );

(12) Creating a proxy (long) try { Class proxyClass = Proxy.getProxyClass( TheInterface.class.getClassLoader(), new Class[] { TheInterface.class } ); Constructor constructor = proxyClass.getConstructor(new Class[] { InvocationHandler.class }); InvocationHandler handler = new SimpleHandler(); TheInterface object = (TheInterface) constructor.newInstance(new Object[] { handler }); } catch (Exception e) { … }

(13) Proxy Properties Can be cast to any interface used in creating the proxy class. instanceof works as expected Proxy.isProxyClass() is true for the class Class name is undetermined, but will probably be something like Proxy$1. Method invocation is encoded and dispatched to the handler’s invoke method. Is Serializable This is huge! Implications for RMI, JNDI, J2EE

(14) Simple proxy use Client Factory Get proxy reference Service Proxy handler Service

(15) Advanced proxy use Client P1P2 P3 Service

(16) Downsides Loss of static guarantees Can make code difficult to understand Can’t proxy classes, only interfaces Slow? Requires JDK 1.3 All invocations go through the handler, even toString, equals(), etc., which were not in any interface. The creation syntax is ugly.

(17) Upsides Proxy handlers don’t have to be updated when service interfaces change. SOC: We can add behavior w/o changing servers or clients. Serializable means we can store proxies anywhere we like. c.f. App Servers: WebLogic, JBOSS, etc. Slow? Not really.

(18) Proxy examples Simple example Simple (but slightly more realistic) example Logging and profiling method calls A “memoizing” handler Load balancing and fail-over Some timing examples A “real world” example, time permitting

(19) References java.lang.reflect API docs Sun’s web page describing dynamic proxies. Contains simple examples and one more complicated example. Good starting point. Post to RMI-USERS mailing list describing how to use dynamic proxies to eliminate the need for rmic. Mind bending, not for the faint hearted. Related projects: cglib, BCEL, AoP