1 /* 2 * Copyright (c) 2007, Fraunhofer-Gesellschaft 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: 8 * 9 * (1) Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the disclaimer at the end. 11 * Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in 13 * the documentation and/or other materials provided with the 14 * distribution. 15 * 16 * (2) Neither the name of Fraunhofer nor the names of its 17 * contributors may be used to endorse or promote products derived 18 * from this software without specific prior written permission. 19 * 20 * DISCLAIMER 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 * 34 */ 35 package org.ogf.graap.wsag.server.monitoring; 36 37 import org.ogf.graap.wsag.api.AgreementOffer; 38 import org.ogf.graap.wsag.api.types.AbstractAgreementType; 39 import org.ogf.graap.wsag.server.api.AgreementTerminationHandler; 40 import org.ogf.schemas.graap.wsAgreement.TerminateInputType; 41 42 /** 43 * TODO: use MonitorableAgreement as default agreement implementation 44 * 45 * This class will be used in future as default agreement implementation. There will be a re-factoring of the 46 * WSAG4J API in version 2. 47 * 48 * This class implements an agreement that is used in conjunction with a {@link MonitorableAgreement}. When a 49 * {@link SimpleMonitoredAgreement} is instantiated the {@link MonitorableAgreement} uses is used as default 50 * agreement implementation. 51 * 52 * @author owaeld 53 * 54 */ 55 public class SimpleMonitoredAgreement extends AbstractAgreementType 56 { 57 58 private AgreementTerminationHandler terminationHandler; 59 60 private MonitorableAgreement monitor; 61 62 /** 63 * Creates a simple monitored agreement implementation that invokes the 64 * {@link AgreementTerminationHandler} when the agreement's terminate method is called. the termination 65 * handler implements the domain specific logic to terminate this particular agreement instance. 66 * 67 * @param offer 68 * the offer used to create the agreement 69 * 70 * @param terminationHandler 71 * the agreement termination handler 72 */ 73 public SimpleMonitoredAgreement( AgreementOffer offer, AgreementTerminationHandler terminationHandler ) 74 { 75 super( offer ); 76 this.terminationHandler = terminationHandler; 77 } 78 79 // @formatter:off 80 /** 81 * The terminate method invokes the {@link AgreementTerminationHandler#terminate(TerminateInputType, 82 * org.ogf.graap.wsag.server.api.IAgreementContext)} method. The {@link AgreementTerminationHandler} 83 * implements the domain-specific logic to terminate an agreement instance. 84 * 85 * @param reason 86 * the agreement termination reason 87 * 88 * @see org.ogf.graap.wsag.api.Agreement#terminate(org.ogf.schemas.graap.wsAgreement.TerminateInputType) 89 */ 90 // @formatter:on 91 public void terminate( TerminateInputType reason ) 92 { 93 terminationHandler.terminate( reason, monitor.getExecutionContext() ); 94 } 95 96 // @formatter:off 97 /** 98 * Sets the associated monitorable agreement instance that uses this implementation. This property is a 99 * backward reference to a {@link MonitorableAgreement}. This reference is used to resolve the agreement 100 * execution context when the terminate method is called. The terminate method essentially invokes the 101 * {@link AgreementTerminationHandler#terminate(TerminateInputType, 102 * org.ogf.graap.wsag.server.api.IAgreementContext)} method. 103 * 104 * @param monitorable 105 * the monitorable agreement to set 106 * 107 * @see AgreementTerminationHandler#terminate(TerminateInputType, 108 * org.ogf.graap.wsag.server.api.IAgreementContext) 109 * @see MonitorableAgreement#getExecutionContext() 110 */ 111 // @formatter:on 112 public void setMonitorableAgreement( MonitorableAgreement monitorable ) 113 { 114 this.monitor = monitorable; 115 } 116 }