1 Listeners A listener is an event handler that the server invokes when certain events occur (e.g. web application initialization/shutdown, session created/timed.

Slides:



Advertisements
Similar presentations
Dispatching, monitoring, filtering
Advertisements

Mari Göransson - KaU - Datavetenskap - DAVD11 1 Java Event Handling --
Winter 2007ACS-3913 Ron McFadyen1 Also known as publish/subscribe The essence of this pattern is that one or more objects (called observers or listeners)
OOP Design Patterns Chapters Design Patterns The main idea behind design patterns is to extract the high level interactions between objects and.
March Ron McFadyen1 Design Patterns In software engineering, a design pattern is a generally repeatable solution to a commonly-occurring problem.
Fall 2009ACS-3913 Ron McFadyen1 Observer Problem: There are many objects (subscribers) needing to know of the state changes, or events, of another object.
MC365 Application Servers: Servlets. Today We Will Cover: What a servlet is The HTTPServlet and some of its more important methods How to configure the.
Chapter 9 Problems TC 1, 2. TC 1 Solution is to create an adapter that adapts calls from the payroll system to the payroll tax subsystem. TaxCalcAdapter.
Server Architecture Models Operating Systems Hebrew University Spring 2004.
Winter 2007ACS-3913 Ron McFadyen1 Observer Pattern Problem: There are many objects (observers / subscribers) needing to know of the state changes, or events,
Design patterns Observer,Strategi, Composite,Template (Chap 5, 6)
Session-02.
Chapter 4: Threads Adapted to COP4610 by Robert van Engelen.
GT3 Tutorial Chapter 5, 6, and 7 Lecture for Cluster and Grid Computing, CSCE 490/590 Fall 2004, University of Arkansas, Dr. Amy Apon
Behavioral Patterns  Behavioral patterns are patterns whose purpose is to facilitate the work of algorithmic calculations and communication between classes.
Silberschatz, Galvin and Gagne ©2011Operating System Concepts Essentials – 8 th Edition Chapter 4: Threads.
Java Servlets CS-422. Application Mapping Your servlet application will be mapped to a directory structure: –“myapp” maps to some directory C:/docs/apps/myapp.
AN OVERVIEW OF SERVLET TECHNOLOGY SERVER SETUP AND CONFIGURATION WEB APPLICATION STRUCTURE BASIC SERVLET EXAMPLE Java Servlets - Compiled By Nitin Pai.
Web Application Basic Scopes Application Session Request Page 1.
1 JSP with Custom Tags Blake Adams Introduction Advanced Java Server Pages – Custom Tags Keyterms: - Tag Library Descriptor(TLD) - Tag Libraries.
Behavioral Pattern: Observer C h a p t e r 5 – P a g e 186 A large monolithic design does not scale well as additional graphical and monitoring requirements.
® IBM Software Group © 2007 IBM Corporation Servlet Listeners
Java Servlets Lec 27. Creating a Simple Web Application in Tomcat.
CS 350 – Software Design The Observer Pattern – Chapter 18 Let’s expand the case study to include new features: Sending a welcome letter to new customers.
Chapter 9 Session Tracking. Session Tracking Basics Accessing the session object associated with the current request: Call request.getSession to get an.
J2EE Servlets Ch. 10 (Architecture) Ch. 12 (21 Days)
Architectural pattern: Interceptor Source: POSA II pp 109 – 140POSA II Environment: developing frameworks that can be extended transparently Recurring.
JSP Tag Libraries Lec Last Lecture Example We incorporated JavaBeans in “Course Outline” Example But still have to write java code inside java.jsp.
FTP Server API Implementing the FTP Server Registering FTP Command Callbacks Data and Control Port Close Callbacks Other Server Calls.
Observer design pattern A closer look at INotifyPropertyChanged, INotifyPropertyChanging and ObservableCollection Observer design pattern1.
SOFTWARE DESIGN AND ARCHITECTURE LECTURE 13. Review Shared Data Software Architectures – Black board Style architecture.
Anonymous Classes An anonymous class is a local class that does not have a name. An anonymous class allows an object to be created using an expression.
Chapter 9 Putting together a complete system. This chapter discusses n Designing a complete system. n Overview of the design and implementation process.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 27 JavaBeans and.
SE-2840 Dr. Mark L. Hornick1 Servlet Threads and Sessions.
Processes CS 6560: Operating Systems Design. 2 Von Neuman Model Both text (program) and data reside in memory Execution cycle Fetch instruction Decode.
Architectural pattern: Reactor Source: POSA II pp 179 – 214POSA II Environment: an application that receives multiple requests simultaneously but may process.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 14 Threads 2 Read Ch.
Servlet Filters JAVA Enterprise Edition. Servlet Filters Servlet Filters are Java classes that can be used in Servlet Programming for the following purposes:
Concordia University Department of Computer Science and Software Engineering Click to edit Master title style ADVANCED PROGRAMMING PRACTICES Model View.
CSI 3125, Preliminaries, page 1 SERVLET. CSI 3125, Preliminaries, page 2 SERVLET A servlet is a server-side software program, written in Java code, that.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 32 JavaBeans and Bean.
Lorenz: Visitor Beans: An Aspect-Oriented Pattern Aspect-oriented pattern: describes a solution to a tangling problem in a particular context.
Changing Meta Data and WSDL OPEN Development Conference September 17-19, 2008 Ravi Rajaram IT Development Manager Max Lin Senior Systems Analyst.
Java Programming: Advanced Topics 1 Building Web Applications Chapter 13.
The Chain of Responsibility Pattern (Behavioral) ©SoftMoore ConsultingSlide 1.
DEVELOPING WEB SERVICES WITH JAVA DESIGN WEB SERVICE ENDPOINT.
1 Lecture 8 George Koutsogiannakis/Summer 2011 CS441 CURRENT TOPICS IN PROGRAMMING LANGUAGES.
CS-4220 Dr. Mark L. Hornick1 Single class doing too many things =Bad Code Smell.
Chapter 32 JavaBeans and Bean Events
Observer Pattern Context:
Java SWING and Model View Controller (MVC)
Event Handling Mimi Opkins CECS 493 Fall 2016.
Chapter 36 JavaBeans and Bean Events
Slide design: Dr. Mark L. Hornick
Servlet Sessions and Cookies
Java Servlets By: Tejashri Udavant..
JavaServer Pages (JSP)
Java Servlets.
Java Beans Sagun Dhakhwa.
Delegates and Events 14: Delegates and Events
Pre-assessment Questions
Servlet.
Model-View-Controller
Objectives In this lesson you will learn about: Need for servlets
Advanced ProgramMING Practices
Advanced ProgramMING Practices
Pre-assessment Questions
Chapter 4: Threads.
Preference Activity class
Presentation transcript:

1 Listeners A listener is an event handler that the server invokes when certain events occur (e.g. web application initialization/shutdown, session created/timed out…) In design pattern terms – observer pattern: An observer (in this case the listener) is notified when an event occurs in the subject(server). Typical uses:  Application-wide initialization routines  Managing dependencies between data stored in context or session attributes  Monitoring the running application (e.g. number of current sessions)

2 Listeners – Cont. There are different kinds of listener, each corresponding to an interface and a group pf events. Some of them are: ServletContextListener  Web application initialized / shut down ServletRequestListener  request handler starting / finishing HttpSessionListener  session created / invalidated ServletContextAttributeListener  context attribute added / removed / replaced HttpSessionAttributeListener  session attribute added / removed / replaced

3 Listeners – Cont. To use a listener one simply implements the appropriate interface and registers the listener in the deployment descriptor. As an example, the following listener monitors the current and maximum number of active sessions.  This class implements both HttpSessionListener and ServletContextListener such that it is notified when the application starts, to initialize the context attributes, and when a session is created or invalidated.

4 Example: SessionMonitor (1/2) import javax.servlet.*; import javax.servlet.http.*; public class SessionMonitor implements HttpSessionListener, ServletContextListener { private int active = 0, max = 0; public void contextInitialized(ServletContextEvent sce) { store(sce.getServletContext()); } public void contextDestroyed(ServletContextEvent sce) {} public void sessionCreated(HttpSessionEvent se) { active++; if (active>max) max = active; store(se.getSession().getServletContext()); } Next Slide (Update Context Attributes)

5 Example: SessionMonitor (2/2) public void sessionDestroyed(HttpSessionEvent se) { active--; store(se.getSession().getServletContext()); } private void store(ServletContext c) { c.setAttribute("sessions_active", new Integer(active)); c.setAttribute("sessions_max", new Integer(max)); } Registration in web.xml : SessionMonitor Now that we have the class, what must we do? Context Attributes