001    /**
002     * Licensed to the Apache Software Foundation (ASF) under one or more
003     * contributor license agreements.  See the NOTICE file distributed with
004     * this work for additional information regarding copyright ownership.
005     * The ASF licenses this file to You under the Apache License, Version 2.0
006     * (the "License"); you may not use this file except in compliance with
007     * the License.  You may obtain a copy of the License at
008     *
009     *      http://www.apache.org/licenses/LICENSE-2.0
010     *
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the License for the specific language governing permissions and
015     * limitations under the License.
016     */
017    package org.apache.activemq.openwire;
018    
019    import org.apache.activemq.command.WireFormatInfo;
020    import org.apache.activemq.wireformat.WireFormat;
021    import org.apache.activemq.wireformat.WireFormatFactory;
022    
023    /**
024     * 
025     */
026    public class OpenWireFormatFactory implements WireFormatFactory {
027    
028        //
029        // The default values here are what the wire format changes to after a
030        // default negotiation.
031        //
032    
033        private int version = OpenWireFormat.DEFAULT_WIRE_VERSION;
034        private boolean stackTraceEnabled = true;
035        private boolean tcpNoDelayEnabled = true;
036        private boolean cacheEnabled = true;
037        private boolean tightEncodingEnabled = true;
038        private boolean sizePrefixDisabled;
039        private long maxInactivityDuration = 30*1000;
040        private long maxInactivityDurationInitalDelay = 10*1000;
041        private int cacheSize = 1024;
042        private long maxFrameSize = OpenWireFormat.DEFAULT_MAX_FRAME_SIZE;
043    
044        public WireFormat createWireFormat() {
045            WireFormatInfo info = new WireFormatInfo();
046            info.setVersion(version);
047    
048            try {
049                info.setStackTraceEnabled(stackTraceEnabled);
050                info.setCacheEnabled(cacheEnabled);
051                info.setTcpNoDelayEnabled(tcpNoDelayEnabled);
052                info.setTightEncodingEnabled(tightEncodingEnabled);
053                info.setSizePrefixDisabled(sizePrefixDisabled);
054                info.setMaxInactivityDuration(maxInactivityDuration);
055                info.setMaxInactivityDurationInitalDelay(maxInactivityDurationInitalDelay);
056                info.setCacheSize(cacheSize);
057                info.setMaxFrameSize(maxFrameSize);
058            } catch (Exception e) {
059                IllegalStateException ise = new IllegalStateException("Could not configure WireFormatInfo");
060                ise.initCause(e);
061                throw ise;
062            }
063    
064            OpenWireFormat f = new OpenWireFormat(version);
065            f.setMaxFrameSize(maxFrameSize);
066            f.setPreferedWireFormatInfo(info);
067            return f;
068        }
069    
070        public boolean isStackTraceEnabled() {
071            return stackTraceEnabled;
072        }
073    
074        public void setStackTraceEnabled(boolean stackTraceEnabled) {
075            this.stackTraceEnabled = stackTraceEnabled;
076        }
077    
078        public boolean isTcpNoDelayEnabled() {
079            return tcpNoDelayEnabled;
080        }
081    
082        public void setTcpNoDelayEnabled(boolean tcpNoDelayEnabled) {
083            this.tcpNoDelayEnabled = tcpNoDelayEnabled;
084        }
085    
086        public int getVersion() {
087            return version;
088        }
089    
090        public void setVersion(int version) {
091            this.version = version;
092        }
093    
094        public boolean isCacheEnabled() {
095            return cacheEnabled;
096        }
097    
098        public void setCacheEnabled(boolean cacheEnabled) {
099            this.cacheEnabled = cacheEnabled;
100        }
101    
102        public boolean isTightEncodingEnabled() {
103            return tightEncodingEnabled;
104        }
105    
106        public void setTightEncodingEnabled(boolean tightEncodingEnabled) {
107            this.tightEncodingEnabled = tightEncodingEnabled;
108        }
109    
110        public boolean isSizePrefixDisabled() {
111            return sizePrefixDisabled;
112        }
113    
114        public void setSizePrefixDisabled(boolean sizePrefixDisabled) {
115            this.sizePrefixDisabled = sizePrefixDisabled;
116        }
117    
118        public long getMaxInactivityDuration() {
119            return maxInactivityDuration;
120        }
121    
122        public void setMaxInactivityDuration(long maxInactivityDuration) {
123            this.maxInactivityDuration = maxInactivityDuration;
124        }
125    
126        public int getCacheSize() {
127            return cacheSize;
128        }
129    
130        public void setCacheSize(int cacheSize) {
131            this.cacheSize = cacheSize;
132        }
133    
134        public long getMaxInactivityDurationInitalDelay() {
135            return maxInactivityDurationInitalDelay;
136        }
137    
138        public void setMaxInactivityDurationInitalDelay(
139                long maxInactivityDurationInitalDelay) {
140            this.maxInactivityDurationInitalDelay = maxInactivityDurationInitalDelay;
141        }
142    
143        public long getMaxFrameSize() {
144            return maxFrameSize;
145        }
146    
147        public void setMaxFrameSize(long maxFrameSize) {
148            this.maxFrameSize = maxFrameSize;
149        }
150    }