001: /*
002: * $Id: CallResult.java,v 1.23 2007/03/15 17:08:27 agoubard Exp $
003: *
004: * Copyright 2003-2007 Orange Nederland Breedband B.V.
005: * See the COPYRIGHT file for redistribution and use restrictions.
006: */
007: package org.xins.common.service;
008:
009: import java.io.Serializable;
010:
011: import org.xins.common.MandatoryArgumentChecker;
012:
013: /**
014: * Result of a call to a service. The actual result is returned, combined with
015: * links to the services that failed and a link to the service to which the
016: * call succeeded.
017: *
018: * <p>This is an <code>abstract</code> class. Service callers return a
019: * specific kind of result, which is derived from this class.
020: *
021: * @version $Revision: 1.23 $ $Date: 2007/03/15 17:08:27 $
022: * @author <a href="mailto:ernst@ernstdehaan.com">Ernst de Haan</a>
023: *
024: * @since XINS 1.0.0
025: */
026: public abstract class CallResult implements Serializable {
027:
028: /**
029: * The call request. This field cannot be <code>null</code>.
030: */
031: private final CallRequest _request;
032:
033: /**
034: * The target for which the call succeeded. This field cannot be
035: * <code>null</code>.
036: */
037: private final TargetDescriptor _succeededTarget;
038:
039: /**
040: * The call duration, in milliseconds.
041: */
042: private final long _duration;
043:
044: /**
045: * The list of <code>CallException</code>s. This field may be
046: * <code>null</code>.
047: */
048: private final CallExceptionList _exceptions;
049:
050: /**
051: * Constructs a new <code>CallResult</code> object.
052: *
053: * @param request
054: * the call request that resulted in this result, cannot be
055: * <code>null</code>.
056: *
057: * @param succeededTarget
058: * the target for which the call succeeded, cannot be <code>null</code>.
059: *
060: * @param duration
061: * the call duration in milliseconds, cannot be a negative number.
062: *
063: * @param exceptions
064: * the list of {@link CallException}s, or <code>null</code> if the first
065: * call attempt succeeded.
066: *
067: * @throws IllegalArgumentException
068: * if <code>request == null
069: * || succeededTarget == null
070: * || duration < 0L</code>.
071: */
072: protected CallResult(CallRequest request,
073: TargetDescriptor succeededTarget, long duration,
074: CallExceptionList exceptions)
075: throws IllegalArgumentException {
076:
077: // Check preconditions
078: MandatoryArgumentChecker.check("request", request,
079: "succeededTarget", succeededTarget);
080: if (duration < 0L) {
081: throw new IllegalArgumentException("duration (" + duration
082: + "L) < 0L");
083: }
084:
085: // Set fields
086: _request = request;
087: _succeededTarget = succeededTarget;
088: _duration = duration;
089: _exceptions = exceptions;
090: }
091:
092: /**
093: * Returns the call request.
094: *
095: * @return
096: * the {@link CallRequest}, never <code>null</code>.
097: */
098: public final CallRequest getRequest() {
099: return _request;
100: }
101:
102: /**
103: * Returns the target for which the call succeeded.
104: *
105: * @return
106: * the {@link TargetDescriptor} for which the call succeeded, not
107: * <code>null</code>.
108: */
109: public final TargetDescriptor getSucceededTarget() {
110: return _succeededTarget;
111: }
112:
113: /**
114: * Returns the call duration, in milliseconds.
115: *
116: * @return
117: * the duration of the succeeded call, in milliseconds, guaranteed to
118: * be a non-negative number.
119: */
120: public final long getDuration() {
121: // XXX: Duration of succeeded call or of the complete attempt?
122: return _duration;
123: }
124:
125: /**
126: * Returns the list of <code>CallException</code>s.
127: *
128: * @return
129: * the {@link CallException}s, collected in a {@link CallExceptionList}
130: * object, or <code>null</code> if the first call attempt succeeded.
131: */
132: public final CallExceptionList getExceptions() {
133: return _exceptions;
134: }
135: }
|