001/* A subscriber to exceptions that are handled by CatchExceptionAttribute. 002 003 Copyright (c) 2014 The Regents of the University of California. 004 All rights reserved. 005 Permission is hereby granted, without written agreement and without 006 license or royalty fees, to use, copy, modify, and distribute this 007 software and its documentation for any purpose, provided that the above 008 copyright notice and the following two paragraphs appear in all copies 009 of this software. 010 011 IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY 012 FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 013 ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF 014 THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF 015 SUCH DAMAGE. 016 017 THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, 018 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 019 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE 020 PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF 021 CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, 022 ENHANCEMENTS, OR MODIFICATIONS. 023 024 PT_COPYRIGHT_VERSION_2 025 COPYRIGHTENDKEY 026 027 */ 028 029package ptolemy.actor.lib; 030 031////////////////////////////////////////////////////////////////////////// 032//// ExceptionSubscriber 033 034/** 035 * An ExceptionSubscriber is an entity that is informed of exceptions and the 036 * handling policy for exceptions caught by 037 * {@link ptolemy.actor.lib.CatchExceptionAttribute}. 038 * The ExceptionSubscriber can then take some action, if desired. 039 * For example, actors that communicate with outside clients may want to pass 040 * along information about the error that has occurred, instead of returning 041 * a generic message or a timeout error response. 042 * 043 * This follows the Command design pattern, where the invoker is 044 * {@link ptolemy.actor.lib.CatchExceptionAttribute}, the client is 045 * the Ptolemy developer (defines commands by dragging and dropping 046 * attributes into the model), and the receiver is a Ptolemy entity 047 * (such as an attribute that writes to a file. 048 * 049 * @author Elizabeth Latronico 050 * @version $Id: ExceptionSubscriber.java 69467 2014-06-29 14:35:19Z beth@berkeley.edu$ 051 * @since Ptolemy II 10.0 052 * @Pt.ProposedRating Red (beth) 053 * @Pt.AcceptedRating Red (beth) 054 * @see ptolemy.actor.lib.CatchExceptionAttribute 055 */ 056 057public interface ExceptionSubscriber { 058 /** Invoked by an exception handler (e.g. {@link ptolemy.actor.lib.ExceptionManager}) when an 059 * exception occurs. Some subscribers may need to set up access to 060 * resources (such as opening a file) prior to being notified of an 061 * exception. These could extend AbstractInitalizableAttribute to do so. 062 * 063 * @param policy The exception handling policy (for example, restart) of 064 * the exception handler; see {@link ptolemy.actor.lib.CatchExceptionAttribute} 065 */ 066 067 /** Action to execute upon the occurrence of an exception. 068 * Some ExceptionReactions may need to set up and close access to resources 069 * (such as opening and closing a file). These could extend 070 * AbstractInitalizableAttribute to do so. 071 * 072 * @param policy The handling policy of the exception manager (for example, 073 * restart); see {@link ptolemy.actor.lib.CatchExceptionAttribute} 074 * @param exception The exception 075 * @return True if the subscriber successfully processed the information; 076 * false otherwise (for example, an ExceptionEmailer that fails to send 077 * an email) 078 */ 079 080 public boolean exceptionOccurred(String policy, Throwable exception); 081 082 /** Invoked by an exception handler (e.g. {@link ptolemy.actor.lib.ExceptionManager}) after 083 * an exception has been handled. 084 * 085 * @param successful True if the exception was successfully handled; false 086 * otherwise 087 * @param message A status message from the exception handler 088 * @return True if the subscriber successfully processed the information; 089 * false otherwise (for example, an ExceptionEmailer that fails to send 090 * an email) 091 */ 092 public boolean exceptionHandled(boolean successful, String message); 093}