01: /*
02: * <copyright>
03: *
04: * Copyright 1997-2004 BBNT Solutions, LLC
05: * under sponsorship of the Defense Advanced Research Projects
06: * Agency (DARPA).
07: *
08: * You can redistribute this software and/or modify it under the
09: * terms of the Cougaar Open Source License as published on the
10: * Cougaar Open Source Website (www.cougaar.org).
11: *
12: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
13: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
14: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
15: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
16: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
17: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
18: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23: *
24: * </copyright>
25: */
26:
27: package org.cougaar.mts.std;
28:
29: import java.util.ArrayList;
30: import java.util.Iterator;
31:
32: import org.cougaar.core.mts.MessageTransportWatcher;
33: import org.cougaar.core.service.MessageWatcherService;
34: import org.cougaar.mts.base.MessageTransportServiceProvider; // javadoc
35:
36: /**
37: * This entity implements the {@link MessageWatcherService}. It's
38: * used in conjunction with the {@link WatcherAspect}. Both are
39: * instantiated by the {@link MessageTransportServiceProvider}, which
40: * is the provider of the {@link MessageWatcherService}. The actual
41: * "watching" happens in the Aspect. This service is a core front-end.
42: */
43: public class MessageWatcherServiceImpl implements MessageWatcherService {
44: private WatcherAspect aspect;
45: private ArrayList watchers;
46:
47: public MessageWatcherServiceImpl(WatcherAspect aspect) {
48: this .aspect = aspect;
49: this .watchers = new ArrayList();
50: }
51:
52: public synchronized void release() {
53: Iterator itr = watchers.iterator();
54: while (itr.hasNext()) {
55: MessageTransportWatcher watcher = (MessageTransportWatcher) itr
56: .next();
57: aspect.removeWatcher(watcher);
58: }
59: watchers = null;
60: aspect = null;
61: }
62:
63: public void addMessageTransportWatcher(
64: MessageTransportWatcher watcher) {
65: aspect.addWatcher(watcher);
66: synchronized (this ) {
67: watchers.add(watcher);
68: }
69: }
70:
71: public void removeMessageTransportWatcher(
72: MessageTransportWatcher watcher) {
73: aspect.removeWatcher(watcher);
74: synchronized (this) {
75: watchers.remove(watcher);
76: }
77: }
78:
79: }
|