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.io.BufferedInputStream;
30: import java.io.BufferedOutputStream;
31: import java.io.InputStream;
32: import java.io.ObjectInput;
33: import java.io.ObjectOutput;
34: import java.io.OutputStream;
35:
36: import org.cougaar.mts.base.MessageReader;
37: import org.cougaar.mts.base.MessageReaderDelegateImplBase;
38: import org.cougaar.mts.base.MessageWriter;
39: import org.cougaar.mts.base.MessageWriterDelegateImplBase;
40: import org.cougaar.mts.base.StandardAspect;
41:
42: /**
43: * This Aspect uses buffered streams in the {@link MessageReader} and
44: * {@link MessageWriter}.
45: */
46: public class BufferedStreamsAspect extends StandardAspect {
47:
48: public Object getDelegate(Object delegatee, Class type) {
49: if (type == MessageWriter.class) {
50: MessageWriter wtr = (MessageWriter) delegatee;
51: return new BufferedMessageWriter(wtr);
52: } else if (type == MessageReader.class) {
53: MessageReader rdr = (MessageReader) delegatee;
54: return new BufferedMessageReader(rdr);
55: } else {
56: return null;
57: }
58: }
59:
60: private class BufferedMessageWriter extends
61: MessageWriterDelegateImplBase {
62:
63: BufferedMessageWriter(MessageWriter delegatee) {
64: super (delegatee);
65: }
66:
67: // Join point
68: public OutputStream getObjectOutputStream(ObjectOutput out)
69: throws java.io.IOException {
70: OutputStream raw_oos = super .getObjectOutputStream(out);
71: return new BufferedOutputStream(raw_oos);
72: }
73:
74: }
75:
76: private class BufferedMessageReader extends
77: MessageReaderDelegateImplBase {
78:
79: BufferedMessageReader(MessageReader delegatee) {
80: super (delegatee);
81: }
82:
83: public InputStream getObjectInputStream(ObjectInput in)
84: throws java.io.IOException, ClassNotFoundException {
85: InputStream raw_ois = super .getObjectInputStream(in);
86: return new BufferedInputStream(raw_ois);
87: }
88:
89: }
90:
91: }
|