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 */
017package org.apache.activemq.openwire;
018
019import org.apache.activemq.command.CommandTypes;
020import org.apache.activemq.command.WireFormatInfo;
021import org.apache.activemq.wireformat.WireFormat;
022import org.apache.activemq.wireformat.WireFormatFactory;
023
024/**
025 * 
026 */
027public class OpenWireFormatFactory implements WireFormatFactory {
028
029    //
030    // The default values here are what the wire format changes to after a
031    // default negotiation.
032    //
033
034    private int version = CommandTypes.PROTOCOL_VERSION;
035    private boolean stackTraceEnabled = true;
036    private boolean tcpNoDelayEnabled = true;
037    private boolean cacheEnabled = true;
038    private boolean tightEncodingEnabled = true;
039    private boolean sizePrefixDisabled;
040    private long maxInactivityDuration = 30*1000;
041    private long maxInactivityDurationInitalDelay = 10*1000;
042    private int cacheSize = 1024;
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        } catch (Exception e) {
058            IllegalStateException ise = new IllegalStateException("Could not configure WireFormatInfo");
059            ise.initCause(e);
060            throw ise;
061        }
062
063        OpenWireFormat f = new OpenWireFormat(version);
064        f.setPreferedWireFormatInfo(info);
065        return f;
066    }
067
068    public boolean isStackTraceEnabled() {
069        return stackTraceEnabled;
070    }
071
072    public void setStackTraceEnabled(boolean stackTraceEnabled) {
073        this.stackTraceEnabled = stackTraceEnabled;
074    }
075
076    public boolean isTcpNoDelayEnabled() {
077        return tcpNoDelayEnabled;
078    }
079
080    public void setTcpNoDelayEnabled(boolean tcpNoDelayEnabled) {
081        this.tcpNoDelayEnabled = tcpNoDelayEnabled;
082    }
083
084    public int getVersion() {
085        return version;
086    }
087
088    public void setVersion(int version) {
089        this.version = version;
090    }
091
092    public boolean isCacheEnabled() {
093        return cacheEnabled;
094    }
095
096    public void setCacheEnabled(boolean cacheEnabled) {
097        this.cacheEnabled = cacheEnabled;
098    }
099
100    public boolean isTightEncodingEnabled() {
101        return tightEncodingEnabled;
102    }
103
104    public void setTightEncodingEnabled(boolean tightEncodingEnabled) {
105        this.tightEncodingEnabled = tightEncodingEnabled;
106    }
107
108    public boolean isSizePrefixDisabled() {
109        return sizePrefixDisabled;
110    }
111
112    public void setSizePrefixDisabled(boolean sizePrefixDisabled) {
113        this.sizePrefixDisabled = sizePrefixDisabled;
114    }
115
116    public long getMaxInactivityDuration() {
117        return maxInactivityDuration;
118    }
119
120    public void setMaxInactivityDuration(long maxInactivityDuration) {
121        this.maxInactivityDuration = maxInactivityDuration;
122    }
123
124    public int getCacheSize() {
125        return cacheSize;
126    }
127
128    public void setCacheSize(int cacheSize) {
129        this.cacheSize = cacheSize;
130    }
131
132    public long getMaxInactivityDurationInitalDelay() {
133        return maxInactivityDurationInitalDelay;
134    }
135
136    public void setMaxInactivityDurationInitalDelay(
137            long maxInactivityDurationInitalDelay) {
138        this.maxInactivityDurationInitalDelay = maxInactivityDurationInitalDelay;
139    }
140}