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.WireFormatInfo;
020import org.apache.activemq.wireformat.WireFormat;
021import org.apache.activemq.wireformat.WireFormatFactory;
022
023/**
024 * 
025 */
026public 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    private String host=null;
044
045    public WireFormat createWireFormat() {
046        WireFormatInfo info = new WireFormatInfo();
047        info.setVersion(version);
048
049        try {
050            info.setStackTraceEnabled(stackTraceEnabled);
051            info.setCacheEnabled(cacheEnabled);
052            info.setTcpNoDelayEnabled(tcpNoDelayEnabled);
053            info.setTightEncodingEnabled(tightEncodingEnabled);
054            info.setSizePrefixDisabled(sizePrefixDisabled);
055            info.setMaxInactivityDuration(maxInactivityDuration);
056            info.setMaxInactivityDurationInitalDelay(maxInactivityDurationInitalDelay);
057            info.setCacheSize(cacheSize);
058            info.setMaxFrameSize(maxFrameSize);
059            if( host!=null ) {
060                info.setHost(host);
061            }
062        } catch (Exception e) {
063            IllegalStateException ise = new IllegalStateException("Could not configure WireFormatInfo");
064            ise.initCause(e);
065            throw ise;
066        }
067
068        OpenWireFormat f = new OpenWireFormat(version);
069        f.setMaxFrameSize(maxFrameSize);
070        f.setPreferedWireFormatInfo(info);
071        return f;
072    }
073
074    public boolean isStackTraceEnabled() {
075        return stackTraceEnabled;
076    }
077
078    public void setStackTraceEnabled(boolean stackTraceEnabled) {
079        this.stackTraceEnabled = stackTraceEnabled;
080    }
081
082    public boolean isTcpNoDelayEnabled() {
083        return tcpNoDelayEnabled;
084    }
085
086    public void setTcpNoDelayEnabled(boolean tcpNoDelayEnabled) {
087        this.tcpNoDelayEnabled = tcpNoDelayEnabled;
088    }
089
090    public int getVersion() {
091        return version;
092    }
093
094    public void setVersion(int version) {
095        this.version = version;
096    }
097
098    public boolean isCacheEnabled() {
099        return cacheEnabled;
100    }
101
102    public void setCacheEnabled(boolean cacheEnabled) {
103        this.cacheEnabled = cacheEnabled;
104    }
105
106    public boolean isTightEncodingEnabled() {
107        return tightEncodingEnabled;
108    }
109
110    public void setTightEncodingEnabled(boolean tightEncodingEnabled) {
111        this.tightEncodingEnabled = tightEncodingEnabled;
112    }
113
114    public boolean isSizePrefixDisabled() {
115        return sizePrefixDisabled;
116    }
117
118    public void setSizePrefixDisabled(boolean sizePrefixDisabled) {
119        this.sizePrefixDisabled = sizePrefixDisabled;
120    }
121
122    public long getMaxInactivityDuration() {
123        return maxInactivityDuration;
124    }
125
126    public void setMaxInactivityDuration(long maxInactivityDuration) {
127        this.maxInactivityDuration = maxInactivityDuration;
128    }
129
130    public int getCacheSize() {
131        return cacheSize;
132    }
133
134    public void setCacheSize(int cacheSize) {
135        this.cacheSize = cacheSize;
136    }
137
138    public long getMaxInactivityDurationInitalDelay() {
139        return maxInactivityDurationInitalDelay;
140    }
141
142    public void setMaxInactivityDurationInitalDelay(
143            long maxInactivityDurationInitalDelay) {
144        this.maxInactivityDurationInitalDelay = maxInactivityDurationInitalDelay;
145    }
146
147    public long getMaxFrameSize() {
148        return maxFrameSize;
149    }
150
151    public void setMaxFrameSize(long maxFrameSize) {
152        this.maxFrameSize = maxFrameSize;
153    }
154
155    public String getHost() {
156        return host;
157    }
158
159    public void setHost(String host) {
160        this.host = host;
161    }
162}